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); }
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); 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); }