public void RepackBsa(List <InformationOrder> bsaOrders, string bsarchGameParameter, bool isMultithread, bool verbose) { // Progresser.EventStart(ProgressRepacking); // foreach (var order in bsaOrders) { Progresser.ChangeProgress(ProgressRepacking, bsaOrders.Count); // if (verbose) { Logger.Log("Repacking {0}", order.FileSource.Name); } // var dirPath = FileUtils.GetBsaTempDirectory(order.FileSource); var dir = new DirectoryInfo(dirPath); // if (dir.Exists) { var res = ExternalTools.CallBsaPack(order.FileSource.FullName, dir.FullName, order.IsBsaFormatCompressed, bsarchGameParameter, isMultithread, verbose); if (verbose) { foreach (var re in res) { Logger.Log(re); } } } } // Logger.Log("Repacking BSA complete. {0} packing done ", bsaOrders.Count); Progresser.EventEnd(ProgressRepacking); }
public void Merge(ConfigurationMain mainCfg, List <InformationCopy> copies) { Progresser.EventStart(ProgressMerge); // foreach (InformationCopy informationCopy in copies) { Progresser.ChangeProgress(ProgressMerge, copies.Count); FileUtils.ExecuteCopyOrDelete(informationCopy); } // Logger.Log("Merge complete. {0} files copied ", copies.Count); Progresser.EventEnd(ProgressMerge); }
public void DeleteFiles(ConfigurationMain mainCfg, List <InformationFileDeletion> deletes) { Progresser.EventStart(ProgressMerge); // foreach (InformationFileDeletion informationFileDeletion in deletes) { Progresser.ChangeProgress(ProgressMerge, deletes.Count); informationFileDeletion.FileToDelete.Refresh(); if (informationFileDeletion.FileToDelete.Exists) { informationFileDeletion.FileToDelete.Delete(); } } // Logger.Log("Merge complete. {0} files copied ", deletes.Count); Progresser.EventEnd(ProgressMerge); }
public void CopyBsaAsLoose(List <InformationOrder> bsaOrders, ConfigurationMain mainCfg) { Progresser.EventStart(ProgressCopyBsaAsLoose); // foreach (var order in bsaOrders) { Progresser.ChangeProgress(ProgressCopyBsaAsLoose, bsaOrders.Count); // if (mainCfg.IsVerbose) { Logger.Log("Copying BSA as loose files {0}", order.FileSource.Name); } // var dirPath = FileUtils.GetBsaTempDirectory(order.FileSource); var bsaDir = new DirectoryInfo(dirPath); if (!bsaDir.Exists) { throw new DirectoryNotFoundException(string.Format("BSA temp directory don't exist for unknow reason, unpacking seems to have fails. Canceling copy and deletion of bsa file: {0}", dirPath)); } if (mainCfg.IsVerbose) { Logger.Log("Copying as loose files: {0}", order.FileSource.Name); } Dictionary <long, InformationCopy> copies = new Dictionary <long, InformationCopy>(); FileUtils.CopyDirContent(bsaDir, order.FileSource.Directory, copies, mainCfg.IsMergeAssertCase); string title = string.Format("{0}: {1}", ProgressCopyBsaAsLoose, order.FileSource.Name); foreach (InformationCopy informationCopy in copies.Values) { Progresser.ChangeProgress(title, copies.Count); FileUtils.ExecuteMove(informationCopy); } // if (mainCfg.IsVerbose) { Logger.Log("Deleting BSA {0}", order.FileSource.Name); } // order.FileSource.Delete(); } // Logger.Log("Copy BSA as loose files complete. {0} archives done ", bsaOrders.Count); Progresser.EventEnd(ProgressCopyBsaAsLoose); }
public void CopyBsaAsLooseSimplified(List <InformationOrder> bsaOrders, ConfigurationMain mainCfg) { // Progresser.EventStart(ProgressUnpacking); // foreach (var order in bsaOrders) { Progresser.ChangeProgress(ProgressUnpacking, bsaOrders.Count); // if (mainCfg.IsVerbose) { Logger.Log("Unpacking {0}", order.FileSource.Name); } // if (order.FileSource.Directory == null) { Logger.Log("Bsa unpacking bad directory for {0}", order.FileSource.FullName, TypeLog.Error); continue; } // var dir = order.FileSource.Directory; // try { ExternalTools.CallBsaUnPack(order.FileSource.FullName, dir.FullName, mainCfg.IsUseMultithreading, mainCfg.IsVerbose); // if (mainCfg.IsVerbose) { Logger.Log("Deleting BSA {0}", order.FileSource.Name); } order.FileSource.Delete(); } catch (Exception e) { Logger.Log(e); } // } // Logger.Log("Unpacking BSA complete. {0} unpacking done ", bsaOrders.Count); Progresser.EventEnd(ProgressUnpacking); }
public void UnpackBsa(List <InformationOrder> bsaOrders, ConfigurationMain mainCfg) { // Progresser.EventStart(ProgressUnpacking); // foreach (var order in bsaOrders) { Progresser.ChangeProgress(ProgressUnpacking, bsaOrders.Count); // if (mainCfg.IsVerbose) { Logger.Log("Unpacking {0}", order.FileSource.Name); } // if (order.FileSource.Directory == null) { Logger.Log("Bsa unpacking error for {0} unrecognized file source directory", order.FileSource.FullName, TypeLog.Error); continue; } // var dirPath = FileUtils.GetBsaTempDirectory(order.FileSource); var dir = new DirectoryInfo(dirPath); // if (!dir.Exists) { dir.Create(); // try { ExternalTools.CallBsaUnPack(order.FileSource.FullName, dir.FullName, mainCfg.IsUseMultithreading, mainCfg.IsVerbose); } catch (Exception e) { Logger.Log(e); } } } // Logger.Log("Unpacking BSA complete. {0} unpacking done ", bsaOrders.Count); Progresser.EventEnd(ProgressUnpacking); }
public void CleanBsa(List <InformationOrder> bsaOrders, bool verbose) { Progresser.EventStart(ProgressCleaningBsa); // foreach (var order in bsaOrders) { Progresser.ChangeProgress(ProgressCleaningBsa, bsaOrders.Count); // if (verbose) { Logger.Log("Cleaning Temp BSA {0}", order.FileSource.Name); } // var dirPath = FileUtils.GetBsaTempDirectory(order.FileSource); // //Directory.Delete(dirPath, true); FileUtils.DeleteCompleteDirectory(new DirectoryInfo(dirPath)); } // Logger.Log("Cleaning Temp BSA complete. {0} cleaning done ", bsaOrders.Count); Progresser.EventEnd(ProgressCleaningBsa); }
public void GetFileInfos(DirectoryInfo source, List<InformationFile> result, bool isBsa, string eventName, ConfigurationMain mainCfg, int fileCount, bool firstPass) { // var extension = isBsa ? ArchiveExtensionList.List : TextureExtensionList.List; // // // Get each file into the new directory. foreach (FileInfo fileSource in source.GetFiles()) { //ignore no dds file if (!extension.Any(e => string.Equals(e, fileSource.Extension, StringComparison.InvariantCultureIgnoreCase))) { continue; } //#if DEBUG // Thread.CurrentThread.Join(10); //#endif // // Stop here if all validation failed if (!isBsa) { bool passValidation = mainCfg.Search.IsSearchEnabled; // if (!passValidation) { foreach (var scalePass in mainCfg.Passes) { if (scalePass.Selection.GetValidation(Path.GetFileNameWithoutExtension(fileSource.FullName))) { passValidation = true; break; } } } // if (!passValidation) continue; } else { if (!mainCfg.PassBsa.Selection.GetValidation(Path.GetFileNameWithoutExtension(fileSource.FullName))) { continue; } } // if (mainCfg.IsVerbose) { var msg = string.Format("Found: {0}", fileSource.FullName); // Logger.Log(msg); } // Progresser.ChangeProgress(eventName, fileCount); // result.Add(new InformationFile(fileSource, fileSource)); } // if (isBsa && !firstPass) { return; } // Copy each subdirectory using recursion. foreach (DirectoryInfo diSourceSubDir in source.GetDirectories()) { if (firstPass && !mainCfg.Selection.GetValidation(diSourceSubDir.Name)) continue; // GetFileInfos(diSourceSubDir, result, isBsa, eventName, mainCfg, fileCount, false); } }
public void PrepareMerge(ConfigurationMain mainCfg, List <InformationCopy> copies) { if (mainCfg.IsVerbose) { Logger.Log("Preparing a mods merge"); } // var source = new DirectoryInfo(mainCfg.PathSource); // var target = new DirectoryInfo(mainCfg.PathMergeDirectory); if (!target.Exists) { target.Create(); } // List <DirectoryInfo> validatedDirectories = new List <DirectoryInfo>(); foreach (DirectoryInfo directoryInfo in source.GetDirectories()) { if (mainCfg.Selection.GetValidation(directoryInfo.Name)) { validatedDirectories.Add(directoryInfo); } } // List <InformationMerge> merges = new List <InformationMerge>(); // if (string.IsNullOrEmpty(mainCfg.PathMergePriorityFile)) { foreach (DirectoryInfo directoryInfo in validatedDirectories) { merges.Add(new InformationMerge(directoryInfo, target)); } } else { //read cvs file List <InformationPriority> priorities = new List <InformationPriority>(); using (var reader = new StreamReader(mainCfg.PathMergePriorityFile)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); int prio; if (!int.TryParse(values[0].Replace('"', ' ').Trim(), out prio)) { continue; } priorities.Add(new InformationPriority(prio, values[1].Replace('"', ' ').Trim())); } } // //foreach (var priority in priorities.OrderBy(e => e.Priority)) //{ // var dir = validatedDirectories.FirstOrDefault(d => Equals(d.Name, priority.ModName)); // if (dir != null) // { // merges.Add(new InformationMerge(dir, target)); // if (mainCfg.IsVerbose) // { // Logger.Log(string.Format("Mod \"{0}\" added with a priority of {1}", priority.ModName, priority.Priority)); // } // } // else // { // throw new KeyNotFoundException(string.Format("Mod {0} wasn't found in the source directory", priority.ModName)); // } //} // List <InformationPriority> confirmedPriorities = new List <InformationPriority>(); foreach (var vdir in validatedDirectories) { var prio = priorities.FirstOrDefault(d => Equals(d.ModName, vdir.Name)); if (prio != null) { confirmedPriorities.Add(prio); } else { throw new KeyNotFoundException(string.Format("Mod {0} wasn't found in the priority file", vdir.Name)); } } foreach (InformationPriority priority in confirmedPriorities.OrderBy(e => e.Priority)) { var dir = validatedDirectories.FirstOrDefault(d => Equals(d.Name, priority.ModName)); if (dir != null) { merges.Add(new InformationMerge(dir, target)); } else { throw new DirectoryNotFoundException(string.Format("Directory for {0} wasn't found", priority.ModName)); } // if (mainCfg.IsVerbose) { Logger.Log(string.Format("Mod \"{0}\" added with a priority of {1}", priority.ModName, priority.Priority)); } } } // Dictionary <long, InformationCopy> preparedCopies = new Dictionary <long, InformationCopy>(); if (mainCfg.IsMergeDeleteIfNotInSource) { Progresser.EventStart(ProgressMergeDeleteIfNotInSource); FileUtils.AnalyseSourceForDeleteWhenMerge(target, preparedCopies, mainCfg.IsVerbose); Progresser.EventEnd(ProgressMergeDeleteIfNotInSource); } // Progresser.EventStart(ProgressListingMergingOp); if (mainCfg.IsVerbose) { Logger.Log("Listing merging copies operations"); } // foreach (var merge in merges) { // if (mainCfg.IsVerbose) { Logger.Log("Listing copies operations for {0}", merge.DirSource.Name); } // Progresser.ChangeProgress(ProgressListingMergingOp, merges.Count); FileUtils.CopyDirContent(merge.DirSource, merge.DirTarget, preparedCopies, mainCfg.IsMergeAssertCase); // } // copies.AddRange(preparedCopies.Values.Where(e => e.Confirmed)); // if (mainCfg.IsVerbose) { Logger.Log(string.Format("Copying mods files into merged directory: {0} copy operations", copies.Count)); } // Progresser.EventEnd(ProgressListingMergingOp); }
private void PrepareFileOrder(List <InformationFile> files, ConfigurationMain mainCfg, bool isBsa, InformationFile file, List <InformationOrder> orders, List <InformationOrder> discardedOrders, List <InformationOrder> searchResult, string eventName) { if (mainCfg.IsVerbose) { Logger.Log(string.Format("Analyzing {0}", file.FileSource.FullName)); } // Progresser.ChangeProgress(eventName, files.Count); // var confirmOrder = false; var isBsaMustBeDecompressed = false; var order = new InformationOrder(file.FileSource, file.FileTarget) { IsUseBackup = mainCfg.IsUseBackup && mainCfg.IsBackupActivated }; // if (isBsa) { if (mainCfg.PassBsa.Enabled && mainCfg.PassBsa.Selection.GetValidation(Path.GetFileNameWithoutExtension(file.FileSource.FullName))) { order.IsBsaFormatCompressed = ExternalTools.CallBsarchProperty(file.FileSource.FullName, "*COMPRESSED"); // if (mainCfg.PassBsa.IsCheckFormatIsGameFormat) { string searchForFile = "sse"; switch (mainCfg.PassBsa.GameParameter) { case "fo4": searchForFile = "Fallout 4 General"; break; case "fo4dds": searchForFile = "Fallout 4 DDS"; order.IsBsaFormatCompressed = true; break; } isBsaMustBeDecompressed = ExternalTools.CallBsarchProperty(file.FileSource.FullName, searchForFile); } else if (mainCfg.PassBsa.IsCopyAsLoose) { if (mainCfg.PassBsa.IsTreatNonTextureArchives) { isBsaMustBeDecompressed = true; } else { foreach (var texExtensionName in TextureExtensionList.List) { isBsaMustBeDecompressed = ExternalTools.CallBsarchList(file.FileSource.FullName, texExtensionName); if (isBsaMustBeDecompressed) { break; } } } } // confirmOrder |= isBsaMustBeDecompressed; } } else if (mainCfg.HasTextureOperation() && GetCurrentImageSize(order, mainCfg.IsVerbose)) { // foreach (var scalePass in mainCfg.Passes) { // Stop here if validation failed if (!scalePass.Selection.GetValidation(Path.GetFileNameWithoutExtension(file.FileSource.FullName))) { continue; } // if (scalePass.TypePass == TypePass.ApplyGmic) { order.IsGmicPass = true; order.GmicCommands.Add(scalePass.Command); confirmOrder = true; continue; } // if (scalePass.TypePass == TypePass.ApplyCustom) { order.IsCustomPass = true; order.IsApplyOnPng = scalePass.IsApplyOnPng; order.CustomCommands.Add(scalePass.Command); confirmOrder = true; continue; } // if (scalePass.TypePass == TypePass.Force) { order.IsDoTexconv = true; order.TargetSize.TypeTexCompression = scalePass.TypeTexCompression; confirmOrder = true; continue; } // string f = order.TargetSize.Format; if (!string.IsNullOrEmpty(scalePass.ForceFormat) && !string.Equals(scalePass.ForceFormat, f, StringComparison.OrdinalIgnoreCase)) { order.IsDoTexconv = true; order.TargetSize.Format = scalePass.ForceFormat; order.TargetSize.TypeTexCompression = scalePass.TypeTexCompression; confirmOrder = true; continue; } // // int w = order.TargetSize.Width; int h = order.TargetSize.Height; int m = order.TargetSize.Mipmaps; // int div = 1; int mult = 1; bool applyPass = false; // if (scalePass.TypePass == TypePass.CorrectSize) { //correct to nearby power of 2 value if (!TablePowerOfTwo.ContainsKey(w) || !TablePowerOfTwo.ContainsKey(h)) { w = order.TargetSize.Width = FindNearPowerOf2Value(w); h = order.TargetSize.Height = FindNearPowerOf2Value(h); applyPass = true; // if (mainCfg.IsVerbose) { Logger.Log( "{0} size is not a power of 2 and will be resized to width=>{1} height=>{2}", file.FileSource.Name, w, h, TypeLog.Warning); } } } // find new size and new mipmaps needed if (scalePass.TypePass == TypePass.DownscaleFactor) { // division method if ((w / scalePass.WantedFactor >= scalePass.WantedMinSize && h / scalePass.WantedFactor >= scalePass.WantedMinSize)) { div = scalePass.WantedFactor; applyPass = true; } } // if (scalePass.TypePass == TypePass.DownscaleFixed) { // fixed size method while ((w / div > scalePass.WantedSize || h / div > scalePass.WantedSize) && (w / div > scalePass.WantedMinSize && h / div > scalePass.WantedMinSize)) { div *= 2; applyPass = true; } } // find new size and new mipmaps needed if (scalePass.TypePass == TypePass.UpscaleFactor) { // division method if ((w * scalePass.WantedFactor < scalePass.WantedMaxSize && h * scalePass.WantedFactor < scalePass.WantedMaxSize)) { mult = scalePass.WantedFactor; applyPass = true; } } // if (scalePass.TypePass == TypePass.UpscaleFixed) { // fixed size method while ((w * mult < scalePass.WantedSize || h * mult < scalePass.WantedSize) && (w * mult < scalePass.WantedMaxSize && h * mult < scalePass.WantedMaxSize)) { mult *= 2; applyPass = true; } } // if (scalePass.TypePass == TypePass.CorrectMipmaps && m > 1) { var newSizeToSonsiderFormips = Math.Max(w, h); if (TablePowerOfTwo.ContainsKey(newSizeToSonsiderFormips)) { var goodMipmap = TablePowerOfTwo[newSizeToSonsiderFormips]; if (m != goodMipmap) { m = goodMipmap; applyPass = true; } } } // if (scalePass.TypePass == TypePass.ForceMipmaps) { m = 2; applyPass = true; } // if (applyPass) { // var newWidth = (w / div) * mult; var newHeight = (h / div) * mult; // if (!TablePowerOfTwo.ContainsKey(newWidth) || !TablePowerOfTwo.ContainsKey(newHeight)) { Logger.Log("Texture size is not a power of 2 for {0} (current size: {1}/{2})", file.FileSource.FullName, newWidth, newHeight, TypeLog.Warning); //continue; } // int newMipmap = 1; // if (m > 1) { var newSizeToSonsiderFormips = Math.Max(newWidth, newHeight); if (TablePowerOfTwo.ContainsKey(newSizeToSonsiderFormips)) { newMipmap = TablePowerOfTwo[newSizeToSonsiderFormips]; } else { newMipmap = 0; } } // order.IsDoTexconv = true; order.TargetSize.Width = newWidth; order.TargetSize.Height = newHeight; order.TargetSize.Mipmaps = newMipmap; confirmOrder = true; } } } // if (mainCfg.IsRefreshBackup && mainCfg.IsBackupActivated) { if (((isBsa && isBsaMustBeDecompressed) || !isBsa) && (!order.FileTarget.Exists || order.FileSource.Length > order.FileTarget.Length)) { order.IsRefreshBackup = true; confirmOrder = true; } } // if (mainCfg.IsRecopyOriginal && mainCfg.IsBackupActivated) { if (((isBsa && isBsaMustBeDecompressed) || !isBsa) && (!order.FileSource.Exists || order.FileTarget.Length > order.FileSource.Length)) { order.IsRecopyOriginal = true; confirmOrder = true; } } // if (order != null) { bool searchValidation = true; // if (mainCfg.Search.IsSearchEnabled && !isBsa) { searchValidation = Search(searchResult, order, mainCfg.Search); } // if (confirmOrder && (searchValidation || !mainCfg.Search.IsApplySearchToProcess)) { lock (orders) { orders.Add(order); } } else { if (discardedOrders != null) { lock (discardedOrders) { discardedOrders.Add(order); } } } } }
private void ExecuteOrder(List <InformationOrder> orders, ConfigurationMain mainCfg, InformationOrder order, string eventName) { Progresser.ChangeProgress(eventName, orders.Count); // if (mainCfg.IsVerbose) { Logger.Log(string.Format("Processing {0}", order.FileSource.FullName)); } // if (order.IsRefreshBackup && order.FileTarget != null) { order.FileSource.CopyTo(order.FileTarget.FullName, true); if (mainCfg.IsVerbose) { Logger.Log("Refreshing backup {0}=>{1}", order.FileSource.FullName, order.FileTarget.FullName); } } // if (order.IsRecopyOriginal && order.FileTarget != null) { order.FileTarget.CopyTo(order.FileSource.FullName, true); if (mainCfg.IsVerbose) { Logger.Log("Restoring original file {0}=>{1}", order.FileTarget.FullName, order.FileSource.FullName); } } // if (order.IsGmicPass) { if (order.FileSource.Directory != null) { ExternalTools.CallTexConvDdsToPng(order.FileSource.FullName, order.FileSource.Directory.FullName, false, mainCfg.IsVerbose); var newFilePath = order.FileSource.FullName.Substring(0, order.FileSource.FullName.Length - 4) + ".png"; foreach (var orderGmicCommand in order.GmicCommands) { ExternalTools.CallGmic(newFilePath, orderGmicCommand); } CreateDDS(mainCfg, newFilePath, order); File.Delete(newFilePath); } } // if (order.IsCustomPass) { if (order.FileSource.Directory != null) { string pathSource = order.FileSource.FullName; if (order.IsApplyOnPng) { ExternalTools.CallTexConvDdsToPng(order.FileSource.FullName, order.FileSource.Directory.FullName, false, mainCfg.IsVerbose); pathSource = order.FileSource.FullName.Substring(0, order.FileSource.FullName.Length - 4) + ".png"; } // FileInfo file = new FileInfo(pathSource); foreach (var orderCustomCommand in order.CustomCommands) { string commandWithFile = orderCustomCommand .Replace("%F%", file.FullName) .Replace("%N%", file.Name) .Replace("%E%", file.Extension); ExternalTools.CallCustom(commandWithFile); } // if (order.IsApplyOnPng) { CreateDDS(mainCfg, pathSource, order); File.Delete(pathSource); } } } // if (order.IsDoTexconv && order.TargetSize != null) { if (order.FileSource.Directory != null) { var textureSource = order.IsUseBackup && order.FileTarget != null ? order.FileTarget.FullName : order.FileSource.FullName; // CreateDDS(mainCfg, textureSource, order); } } }