Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     Songs.Clear();
     foreach (var file in lstFolders.Items.Cast <object>().Select(item => item.ToString()).Where(Directory.Exists).Select(
                  folder => Directory.GetFiles(folder, "*.*", chkSubDirs.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)).SelectMany(
                  files => files.Where(file => string.IsNullOrWhiteSpace(Path.GetExtension(file)))).TakeWhile(file => !indexingWorker.CancellationPending))
     {
         if (CancelWorkers)
         {
             return;
         }
         try
         {
             if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
             {
                 continue;
             }
             if (!Parser.ExtractDTA(file))
             {
                 continue;
             }
             if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any())
             {
                 continue;
             }
             foreach (var newEntry in Parser.Songs.Select(song => new SongIndex
             {
                 Name = song.Artist + " - " + song.Name,
                 Location = file,
                 SongID = song.SongIdString
             }))
             {
                 Songs.Add(newEntry);
             }
         }
         catch (Exception)
         {}
     }
     SaveIndex();
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        private void FileExtractor_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var dtafolder  = txtFolder.Text + "\\" + (organizeFilesByType.Checked ? "dta_files\\" : "");
            var dtacount   = 0;
            var midicount  = 0;
            var moggcount  = 0;
            var milocount  = 0;
            var pngcount   = 0;
            var thumbcount = 0;
            var hasdta     = false;
            var rename     = "";
            var counter    = 0;

            foreach (var file in inputFiles.Where(File.Exists).TakeWhile(file => !FileExtractor.CancellationPending))
            {
                try
                {
                    if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
                    {
                        continue;
                    }
                    if (!Parser.ExtractDTA(file))
                    {
                        Log("Error extracting songs.dta from file: '" + Path.GetFileName(file) + "' ... skipping");
                        continue;
                    }
                    if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any())
                    {
                        Log("Error reading that songs.dta file ... skipping");
                        continue;
                    }

                    try
                    {
                        xPackage = new STFSPackage(file);
                        if (!xPackage.ParseSuccess)
                        {
                            Log("Error opening file '" + Path.GetFileName(file) + "' ... skipping");
                            xPackage.CloseIO();
                        }
                        else
                        {
                            hasdta = true;

                            Log("CON file '" + Path.GetFileNameWithoutExtension(file) + "' contains " + Parser.Songs.Count + " " + (Parser.Songs.Count == 1 ? "song" : "songs"));
                            for (var i = 0; i < Parser.Songs.Count; i++)
                            {
                                if (FileExtractor.CancellationPending)
                                {
                                    xPackage.CloseIO();
                                    break;
                                }
                                var song = Parser.Songs[i];
                                counter++;
                                Log("Extracting files for song #" + (counter) + ": '" + song.Artist + " - " + song.Name + "'");
                                var songid = song.InternalName;

                                var name   = Tools.CleanString(song.Name, true);
                                var artist = Tools.CleanString(song.Artist, true);
                                songid = Tools.CleanString(songid, true);

                                rename = arrangeName(name, artist, songid).Replace("!", "").Replace("'", "");
                                rename = Tools.CleanString(rename, false);

                                if (chkMIDI.Checked && !FileExtractor.CancellationPending)
                                {
                                    if (ExtractFile("mid", false, songid, rename))
                                    {
                                        midicount++;
                                    }
                                }
                                if (chkMOGG.Checked && !FileExtractor.CancellationPending)
                                {
                                    if (ExtractFile("mogg", false, songid, rename))
                                    {
                                        moggcount++;
                                    }
                                }
                                if (chkPNG.Checked && !FileExtractor.CancellationPending)
                                {
                                    if (ExtractFile("png_xbox", true, songid, rename, true))
                                    {
                                        pngcount++;
                                    }
                                }
                                if (!chkMILO.Checked)
                                {
                                    continue;
                                }
                                if (ExtractFile("milo_xbox", true, songid, rename))
                                {
                                    milocount++;
                                }
                            }

                            if (FileExtractor.CancellationPending)
                            {
                                xPackage.CloseIO();
                                break;
                            }
                            var xUpgrade = xPackage.GetFile("songs_upgrades/upgrades.dta");
                            if (xUpgrade != null)
                            {
                                var temp_upg = Path.GetTempPath() + "upg.dta";
                                Tools.DeleteFile(temp_upg);

                                if (xUpgrade.ExtractToFile(temp_upg))
                                {
                                    var upg_midi = "";
                                    var sr       = new StreamReader(temp_upg);
                                    while (sr.Peek() >= 0)
                                    {
                                        var line = sr.ReadLine();
                                        if (string.IsNullOrWhiteSpace(line))
                                        {
                                            continue;
                                        }

                                        if (line.Contains("midi_file"))
                                        {
                                            upg_midi = line.Replace("midi_file", "").Replace("songs_upgrades", "")
                                                       .Replace("(", "").Replace(")", "").Replace("\"", "")
                                                       .Replace("/", "").Replace("'", "").Trim();
                                        }

                                        if (string.IsNullOrWhiteSpace(upg_midi))
                                        {
                                            continue;
                                        }
                                        if (chkMIDI.Checked)
                                        {
                                            var xmidi = xPackage.GetFile("songs_upgrades/" + upg_midi);
                                            if (xmidi != null)
                                            {
                                                var outputfolder = txtFolder.Text + "\\" + (organizeFilesByType.Checked ? "midi_files\\" : "");
                                                if (!Directory.Exists(outputfolder))
                                                {
                                                    Directory.CreateDirectory(outputfolder);
                                                }
                                                var out_midi = outputfolder + upg_midi;
                                                Log("Extracting MIDI file " + Path.GetFileName(out_midi));
                                                Tools.DeleteFile(out_midi);
                                                if (xmidi.ExtractToFile(out_midi))
                                                {
                                                    Log("Extracted " + Path.GetFileName(out_midi) + " successfully");
                                                    midicount++;
                                                }
                                                else
                                                {
                                                    Log("There was an error extracting upgrade MIDI file " + upg_midi);
                                                }
                                            }
                                            else
                                            {
                                                Log("Could not find upgrade MIDI file " + upg_midi + " in that file");
                                            }
                                        }
                                        upg_midi = "";
                                    }
                                    sr.Dispose();

                                    if (chkDTA.Checked)
                                    {
                                        if (!Directory.Exists(dtafolder))
                                        {
                                            Directory.CreateDirectory(dtafolder);
                                        }
                                        var upgdta = (string.IsNullOrWhiteSpace(xPackage.Header.Title_Display) ? Path.GetFileName(file) : xPackage.Header.Title_Display).Replace("!", "")
                                                     .Replace("'", "").Replace(" ", replaceSpacesWithUnderscores.Checked ? "_" : (removeSpacesFromFileName.Checked ? "" : " "));
                                        var upg_out = dtafolder + "\\" + Tools.CleanString(upgdta, false) + "_upgrade.dta";
                                        Tools.DeleteFile(upg_out);
                                        if (Tools.MoveFile(temp_upg, upg_out))
                                        {
                                            Log("Extracted " + Path.GetFileName(upg_out) + " successfully");
                                            dtacount++;
                                        }
                                        else
                                        {
                                            Log("There was an error extracting the upgrades.dta for " + Path.GetFileName(file));
                                        }
                                    }
                                }
                                else
                                {
                                    Log("There was an error extracting the upgrades.dta for " + Path.GetFileName(file));
                                }
                            }
                            else if (!hasdta)
                            {
                                Log("Could not find songs.dta or upgrades.dta inside '" + Path.GetFileName(file) + "'");
                            }
                        }

                        var packname = (string.IsNullOrWhiteSpace(xPackage.Header.Title_Display) ? Path.GetFileName(file) : xPackage.Header.Title_Display).Replace("!", "")
                                       .Replace("'", "").Replace(" ", replaceSpacesWithUnderscores.Checked ? "_" : (removeSpacesFromFileName.Checked ? "" : " "));
                        packname = Parser.Songs.Count == 1 && !string.IsNullOrWhiteSpace(rename) ? rename : Tools.CleanString(packname, false);

                        if (chkDTA.Checked && hasdta)
                        {
                            try
                            {
                                var newDTA = dtafolder + packname + (appendsongsToFiles.Checked ? "_songs" : "") + ".dta";
                                Log("Extracting DTA file " + Path.GetFileName(newDTA));
                                if (!Directory.Exists(dtafolder))
                                {
                                    Directory.CreateDirectory(dtafolder);
                                }
                                if (Parser.WriteDTAToFile(newDTA))
                                {
                                    Log(Path.GetFileName(newDTA) + " extracted successfully");
                                    dtacount++;
                                }
                                else
                                {
                                    Log("Looks like extracting the DTA file for " + Path.GetFileName(file) + " failed. Sorry.");
                                }
                            }
                            catch (Exception ex)
                            {
                                Log("Error extracting DTA file for " + Path.GetFileName(file));
                                Log("The error says: " + ex.Message);
                            }
                        }

                        if (chkThumbs.Checked && !FileExtractor.CancellationPending)
                        {
                            var thumbfolder = txtFolder.Text + "\\" + (organizeFilesByType.Checked ? "thumbnails\\" : "");
                            var package     = thumbfolder + packname + " Package.png";
                            var content     = thumbfolder + packname + " Content.png";
                            if (!Directory.Exists(thumbfolder))
                            {
                                Directory.CreateDirectory(thumbfolder);
                            }
                            try
                            {
                                Tools.DeleteFile(content);
                                var img = xPackage.Header.ContentImage;
                                img.Save(content, ImageFormat.Png);
                                img.Dispose();
                                thumbcount++;

                                Tools.DeleteFile(package);
                                img = xPackage.Header.PackageImage;
                                img.Save(package, ImageFormat.Png);
                                img.Dispose();
                                thumbcount++;

                                Log("Extracted thumbnails successfully");
                            }
                            catch (Exception ex)
                            {
                                Log("There was an error extracting the thumbnails");
                                Log("The error says: " + ex.Message);
                            }
                        }
                        xPackage.CloseIO();
                    }
                    catch (Exception ex)
                    {
                        Log("Error processing file '" + Path.GetFileName(file) + "'");
                        Log("The error says: " + ex.Message);
                        xPackage.CloseIO();
                    }
                }
                catch (Exception ex)
                {
                    Log("There was a problem accessing that file");
                    Log("The error says: " + ex.Message);
                    xPackage.CloseIO();
                }
            }

            if (dtacount + midicount + moggcount + milocount + pngcount + thumbcount == 0)
            {
                Log("Nothing was extracted ... please see the log for any failure reports");
            }
            else
            {
                if (dtacount > 0)
                {
                    Log("Extracted " + dtacount + " DTA " + (dtacount > 1 ? "files" : "file"));
                }
                if (pngcount > 0)
                {
                    Log("Extracted " + pngcount + " PNG_XBOX " + (pngcount > 1 ? "files" : "file"));
                    btnConverter.Invoke(new MethodInvoker(() => btnConverter.Visible = true));
                }
                if (midicount > 0)
                {
                    Log("Extracted " + midicount + " MIDI " + (midicount > 1 ? "files" : "file"));
                }
                if (moggcount > 0)
                {
                    Log("Extracted " + moggcount + " MOGG " + (moggcount > 1 ? "files" : "file"));
                }
                if (milocount > 0)
                {
                    Log("Extracted " + milocount + " MILO_XBOX " + (milocount > 1 ? "files" : "file"));
                }
                if (thumbcount > 0)
                {
                    Log("Extracted " + thumbcount + " " + (thumbcount > 1 ? "thumbnails" : "thumbnail"));
                }
            }
            xPackage.CloseIO();
        }
