public string PackSong(string srcPath, string destPath)
        {
            ToggleUIControls(false);
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...", 30);
            Application.DoEvents();
            var errMsg      = String.Empty;
            var archivePath = String.Empty;

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                var srcPlatform = srcPath.GetPlatform();
                archivePath = Packer.Pack(srcPath, destPath, srcPlatform, UpdateSng, UpdateManifest);
                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
            }
            catch (Exception ex)
            {
                errMsg = String.Format("{0}\n{1}", ex.Message, ex.InnerException);
            }

            if (!ConfigGlobals.IsUnitTest)
            {
                PromptComplete(destPath, true, errMsg);
            }

            GlobalExtension.Dispose();
            ToggleUIControls(true);

            return(archivePath);
        }
Example #2
0
        private void UnpackSongs(IEnumerable <string> sourceFileNames, string destPath, bool decode = false, bool overwrite = false)
        {
            ToggleUIControls(false);
            errorsFound = new StringBuilder();
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            Stopwatch sw = new Stopwatch();

            sw.Restart();

            foreach (string sourceFileName in sourceFileNames)
            {
                Application.DoEvents();
                GlobalExtension.ShowProgress(String.Format("Unpacking '{0}'", Path.GetFileName(sourceFileName)), 10);

                try
                {
                    Platform platform = sourceFileName.GetPlatform();
                    Packer.Unpack(sourceFileName, destPath, decode, overwrite, platform);
                }
                catch (Exception ex)
                {
                    errorsFound.AppendLine(String.Format("Error unpacking file '{0}': {1}", Path.GetFileName(sourceFileName), ex.Message));
                }
            }

            sw.Stop();
            GlobalExtension.ShowProgress("Finished unpacking archive (elapsed time): " + sw.Elapsed, 100);
            PromptComplete(destPath, false, errorsFound.ToString());
            GlobalExtension.Dispose();
            ToggleUIControls(true);
        }
Example #3
0
        public string PackSong(string srcPath, string destPath)
        {
            ToggleUIControls(false);
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...", 30);
            Application.DoEvents();
            var errMsg      = String.Empty;
            var archivePath = String.Empty;

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                archivePath = Packer.Pack(srcPath, destPath, updateSng: UpdateSng, updateManifest: UpdateManifest);
                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
            }
            catch (Exception ex)
            {
                errMsg = String.Format("{0}\n{1}", ex.Message, ex.InnerException) + Environment.NewLine + Environment.NewLine +
                         "Confirm GamePlatform and GameVersion are set correctly for desired destination in GeneraConfig";
            }

            if (!GlobalsLib.IsUnitTest)
            {
                PromptComplete(destPath, true, errMsg);
            }

            GlobalExtension.Dispose();
            ToggleUIControls(true);

            return(archivePath);
        }
        private void btnPackSongPack_Click(object sender, EventArgs e)
        {
            string sourcePath;
            string saveFileName;

            using (var fbd = new VistaFolderBrowserDialog())
            {
                fbd.Description = "Select the Song Pack folder";
                fbd.SelectedPath = savePath;

                if (fbd.ShowDialog() != DialogResult.OK)
                    return;

                sourcePath = fbd.SelectedPath;
            }

            saveFileName = Path.GetFileName(sourcePath);

            //using (var sfd = new SaveFileDialog())
            //{
            //    sfd.FileName = Path.GetFileName(sourcePath);

            //    if (sfd.ShowDialog() != DialogResult.OK)
            //        return;

            //    saveFileName = sfd.FileName;
            //}

            GlobalExtension.UpdateProgress = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...");
            Application.DoEvents();

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();

                var songPackDir = AggregateGraph2014.DoLikeSongPack(sourcePath, txtAppId.Text);
                var destFilePath = Path.Combine(Path.GetDirectoryName(sourcePath), String.Format("{0}_p.psarc", Path.GetFileName(sourcePath)));
                Packer.Pack(songPackDir, destFilePath, fixShowlights: false, predefinedPlatform: new Platform(GamePlatform.Pc, GameVersion.RS2014));

                // clean up now (song pack folder)
                //if (Directory.Exists(songPackDir))
                //    DirectoryExtension.SafeDelete(songPackDir);

                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
                MessageBox.Show("Packing is complete.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("{0}\n{1}\n{2}", "Packing error!", ex.Message, ex.InnerException), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // prevents possible cross threading
            GlobalExtension.Dispose();
        }
Example #5
0
        private void btnPack_Click(object sender, EventArgs e)
        {
            var srcPath      = String.Empty;
            var destFileName = String.Empty;

            using (var fbd = new VistaFolderBrowserDialog())
            {
                fbd.SelectedPath = destPath;
                fbd.Description  = "Select CDLC artifacts folder.";

                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                srcPath = destPath = fbd.SelectedPath;
            }

            destFileName = RecycleFolderName(srcPath);

            using (var sfd = new SaveFileDialog())
            {
                sfd.Title    = "Select a new CDLC destination file name or use the system generated default.";
                sfd.FileName = destFileName;

                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                destFileName = sfd.FileName;
            }

            ToggleUIControls(false);
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...", 30);
            Application.DoEvents();
            var errMsg = String.Empty;

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                var packagePlatform = srcPath.GetPlatform();
                Packer.Pack(srcPath, destFileName, UpdateSng, packagePlatform, UpdateManifest);
                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
            }
            catch (Exception ex)
            {
                errMsg = String.Format("{0}\n{1}", ex.Message, ex.InnerException);
            }

            PromptComplete(destFileName, true, errMsg);
            GlobalExtension.Dispose();
            ToggleUIControls(true);
        }
