public bool ExtractDecryptMogg(string CON_file, bool bypass, NemoTools tools, DTAParser parser) { Initialize(); Tools = tools; Parser = parser; Tools.ReleaseStreamHandle(); if (!Parser.ExtractDTA(CON_file)) { ErrorLog.Add("Couldn't extract songs.dta file from that CON file"); return(false); } if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any()) { ErrorLog.Add("Couldn't read that songs.dta file"); return(false); } if (Parser.Songs.Count > 1) { ErrorLog.Add("This feature does not support packs, only single songs\nUse the dePACK feature in C3 CON Tools' Quick Pack Editor to split this pack into single songs and try again"); return(false); } var internal_name = Parser.Songs[0].InternalName; var xCON = new STFSPackage(CON_file); if (!xCON.ParseSuccess) { ErrorLog.Add("Couldn't parse that CON file"); xCON.CloseIO(); return(false); } var xMogg = xCON.GetFile("songs/" + internal_name + "/" + internal_name + ".mogg"); if (xMogg == null) { ErrorLog.Add("Couldn't find the mogg file inside that CON file"); xCON.CloseIO(); return(false); } var mData = xMogg.Extract(); xCON.CloseIO(); if (mData == null || mData.Length == 0) { ErrorLog.Add("Couldn't extract the mogg file from that CON file"); return(false); } LoadLibraries(); if (Tools.DecM(mData, bypass, false, DecryptMode.ToMemory)) { return(true); } ErrorLog.Add("Mogg file is encrypted and I could not decrypt it, can't split it"); return(false); }
private void ProcessInputFile(string file) { Parser.Songs = null; if (VariousFunctions.ReadFileType(file) == XboxFileType.STFS) { var Splitter = new MoggSplitter(); if (Splitter.ExtractDecryptMogg(file, true, Tools, Parser)) { InputFile = file; DrawWaveForm(); } else { var msg = Splitter.ErrorLog.Aggregate("Couldn't process the audio in CON file '" + file + "'\nSee the error log below:", (current, log) => current + "\n" + log); MessageBox.Show(msg, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else if (Path.GetExtension(file).ToLowerInvariant() == ".mogg") { if (Tools.DecM(File.ReadAllBytes(file), true, false, DecryptMode.ToMemory)) { InputFile = file; DrawWaveForm(); return; } MessageBox.Show("Mogg file '" + file + "' is encrypted and I couldn't process it", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { switch (Path.GetExtension(file).ToLowerInvariant()) { case ".ogg": case ".wav": InputFile = file; Tools.PlayingSongOggData = File.ReadAllBytes(file); DrawWaveForm(); break; default: MessageBox.Show("File '" + file + "' is not a valid input file", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); break; } } }
private bool ProcessFiles() { var counter = 0; var success = 0; foreach (var file in inputFiles.Where(File.Exists).TakeWhile(file => !backgroundWorker1.CancellationPending)) { try { if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS) { continue; } Song.NewSong(); Song.ReplaceGenreWithSub = useSubgenreInsteadOfGenreToolStripMenuItem.Checked; try { if (!Directory.Exists(PSFolder)) { Directory.CreateDirectory(PSFolder); } counter++; Parser.ExtractDTA(file); Parser.ReadDTA(Parser.DTA); if (Parser.Songs.Count > 1) { Log("File " + Path.GetFileName(file) + " is a pack, try dePACKing first, skipping..."); continue; } if (!Parser.Songs.Any()) { Log("There was an error processing the songs.dta file"); continue; } if (loadDTA()) { Log("Loaded and processed songs.dta file for song #" + counter + " successfully"); Log("Song #" + counter + " is " + Song.Artist + " - " + Song.Name); } else { return(false); } var songfolder = PSFolder + Tools.CleanString(Song.Artist, false) + " - " + Tools.CleanString(Song.Name, false) + "\\"; if (!Directory.Exists(songfolder)) { Directory.CreateDirectory(songfolder); } var internal_name = Parser.Songs[0].InternalName; var xPackage = new STFSPackage(file); if (!xPackage.ParseSuccess) { Log("Failed to parse '" + Path.GetFileName(file) + "'"); Log("Skipping this file"); continue; } var xArt = xPackage.GetFile("songs/" + internal_name + "/gen/" + internal_name + "_keep.png_xbox"); if (xArt != null) { var newart = songfolder + "album.png_xbox"; if (xArt.ExtractToFile(newart)) { Log("Extracted album art file " + internal_name + "_keep.png_xbox successfully"); fromXbox(newart); } else { Log("There was a problem extracting the album art file"); } } else { Log("WARNING: Did not find album art file in that CON file"); } var xMIDI = xPackage.GetFile("songs/" + internal_name + "/" + internal_name + ".mid"); if (xMIDI != null) { var newmidi = songfolder + "notes.mid"; if (xMIDI.ExtractToFile(newmidi)) { Log("Extracted MIDI file " + internal_name + ".mid successfully"); ProcessMidi(newmidi); } else { Log("There was a problem extracting the MIDI file"); Log("Skipping this song..."); xPackage.CloseIO(); continue; } } else { Log("ERROR: Did not find a MIDI file in that CON file!"); Log("Skipping this song..."); xPackage.CloseIO(); continue; } var xMOGG = xPackage.GetFile("songs/" + internal_name + "/" + internal_name + ".mogg"); if (xMOGG != null) { var newmogg = songfolder + internal_name + ".mogg"; if (radioSeparate.Checked) { xPackage.CloseIO(); SeparateAudio(file, newmogg, songfolder); } else if (radioDownmix.Checked) { xPackage.CloseIO(); DownMixAudio(file, songfolder); } else { var msg = "Extracting audio file " + (radioAudacity.Checked ? "to send to Audacity" : "and leaving it as is"); Log(msg); var mData = xMOGG.Extract(); if (mData != null && mData.Length > 0) { Log("Successfully extracted audio file '" + Path.GetFileName(newmogg) + "'"); if (radioAudacity.Checked) { Log("Sending audio file to Audacity now"); Tools.DecM(mData, false, false, DecryptMode.ToFile, newmogg); Log(Tools.SendtoAudacity(newmogg)); } else { Tools.WriteOutData(Tools.ObfM(mData), newmogg); } } else { Log("There was a problem extracting the audio file"); Log("Skipping this song..."); xPackage.CloseIO(); continue; } } } else { Log("ERROR: Did not find an audio file in that CON file!"); Log("Skipping this song..."); xPackage.CloseIO(); continue; } xPackage.CloseIO(); if (!Directory.Exists(songfolder)) { Directory.CreateDirectory(songfolder); } Song.WriteINIFile(songfolder, !chkNoC3.Checked); var banner = Application.StartupPath + "\\res\\phaseshift\\banner.png"; if (File.Exists(banner) && !chkNoC3.Checked) { Tools.DeleteFile(songfolder + "banner.png"); File.Copy(banner, songfolder + "banner.png"); } var icon = Application.StartupPath + "\\res\\phaseshift\\c3.png"; if (File.Exists(icon) && !chkNoC3.Checked) { Tools.DeleteFile(songfolder + "ccc.png"); File.Copy(icon, songfolder + "ccc.png"); } success++; if (!chkRAR.Checked || backgroundWorker1.CancellationPending) { continue; } var archive = Path.GetFileName(file); archive = archive.Replace(" ", "").Replace("-", "_").Replace("\\", "").Replace("'", "").Replace(",", "").Replace("_rb3con", ""); archive = Tools.CleanString(archive, false); archive = PSFolder + archive + "_ps.rar"; var arg = "a -m5 -ep1 -r \"" + archive + "\" \"" + songfolder.Substring(0, songfolder.Length - 1) + "\""; Log("Creating RAR archive"); Log(Tools.CreateRAR(rar, archive, arg)? "Created RAR archive successfully" : "RAR archive creation failed"); } catch (Exception ex) { Log("There was an error: " + ex.Message); Log("Attempting to continue with the next file"); } } catch (Exception ex) { Log("There was a problem accessing that file"); Log("The error says: " + ex.Message); } } Log("Successfully processed " + success + " of " + counter + " files"); return(true); }