Ejemplo n.º 5
0
        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Tools.CurrentFolder = Path.GetDirectoryName(con);
            Log("Reading CON file " + Path.GetFileName(con));

            var dta    = Path.GetTempPath() + "temp_dta.txt";
            var backup = con + "_backup";

            Tools.DeleteFile(backup);

            if (!Parser.ExtractDTA(con))//grab byte[] content of DTA
            {
                Log("Error extracting DTA file");
                ErrorOut();
                return;
            }
            if (!Parser.WriteDTAToFile(dta)) //write it out to file
            {
                Log("Error extracting DTA file");
                ErrorOut();
                return;
            }

            var song = new STFSPackage(con);

            if (backUpCONFile.Checked)
            {
                Log("Found songs.dta file, making a backup of your file before starting");
                Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!");

                song.CloseIO();
                File.Copy(con, backup);
                song = new STFSPackage(con);
            }

            var xDTA = song.GetFile("/songs/songs.dta");

            Log("Opening DTA file...");

            var process = Process.Start(dta);

            Log("DTA file is being edited by the user ... waiting...");

            do
            {
                //wait while user has DTA file opened
            } while (!process.HasExited);

            process.Dispose();

            Log("DTA file closed by user, continuing...");
            Log("Replacing old DTA file with modified DTA file");
            Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!");

            if (!xDTA.Replace(dta))
            {
                Log("Error replacing DTA file with modified one");
                Tools.DeleteFile(backup);
                ErrorOut();
                return;
            }

            Log("Replaced DTA file successfully");
            song.Header.MakeAnonymous();
            song.Header.ThisType = PackageType.SavedGame;

            var success = false;

            try
            {
                Log("Saving changes to pack ... sit tight");
                Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!");

                signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                song.RebuildPackage(signature);
                song.FlushPackage(signature);
                song.CloseIO();
                success = true;
            }
            catch (Exception ex)
            {
                Log("There was an error: " + ex.Message);
                song.CloseIO();
            }

            if (success)
            {
                Log("Trying to unlock CON file");
                if (Tools.UnlockCON(con))
                {
                    Log("Unlocked CON file successfully");
                }
                else
                {
                    Log("Error unlocking CON file");
                    success = false;
                }
            }

            if (success)
            {
                if (Tools.SignCON(con))
                {
                    Log("CON file signed successfully");
                }
                else
                {
                    Log("Error signing CON file");
                    success = false;
                }
            }

            Tools.DeleteFile(dta);

            Log(success ? "Process completed successfully!" : "Something went wrong along the way, sorry!");
            if (success)
            {
                return;
            }
            if (!backUpCONFile.Checked)
            {
                return;
            }
            Log("Restoring backup file");
            Tools.DeleteFile(con);
            Log(Tools.MoveFile(backup, con) ? "Backup file restored successfully, nothing was lost" : "Sorry, there was an error restoring the backup file");
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private bool extractRBFiles()
        {
            var counter = 0;
            var success = 0;

            foreach (var file in inputFiles)
            {
                if (backgroundWorker1.CancellationPending)
                {
                    return(false);
                }
                try
                {
                    if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
                    {
                        continue;
                    }
                    try
                    {
                        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;
                        }

                        var xPackage = new STFSPackage(file);
                        if (!xPackage.ParseSuccess)
                        {
                            Log("Failed to extract '" + Path.GetFileName(file) + "'");
                            Log("Skipping this file");
                        }

                        //if working inner temp folder exists, delete to start clean
                        var temptempFile = tempFolder + "temp\\";
                        Tools.DeleteFolder(temptempFile, true);

                        if (backgroundWorker1.CancellationPending)
                        {
                            xPackage.CloseIO();
                            return(false);
                        }

                        //extract songs folder, subfolders and all files into a combined directory
                        xPackage.ExtractPayload(temptempFile, true, false);
                        xPackage.CloseIO();
                        temptempFile = temptempFile + "root\\";
                        if (Directory.Exists(temptempFile + "songs\\"))
                        {
                            var subFolders   = Directory.GetDirectories(temptempFile + "songs\\");
                            var tempFileName = subFolders[0].Substring((temptempFile + "songs\\").Length,
                                                                       subFolders[0].Length -
                                                                       (temptempFile + "songs\\").Length);

                            if (subFolders.Count() != 0)
                            //upgrades won't have subdirectories, skip this step in that case
                            {
                                if (File.Exists(temptempFile + "songs\\songs.dta"))
                                {
                                    //move songs.dta to the song's folder for sorting later
                                    //allows to skip duplicates
                                    Tools.MoveFile(temptempFile + "songs\\songs.dta",
                                                   temptempFile + "songs\\" + tempFileName + "\\songs.dta");
                                }
                                foreach (var foldertoMove in subFolders)
                                {
                                    tempFileName = foldertoMove.Substring((temptempFile + "songs\\").Length,
                                                                          foldertoMove.Length -
                                                                          (temptempFile + "songs\\").Length);

                                    var folderpath = tempFolder + "songs\\";

                                    //let's make sure songs folder is there, if not, create it
                                    if (!(Directory.Exists(folderpath)))
                                    {
                                        Directory.CreateDirectory(tempFolder + "songs\\");
                                    }

                                    //if this song already exists in the working directory, delete it
                                    //copy this one instead
                                    Tools.DeleteFolder(folderpath + tempFileName + "\\", true);

                                    if (Path.GetPathRoot(temptempFile) == Path.GetPathRoot(songsFolder))
                                    {
                                        Directory.Move(temptempFile + "songs\\" + tempFileName + "\\",
                                                       folderpath + tempFileName + "\\");
                                    }
                                    else
                                    {
                                        FileSystem.CopyDirectory(temptempFile + "songs\\" + tempFileName + "\\",
                                                                 folderpath + tempFileName + "\\");
                                    }
                                }
                            }

                            Log("Extracting file " + counter + " of " + inputFiles.Count);
                            success++;
                        }

                        //move other root files but no spa.bin files to root directory
                        var rootFiles = Directory.GetFiles(temptempFile);
                        if (rootFiles.Count() != 0)
                        {
                            foreach (var rootFile in rootFiles.Where(rootFile => rootFile.Substring(rootFile.Length - 7, 7) != "spa.bin"))
                            {
                                Tools.MoveFile(rootFile, tempFolder + Path.GetFileName(rootFile));
                            }
                        }

                        //delete folder to get rid of useless files
                        Tools.DeleteFolder(temptempFile, true);
                    }
                    catch (Exception ex)
                    {
                        Log("There was an error: " + ex.Message);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Log("There was a problem accessing that file");
                    Log("The error says: " + ex.Message);
                }
            }
            Log("Successfully extracted " + success + " of " + counter + " files");

            return(true);
        }