Example #6
0
        private void btnPackSongPack_Click(object sender, EventArgs e)
        {
            var srcPath = String.Empty;
            var errMsg  = String.Empty;

            using (var fbd = new VistaFolderBrowserDialog())
            {
                fbd.Description  = "Select the Song Pack folder created in Step #1.";
                fbd.SelectedPath = destPath;

                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                srcPath = fbd.SelectedPath;
            }

            ToggleUIControls(false);
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...", 30);
            Application.DoEvents();

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();

                var songPackDir = AggregateGraph2014.DoLikeSongPack(srcPath, txtAppId.Text);
                destPath = Path.Combine(Path.GetDirectoryName(srcPath), String.Format("{0}_songpack_p.psarc", Path.GetFileName(srcPath)));
                // PC Only for now can't mix platform packages
                Packer.Pack(songPackDir, destPath, predefinedPlatform: new Platform(GamePlatform.Pc, GameVersion.RS2014));

                // clean up now (song pack folder)
                if (Directory.Exists(songPackDir))
                {
                    DirectoryExtension.SafeDelete(songPackDir);
                }

                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
            }
            catch (Exception ex)
            {
                errMsg  = String.Format("{0}\n{1}", ex.Message, ex.InnerException);
                errMsg += Environment.NewLine + "Make sure there aren't any non-PC CDLC in the SongPacks folder.";
            }

            PromptComplete(destPath, true, errMsg);
            GlobalExtension.Dispose();
            ToggleUIControls(true);
        }
        private void packButton_Click(object sender, EventArgs e)
        {
            string sourcePath;
            string saveFileName;

            using (var fbd = new VistaFolderBrowserDialog())
            {
                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                sourcePath = fbd.SelectedPath;
            }

            using (var sfd = new SaveFileDialog())
            {
                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                saveFileName = sfd.FileName;
            }

            GlobalExtension.UpdateProgress        = this.updateProgress;
            GlobalExtension.CurrentOperationLabel = this.currentOperationLabel;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...");

            Application.DoEvents();

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                Packer.Pack(sourcePath, saveFileName, updateSng);
                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
                MessageBox.Show("Packing is complete.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("{0}\n{1}\n{2}", "Packing error!", ex.Message, ex.InnerException), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // prevents possible cross threading
            GlobalExtension.Dispose();
        }
Example #8
0
        public string PackSong(string srcPath, string destPath)
        {
            ToggleUIControls(false);
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            GlobalExtension.ShowProgress("Packing archive ...", 30);
            Application.DoEvents();
            var errMsg      = String.Empty;
            var archivePath = String.Empty;

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Restart();
                archivePath = Packer.Pack(srcPath, destPath, updateSng: UpdateSng, updateManifest: UpdateManifest);
                sw.Stop();
                GlobalExtension.ShowProgress("Finished packing archive (elapsed time): " + sw.Elapsed, 100);
            }
            catch (OutOfMemoryException ex)
            {
                errMsg = String.Format("{0}\n{1}", ex.Message, ex.InnerException) + Environment.NewLine +
                         "Toolkit is not capable of repacking some large system artifact files.   " + Environment.NewLine +
                         "Defragging the hard drive and clearing the 'pagefile.sys' may help.";
            }
            catch (Exception ex)
            {
                errMsg = String.Format("{0}\n{1}", ex.Message, ex.InnerException) + Environment.NewLine +
                         "Confirm GamePlatform and GameVersion are set correctly for" + Environment.NewLine +
                         "the desired destination in the toolkit Configuration settings.";
            }

            if (!GlobalsLib.IsUnitTest)
            {
                PromptComplete(destPath, true, errMsg);
            }

            GlobalExtension.Dispose();
            ToggleUIControls(true);

            return(archivePath);
        }
        private void UnpackSongs(IEnumerable<string> sourceFileNames, string destPath, bool decode = false, bool extract = false)
        {
            ToggleUIControls(false);
            errorsFound = new StringBuilder();
            GlobalExtension.UpdateProgress = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            Stopwatch sw = new Stopwatch();
            sw.Restart();

            foreach (string sourceFileName in sourceFileNames)
            {
                Application.DoEvents();
                Platform platform = Packer.GetPlatform(sourceFileName);
                GlobalExtension.ShowProgress(String.Format("Unpacking '{0}'", Path.GetFileName(sourceFileName)));
                lblCurrentOperation.Refresh();
                
                try
                {
                    Packer.Unpack(sourceFileName, destPath, decode, extract);
                }
                catch (Exception ex)
                {
                    errorsFound.AppendLine(String.Format("Error unpacking file '{0}': {1}", Path.GetFileName(sourceFileName), ex.Message));
                }
            }

            sw.Stop();
            GlobalExtension.ShowProgress("Finished unpacking archive (elapsed time): " + sw.Elapsed, 100);

            if (errorsFound.Length > 0)
                MessageBox.Show("Unpacking is complete with errors. See below: " + Environment.NewLine + Environment.NewLine + errorsFound.ToString(), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else
                MessageBox.Show("Unpacking is complete.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);

            // prevents possible cross threading
            GlobalExtension.Dispose();
            ToggleUIControls(true);
        }
Example #10
0
        private void btnFixLowBassTuning_Click(object sender, EventArgs e)
        {
            string[] srcPaths;
            bool     alreadyFixed;
            bool     hasBass;

            // GET PATH
            using (var ofd = new OpenFileDialog())
            {
                ofd.Title       = "Select the CDLC(s) which to apply Bass Tuning Fix";
                ofd.Filter      = "All Files (*.*)|*.*|Rocksmith 2014 PC|*_p.psarc|Rocksmith 2014 Mac|*_m.psarc|Rocksmith 2014 Xbox|*_xbox|Rocksmith 2014 PS3|*.edat";
                ofd.Multiselect = true;
                ofd.FileName    = destPath;

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                srcPaths = ofd.FileNames;
            }

            var fixLowBass = ConfigRepository.Instance().GetBoolean("creator_fixlowbass");

            ToggleUIControls(false);
            errorsFound = new StringBuilder();
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize
            Stopwatch sw = new Stopwatch();

            sw.Restart();

            foreach (var srcPath in srcPaths)
            {
                // UNPACK
                var packagePlatform = srcPath.GetPlatform();
                var tmpPath         = Path.GetTempPath();
                Application.DoEvents();

                string unpackedDir;
                try
                {
                    unpackedDir = Packer.Unpack(srcPath, tmpPath, overwriteSongXml: true, predefinedPlatform: packagePlatform);
                }
                catch (Exception ex)
                {
                    errorsFound.AppendLine(String.Format("Error trying unpack file '{0}': {1}", Path.GetFileName(srcPath), ex.Message));
                    continue;
                }

                destPath = Path.Combine(Path.GetDirectoryName(srcPaths[0]), Path.GetFileName(unpackedDir));

                GlobalExtension.ShowProgress(String.Format("Loading '{0}' ...", Path.GetFileName(srcPath)), 40);

                // Same name xbox issue fix
                //if (packagePlatform.platform == GamePlatform.XBox360)
                //    destPath = String.Format("{0}_{1}", destPath, GamePlatform.XBox360.ToString());

                DirectoryExtension.Move(unpackedDir, destPath, true);
                unpackedDir = destPath;

                // Low Bass Tuning Fix is for Rocksmith 2014 Only
                packagePlatform = new Platform(packagePlatform.platform, GameVersion.RS2014);
                // LOAD DATA
                var info = DLCPackageData.LoadFromFolder(unpackedDir, packagePlatform, packagePlatform, false);

                switch (packagePlatform.platform)
                {
                case GamePlatform.Pc:
                    info.Pc = true;
                    break;

                case GamePlatform.Mac:
                    info.Mac = true;
                    break;

                case GamePlatform.XBox360:
                    info.XBox360 = true;
                    break;

                case GamePlatform.PS3:
                    info.PS3 = true;
                    break;
                }

                //apply bass fix
                GlobalExtension.ShowProgress(String.Format("Applying Bass Tuning Fix '{0}' ...", Path.GetFileName(srcPath)), 60);
                alreadyFixed = false;
                hasBass      = false;

                for (int i = 0; i < info.Arrangements.Count; i++)
                {
                    Arrangement arr = info.Arrangements[i];
                    if (arr.ArrangementType == ArrangementType.Bass)
                    {
                        hasBass = true;

                        if (arr.TuningStrings.String0 < -4 && arr.TuningPitch != 220.0)
                        {
                            if (!TuningFrequency.ApplyBassFix(arr, fixLowBass))
                            {
                                if (chkVerbose.Checked)
                                {
                                    MessageBox.Show(Path.GetFileName(srcPath) + "  " + Environment.NewLine + "bass arrangement is already at 220Hz pitch.  ", "Error ... Applying Low Bass Tuning Fix", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }

                                alreadyFixed = true;
                            }
                        }
                        else
                        {
                            if (chkVerbose.Checked)
                            {
                                MessageBox.Show(Path.GetFileName(srcPath) + "  " + Environment.NewLine + "bass arrangement tuning does not need to be fixed.  ", "Error ... Applying Low Bass Tuning Fix", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            alreadyFixed = true;
                        }
                    }
                }

                // don't repackage a song that is already fixed or doesn't have bass
                if (alreadyFixed || !hasBass)
                {
                    if (chkVerbose.Checked && !hasBass)
                    {
                        MessageBox.Show(Path.GetFileName(srcPath) + "  " + Environment.NewLine + "has no bass arrangement.  ", "Error ... Applying Low Bass Tuning Fix", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    DirectoryExtension.SafeDelete(unpackedDir);
                    continue;
                }

                var ndx     = srcPath.LastIndexOf('_');
                var srcName = srcPath.Substring(0, ndx);
                var srcExt  = srcPath.Substring(ndx, srcPath.Length - ndx);

                if (!chkQuickBassFix.Checked)
                {
                    using (var ofd = new SaveFileDialog())
                    {
                        ofd.Title    = "Select a name for the Low Bass Tuning Fixed file.";
                        ofd.Filter   = "All Files (*.*)|*.*|Rocksmith 2014 PC|*_p.psarc|Rocksmith 2014 Mac|*_m.psarc|Rocksmith 2014 Xbox|*_xbox|Rocksmith 2014 PS3|*.edat";
                        ofd.FileName = String.Format("{0}_{1}_bassfix{2}", info.SongInfo.ArtistSort, info.SongInfo.SongDisplayNameSort, srcExt);

                        if (ofd.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }

                        destPath = ofd.FileName;
                    }
                }
                else
                {
                    destPath = String.Format("{0}_bassfix{1}", srcName, srcExt);
                }

                if (Path.GetFileName(destPath).Contains(" ") && info.PS3)
                {
                    if (!ConfigRepository.Instance().GetBoolean("creator_ps3pkgnamewarn"))
                    {
                        MessageBox.Show(String.Format("PS3 package name can't support space character due to encryption limitation. {0} Spaces will be automatic removed for your PS3 package name.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        ConfigRepository.Instance()["creator_ps3pkgnamewarn"] = true.ToString();
                    }
                }

                if (chkDeleteSourceFile.Checked)
                {
                    try
                    {
                        File.Delete(srcPath);
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        MessageBox.Show("Access rights required to delete source package, or an error occurred. Package still may exist. Try running as Administrator.");
                    }
                }

                // Generate Fixed Low Bass Tuning Package
                GlobalExtension.ShowProgress(String.Format("Repackaging '{0}' ...", Path.GetFileName(srcPath)), 80);
                // TODO consider user of regular packer here
                RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(destPath, info, packagePlatform);

                if (!GeneralExtensions.IsInDesignMode)
                {
                    DirectoryExtension.SafeDelete(unpackedDir);
                }
            }

            sw.Stop();
            GlobalExtension.ShowProgress("Finished applying low bass tuning fix (elapsed time): " + sw.Elapsed, 100);
            if (String.IsNullOrEmpty(destPath))
            {
                destPath = srcPaths[0];
            }

            PromptComplete(destPath, errMsg: errorsFound.ToString());
            GlobalExtension.Dispose();
            ToggleUIControls(true);
        }
Example #11
0
        private void UnpackSongs(IEnumerable <string> sourceFileNames, string destPath, bool decode = false, bool overwrite = false)
        {
            ToggleUIControls(false);
            errorsFound = new StringBuilder();
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize

            var       structured = ConfigRepository.Instance().GetBoolean("creator_structured");
            var       step       = (int)Math.Floor(100.0 / (sourceFileNames.Count() * 2)); // Math.Floor prevents roundup errors
            int       progress   = 0;
            Stopwatch sw         = new Stopwatch();

            sw.Restart();

            foreach (string sourceFileName in sourceFileNames)
            {
                Application.DoEvents();
                progress += step;
                GlobalExtension.ShowProgress(String.Format("Unpacking: '{0}'", Path.GetFileName(sourceFileName)), progress);

                try
                {
                    Platform platform    = sourceFileName.GetPlatform();
                    var      unpackedDir = Packer.Unpack(sourceFileName, destPath, decode, overwrite, platform);

                    // added a bulk process to create template xml files here so unpacked folders may be loaded quickly in CDLC Creator if desired
                    progress += step;
                    GlobalExtension.ShowProgress(String.Format("Creating Template XML file for: '{0}'", Path.GetFileName(sourceFileName)), progress);
                    using (var packageCreator = new DLCPackageCreator.DLCPackageCreator())
                    {
                        DLCPackageData info = null;
                        if (platform.version == GameVersion.RS2014)
                        {
                            info = DLCPackageData.LoadFromFolder(unpackedDir, platform, platform, true, true);
                        }
                        else
                        {
                            info = DLCPackageData.RS1LoadFromFolder(unpackedDir, platform, false);
                        }

                        info.GameVersion = platform.version;

                        switch (platform.platform)
                        {
                        case GamePlatform.Pc:
                            info.Pc = true;
                            break;

                        case GamePlatform.Mac:
                            info.Mac = true;
                            break;

                        case GamePlatform.XBox360:
                            info.XBox360 = true;
                            break;

                        case GamePlatform.PS3:
                            info.PS3 = true;
                            break;
                        }

                        packageCreator.FillPackageCreatorForm(info, unpackedDir);
                        // fix descrepancies
                        packageCreator.CurrentGameVersion = platform.version;
                        //packageCreator.SelectComboAppId(info.AppId);
                        packageCreator.AppId = info.AppId;
                        // save template xml file except when SongPack
                        if (!sourceFileName.Contains("_sp_") && !sourceFileName.Contains("_songpack_"))
                        {
                            packageCreator.SaveTemplateFile(unpackedDir, false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorsFound.AppendLine(String.Format("Error unpacking file: '{0}' ... {1}", Path.GetFileName(sourceFileName), ex.Message));
                }
            }

            sw.Stop();
            GlobalExtension.ShowProgress("Finished unpacking archive (elapsed time): " + sw.Elapsed, 100);
            PromptComplete(destPath, false, errorsFound.ToString());
            GlobalExtension.Dispose();
            ToggleUIControls(true);
        }
        public List <string> UnpackSongs(IEnumerable <string> srcPaths, string destPath)
        {
            ToggleUIControls(false);
            errorsFound = new StringBuilder();
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize

            var       unpackedDirs = new List <string>();
            var       structured   = ConfigRepository.Instance().GetBoolean("creator_structured");
            var       step         = (int)Math.Floor(100.0 / (srcPaths.Count() * 2)); // Math.Floor prevents roundup errors
            int       progress     = 0;
            Stopwatch sw           = new Stopwatch();

            sw.Restart();

            foreach (string srcPath in srcPaths)
            {
                Application.DoEvents();
                progress += step;
                GlobalExtension.ShowProgress(String.Format("Unpacking: '{0}'", Path.GetFileName(srcPath)), progress);

                try
                {
                    Platform srcPlatform = srcPath.GetPlatform();
                    var      unpackedDir = Packer.Unpack(srcPath, destPath, srcPlatform, DecodeAudio, OverwriteSongXml);

                    // added a bulk process to create template xml files here so unpacked folders may be loaded quickly in CDLC Creator if desired
                    progress += step;
                    GlobalExtension.ShowProgress(String.Format("Creating Template XML file for: '{0}'", Path.GetFileName(srcPath)), progress);
                    using (var packageCreator = new DLCPackageCreator.DLCPackageCreator())
                    {
                        DLCPackageData info = null;
                        if (srcPlatform.version == GameVersion.RS2014)
                        {
                            info = DLCPackageData.LoadFromFolder(unpackedDir, srcPlatform, srcPlatform, true, true);
                        }
                        else
                        {
                            info = DLCPackageData.RS1LoadFromFolder(unpackedDir, srcPlatform, false);
                        }

                        info.GameVersion = srcPlatform.version;

                        switch (srcPlatform.platform)
                        {
                        case GamePlatform.Pc:
                            info.Pc = true;
                            break;

                        case GamePlatform.Mac:
                            info.Mac = true;
                            break;

                        case GamePlatform.XBox360:
                            info.XBox360 = true;
                            break;

                        case GamePlatform.PS3:
                            info.PS3 = true;
                            break;
                        }

                        // save template xml file (except SongPacks)
                        if (ConfigRepository.Instance().GetBoolean("creator_autosavetemplate") &&
                            !srcPath.Contains("_sp_") && !srcPath.Contains("_songpack_"))
                        {
                            packageCreator.FillPackageCreatorForm(info, unpackedDir);
                            // fix descrepancies
                            packageCreator.CurrentGameVersion = srcPlatform.version;
                            // console files do not have an AppId
                            if (!srcPlatform.IsConsole)
                            {
                                packageCreator.AppId = info.AppId;
                            }

                            packageCreator.SaveTemplateFile(unpackedDir, false);
                        }
                    }

                    unpackedDirs.Add(unpackedDir);
                }
                catch (Exception ex)
                {
                    // ignore any 'Index out of range' exceptions
                    if (!ex.Message.StartsWith("Index"))
                    {
                        errorsFound.AppendLine(String.Format("<ERROR> Unpacking file: '{0}' ... {1}", Path.GetFileName(srcPath), ex.Message));
                    }
                }
            }

            sw.Stop();
            GlobalExtension.ShowProgress("Finished unpacking archive (elapsed time): " + sw.Elapsed, 100);

            if (!ConfigGlobals.IsUnitTest)
            {
                PromptComplete(destPath, false, errorsFound.ToString());
            }

            GlobalExtension.Dispose();
            ToggleUIControls(true);

            return(unpackedDirs);
        }
Example #13
0
        public List <string> UnpackSongs(IEnumerable <string> srcPaths, string destPath)
        {
            ToggleUIControls(false);
            Packer.ErrMsg = new StringBuilder();
            errorsFound   = new StringBuilder();
            GlobalExtension.UpdateProgress        = this.pbUpdateProgress;
            GlobalExtension.CurrentOperationLabel = this.lblCurrentOperation;
            Thread.Sleep(100); // give Globals a chance to initialize

            var       unpackedDirs = new List <string>();
            var       structured   = ConfigRepository.Instance().GetBoolean("creator_structured");
            var       step         = (int)Math.Floor(100.0 / (srcPaths.Count() * 2)); // Math.Floor prevents roundup errors
            int       progress     = 0;
            Stopwatch sw           = new Stopwatch();

            sw.Restart();

            foreach (string srcPath in srcPaths)
            {
                Application.DoEvents();
                progress += step;
                GlobalExtension.ShowProgress(String.Format("Unpacking: '{0}'", Path.GetFileName(srcPath)), progress);
                Platform srcPlatform = srcPath.GetPlatform();
                var      unpackedDir = String.Empty;

                try
                {
                    unpackedDir = Packer.Unpack(srcPath, destPath, srcPlatform, DecodeAudio, OverwriteSongXml);
                    unpackedDirs.Add(unpackedDir);
                }
                catch (Exception ex)
                {
                    errorsFound.AppendLine(String.Format("<ERROR> Unpacking file: {0}{1}{2}", Path.GetFileName(srcPath), Environment.NewLine, ex.Message));
                    continue;
                }

                // added bulk process to create template xml files here so unpacked folders may be loaded quickly in CDLC Creator if desired
                if (ConfigRepository.Instance().GetBoolean("creator_autosavetemplate")) // && !srcPath.Contains("_sp_") && !srcPath.Contains("_songpack_"))
                {
                    try
                    {
                        var isSongPack = Directory.EnumerateFiles(unpackedDir, "*.wem", SearchOption.AllDirectories).Count() > 2;
                        if (isSongPack)
                        {
                            throw new Exception("<ERROR> Found too many *.wem files for template to" + Environment.NewLine +
                                                "process and load.  Uncheck the Autosave Template" + Environment.NewLine +
                                                "checkbox in General Config to prevent this exception." + Environment.NewLine);
                        }

                        //var isODLC = !Directory.EnumerateFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories).Any();
                        //if (isODLC)
                        //    throw new Exception("Uncheck 'Autosave Templates' in 'General Config' to avoid this error.");

                        if (srcPlatform.platform == GamePlatform.None)
                        {
                            throw new Exception("Could not determine GamePlatform.");
                        }

                        progress += step;
                        GlobalExtension.ShowProgress(String.Format("Creating Template XML file for: '{0}'", Path.GetFileName(srcPath)), progress);

                        using (var packageCreator = new DLCPackageCreator.DLCPackageCreator())
                        {
                            DLCPackageData info = null;
                            if (srcPlatform.version == GameVersion.RS2014)
                            {
                                info = DLCPackageData.LoadFromFolder(unpackedDir, srcPlatform, srcPlatform, true, true);
                            }
                            else
                            {
                                info = DLCPackageData.RS1LoadFromFolder(unpackedDir, srcPlatform, false);
                            }

                            info.GameVersion = srcPlatform.version;

                            switch (srcPlatform.platform)
                            {
                            case GamePlatform.Pc:
                                info.Pc = true;
                                break;

                            case GamePlatform.Mac:
                                info.Mac = true;
                                break;

                            case GamePlatform.XBox360:
                                info.XBox360 = true;
                                break;

                            case GamePlatform.PS3:
                                info.PS3 = true;
                                break;
                            }

                            packageCreator.FillPackageCreatorForm(info, unpackedDir);
                            // fix descrepancies
                            packageCreator.CurrentGameVersion = srcPlatform.version;
                            // console files do not have an AppId
                            if (!srcPlatform.IsConsole)
                            {
                                packageCreator.AppId = info.AppId;
                            }

                            packageCreator.SaveTemplateFile(unpackedDir, false);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("Object reference"))
                        {
                            errorsFound.AppendLine(String.Format("Could not create Template XML file for:{0}{1}", Environment.NewLine, Path.GetFileName(srcPath) + new string(' ', 5)));
                        }
                        else
                        {
                            errorsFound.AppendLine(String.Format("Could not create Template XML file for:{0}{1}{0}{0}{2}", Environment.NewLine, Path.GetFileName(srcPath) + new string(' ', 5), ex.Message));
                        }
                    }
                }
            }

            sw.Stop();
            GlobalExtension.ShowProgress("Finished unpacking archive (elapsed time): " + sw.Elapsed, 100);

            // insert any Packer error messages
            if (!String.IsNullOrEmpty(Packer.ErrMsg.ToString()))
            {
                errorsFound.Insert(0, Packer.ErrMsg.ToString());
            }

            if (!GlobalsLib.IsUnitTest)
            {
                PromptComplete(destPath, false, errorsFound.ToString());
            }

            GlobalExtension.Dispose();
            ToggleUIControls(true);

            return(unpackedDirs);
        }
Example #14
0
        private void unpackButton_Click(object sender, EventArgs e)
        {
            string[] sourceFileNames;
            savePath = String.Empty;

            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter      = "All Files (*.*)|*.*";
                ofd.Multiselect = true;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                sourceFileNames = ofd.FileNames;
            }

            using (var fbd = new VistaFolderBrowserDialog())
            {
                fbd.SelectedPath = Path.GetDirectoryName(sourceFileNames[0]) + Path.DirectorySeparatorChar;
                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                savePath = fbd.SelectedPath;
            }

            // commented out bWorker aspects to test GlobalExtension ProgressBar function
            //if (!bwUnpack.IsBusy && sourceFileNames.Length > 0)
            //{
            //    updateProgress.Value = 0;
            //    updateProgress.Visible = true;
            //    currentOperationLabel.Visible = true;
            unpackButton.Enabled = false;
            //    bwUnpack.RunWorkerAsync(sourceFileNames);
            //}
            //}

            //private void Unpack(object sender, DoWorkEventArgs e)
            //{
            //    var sourceFileNames = e.Argument as string[];
            errorsFound = new StringBuilder();
            //var step = (int)Math.Round(1.0 / sourceFileNames.Length * 100, 0);
            //int progress = 0;

            GlobalExtension.UpdateProgress        = this.updateProgress;
            GlobalExtension.CurrentOperationLabel = this.currentOperationLabel;
            Thread.Sleep(100); // give Globals a chance to initialize

            foreach (string sourceFileName in sourceFileNames)
            {
                Application.DoEvents();
                Platform platform = Packer.GetPlatform(sourceFileName);
                // bwUnpack.ReportProgress(progress, String.Format("Unpacking '{0}'", Path.GetFileName(sourceFileName)));

                GlobalExtension.ShowProgress(String.Format("Unpacking '{0}'", Path.GetFileName(sourceFileName)));

                // remove this exception handler for testing
                try
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Restart();
                    Packer.Unpack(sourceFileName, savePath, decodeAudio, extractSongXml);
                    sw.Stop();
                    GlobalExtension.ShowProgress("Finished unpacking archive (elapsed time): " + sw.Elapsed, 100);
                }
                catch (Exception ex)
                {
                    errorsFound.AppendLine(String.Format("Error unpacking file '{0}': {1}", Path.GetFileName(sourceFileName), ex.Message));
                }

                // progress += step;
                // bwUnpack.ReportProgress(progress);
            }
            //  bwUnpack.ReportProgress(100);
            //  e.Result = "unpack";

            // add this message while bWorker is commented out
            if (errorsFound.Length <= 0)
            {
                MessageBox.Show("Unpacking is complete.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Unpacking is complete with errors. See below: " + Environment.NewLine + Environment.NewLine + errorsFound.ToString(), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            unpackButton.Enabled = true;
            // prevents possible cross threading
            GlobalExtension.Dispose();
        }