public void AutoImportDirectory(string folderName, bool addCrowd)
{
if (!Directory.Exists(folderName))
return;
string ghostSettings = string.Format(@"{0}\TheGHOST_Settings.tgs", folderName.TrimEnd('\\'));
if (File.Exists(ghostSettings))
{
//remove existing songs
for (int i = this.Audio.SongFiles.Count - 1; i >= 0; i--)
this.Audio.SongFiles.RemoveAt(i);
for (int i = this.Notes.Files.Length - 1; i >= 0; i--)
this.Notes.RemoveFile(this.Notes.Files[i]);
_project.Settings.LoadSongXmlSettings(ghostSettings, this);
this.LastChanged = DateTime.Now;
}
else
{
DirectoryInfo di = new DirectoryInfo(folderName);
string mask = string.Format(@"{0}\{{0}}.{{1}}", di.FullName);
string[] exts = new string[] { "wav", "flac", "ogg", "mp3" }; //order is important
List<string> song = new List<string>();
string guitar = null;
string rhythm = null;
string[] songNames = { "song", "song1", "song2", "song3", "song4", "song5", "song6", "song7", "song8", "song9",
"drums", "drums1", "drums2", "drums3" };
foreach (string ext in exts)
{
//search for all the song types
foreach (string s in songNames)
{
if (File.Exists(string.Format(mask, s, ext)))
song.Add(string.Format(mask, s, ext));
}
//add the crowd if required
if (addCrowd && File.Exists(string.Format(mask, "crowd", ext)))
song.Add(string.Format(mask, "crowd", ext));
if (guitar == null && File.Exists(string.Format(mask, "guitar", ext)))
guitar = string.Format(mask, "guitar", ext);
if (rhythm == null && File.Exists(string.Format(mask, "rhythm", ext)))
rhythm = string.Format(mask, "rhythm", ext);
}
//if guitar with no song them use only song - TheGHOST will duplicate it to the guitar when making wads
if (song.Count == 0 && guitar != null)
{
song.Add(guitar);
guitar = null;
}
for (int i = this.Notes.Files.Length - 1; i >= 0; i--)
this.Notes.RemoveFile(this.Notes.Files[i]);
foreach (GhNotesItem ghi in this.Notes.GhItems)
{
if (ghi.IsMapped)
this.Notes.UnMapGhItem(ghi); //remove generated items
}
int delay = 0;
if (File.Exists(string.Format(mask, "song", "ini")))
delay = this.AutoImportSongIni(string.Format(mask, "song", "ini"));
NotesFile nf = null;
//if notes.chart exists then import as first mid.
if (File.Exists(string.Format(mask, "notes", "mid")))
nf = this.Notes.ParseFile(string.Format(mask, "notes", "mid"));
if (nf != null)
{
foreach (NotesFileItem nfi in nf.Items)
nfi.SyncOffset = delay;
nf.NonNoteSyncOffset = delay;
nf = null;
}
//if notes.chart exists then import as chart.
if (File.Exists(string.Format(mask, "notes", "chart")))
nf = this.Notes.ParseFile(string.Format(mask, "notes", "chart"));
if (nf != null)
{
foreach (NotesFileItem nfi in nf.Items)
nfi.SyncOffset = delay;
nf.NonNoteSyncOffset = delay;
nf = null;
}
//add other mids
foreach (FileInfo fi in (new DirectoryInfo(folderName)).GetFiles("*.mid"))
{
if (fi.Name.ToLower() != "notes.mid") //already added
{
nf = this.Notes.ParseFile(fi.FullName);
if (nf != null)
{
foreach (NotesFileItem nfi in nf.Items)
nfi.SyncOffset = delay;
nf.NonNoteSyncOffset = delay;
nf = null;
}
}
}
//add other charts
foreach (FileInfo fi in (new DirectoryInfo(folderName)).GetFiles("*.chart"))
{
if (fi.Name.ToLower() != "notes.chart") //already added
{
nf = this.Notes.ParseFile(fi.FullName);
if (nf != null)
{
foreach (NotesFileItem nfi in nf.Items)
nfi.SyncOffset = delay;
nf = null;
}
}
}
//set the sync value
if (this.Notes.BaseFile != null)
{
foreach (GhNotesItem ghi in this.Notes.GhItems)
{
if (ghi.IsMapped)
ghi.MappedFileItem.SyncOffset = this.Notes.BaseFile.NonNoteSyncOffset;
}
}
//there must be a song / guitar to continue
if (song.Count != 0)
{
//remove existing songs
for (int i = this.Audio.SongFiles.Count - 1; i >= 0; i--)
this.Audio.SongFiles.RemoveAt(i);
foreach (string s in song)
this.Audio.SongFiles.Add(this.Audio.CreateAudioFile(s, _project.Defaults.AudioSongVolume));
this.Audio.GuitarFile = guitar == null ? null : this.Audio.CreateAudioFile(guitar, _project.Defaults.AudioGuitarVolume);
this.Audio.RhythmFile = rhythm == null ? null : this.Audio.CreateAudioFile(rhythm, _project.Defaults.AudioRhythmVolume);
}
}
for (int i = 0; i < this.Audio.SongFiles.Count; i++)
this.Audio.Import(this.Audio.SongFiles[i].Name, this.Audio.RawSongFilenames[i]);
if (this.Audio.GuitarFile != null && this.Audio.GuitarFile.Name.Length != 0)
this.Audio.Import(this.Audio.GuitarFile.Name, this.Audio.RawGuitarFilename);
if (this.Audio.RhythmFile != null && this.Audio.RhythmFile.Name.Length != 0)
this.Audio.Import(this.Audio.RhythmFile.Name, this.Audio.RawRhythmFilename);
}