public static ResultInfo MappingMode(string option, string link, string target) { ResultInfo result = DataDeal(ref option, ref link, ref target); if (!result.IsSuccess) { return(result); } try { if (File.Exists(target)) { File.Move(target, link); } else if (Directory.Exists(target)) { DirectoryExtension.Move(target, link); } else { return(new ResultInfo(false, "请确保文件或目录存在")); } Cmd cmd = new Cmd(); result = cmd.Start(MkLinkCommand, option, target, link); cmd.Close(); return(result); } catch (Exception e) { return(new ResultInfo(false, e.Message)); } }
private static void UnpackPS3Package(string sourceFileName, string savePath, Platform platform) { var rootDir = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "edat"); var outputFilename = Path.Combine(rootDir, Path.GetFileName(sourceFileName)); if (!Directory.Exists(rootDir)) { Directory.CreateDirectory(rootDir); } if (File.Exists(sourceFileName)) { File.Copy(sourceFileName, outputFilename, true); } else { throw new FileNotFoundException(String.Format("File '{0}' not found.", sourceFileName)); } var outputMessage = RijndaelEncryptor.DecryptPS3Edat(); if (File.Exists(outputFilename)) { File.Delete(outputFilename); } foreach (var fileName in Directory.EnumerateFiles(rootDir, "*.psarc.dat")) { using (var outputFileStream = File.OpenRead(fileName)) { ExtractPSARC(fileName, Path.GetDirectoryName(fileName), outputFileStream, new Platform(GamePlatform.PS3, GameVersion.None)); } if (File.Exists(fileName)) { File.Delete(fileName); } } var outName = Path.GetFileNameWithoutExtension(sourceFileName); var outputDir = Path.Combine(savePath, outName.Substring(0, outName.LastIndexOf(".")) + String.Format("_{0}", platform.platform.ToString())); foreach (var unpackedDir in Directory.EnumerateDirectories(rootDir)) { if (Directory.Exists(unpackedDir)) { if (Directory.Exists(outputDir)) { DirectoryExtension.SafeDelete(outputDir); } DirectoryExtension.Move(unpackedDir, outputDir); } } if (outputMessage.IndexOf("Decrypt all EDAT files successfully") < 0) { throw new InvalidOperationException("Rebuilder error, please check if .edat files are created correctly and see output below:" + Environment.NewLine + Environment.NewLine + outputMessage); } }
private static void ConvertPackageForSimilarPlatform(string unpackedDir, string targetFileName, Platform sourcePlatform, Platform targetPlatform, string appId) { // Old and new paths var sourceDir0 = sourcePlatform.GetPathName()[0].ToLower(); var sourceDir1 = sourcePlatform.GetPathName()[1].ToLower(); var targetDir0 = targetPlatform.GetPathName()[0].ToLower(); var targetDir1 = targetPlatform.GetPathName()[1].ToLower(); if (!targetPlatform.IsConsole) { // Replace AppId var appIdFile = Path.Combine(unpackedDir, "appid.appid"); File.WriteAllText(appIdFile, appId); } // Replace aggregate graph values var aggregateFile = Directory.EnumerateFiles(unpackedDir, "*.nt", SearchOption.AllDirectories).FirstOrDefault(); var aggregateGraphText = File.ReadAllText(aggregateFile); // Tags aggregateGraphText = Regex.Replace(aggregateGraphText, GraphItem.GetPlatformTagDescription(sourcePlatform.platform), GraphItem.GetPlatformTagDescription(targetPlatform.platform), RegexOptions.Multiline); // Paths aggregateGraphText = Regex.Replace(aggregateGraphText, sourceDir0, targetDir0, RegexOptions.Multiline); aggregateGraphText = Regex.Replace(aggregateGraphText, sourceDir1, targetDir1, RegexOptions.Multiline); File.WriteAllText(aggregateFile, aggregateGraphText); // Rename directories foreach (var dir in Directory.GetDirectories(unpackedDir, "*.*", SearchOption.AllDirectories)) { if (dir.EndsWith(sourceDir0)) { var newDir = dir.Substring(0, dir.LastIndexOf(sourceDir0)) + targetDir0; DirectoryExtension.SafeDelete(newDir); DirectoryExtension.Move(dir, newDir); } else if (dir.EndsWith(sourceDir1)) { var newDir = dir.Substring(0, dir.LastIndexOf(sourceDir1)) + targetDir1; DirectoryExtension.SafeDelete(newDir); DirectoryExtension.Move(dir, newDir); } } // Recreates SNG because SNG have different keys in PC and Mac bool updateSNG = ((sourcePlatform.platform == GamePlatform.Pc && targetPlatform.platform == GamePlatform.Mac) || (sourcePlatform.platform == GamePlatform.Mac && targetPlatform.platform == GamePlatform.Pc)); // Packing var dirToPack = unpackedDir; if (sourcePlatform.platform == GamePlatform.XBox360) { dirToPack = Directory.GetDirectories(Path.Combine(unpackedDir, Packer.ROOT_XBox360))[0]; } Packer.Pack(dirToPack, targetFileName, updateSNG, targetPlatform); DirectoryExtension.SafeDelete(unpackedDir); }
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); }