public static List <Tone> Import(string filePath) { var tones = new List <Tone>(); var toneExtension = Path.GetExtension(filePath); switch (toneExtension) { case ".json": tones.Add(ReadFromManifest(filePath)); break; case ".xml": tones.Add(ReadFromRocksmithExportedXml(filePath)); break; default: var platform = Packer.GetPlatform(filePath); switch (platform.platform) { case GamePlatform.Pc: case GamePlatform.XBox360: return(ReadFromPackage(filePath, platform)); case GamePlatform.PS3: throw new InvalidOperationException("PS3 platform is not supported at this time :("); default: throw new NotSupportedException(String.Format("Unknown file extension exception '{0}'. File not supported.", toneExtension)); } } return(tones); }
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; foreach (string sourceFileName in sourceFileNames) { Application.DoEvents(); Platform platform = Packer.GetPlatform(sourceFileName); bwUnpack.ReportProgress(progress, String.Format("Unpacking '{0}'", Path.GetFileName(sourceFileName))); try { Packer.Unpack(sourceFileName, savePath, decodeAudio, extractSongXml); } catch (Exception ex) { errorsFound.AppendLine(String.Format("Error trying unpack file '{0}': {1}", Path.GetFileName(sourceFileName), ex.Message)); } progress += step; bwUnpack.ReportProgress(progress); } e.Result = "unpack"; }
public static List <Tone2014> Import(string filePath) { List <Tone2014> tones = new List <Tone2014>(); var toneExtension = Path.GetExtension(filePath); switch (toneExtension) { case ".json": tones.AddRange(ReadFromManifest(filePath)); break; default: var platform = Packer.GetPlatform(filePath); switch (platform.platform) { case GamePlatform.Pc: case GamePlatform.Mac: case GamePlatform.XBox360: case GamePlatform.PS3: return(ReadFromPackage(filePath, platform)); default: throw new NotSupportedException(String.Format("Unknown file extension exception '{0}'. File not supported.", toneExtension)); } } return(tones); }
/// <summary> /// Loads DLCPackageData from unpacked archive (RS1 and RS2014 Compatible) /// </summary> /// <param name="fixMultitoneEx">convert multi tones to single tone, prevents some in-game hangs</param> /// <param name="fixLowBass">fix low bass tuning issues</param> /// <param name="decodeAudio">converts wem to ogg files</param> /// <returns>DLCPackageData</returns> public DLCPackageData ReadPackage(string srcPath, bool fixMultiTone = false, bool fixLowBass = false, bool decodeAudio = false) { // UNPACK packageDir = Packer.Unpack(srcPath, Path.GetTempPath(), decodeAudio: decodeAudio); // LOAD DLCPackageData var srcPlatform = Packer.GetPlatform(srcPath); DLCPackageData info = null; if (srcPlatform.version == GameVersion.RS2014) { // REORGANIZE (RS2014) packageDir = DLCPackageData.DoLikeProject(packageDir); info = DLCPackageData.LoadFromFolder(packageDir, srcPlatform, srcPlatform, fixMultiTone, fixLowBass); } else { info = DLCPackageData.RS1LoadFromFolder(packageDir, srcPlatform, false); } return(info); }
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); }
static int Main(string[] args) { var arguments = DefaultArguments(); var options = GetOptions(arguments); try { options.Parse(args); if (arguments.ShowHelp) { options.WriteOptionDescriptions(Console.Out); return(0); } if (!arguments.Pack && !arguments.Unpack && !arguments.Build) { ShowHelpfulError("Must especify a primary command as 'pack', 'unpack', 'build'."); return(1); } if (arguments.Build && arguments.Pack || arguments.Build && arguments.Unpack || arguments.Pack && arguments.Unpack) { ShowHelpfulError("The primary command 'build', 'pack' and 'unpack' can't be used at same time."); return(1); } if (arguments.Pack || arguments.Unpack) { if (arguments.Input == null && arguments.Input.Length <= 0) { ShowHelpfulError("Must specify an 'input' file or directory."); return(1); } if (string.IsNullOrEmpty(arguments.Output)) { ShowHelpfulError("Must specified an 'output' file or directory."); return(1); } if ((arguments.Platform.platform == GamePlatform.None && arguments.Platform.version != GameVersion.None) || (arguments.Platform.platform != GamePlatform.None && arguments.Platform.version == GameVersion.None)) { ShowHelpfulError("'platform' argument require 'version' and vice-versa to define platform. Use this option only if you have problem with platform auto identifier"); return(1); } } // BUILD PACKAGE FROM TEMPLATE if (arguments.Build) { if (string.IsNullOrEmpty(arguments.Template)) { ShowHelpfulError("Must specify an 'template' argument with path of the Rocksmith DLC template (*.dlc.xml)."); return(1); } if (string.IsNullOrEmpty(arguments.Output)) { ShowHelpfulError("Must specified an 'output' file."); return(1); } if (arguments.Output.IsDirectory()) { ShowHelpfulError("The 'output' argument in 'build' command must be a file."); return(1); } try { Console.WriteLine("Warning: You should load and save XML with 'RocksmithToolkitGUI 2.3.0.0' or above to make sure it is still valid and compatible with this feature!"); DLCPackageData info = null; var serializer = new DataContractSerializer(typeof(DLCPackageData)); using (var stm = new XmlTextReader(arguments.Template)) { info = (DLCPackageData)serializer.ReadObject(stm); } var gameVersion = info.GameVersion; FixPaths(info, arguments.Template, gameVersion); if (info.Pc) { DLCPackageCreator.Generate(arguments.Output, info, new Platform(GamePlatform.Pc, gameVersion)); } if (gameVersion == GameVersion.RS2014) { if (info.Mac) { DLCPackageCreator.Generate(arguments.Output, info, new Platform(GamePlatform.Mac, gameVersion)); } } if (info.XBox360) { DLCPackageCreator.Generate(Path.Combine(Path.GetDirectoryName(arguments.Output), Path.GetFileNameWithoutExtension(arguments.Output)), info, new Platform(GamePlatform.XBox360, gameVersion)); } if (info.PS3) { DLCPackageCreator.Generate(Path.Combine(Path.GetDirectoryName(arguments.Output), Path.GetFileNameWithoutExtension(arguments.Output)), info, new Platform(GamePlatform.PS3, gameVersion)); } Console.WriteLine("Package was generated."); return(0); } catch (Exception ex) { Console.WriteLine(String.Format("{0}\n{1}\n{2}", "Build error!", ex.Message, ex.InnerException)); return(1); } } // PACK A FOLDER TO A PACKAGE if (arguments.Pack) { if (!arguments.Input[0].IsDirectory()) { ShowHelpfulError("The 'input' argument in 'pack' command must be a directory."); return(1); } var srcFiles = arguments.Input; foreach (string srcFileName in srcFiles) { try { if (arguments.Platform.platform != GamePlatform.None && arguments.Platform.version != GameVersion.None) { Packer.Pack(Path.GetFullPath(srcFileName), Path.GetFullPath(arguments.Output), arguments.UpdateSng, arguments.Platform, arguments.UpdateManifest); } else { Packer.Pack(Path.GetFullPath(srcFileName), Path.GetFullPath(arguments.Output), arguments.UpdateSng, updateManifest: arguments.UpdateManifest); } Console.WriteLine("Packing is complete."); return(0); } catch (Exception ex) { Console.WriteLine(String.Format("Packing error!\nFile: {0}\n{1}\n{2}", srcFileName, ex.Message, ex.InnerException)); return(1); } } } // UNPACK A PACKAGE FILE if (arguments.Unpack) { if (!arguments.Output.IsDirectory()) { ShowHelpfulError("The 'output' argument in 'unpack' command must be a directory."); return(1); } var srcFiles = new List <string>(); foreach (var name in arguments.Input) { if (name.IsDirectory()) { srcFiles.AddRange(Directory.EnumerateFiles(Path.GetFullPath(name), "*.psarc", SearchOption.AllDirectories)); } if (File.Exists(name)) { srcFiles.Add(name); } } foreach (string srcFileName in srcFiles) { Platform platform = Packer.GetPlatform(srcFileName); if (platform.platform == GamePlatform.None) { Console.WriteLine("Error: Platform not found or invalid 'input' file:" + srcFileName); continue; } try { Packer.Unpack(Path.GetFullPath(srcFileName), Path.GetFullPath(arguments.Output), arguments.DecodeOGG, arguments.OverwriteSongXml); } catch (Exception ex) { Console.WriteLine(String.Format("Unpacking error!\nFile: {0}\n{1}\n{2}", srcFileName, ex.Message, ex.InnerException)); return(1); } } Console.WriteLine("Unpacking is complete."); return(0); } } catch (OptionException ex) { ShowHelpfulError(ex.Message); return(1); } return(0); }
static int Main(string[] args) { try { Console.SetWindowSize(85, 40); // to prevent ioexceptions Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; } catch { /* DO NOTHING */ } #if (DEBUG) // give the progie some dumby data to work with args = new string[] { "-u", "-x", "-d", "-input=D:\\Temp\\PeppaPig_p.psarc", "-output=D:\\Temp", "-v=RS2014", "-c", "-f=Pc" }; // args = new string[] {"-?"}; Console.WriteLine("Running in Debug Mode ... help is not available"); #endif var arguments = DefaultArguments(); var options = GetOptions(arguments); try { options.Parse(args); if (arguments.ShowHelp) { options.WriteOptionDescriptions(Console.Out); Console.WriteLine(""); Console.WriteLine("Press any key to close window ..."); Console.ReadLine(); return(0); } if (!arguments.Pack && !arguments.Unpack && !arguments.Build) { ShowHelpfulError("Must especify a primary command as 'pack', 'unpack', 'build'."); return(1); } if (arguments.Build && arguments.Pack || arguments.Build && arguments.Unpack || arguments.Pack && arguments.Unpack) { ShowHelpfulError("The primary command 'build', 'pack' and 'unpack' can't be used at same time."); return(1); } if (arguments.Pack || arguments.Unpack) { if (arguments.Input == null && arguments.Input.Length <= 0) { ShowHelpfulError("Must specify an 'input' file or directory."); return(1); } if (string.IsNullOrEmpty(arguments.Output)) { ShowHelpfulError("Must specified an 'output' file or directory."); return(1); } if ((arguments.Platform.platform == GamePlatform.None && arguments.Platform.version != GameVersion.None) || (arguments.Platform.platform != GamePlatform.None && arguments.Platform.version == GameVersion.None)) { ShowHelpfulError("'platform' argument require 'version' and vice-versa to define platform. Use this option only if you have problem with platform auto identifier"); return(1); } } // BUILD PACKAGE FROM TEMPLATE if (arguments.Build) { if (string.IsNullOrEmpty(arguments.Template)) { ShowHelpfulError("Must specify an 'template' argument with path of the Rocksmith DLC template (*.dlc.xml)."); return(1); } if (string.IsNullOrEmpty(arguments.Output)) { ShowHelpfulError("Must specified an 'output' file."); return(1); } if (arguments.Output.IsDirectory()) { ShowHelpfulError("The 'output' argument in 'build' command must be a file."); return(1); } try { Console.WriteLine("Warning: You should load and save XML with 'RocksmithToolkitGUI 2.3.0.0' or above to make sure it is still valid and compatible with this feature!"); DLCPackageData info = null; var serializer = new DataContractSerializer(typeof(DLCPackageData)); using (var stm = new XmlTextReader(arguments.Template)) { info = (DLCPackageData)serializer.ReadObject(stm); } var gameVersion = info.GameVersion; FixPaths(info, arguments.Template, gameVersion); if (info.Pc) { DLCPackageCreator.Generate(arguments.Output, info, new Platform(GamePlatform.Pc, gameVersion)); } if (gameVersion == GameVersion.RS2014) { if (info.Mac) { DLCPackageCreator.Generate(arguments.Output, info, new Platform(GamePlatform.Mac, gameVersion)); } } if (info.XBox360) { DLCPackageCreator.Generate(Path.Combine(Path.GetDirectoryName(arguments.Output), Path.GetFileNameWithoutExtension(arguments.Output)), info, new Platform(GamePlatform.XBox360, gameVersion)); } if (info.PS3) { DLCPackageCreator.Generate(Path.Combine(Path.GetDirectoryName(arguments.Output), Path.GetFileNameWithoutExtension(arguments.Output)), info, new Platform(GamePlatform.PS3, gameVersion)); } Console.WriteLine("Package was generated."); } catch (Exception ex) { Console.WriteLine(String.Format("{0}\n{1}\n{2}", "Build error!", ex.Message, ex.InnerException)); return(1); } } // PACK A FOLDER TO A PACKAGE if (arguments.Pack) { if (!arguments.Input[0].IsDirectory()) { ShowHelpfulError("The 'input' argument in 'pack' command must be a directory."); return(1); } var srcFiles = arguments.Input; foreach (string srcFileName in srcFiles) { try { if (arguments.Platform.platform != GamePlatform.None && arguments.Platform.version != GameVersion.None) { Packer.Pack(Path.GetFullPath(srcFileName), Path.GetFullPath(arguments.Output), arguments.Platform, arguments.UpdateSng, arguments.UpdateManifest); } else { Packer.Pack(Path.GetFullPath(srcFileName), Path.GetFullPath(arguments.Output), null, arguments.UpdateSng, arguments.UpdateManifest); } Console.WriteLine("Packing is complete."); } catch (Exception ex) { Console.WriteLine(String.Format("Packing error!\nFile: {0}\n{1}\n{2}", srcFileName, ex.Message, ex.InnerException)); return(1); } } } // UNPACK A PACKAGE FILE if (arguments.Unpack) { if (!arguments.Output.IsDirectory()) { ShowHelpfulError("The 'output' argument in 'unpack' command must be a directory."); return(1); } var srcFiles = new List <string>(); foreach (var name in arguments.Input) { if (name.IsDirectory()) { srcFiles.AddRange(Directory.EnumerateFiles(Path.GetFullPath(name), "*.psarc", SearchOption.AllDirectories)); } if (File.Exists(name)) { srcFiles.Add(name); } } foreach (string srcFileName in srcFiles) { Console.WriteLine(String.Format("Unpacking File: {0}", srcFileName)); Platform platform = Packer.GetPlatform(srcFileName); if (platform.platform == GamePlatform.None) { Console.WriteLine("Error: Platform not found or invalid 'input' file:" + srcFileName); continue; } try { var unpackedDir = Packer.Unpack(Path.GetFullPath(srcFileName), Path.GetFullPath(arguments.Output), null, arguments.DecodeOGG, arguments.OverwriteSongXml); // create template xml file if (arguments.CreateTemplateXml) { Console.WriteLine(String.Format("Creating Template XML file for: '{0}'", Path.GetFileName(srcFileName))); CreateTemplate(unpackedDir, platform); } } catch (Exception ex) { Console.WriteLine(String.Format("Unpacking error!\nFile: {0}\n{1}\n{2}", srcFileName, ex.Message, ex.InnerException)); return(1); } } Console.WriteLine("Unpacking is complete."); } } catch (OptionException ex) { ShowHelpfulError(ex.Message); return(1); } #if DEBUG Console.WriteLine(""); Console.WriteLine("Press any key to close window ..."); Console.ReadLine(); #endif return(0); }
private void ExtractBeforeConvert(string inputFile, string savePath, bool all) { string appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Packer.Unpack(inputFile, appDir); string unpackedDir = Path.Combine(appDir, Path.GetFileNameWithoutExtension(inputFile) + String.Format("_{0}", Packer.GetPlatform(inputFile).platform.ToString())); string[] sngFiles = Directory.GetFiles(unpackedDir, "*.sng", SearchOption.AllDirectories); foreach (var sng in sngFiles) { Convert(sng, savePath, all); } DirectoryExtension.SafeDelete(unpackedDir); }
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(); }