private string ExtractMIDI(string con, bool isUpgrade) { var midi = ""; var xPackage = new STFSPackage(con); if (!xPackage.ParseSuccess) { MessageBox.Show("There was an error parsing CON file, can't extract MIDI", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Log("Can't work with this CON file, try again"); return(""); } try { var xent = xPackage.GetFolder("songs"); if (xent == null && !isUpgrade) { xent = xPackage.GetFolder("songs_upgrades"); MessageBox.Show(xent != null ? "This looks like a pro upgrade, only song files are valid here" : "I can't find a 'songs' folder in that CON file, make sure sure it's a Rock Band song file", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } //we can't work with packs or pro upgrades, so check and skip xent = xPackage.GetFolder("songs_upgrades"); if (xent != null && !isUpgrade) { xent = xPackage.GetFolder("songs"); MessageBox.Show(xent != null ? "It looks like this is a pack, only individual song files are valid here" : "This looks like a pro upgrade, only song files are valid here", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } var folder = isUpgrade ? "songs_upgrades/" : "songs/"; var dtaFile = isUpgrade ? "upgrades.dta" : "songs.dta"; var dta = temp_folder + dtaFile; if (Parser.ExtractDTA(xPackage, false, isUpgrade)) { if (Parser.ReadDTA(Parser.DTA) && Parser.Songs.Count > 1) { MessageBox.Show("It looks like this is a pack, only individual song files are valid here", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } } var xFile = xPackage.GetFile(folder + dtaFile); if (xFile == null) { MessageBox.Show("Can't find " + dtaFile + " inside this CON file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } var fileName = Path.GetFileName(con); if (fileName != null) { if (!Parser.WriteDTAToFile(dta)) { MessageBox.Show("Something went wrong in extracting the " + dtaFile + " file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } } var artists = 0; var songname = ""; var sr = new StreamReader(dta, Parser.GetDTAEncoding(Parser.DTA)); // read one line at a time until the end while (sr.Peek() >= 0) { var line = sr.ReadLine(); if (string.IsNullOrWhiteSpace(line.Trim())) { continue; } if (line.ToLowerInvariant().Contains("artist") && !line.ToLowerInvariant().Contains(";") && !isUpgrade) { artists++; } else if (line.ToLowerInvariant().Contains("songs/") && !line.Contains("midi_file") && !isUpgrade) { songname = Parser.GetInternalName(line); song_int_name = songname; } else if (line.Contains("song_id")) { if (isUpgrade) { upgradeID = Parser.GetSongID(line); } else { songID = Parser.GetSongID(line); CheckIDMatch(); } } else if (line.Contains("midi_file") && isUpgrade) { var midipath = line.Replace("(", ""); midipath = midipath.Replace(")", ""); midipath = midipath.Replace("midi_file", ""); midipath = midipath.Replace("songs_upgrades", ""); midipath = midipath.Replace("\"", ""); midipath = midipath.Replace("/", ""); songname = midipath.Trim(); upgrade_int_name = songname.Replace(".mid", ""); } } sr.Dispose(); if (artists > 1) //if single song, packs will have values > 1 { MessageBox.Show("It looks like this is a pack, only individual song files are valid here", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } xFile = xPackage.GetFile(folder + songname + (isUpgrade ? "" : "/" + songname + ".mid")); if (xFile != null) { midi = temp_folder + songname + (isUpgrade? "" : ".mid"); Tools.DeleteFile(midi); if (!xFile.ExtractToFile(midi)) { MessageBox.Show("Can't find a MIDI file inside this CON file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } } xPackage.CloseIO(); if (isUpgrade) { newupgdta = dta; ReadUpgDTA(newupgdta); } else { orig_dta = dta; } } catch (Exception ex) { MessageBox.Show("There was an error:\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); xPackage.CloseIO(); } return(midi); }