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); }
public static byte[] CreateRB3Pro(CreateProConfig config) { STFSPackage pk = null; bool loadedExisting = false; if (config.existingCONFile != null) { try { pk = LoadSTFS(config.existingCONFile); } catch { } if (pk == null) { pk = LoadSTFS(Resources.proconfile); } else { loadedExisting = true; } } else { pk = LoadSTFS(Resources.proconfile); } bool loadedOK = false; if (pk != null) { //pk.Header.ContentImage = Resources.rockband; //pk.Header.PackageImage = Resources.rockband2; pk.Header.TitleID = config.TitleID; //pk.Header.MediaID = 4FC9256F; pk.Header.Description = config.description; pk.Header.Title_Display = config.displayTitle; var folder = pk.GetFolder("songs_upgrades"); if (loadedExisting) { var files = folder.GetSubFiles(); bool foundDTA = false; bool foundMID = false; foreach (var f in files) { if (string.Compare(f.Name, "upgrades.dta", StringComparison.OrdinalIgnoreCase) == 0) { string upgradeFile = Encoding.ASCII.GetString(Resources.upgrades); upgradeFile = upgradeFile.Replace("##songshortname##", config.songShortName); upgradeFile = upgradeFile.Replace("##profilename##", config.proMidiFileName); upgradeFile = upgradeFile.Replace("##songid##", config.song_id); upgradeFile = upgradeFile.Replace("##guitardifficulty##", config.guitarDifficulty); upgradeFile = upgradeFile.Replace("##bassdifficulty##", config.bassDifficulty); f.Replace(Encoding.ASCII.GetBytes(upgradeFile)); foundDTA = true; } else if (string.Compare(f.Name, config.proMidiFileName, StringComparison.OrdinalIgnoreCase) == 0) { f.Replace(config.midFileContents); foundMID = true; } } loadedOK = foundDTA && foundMID; if (!loadedOK) { pk.CloseIO(); config.existingCONFile = null; return CreateRB3Pro(config); } } else { foreach (var f in folder.GetSubFiles()) { if (f.Name.EndsWith(".mid", StringComparison.OrdinalIgnoreCase) || f.Name.EndsWith(".midi", StringComparison.OrdinalIgnoreCase)) { f.Name = config.proMidiFileName; f.Replace(config.midFileContents); } else if (f.Name.EndsWith(".dta", StringComparison.OrdinalIgnoreCase)) { string upgradeFile = Encoding.ASCII.GetString(Resources.upgrades); f.Name = "upgrades.dta"; upgradeFile = upgradeFile.Replace("##songshortname##", config.songShortName); upgradeFile = upgradeFile.Replace("##profilename##", config.proMidiFileName); upgradeFile = upgradeFile.Replace("##songid##", config.song_id); upgradeFile = upgradeFile.Replace("##guitardifficulty##", config.guitarDifficulty); upgradeFile = upgradeFile.Replace("##bassdifficulty##", config.bassDifficulty); f.Replace(Encoding.ASCII.GetBytes(upgradeFile)); } } } } var bytes = pk.RebuildPackageInMemory( new RSAParams(new DJsIO(Resources.KV, true))); pk.CloseIO(); return bytes; }