Ejemplo n.º 8
0
        private void CONExplorer_Shown(object sender, EventArgs e)
        {
            var xfile = xPackage.GetFile("songs/songs.dta") ?? xPackage.GetFile("songs_upgrades/upgrades.dta");

            if (xfile == null)
            {
                return;
            }

            var    isUpgrade = false;
            string internalname;

            if (!Parser.ExtractDTA(xPackage, false))
            {
                isUpgrade = Parser.ExtractDTA(xPackage, false, true);
                if (!isUpgrade)
                {
                    return;
                }
            }
            if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any())
            {
                return;
            }

            activeUPG = xPackage.GetFile("songs_upgrades/upgrades.dta");
            activeDTA = xPackage.GetFile("songs/songs.dta");
            if (!isUpgrade)
            {
                internalname = Parser.Songs[0].InternalName;
                if (!string.IsNullOrWhiteSpace(internalname) && Parser.Songs.Count == 1)
                {
                    activeMIDI = xPackage.GetFile("songs/" + internalname + "/" + internalname + ".mid");
                    activeMOGG = xPackage.GetFile("songs/" + internalname + "/" + internalname + ".mogg");
                    activePNG  = xPackage.GetFile("songs/" + internalname + "/gen/" + internalname + "_keep.png_xbox");
                }
            }
            else
            {
                internalname = Parser.Songs[0].MIDIFile;
                activeMIDI   = xPackage.GetFile(internalname);
            }

            btnDTA.Enabled  = activeDTA != null || activeUPG != null;
            btnMIDI.Enabled = activeMIDI != null && Parser.Songs.Count < 2;
            btnMOGG.Enabled = activeMOGG != null && Parser.Songs.Count < 2;
            btnPNG.Enabled  = activePNG != null && Parser.Songs.Count < 2;

            btnDTA.BackColor  = btnDTA.Enabled ? Color.LightYellow : Color.LightGray;
            btnMIDI.BackColor = btnMIDI.Enabled ? Color.LightYellow : Color.LightGray;
            btnMOGG.BackColor = btnMOGG.Enabled ? Color.LightYellow : Color.LightGray;
            btnPNG.BackColor  = btnPNG.Enabled ? Color.LightYellow : Color.LightGray;

            btnDTA.Text = activeDTA != null && activeUPG != null ? "DTAs" : "DTA";

            if (Parser.Songs.Count > 1)
            {
                lblSongID.Text       = "N/A - PACK";
                btnVisualize.Visible = false;
                btnChange.Visible    = false;
                return;
            }
            if (Parser.Songs[0].SongId == 0 || string.IsNullOrWhiteSpace(Parser.Songs[0].SongIdString))
            {
                lblSongID.Text       = Parser.Songs[0].HasSongIDError ? "SONG ID MISSING" : "NOT PRESENT IN DTA";
                btnVisualize.Visible = Parser.Songs[0].HasSongIDError && !isUpgrade;
                btnChange.Visible    = !isUpgrade;
                return;
            }
            lblSongID.Text   = Parser.Songs[0].SongIdString;
            lblSongID.Cursor = Cursors.Hand;
            lblIDTop.Cursor  = lblSongID.Cursor;
            toolTip1.SetToolTip(lblSongID, "Click to copy song ID to clipboard");
            toolTip1.SetToolTip(lblIDTop, "Click to copy song ID to clipboard");
            btnVisualize.Visible = btnVisualize.Visible && !isUpgrade && !txtTitle.Text.Contains("Rock Band 3 Song Cache");
            btnChange.Visible    = !isUpgrade;
        }