public void IntroScreensCreator_Dispose(object sender, EventArgs e) { if (Directory.Exists(tmpWorkDir)) { IOExtension.DeleteDirectory(tmpWorkDir); } }
public void DLCInlayCreator_Dispose(object sender, EventArgs e) { if (Directory.Exists(defaultDir)) { IOExtension.DeleteDirectory(defaultDir); } }
/// <summary> /// Converts CDLC packages between platforms /// </summary> /// <param name="sourcePackage"></param> /// <param name="sourcePlatform"></param> /// <param name="targetPlatform"></param> /// <param name="appId"></param> /// <returns>Errors if any</returns> public static string Convert(string sourcePackage, Platform sourcePlatform, Platform targetPlatform, string appId) { var needRebuildPackage = sourcePlatform.IsConsole != targetPlatform.IsConsole; var tmpDir = Path.GetTempPath(); // key to good conversion is to overwriteSongXml var unpackedDir = Packer.Unpack(sourcePackage, tmpDir, sourcePlatform, false, true); // DESTINATION var nameTemplate = (!targetPlatform.IsConsole) ? "{0}{1}.psarc" : "{0}{1}"; var packageName = Path.GetFileNameWithoutExtension(sourcePackage).StripPlatformEndName(); packageName = packageName.Replace(".", "_"); var targetFileName = String.Format(nameTemplate, Path.Combine(Path.GetDirectoryName(sourcePackage), packageName), targetPlatform.GetPathName()[2]); // force package rebuilding for testing // needRebuildPackage = true; // CONVERSION if (needRebuildPackage) { ConvertPackageRebuilding(unpackedDir, targetFileName, sourcePlatform, targetPlatform, appId); } else { ConvertPackageForSimilarPlatform(unpackedDir, targetFileName, sourcePlatform, targetPlatform, appId); } IOExtension.DeleteDirectory(unpackedDir); return(String.Empty); }
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; IOExtension.DeleteDirectory(newDir); IOExtension.MoveDirectory(dir, newDir); } else if (dir.EndsWith(sourceDir1)) { var newDir = dir.Substring(0, dir.LastIndexOf(sourceDir1)) + targetDir1; IOExtension.DeleteDirectory(newDir); IOExtension.MoveDirectory(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, targetPlatform, updateSNG); IOExtension.DeleteDirectory(unpackedDir); }
protected virtual void Dispose(Boolean disposing) { if (disposing) { if (_deleteOnClose && Directory.Exists(packageDir)) { IOExtension.DeleteDirectory(packageDir); } } }
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, NewAppId); 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)) { IOExtension.DeleteDirectory(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 UpdateStatic() { // unpack static.psarc const int numSteps = 5; // max number of times ReportProgress will be called var step = (int)Math.Round(1.0 / (numSteps + 2) * 100, 0); var progress = 0; progress += step; ProcessStarted(progress, "Unpacking static file ... "); var srcPath = Path.Combine(rsDir, "static.psarc"); var destPath = Path.Combine(rsDir, "static.psarc.org"); // backup the original static.psarc and never overwrite it if (!File.Exists(destPath)) { File.Copy(srcPath, destPath, false); } var tmpModDir = Path.Combine(tmpWorkDir, "cis_static"); if (Directory.Exists(tmpModDir)) { IOExtension.DeleteDirectory(tmpModDir, true); } Directory.CreateDirectory(tmpModDir); destPath = tmpModDir; // Packer.Unpack(srcPath, destPath); // not working here ExternalApps.UnpackPsarc(srcPath, destPath, DLCInlayCreator.GlobalTitlePlatform); // convert user png images to dds images progress += step * 3; ProcessStarted(progress, "Converting user PNG images ..."); // CRITICAL PATH AND ARGS var rootDir = string.Format("static_{0}", DLCInlayCreator.GlobalTitlePlatform); srcPath = imageArray[6, 3]; destPath = Path.Combine(tmpModDir, rootDir, "gfxassets\\views", Path.GetFileName(imageArray[6, 2])); ExternalApps.Png2Dds(srcPath, destPath, ImageHandler.Size2IntX(imageArray[6, 1]), ImageHandler.Size2IntY(imageArray[6, 1])); // repack static.psarc progress += step; ProcessStarted(progress, "Repacking static file ..."); srcPath = Path.Combine(tmpModDir, rootDir); destPath = Path.Combine(rsDir, "static.psarc"); // Packer.Pack(srcPath, destPath); // not working ExternalApps.RepackPsarc(srcPath, destPath, DLCInlayCreator.GlobalTitlePlatform); ProcessCompleted(null, null); }
public void Init() { TestSettings.Instance.Load(); if (!TestSettings.Instance.ResourcePaths.Any()) { Assert.Fail("TestSettings Load Failed ..."); } ConfigGlobals.IsUnitTest = true; packageCreator = new DLCPackageCreator.DLCPackageCreator(); // empty the 'Local Settings/Temp/UnitTest' directory before starting IOExtension.DeleteDirectory(TestSettings.Instance.TmpDestDir); }
public void ExtractBeforeConvert(string inputPath, string outputDir, bool allDif) { // unpacker creates the sng2tabDir directory if it doesn't exist string sng2tabDir = Path.Combine(tmpWorkDir, "sng2tab"); string unpackedDir = Packer.Unpack(inputPath, sng2tabDir); var sngFiles = Directory.EnumerateFiles(unpackedDir, "*.sng", SearchOption.AllDirectories); foreach (var sngFilePath in sngFiles) { Convert(sngFilePath, outputDir, allDif); } IOExtension.DeleteDirectory(sng2tabDir); }
public void Load() { ResourcesDir = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Resources"); string[] fileExt = new string[] { "_p.psarc", "_m.psarc", "_ps3.psarc.edat", "_xbox", ".dat" }; ResourcePaths = Directory.EnumerateFiles(ResourcesDir, "*", SearchOption.TopDirectoryOnly).Where(fi => fileExt.Any(fi.ToLower().EndsWith)).ToList(); if (!ResourcePaths.Any()) { throw new Exception("The 'Resources' directory contains no valid archive files ..."); } TmpDestDir = Path.Combine(Path.GetTempPath(), "UnitTest"); // start with clean 'Local Settings/Temp/UnitTest' directory IOExtension.DeleteDirectory(TmpDestDir); Directory.CreateDirectory(TmpDestDir); }
private void SaveImages(object sender, DoWorkEventArgs e) { // method using Background Worker to report progress var savePath = e.Argument as string; const int numSteps = 7; // max number of times progress change is reported var step = (int)Math.Round(1.0 / (numSteps + 2) * 100, 0); var progress = 0; // Create temp folder for zipping files var tmpZipDir = Path.Combine(tmpWorkDir, "cis_zip"); if (Directory.Exists(tmpZipDir)) { IOExtension.DeleteDirectory(tmpZipDir, true); } Directory.CreateDirectory(tmpZipDir); // convert user png images to dds images for (int i = 0; i < imageArray.GetUpperBound(0); i++) { progress += step; bwSaveImages.ReportProgress(progress, "Converting user PNG images ... " + i.ToString()); if (imageArray[i, 3] != null) // user has specified a replacement image { // CRITICAL PATH AND ARGS var srcPath = imageArray[i, 3]; var destPath = Path.Combine(tmpZipDir, Path.GetFileName(imageArray[i, 2])); ExternalApps.Png2Dds(srcPath, destPath, ImageHandler.Size2IntX(imageArray[i, 1]), ImageHandler.Size2IntY(imageArray[i, 1])); } } progress += step; bwSaveImages.ReportProgress(progress, "Saving Intro Screens Template file ... "); // Write ini file setup.smb var iniFile = Path.Combine(tmpZipDir, "setup.smb"); Configuration iniCFG = new Configuration(); iniCFG["General"].Add(new Setting("author", String.IsNullOrEmpty(txtAuthor.Text) ? "CSC" : txtAuthor.Text)); iniCFG["General"].Add(new Setting("seqname", String.IsNullOrEmpty(txtSeqName.Text) ? "SystemSaved" : txtSeqName.Text)); iniCFG["General"].Add(new Setting("cscvers", ToolkitVersion.RSTKGuiVersion)); iniCFG["General"].Add(new Setting("modified", DateTime.Now.ToShortDateString())); iniCFG.Save(iniFile); // Zip intro sequence *.cis file ExternalApps.InjectZip(tmpZipDir, savePath, false, true); }
private static List <Tone> ReadFromPackage(string packagePath, Platform platform) { List <Tone> tones = new List <Tone>(); string appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string unpackedDir = Packer.Unpack(packagePath, appDir); string[] toneManifestFiles = Directory.GetFiles(unpackedDir, "tone*.manifest.json", SearchOption.AllDirectories); foreach (var file in toneManifestFiles) { tones.Add(ReadFromManifest(file)); } IOExtension.DeleteDirectory(unpackedDir); return(tones); }
public static void ExtractTemplate(string packedTemplatePath) { if (!File.Exists(packedTemplatePath)) { throw new Exception("<ERROR> Could not find packed template: " + packedTemplatePath + Environment.NewLine + "Try re-installing the toolkit ..." + Environment.NewLine); } var templateDir = Path.Combine(ExternalApps.TOOLKIT_ROOT, "Template"); IOExtension.DeleteDirectory(templateDir); using (var packedTemplate = File.OpenRead(packedTemplatePath)) using (var bz2 = new BZip2InputStream(packedTemplate)) using (var tar = TarArchive.CreateInputTarArchive(bz2)) { tar.ExtractContents(ExternalApps.TOOLKIT_ROOT); } }
private static List <Tone2014> ReadFromPackage(string packagePath, Platform platform) { var tones = new List <Tone2014>(); var tmpDir = Packer.Unpack(packagePath, Path.GetTempPath()); var toneManifestFiles = Directory.EnumerateFiles(tmpDir, "*.json", SearchOption.AllDirectories); foreach (var file in toneManifestFiles) { foreach (Tone2014 tone in ReadFromManifest(file)) { if (tones.All(a => a.Name != tone.Name)) { tones.Add(tone); } } } IOExtension.DeleteDirectory(tmpDir); return(tones); }
private void saveCGMButton_Click(object sender, EventArgs e) { var saveFile = String.Empty; using (var sfd = new SaveFileDialog()) { sfd.Title = "Select a location to store your CGM file"; sfd.Filter = "CGM file (*.cgm)|*.cgm"; sfd.InitialDirectory = Path.Combine(workDir, "cgm"); sfd.FileName = (InlayName.GetValidInlayName(Frets24)) + "_" + StringExtensions.GetValidAcronym(Author) + ".cgm".GetValidFileName(); if (sfd.ShowDialog() != DialogResult.OK) { return; } saveFile = sfd.FileName; } // Create workDir folder var tmpWorkDir = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(saveFile)); if (Directory.Exists(tmpWorkDir)) { IOExtension.DeleteDirectory(tmpWorkDir); } if (!Directory.Exists(tmpWorkDir)) { Directory.CreateDirectory(tmpWorkDir); } // Convert PNG to DDS ExternalApps.Png2Dds(IconFile, Path.Combine(tmpWorkDir, "icon.dds"), 512, 512); ExternalApps.Png2Dds(InlayFile, Path.Combine(tmpWorkDir, "inlay.dds"), 1024, 512); // Create setup.smb var iniFile = Path.Combine(tmpWorkDir, "setup.smb"); Configuration iniCFG = new Configuration(); // sharpconfig.dll automatically creates a new [General] section in the INI file iniCFG["General"].Add(new Setting("author", String.IsNullOrEmpty(Author) ? "CSC" : Author)); iniCFG["General"].Add(new Setting("inlayname", String.IsNullOrEmpty(InlayName) ? "null" : InlayName)); iniCFG["General"].Add(new Setting("24frets", Convert.ToString(Convert.ToInt32(Frets24)))); iniCFG["General"].Add(new Setting("colored", Convert.ToString(Convert.ToInt32(Colored)))); iniCFG["General"].Add(new Setting("cscvers", ToolkitVersion.RSTKGuiVersion.Replace("-00000000", ""))); iniCFG["General"].Add(new Setting("modified", DateTime.Now.ToShortDateString())); iniCFG.Save(iniFile); // Pack file into a .cgm file (7zip file format) ExternalApps.InjectZip(tmpWorkDir, saveFile, false, true); // Delete temp work dir if (Directory.Exists(tmpWorkDir)) { IOExtension.DeleteDirectory(tmpWorkDir); } if (MessageBox.Show("Inlay template was saved." + Environment.NewLine + "Would you like to open the folder?", MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Process.Start(Path.GetDirectoryName(saveFile)); } if (Path.GetDirectoryName(saveFile) == Path.Combine(workDir, "cgm")) { inlayTemplateCombo.Items.Add(Path.GetFileNameWithoutExtension(saveFile)); inlayTemplateCombo.SelectedIndex = (inlayTemplateCombo.Items.Count - 1); } }
private void LoadCGM(string customCGM) { if (!String.IsNullOrEmpty(customCGM)) { // Unpack CGM file (7z file format) var unpackedFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(customCGM)); if (Directory.Exists(unpackedFolder)) { IOExtension.DeleteDirectory(unpackedFolder); } ExternalApps.ExtractZip(customCGM, unpackedFolder); var errorMessage = string.Format("Template {0} can't be loaded, maybe doesn't exists or is corrupted.", customCGM); if (!Directory.Exists(unpackedFolder)) { MessageBox.Show(errorMessage, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Setup inlay pre-definition Frets24Checkbox.Checked = ColoredCheckbox.Checked = chkFlipX.Checked = chkFlipY.Checked = false; // Open the setup.smb INI file Configuration iniConfig = Configuration.LoadFromFile(Path.Combine(unpackedFolder, "setup.smb")); // switch to new sharpconfig.dll ini file format with [General] section // allow for backward compatibility with old *.cgm files try { Author = iniConfig["General"]["author"].Value; InlayName = iniConfig["General"]["inlayname"].Value; Frets24 = iniConfig["General"]["24frets"].GetValue <bool>(); Colored = iniConfig["General"]["colored"].GetValue <bool>(); } catch { Author = iniConfig["Setup"]["creatorname"].Value; InlayName = iniConfig["Setup"]["guitarname"].Value; try { // skip exception for templates created with old v2.0.0.71b Frets24 = iniConfig["Setup"]["24frets"].GetValue <bool>(); } catch (Exception e) { Console.WriteLine("Exception: Incomplete INI file - " + e.Message); } Colored = iniConfig["Setup"]["coloredinlay"].GetValue <bool>(); } // Convert the dds files to png var iconFile = Path.Combine(unpackedFolder, "icon.dds"); ExternalApps.Dds2Png(iconFile); var inlayFile = Path.Combine(unpackedFolder, "inlay.dds"); ExternalApps.Dds2Png(inlayFile); if (!File.Exists(iconFile) || !File.Exists(inlayFile)) { MessageBox.Show(errorMessage, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Load png into picBoxes and save paths picIcon.ImageLocation = IconFile = Path.ChangeExtension(iconFile, ".png"); picInlay.ImageLocation = InlayFile = Path.ChangeExtension(inlayFile, ".png"); } }
/// <summary> /// Unpack\modify\load wwise template. /// </summary> /// <returns>Modified wwise template directory.</returns> /// <param name="sourcePath">Source path.</param> /// <param name="audioQuality">Audio quality (-2 to 10).</param> public static string LoadWwiseTemplate(string sourcePath, int audioQuality) { // TODO: add Wwise template validation to ExternalApps var templateDir = Path.Combine(ExternalApps.TOOLKIT_ROOT, "Template"); // Unpack required template here, based on Wwise version installed. switch (Selected) { // add legacy support for RS1 CDLC here case OggFile.WwiseVersion.Wwise2010: // add support for new versions of Wwise for RS2014 here case OggFile.WwiseVersion.Wwise2013: case OggFile.WwiseVersion.Wwise2014: case OggFile.WwiseVersion.Wwise2015: case OggFile.WwiseVersion.Wwise2016: case OggFile.WwiseVersion.Wwise2017: // for fewer headaches ... start with fresh Wwise 2010 Template if (Directory.Exists(templateDir) && Selected == OggFile.WwiseVersion.Wwise2010) { IOExtension.DeleteDirectory(templateDir, true); } ExtractTemplate(Path.Combine(ExternalApps.TOOLKIT_ROOT, Selected + ".tar.bz2")); break; default: throw new FileNotFoundException("<ERROR> Wwise path is incompatible." + Environment.NewLine); } var workUnitPath = Path.Combine(templateDir, "Interactive Music Hierarchy", "Default Work Unit.wwu"); using (var sr = new StreamReader(File.OpenRead(workUnitPath))) { var workUnit = sr.ReadToEnd(); sr.Close(); workUnit = workUnit.Replace("%QF1%", Convert.ToString(audioQuality)); if (Selected != OggFile.WwiseVersion.Wwise2010) { workUnit = workUnit.Replace("%QF2%", "4"); //preview audio } var tw = new StreamWriter(workUnitPath, false); tw.Write(workUnit); tw.Flush(); } // use IOExtensions here for better control // deleting GeneratedSoundBanks gives new hex value to wem/ogg files var bnk = Path.Combine(templateDir, "GeneratedSoundBanks"); if (Directory.Exists(bnk)) { IOExtension.DeleteDirectory(bnk, true); } var orgSfxDir = Path.Combine(templateDir, "Originals", "SFX"); if (Directory.Exists(Path.Combine(templateDir, "Originals"))) { IOExtension.DeleteDirectory(Path.Combine(templateDir, "Originals"), true); } IOExtension.MakeDirectory(orgSfxDir); var cacheWinSfxDir = Path.Combine(templateDir, ".cache", "Windows", "SFX"); if (Directory.Exists(Path.Combine(templateDir, ".cache"))) { IOExtension.DeleteDirectory(Path.Combine(templateDir, ".cache"), true); } IOExtension.MakeDirectory(cacheWinSfxDir); var vcache = Directory.EnumerateFiles(templateDir, "Template.*.validationcache").FirstOrDefault(); if (File.Exists(vcache)) { IOExtension.DeleteFile(vcache); } if (Selected != OggFile.WwiseVersion.Wwise2010) { var dirName = Path.GetDirectoryName(sourcePath); var fileName = Path.GetFileNameWithoutExtension(sourcePath); var dirFileName = Path.Combine(dirName, fileName); var sourcePreviewWave = String.Format("{0}_{1}.wav", dirFileName, "preview"); IOExtension.CopyFile(sourcePreviewWave, Path.Combine(orgSfxDir, "Audio_preview.wav"), true, false); } IOExtension.CopyFile(sourcePath, Path.Combine(orgSfxDir, "Audio.wav"), true, false); return(templateDir); }
public static string DoLikeSongPack(string srcPath, string appId = "248750") { // create SongPack directory structure var dlcName = Path.GetFileName(srcPath).ToLower(); var songPackDir = Path.Combine(Path.GetTempPath(), String.Format("{0}_songpack_p_Pc", dlcName)); var audioWindowDir = Path.Combine(songPackDir, "audio", "windows"); var flatmodelsRsDir = Path.Combine(songPackDir, "flatmodels", "rs"); var gamexblocksNsongsDir = Path.Combine(songPackDir, "gamexblocks", "nsongs"); var gfxassetsAlbumArtDir = Path.Combine(songPackDir, "gfxassets", "album_art"); var manifestSongsDir = Path.Combine(songPackDir, "manifests", String.Format("songs_dlc_{0}", dlcName)); var songsArrDir = Path.Combine(songPackDir, "songs", "arr"); var binGenericDir = Path.Combine(songPackDir, "songs", "bin", "generic"); if (Directory.Exists(songPackDir)) { IOExtension.DeleteDirectory(songPackDir); } Directory.CreateDirectory(songPackDir); Directory.CreateDirectory(audioWindowDir); Directory.CreateDirectory(flatmodelsRsDir); Directory.CreateDirectory(gamexblocksNsongsDir); Directory.CreateDirectory(gfxassetsAlbumArtDir); Directory.CreateDirectory(manifestSongsDir); Directory.CreateDirectory(songsArrDir); Directory.CreateDirectory(binGenericDir); // populate SongPack temporary directory var audioWemFiles = Directory.EnumerateFiles(srcPath, "*.wem", SearchOption.AllDirectories).ToArray(); foreach (var wem in audioWemFiles) { File.Copy(wem, Path.Combine(audioWindowDir, Path.GetFileName(wem))); } var audioBnkFiles = Directory.EnumerateFiles(srcPath, "*.bnk", SearchOption.AllDirectories).ToArray(); foreach (var bnk in audioBnkFiles) { File.Copy(bnk, Path.Combine(audioWindowDir, Path.GetFileName(bnk))); } var xblockFiles = Directory.EnumerateFiles(srcPath, "*.xblock", SearchOption.AllDirectories).ToArray(); foreach (var xblock in xblockFiles) { File.Copy(xblock, Path.Combine(gamexblocksNsongsDir, Path.GetFileName(xblock))); } var albumArtFiles = Directory.EnumerateFiles(srcPath, "*.dds", SearchOption.AllDirectories).ToArray(); foreach (var albumArt in albumArtFiles) { File.Copy(albumArt, Path.Combine(gfxassetsAlbumArtDir, Path.GetFileName(albumArt))); } var jsonFiles = Directory.EnumerateFiles(srcPath, "*.json", SearchOption.AllDirectories).ToArray(); foreach (var json in jsonFiles) { File.Copy(json, Path.Combine(manifestSongsDir, Path.GetFileName(json))); } var hsanFiles = Directory.EnumerateFiles(srcPath, "*.hsan", SearchOption.AllDirectories).ToArray(); foreach (var hsan in hsanFiles) { File.Copy(hsan, Path.Combine(manifestSongsDir, Path.GetFileName(hsan))); } var sngFiles = Directory.EnumerateFiles(srcPath, "*.sng", SearchOption.AllDirectories).ToArray(); foreach (var sng in sngFiles) { File.Copy(sng, Path.Combine(binGenericDir, Path.GetFileName(sng))); } // declare variables one time for use in DDC generation DDCSettings.Instance.LoadConfigXml(); var phraseLen = DDCSettings.Instance.PhraseLen; // removeSus may be depricated in latest DDC but left here for comptiblity var removeSus = DDCSettings.Instance.RemoveSus; var rampPath = DDCSettings.Instance.RampPath; var cfgPath = DDCSettings.Instance.CfgPath; // generate SongPack comment var spComment = "(Remastered by SongPack Maker)"; var addDD = false; if (ConfigRepository.Instance().GetBoolean("ddc_autogen")) { addDD = true; spComment += " " + "(DDC by SongPack Maker)"; } var xmlFiles = Directory.EnumerateFiles(srcPath, "*.xml", SearchOption.AllDirectories).ToArray(); foreach (var xml in xmlFiles) { // completely skip dlc.xml template files if (xml.EndsWith("_RS2014.dlc.xml")) { continue; } var xmlSongPack = Path.Combine(songsArrDir, Path.GetFileName(xml)); File.Copy(xml, xmlSongPack); // skip vocal and showlight xml files if (xml.EndsWith("_vocals.xml") || xml.EndsWith("_showlights.xml")) { continue; } // add DDC to xml arrangement if (addDD) { // check if arrangment has pre existing DD and do not overwrite var songXml = Song2014.LoadFromFile(xml); var mf = new ManifestFunctions(GameVersion.RS2014); if (mf.GetMaxDifficulty(songXml) == 0) { var consoleOutput = String.Empty; // apply DD to xml arrangments... 0 = Ends normally with no error var result = DDCreator.ApplyDD(xmlSongPack, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true); if (result == 1) { Debug.WriteLine(String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(xml), "DDC ended with system error " + consoleOutput)); } else if (result == 2) { Debug.WriteLine(String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(xml), "DDC ended with application error " + consoleOutput)); } } } } // generate new Aggregate Graph var aggGraphPack = new AggregateGraph2014(); aggGraphPack.JsonDB = new List <GraphItem>(); aggGraphPack.HsonDB = new List <GraphItem>(); // used for consoles ONLY aggGraphPack.HsanDB = new GraphItem(); aggGraphPack.MusicgameSong = new List <GraphItemLLID>(); aggGraphPack.SongXml = new List <GraphItemLLID>(); aggGraphPack.ShowlightXml = new List <GraphItemLLID>(); aggGraphPack.ImageArt = new List <GraphItemLLID>(); aggGraphPack.Soundbank = new List <GraphItemLLID>(); aggGraphPack.GameXblock = new List <GraphItem>(); // fix aggregate graph entries, reusing existing Persistent ID var currentPlatform = new Platform(GamePlatform.Pc, GameVersion.RS2014); var aggregateGraphFiles = Directory.EnumerateFiles(srcPath, "*.nt", SearchOption.AllDirectories).ToArray(); foreach (var aggGraph in aggregateGraphFiles) { var agg = LoadFromFile(aggGraph); foreach (var json in agg.JsonDB) { json.Canonical = String.Format(CANONICAL_MANIFEST_PC, dlcName); json.RelPathDirectory = json.Canonical; json.Tag = new List <string>(); json.Tag.Add(TagValue.Database.GetDescription()); json.Tag.Add(TagValue.JsonDB.GetDescription()); json.UUID = IdGenerator.Guid(); json.RelPathFile = String.Format("{0}.json", json.Name); } aggGraphPack.JsonDB.AddRange(agg.JsonDB); aggGraphPack.MusicgameSong.AddRange(agg.MusicgameSong); aggGraphPack.SongXml.AddRange(agg.SongXml); aggGraphPack.ShowlightXml.AddRange(agg.ShowlightXml); aggGraphPack.ImageArt.AddRange(agg.ImageArt); aggGraphPack.Soundbank.AddRange(agg.Soundbank); aggGraphPack.GameXblock.AddRange(agg.GameXblock); } // create a single hsanDB entry aggGraphPack.HsanDB.Name = String.Format("songs_dlc_{0}", dlcName); aggGraphPack.HsanDB.Canonical = String.Format(CANONICAL_MANIFEST_PC, dlcName); aggGraphPack.HsanDB.RelPathDirectory = aggGraphPack.HsanDB.Canonical; aggGraphPack.HsanDB.Tag = new List <string>(); aggGraphPack.HsanDB.Tag.Add(TagValue.Database.GetDescription()); aggGraphPack.HsanDB.Tag.Add(TagValue.HsanDB.GetDescription()); aggGraphPack.HsanDB.UUID = IdGenerator.Guid(); aggGraphPack.HsanDB.RelPathFile = String.Format("{0}.hsan", aggGraphPack.HsanDB.Name); var aggregateGraphFileName = Path.Combine(songPackDir, String.Format("{0}_aggregategraph.nt", dlcName)); using (var fs = new FileStream(aggregateGraphFileName, FileMode.Create)) using (var ms = new MemoryStream()) { aggGraphPack.Serialize(ms); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); } MergeHsanFiles(songPackDir, dlcName, manifestSongsDir); var appIdFile = Path.Combine(songPackDir, "appid.appid"); File.WriteAllText(appIdFile, appId); var toolkitVersionFile = Path.Combine(songPackDir, "toolkit.version"); using (var fs = new FileStream(toolkitVersionFile, FileMode.Create)) using (var ms = new MemoryStream()) { DLCPackageCreator.GenerateToolkitVersion(ms, packageVersion: "SongPack Maker v1.2", packageComment: spComment); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); } var rootFlatFile = Path.Combine(flatmodelsRsDir, "rsenumerable_root.flat"); using (var fs = new FileStream(rootFlatFile, FileMode.Create)) using (var ms = new MemoryStream(Resources.rsenumerable_root)) { ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); } var songFlatFile = Path.Combine(flatmodelsRsDir, "rsenumerable_song.flat"); using (var fs = new FileStream(songFlatFile, FileMode.Create)) using (var ms = new MemoryStream(Resources.rsenumerable_song)) { ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); } return(songPackDir); }
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()); IOExtension.MoveDirectory(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); } IOExtension.DeleteDirectory(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 (!GeneralExtension.IsInDesignMode) { IOExtension.DeleteDirectory(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); }
private void LoadImages(string cisPath) { // init image array and clear pics InitImageArray(); InitImagePics(); if (!File.Exists(cisPath)) { return; } // background worker does not work with this method because it updates the // form/controls, so using alternate method to report progress const int numSteps = 7; // max number of times progress change is reported var step = (int)Math.Round(1.0 / (numSteps + 2) * 100, 0); var progress = 10; ProcessStarted(progress, "Loading images from Intro Screens Template file ..."); // create temp folder for unzipping *.cis file var tmpUnzipDir = Path.Combine(tmpWorkDir, "cis_unzip"); if (Directory.Exists(tmpUnzipDir)) { IOExtension.DeleteDirectory(tmpUnzipDir, true); } if (!Directory.Exists(tmpUnzipDir)) { Directory.CreateDirectory(tmpUnzipDir); } var srcPath = cisPath; var destPath = tmpUnzipDir; ExternalApps.ExtractZip(srcPath, destPath); // Open the setup.smb INI file Configuration iniConfig = Configuration.LoadFromFile(Path.Combine(tmpUnzipDir, "setup.smb")); txtAuthor.Text = iniConfig["General"]["author"].Value; txtSeqName.Text = iniConfig["General"]["seqname"].Value; txtAuthor.ForeColor = Color.Black; txtSeqName.ForeColor = Color.Black; // Convert the dds files to png IEnumerable <string> ismList = Directory.EnumerateFiles(tmpUnzipDir, "*.dds"); foreach (string imagePath in ismList) { progress += step; ProcessStarted(progress, "Converting images to PNG files ... " + progress); ExternalApps.Dds2Png(imagePath); for (int i = 0; i < imageArray.GetUpperBound(0); i++) { if (Path.GetFileName(imageArray[i, 2]) == Path.GetFileName(imagePath)) { // Load user image paths and png into picBoxes imageArray[i, 3] = Path.ChangeExtension(imagePath, ".png"); switch (Path.GetFileName(imagePath)) { case "introsequence_i15.dds": picBackground.ImageLocation = imageArray[i, 3]; lblBackground.Visible = false; break; case "introsequence_i11.dds": picCredits.ImageLocation = imageArray[i, 3]; lblCredits.Visible = false; break; case "ubisoft_logo.png.dds": picUbi.ImageLocation = imageArray[i, 3]; lblUbi.Visible = false; break; case "gamebryo_logo.png.dds": picLightspeed.ImageLocation = imageArray[i, 3]; lblLightspeed.Visible = false; break; case "intro_studio_logos.png.dds": picPedals.ImageLocation = imageArray[i, 3]; lblPedals.Visible = false; break; case "rocksmith_2014_logo.dds": picTitle.ImageLocation = imageArray[i, 3]; lblTitle.Visible = false; break; } } } } ProcessCompleted(null, null); }
static int Main(string[] args) { try { Console.SetWindowSize(85, 40); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; } catch { /* DO NOTHING */ } #if (DEBUG) // give the progie some dumby file to work on args = new string[] { "D:\\Temp\\Test" }; #endif // catch if there are no cmd line arguments if (args.GetLength(0) == 0) { args = new string[] { "?" } } ; if (args[0].Contains("?") || args[0].ToLower().Contains("help")) { Console.WriteLine(@"Rocksmith 2012 CDCL Converter DropletApp"); Console.WriteLine(@" - Version: " + ProjectVersion()); Console.WriteLine(@" Copyright (C) 2015 CST Developers"); Console.WriteLine(); Console.WriteLine(@" - Purpose: Converts RS2012 CDLC dat file to RS2014 CDLC psarc file"); Console.WriteLine(); Console.WriteLine(@" - Usage: Drag/Drop folder with *.dat files onto the console executable icon."); Console.Read(); return(0); } Console.WriteLine(@"Initializing Rocksmith 2012 CDLC Converter CLI ..."); Console.WriteLine(); var srcDir = args[0]; // iterate through cdlc folders and find *.dat files var cdlcFilesPaths = Directory.GetFiles(srcDir, "*.dat", SearchOption.AllDirectories); var cdlcSaveDir = Path.Combine(Path.GetDirectoryName(cdlcFilesPaths[0]), "Converted CDLC"); if (!Directory.Exists(cdlcSaveDir)) { Directory.CreateDirectory(cdlcSaveDir); } foreach (var cdlcFilePath in cdlcFilesPaths) { // Unpack Console.WriteLine(@"Unpacking: " + Path.GetFileName(cdlcFilePath)); var unpackedDirPath = Path.Combine(Path.GetDirectoryName(cdlcFilePath), String.Format("{0}_Pc", Path.GetFileNameWithoutExtension(cdlcFilePath))); var unpackedDest = Path.GetDirectoryName(cdlcFilePath); if (Directory.Exists(unpackedDirPath)) { IOExtension.DeleteDirectory(unpackedDirPath); } try { Packer.Unpack(cdlcFilePath, unpackedDest, null, true); // Load Package Data Console.WriteLine(@"Converting RS2012 CDLC to RS2014 CDLC ..."); DLCPackageData info = new DLCPackageData(); // DLCPackageData specific to RS2 info = DLCPackageData.RS1LoadFromFolder(unpackedDirPath, new Platform(GamePlatform.Pc, GameVersion.RS2014), true); // Convert Audio to Wem Format info = ConvertAudio(info); // Update Album Art info = ConvertAlbumArt(cdlcFilePath, info); foreach (var arr in info.Arrangements) { Console.WriteLine(@"Converting XML Arrangement: " + arr); arr.SongFile.File = ""; if (arr.ArrangementType != ArrangementType.Vocal) { UpdateXml(arr, info); } } // Repack var cdlcVersion = "c1"; // conversion 1 var cdlcFileName = StringExtensions.GetValidShortFileName(info.SongInfo.Artist, info.SongInfo.SongDisplayName, cdlcVersion, ConfigRepository.Instance().GetBoolean("creator_useacronyms")); var cdlcSavePath = Path.Combine(cdlcSaveDir, cdlcFileName); Console.WriteLine(@"Repacking as RS2014 CDLC: " + cdlcFileName + @".psarc"); Console.WriteLine(""); DLCPackageCreator.Generate(cdlcSavePath, info, new Platform(GamePlatform.Pc, GameVersion.RS2014), pnum: 1); IOExtension.DeleteDirectory(unpackedDirPath); } catch (Exception ex) { Console.WriteLine(@"Conversion could not be completed: " + ex.Message); Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine(@"Done Processing CDLC Folder ..."); Console.WriteLine(@"Converted CDLC Saved To: " + cdlcSaveDir); Console.WriteLine(@"Remember ... CDLC Arrangements, Tones, Volumes, etc"); Console.WriteLine(@"can be modified using the toolkit GUI, Creator tab"); Console.WriteLine(); Console.WriteLine(@"Press any key to continue ..."); Console.Read(); return(0); }
private int ApplyPackageDD(string srcPath, int phraseLen, bool removeSus, string rampPath, string cfgPath, out string consoleOutput, bool overWrite = false, bool keepLog = false) { int result = 0; // Ends normally with no error DLCPackageData packageData; consoleOutput = String.Empty; try { using (var psarcOld = new PsarcPackager()) packageData = psarcOld.ReadPackage(srcPath); } catch (Exception ex) { consoleOutput = "Error Reading : " + srcPath + Environment.NewLine + ex.Message; return(-1); // Read Error } // Update arrangement song info foreach (Arrangement arr in packageData.Arrangements) { if (chkGenArrIds.Checked) { // generate new AggregateGraph arr.SongFile = new RocksmithToolkitLib.DLCPackage.AggregateGraph.SongFile() { File = "" }; // generate new Arrangement IDs arr.Id = IdGenerator.Guid(); arr.MasterId = RandomGenerator.NextInt(); } // skip vocal and showlight arrangements if (arr.ArrangementType == ArrangementType.Vocal || arr.ArrangementType == ArrangementType.ShowLight) { continue; } // validate (QC) RS2014 packageData if (packageData.GameVersion == GameVersion.RS2014) { // validate existing SongInfo var songXml = Song2014.LoadFromFile(arr.SongXml.File); songXml.ArtistName = packageData.SongInfo.Artist.GetValidAtaSpaceName(); songXml.Title = packageData.SongInfo.SongDisplayName.GetValidAtaSpaceName(); songXml.AlbumName = packageData.SongInfo.Album.GetValidAtaSpaceName(); songXml.ArtistNameSort = packageData.SongInfo.ArtistSort.GetValidSortableName(); songXml.SongNameSort = packageData.SongInfo.SongDisplayNameSort.GetValidSortableName(); songXml.AlbumNameSort = packageData.SongInfo.AlbumSort.GetValidSortableName(); songXml.AverageTempo = Convert.ToSingle(packageData.SongInfo.AverageTempo.ToString().GetValidTempo()); songXml.AlbumYear = packageData.SongInfo.SongYear.ToString().GetValidYear(); // update packageData with validated SongInfo packageData.SongInfo.Artist = songXml.ArtistName; packageData.SongInfo.SongDisplayName = songXml.Title; packageData.SongInfo.Album = songXml.AlbumName; packageData.SongInfo.ArtistSort = songXml.ArtistNameSort; packageData.SongInfo.SongDisplayNameSort = songXml.SongNameSort; packageData.SongInfo.AlbumSort = songXml.AlbumNameSort; packageData.SongInfo.AverageTempo = (int)songXml.AverageTempo; packageData.SongInfo.SongYear = Convert.ToInt32(songXml.AlbumYear); // write updated xml arrangement using (var stream = File.Open(arr.SongXml.File, FileMode.Create)) songXml.Serialize(stream, false); // restore arrangment comments Song2014.WriteXmlComments(arr.SongXml.File, arr.XmlComments); } // apply DD to xml arrangments... 0 = Ends normally with no error result = DDCreator.ApplyDD(arr.SongXml.File, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true, keepLog); if (result == 0) // Ends normally with no error { /* DO NOTHING */ } else if (result == 1) // Ends with system error { consoleOutput = "DDC System Error: " + Environment.NewLine + "Arrangment file: " + Path.GetFileName(arr.SongXml.File) + Environment.NewLine + "CDLC file: " + srcPath; return(result); } else if (result == 2) // Ends with application error { consoleOutput = "DDC Application Error: " + Environment.NewLine + "Arrangment file: " + Path.GetFileName(arr.SongXml.File) + Environment.NewLine + "CDLC file: " + srcPath; return(result); } if (keepLog) { var unpackedDir = Path.GetDirectoryName(Path.GetDirectoryName(arr.SongXml.File)); var logFiles = Directory.EnumerateFiles(unpackedDir, "*.log", SearchOption.AllDirectories); var clogDir = Path.Combine(Path.GetDirectoryName(srcPath), "DDC_Log"); var plogDir = Path.Combine(clogDir, Path.GetFileNameWithoutExtension(srcPath).StripPlatformEndName().Replace("_DD", "").Replace("_NDD", "")); if (!Directory.Exists(clogDir)) { Directory.CreateDirectory(clogDir); } IOExtension.DeleteDirectory(plogDir); Directory.CreateDirectory(plogDir); foreach (var logFile in logFiles) { File.Copy(logFile, Path.Combine(plogDir, Path.GetFileName(logFile))); } } // put arrangment comments in correct order Song2014.WriteXmlComments(arr.SongXml.File); } if (chkGenArrIds.Checked) { // add comment to ToolkitInfo to identify CDLC var arrIdComment = packageData.ToolkitInfo.PackageComment; if (String.IsNullOrEmpty(arrIdComment)) { arrIdComment = TKI_ARRID; } else if (!arrIdComment.Contains(TKI_ARRID)) { arrIdComment = arrIdComment + " " + TKI_ARRID; } packageData.ToolkitInfo.PackageComment = arrIdComment; } // add comment to ToolkitInfo to identify CDLC var remasterComment = packageData.ToolkitInfo.PackageComment; if (String.IsNullOrEmpty(remasterComment)) { remasterComment = TKI_REMASTER; } else if (!remasterComment.Contains(TKI_REMASTER)) { remasterComment = remasterComment + " " + TKI_REMASTER; } packageData.ToolkitInfo.PackageComment = remasterComment; // add default package version if missing if (String.IsNullOrEmpty(packageData.ToolkitInfo.PackageVersion)) { packageData.ToolkitInfo.PackageVersion = "1"; } else { packageData.ToolkitInfo.PackageVersion = packageData.ToolkitInfo.PackageVersion.GetValidVersion(); } // validate packageData (important) packageData.Name = packageData.Name.GetValidKey(); // DLC Key var destPath = srcPath; if (!overWrite) { destPath = GenerateDdcFilePath(srcPath); } try { // regenerates the archive with DDC changes and repairs using (var psarcNew = new PsarcPackager(true)) psarcNew.WritePackage(destPath, packageData, srcPath); } catch (Exception ex) { consoleOutput = "Error Writing: " + srcPath + Environment.NewLine + ex.Message; result = -2; // Write Error } return(result); }
private void UpdateCache() { // unpack cache.psarc const int numSteps = 8; // max number of times ReportProgress will be called var step = (int)Math.Round(1.0 / (numSteps + 2) * 100, 0); int progress = 0; progress += step; ProcessStarted(progress, "Unpacking cache file ... "); var srcPath = Path.Combine(rsDir, "cache.psarc"); var destPath = Path.Combine(rsDir, "cache.psarc.org"); // backup the original cache.psarc and never overwrite it if (!File.Exists(destPath)) { File.Copy(srcPath, destPath, false); } var tmpCisDir = Path.Combine(tmpWorkDir, "cis_cache"); if (Directory.Exists(tmpCisDir)) { IOExtension.DeleteDirectory(tmpCisDir, true); } // CRITCAL PATH Directory.CreateDirectory(Path.Combine(tmpCisDir, "cache4\\gfxassets\\views")); destPath = tmpCisDir; Packer.Unpack(srcPath, destPath); // ExternalApps.UnpackPsarc(srcPath, destPath, DLCInlayCreator.GlobalTitlePlatform); // convert user png images to dds images for (int i = 0; i < 5; i++) { progress += step; ProcessStarted(progress, "Converting user PNG images ..."); if (imageArray[i, 3] != null) // user has specified a replacement image { // CRITICAL PATH AND ARGS srcPath = imageArray[i, 3]; destPath = Path.Combine(tmpCisDir, "cache4\\gfxassets\\views", Path.GetFileName(imageArray[i, 2])); ExternalApps.Png2Dds(srcPath, destPath, ImageHandler.Size2IntX(imageArray[i, 1]), ImageHandler.Size2IntY(imageArray[i, 1])); } } // update user images to zip file progress += step; ProcessStarted(progress, "Injecting user images ..."); // SUPER CRITICAL PATH AND ARGS var rootDir = string.Format("cache_{0}", DLCInlayCreator.GlobalTitlePlatform); srcPath = Path.Combine(tmpCisDir, "cache4\\gfxassets"); destPath = Path.Combine(tmpCisDir, rootDir, "cache4.7z"); ExternalApps.InjectZip(srcPath, destPath, true); // repack cache.psarc progress += step; ProcessStarted(progress, "Repacking cache file ..."); srcPath = Path.Combine(tmpCisDir, rootDir); destPath = Path.Combine(rsDir, "cache.psarc"); Packer.Pack(srcPath, destPath); // ExternalApps.RepackPsarc(srcPath, destPath, DLCInlayCreator.GlobalTitlePlatform); ProcessCompleted(null, null); }