Ejemplo n.º 1
0
        private void backgroundWorker2_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var counter = 0;

            foreach (var file in FilesToConvert.TakeWhile(file => !backgroundWorker2.CancellationPending))
            {
                Log("Converting STFS file '" + Path.GetFileName(file) + "'");
                try
                {
                    var xFile = new STFSPackage(file);
                    if (!xFile.ParseSuccess)
                    {
                        Log("Couldn't parse that file, skipping...");
                        continue;
                    }
                    xFile.Header.MakeAnonymous();
                    xFile.Header.ThisType = doLIVE ? PackageType.MarketPlace : PackageType.SavedGame;
                    var signature = doLIVE ? new RSAParams(StrongSigned.LIVE) : new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                    xFile.RebuildPackage(signature);
                    xFile.FlushPackage(signature);
                    xFile.CloseIO();
                    Tools.UnlockCON(file);
                    if (!doLIVE)
                    {
                        Tools.SignCON(file);
                    }
                    Log("Successfully converted '" + Path.GetFileName(file) + "' to " + (doLIVE ? "LIVE" : "CON..."));
                    counter++;
                    xFile.CloseIO();
                }
                catch (Exception ex)
                {
                    Log("There was an error converting that file");
                    Log("The error says: " + ex.Message);
                }
            }
            Log("Finished converting " + (counter == 1 ? "file" : "files"));
            Log("Ready");
        }
Ejemplo n.º 2
0
        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            if (!File.Exists(orig_con))
            {
                Log("CON file " + Path.GetFileName(orig_con) + " seems to have been deleted, can't continue without it");
                return;
            }

            var BundleFile = orig_con + " (bundled)";

            Tools.DeleteFile(BundleFile);
            File.Copy(orig_con, BundleFile);


            var xPackage = new STFSPackage(BundleFile);

            if (!xPackage.ParseSuccess)
            {
                Log("There was an error parsing CON file to bundle");
                xPackage.CloseIO();
                return;
            }

            var xent = xPackage.GetFile("/songs/songs.dta");

            if (xent != null)
            {
                if (xent.Replace(newDTA))
                {
                    Log("Bundled DTA file successfully");
                }
            }

            xent = xPackage.GetFile("/songs/" + Path.GetFileNameWithoutExtension(orig_midi) + "/" + Path.GetFileName(orig_midi));
            if (xent != null)
            {
                if (xent.Replace(newMIDI))
                {
                    Log("Bundled MIDI file successfully");
                }
            }

            xPackage.Header.MakeAnonymous();
            xPackage.Header.ThisType = PackageType.SavedGame;

            var success = false;

            try
            {
                Log("Rebuilding CON file ... this might take a little while");
                signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                if (ChangeGameID.Checked)
                {
                    xPackage.Header.TitleID            = 0x45410914;
                    xPackage.Header.Title_Package      = "Rock Band 3";
                    xPackage.Header.ContentImageBinary = Resources.RB3.ImageToBytes(ImageFormat.Png);
                }
                xPackage.RebuildPackage(signature);
                xPackage.FlushPackage(signature);
                xPackage.CloseIO();
                success = true;
            }
            catch (Exception ex)
            {
                Log("There was an error: " + ex.Message);
                xPackage.CloseIO();
            }

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

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

            Log(success ? "Your files were bundled successfully!" : "Something went wrong along the way, sorry!");

            if (!cleanUpAfterBundlingFiles.Checked)
            {
                return;
            }
            Log("Cleaning up");
            CleanUp();
        }
Ejemplo n.º 3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            foreach (var file in FilesToConvert)
            {
                if (backgroundWorker1.CancellationPending)
                {
                    return;
                }
                var replaced = 0;
                try
                {
                    var xFile = new STFSPackage(file);
                    if (!xFile.ParseSuccess)
                    {
                        ProblemFiles.Add(file);
                        continue;
                    }

                    var xent = xFile.GetFile("/songs/songs.dta");
                    if (xent == null)
                    {
                        xFile.CloseIO();
                        ProblemFiles.Add(file);
                        continue;
                    }

                    var dta1 = Application.StartupPath + "\\bin\\dta1.txt";
                    Tools.DeleteFile(dta1);

                    if (!xent.Extract(dta1))
                    {
                        xFile.CloseIO();
                        ProblemFiles.Add(file);
                        continue;
                    }

                    var dta2 = Application.StartupPath + "\\bin\\dta2.txt";
                    Tools.DeleteFile(dta2);

                    var sr = new StreamReader(dta1, Encoding.Default);
                    var sw = new StreamWriter(dta2, false, Encoding.Default);
                    while (sr.Peek() >= 0)
                    {
                        var line = sr.ReadLine();
                        if (string.IsNullOrEmpty(line.Trim()))
                        {
                            continue;
                        }

                        if (line.Contains(";ORIG_ID="))
                        {
                            if (DoReverseBatch)
                            {
                                var id = line.Replace(";", "").Replace("ORIG_ID=", "").Trim();
                                sw.WriteLine("   ('song_id' " + id + ")");
                                sr.ReadLine();//skip the old song_id line
                                line = sr.ReadLine();
                                TotalSongs++;
                                replaced++;
                            }
                            else
                            {
                                sw.WriteLine(line);
                                line = sr.ReadLine();
                                sw.WriteLine(line);
                                line = sr.ReadLine();
                            }
                        }
                        else if (line.Contains("song_id") && !DoReverseBatch)
                        {
                            if (!Parser.IsNumericID(line))
                            {
                                line = ";ORIG_ID=" + Parser.GetSongID(line);
                                sw.WriteLine(line);
                                line = "   ('song_id' " + mMainForm.GetNumericID() + ")";
                                TotalSongs++;
                                replaced++;
                            }
                            else
                            {
                                SkippedFiles.Add(file);
                            }
                        }

                        if (!string.IsNullOrEmpty(line.Trim()))
                        {
                            sw.WriteLine(line);
                        }
                    }
                    sr.Dispose();
                    sw.Dispose();

                    if (replaced == 0) //don't modify this CON file if nothing is edited in this DTA file
                    {
                        if (!SkippedFiles.Contains(file))
                        {
                            SkippedFiles.Add(file);
                        }
                        xFile.CloseIO();
                        continue;
                    }

                    if (backgroundWorker1.CancellationPending)
                    {
                        xFile.CloseIO();
                        return;
                    }
                    if (!xent.Replace(dta2))
                    {
                        xFile.CloseIO();
                        ProblemFiles.Add(file);
                        continue;
                    }

                    Tools.DeleteFile(dta1);
                    Tools.DeleteFile(dta2);

                    xFile.Header.MakeAnonymous();
                    xFile.Header.ThisType = PackageType.SavedGame;
                    var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                    xFile.RebuildPackage(signature);
                    xFile.FlushPackage(signature);
                    xFile.CloseIO();
                    Tools.UnlockCON(file);
                    Tools.SignCON(file);
                    xFile.CloseIO();
                }
                catch (Exception)
                {
                    ProblemFiles.Add(file);
                }
            }
        }