public void Write(ConfigurationMain configuration, string fileName = ConfigurationFileOctagonExt) { using (StreamWriter file = File.CreateText(fileName)) { Serializer.Serialize(file, configuration); } }
//private bool GetCurrentImageSize3(InformationOrder order) //{ // int w, h, m; // string f; // // // var textureSource = order.IsUseBackup && order.FileTarget != null ? order.FileTarget.FullName : order.FileSource.FullName; // // // if (ExternalTools.CallDxDiagDirect(textureSource, out w, out h, out m, out f)) // { // Logger.Log("DxDiag unable to get info: {0}", textureSource, TypeLog.Error); // return false; // } // // // order.TargetSize = new InformationImage { Width = w, Height = h, Mipmaps = m, Format = f }; // order.OriginalSize = new InformationImage { Width = w, Height = h, Mipmaps = m, Format = f, TypeTexCompression = TypeTexCompression.None }; // return true; //} public void PrepareUnmerge(ConfigurationMain mainCfg, List <InformationFileDeletion> deletes) { if (mainCfg.IsVerbose) { Logger.Log("Preparing a mods unmerge"); } // var source = new DirectoryInfo(mainCfg.PathSource); // var target = new DirectoryInfo(mainCfg.PathMergeDirectory); // List <DirectoryInfo> validatedDirectories = new List <DirectoryInfo>(); foreach (DirectoryInfo directoryInfo in source.GetDirectories()) { if (mainCfg.Selection.GetValidation(directoryInfo.Name)) { validatedDirectories.Add(directoryInfo); } } // foreach (DirectoryInfo directoryInfo in validatedDirectories) { FileUtils.DeleteIfFound(directoryInfo, target, deletes); } }
public ModelConfigurationMain(ConfigurationMain main) { Main = main; ModelSelection = new ModelConfigurationSelection(main.Selection); ModelPath = new ModelConfigurationPath(main.Paths); ModelPassBsa = new ModelConfigurationPassBsa(main.PassBsa); ModelSearch = new ModelConfigurationSearch(main.Search); ModelPasses = new ObservableCollection <ModelConfigurationPass>(main.Passes.Select(e => new ModelConfigurationPass(e))); DeleteItemCommand = new DelegateCommand(RemovePass); }
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 ProcessorArgs(ConfigurationMain configurationMain) { ConfigurationMain = configurationMain; Folders = new Dictionary <string, InformationDirectory>(); FilesDds = new List <InformationFile>(); FilesBsa = new List <InformationFile>(); Orders = new List <InformationOrder>(); DiscardedOrders = new List <InformationOrder>(); SearchResults = new List <InformationOrder>(); BsaOrders = new List <InformationOrder>(); CopyOrders = new List <InformationCopy>(); DeleteOrders = new List <InformationFileDeletion>(); }
public ModelConfiguration() { Persistence = new Persistence(); // try { Main = new ModelConfigurationMain(Persistence.Read()); } catch (Exception) { var newCfg = new ConfigurationMain(); newCfg.PassBsa.SetDefaultRepacks(); Main = new ModelConfigurationMain(newCfg); } //Main = new ModelConfigurationMain(Persistence.Read() ?? new ConfigurationMain()); }
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); }
internal void PrepareTreat(List <InformationFile> files, ConfigurationMain mainCfg, List <InformationOrder> orders, List <InformationOrder> discardedOrders, List <InformationOrder> searchResult, bool isBsa) { var eventName = isBsa ? ProgressAnalyzingArchives : ProgressAnalyzingTextures; // Progresser.EventStart(eventName); if (mainCfg.IsUseMultithreading) { var exceptions = new ConcurrentQueue <Exception>(); Parallel.ForEach(files, (file, state) => { try { PrepareFileOrder(files, mainCfg, isBsa, file, orders, discardedOrders, searchResult, eventName); } catch (Exception e) { exceptions.Enqueue(e); state.Break(); } }); if (exceptions.Count > 0) { throw new AggregateException(exceptions); } } else { foreach (var file in files) { PrepareFileOrder(files, mainCfg, isBsa, file, orders, discardedOrders, searchResult, eventName); } } orders.Remove(null); if (discardedOrders != null) { discardedOrders.Remove(null); } // Logger.Log("Files preparation complete. {0} operations queued ", orders.Count); Progresser.EventEnd(eventName); // }
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); }
private void CreateDDS(ConfigurationMain mainCfg, string textureSource, InformationOrder order) { var tTexConv = ExternalTools.CallTexConv(textureSource, order.FileSource.Directory.FullName, order.TargetSize.Width, order.TargetSize.Height, Math.Max(order.TargetSize.Mipmaps, 1), order.TargetSize.Format, order.TargetSize.TypeTexCompression, false, mainCfg.IsVerbose); // if (tTexConv.HasError) { Logger.Log("Failed to process {0} with parameters w={1} h={2} m={3}", order.FileSource.FullName, order.TargetSize.Width, order.TargetSize.Height, order.TargetSize.Mipmaps, TypeLog.Error); } else { if (mainCfg.IsVerbose) { Logger.Log(string.Format("Processed to: w={0} h={1} m={2}", order.TargetSize.Width, order.TargetSize.Height, order.TargetSize.Mipmaps)); } } }
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); }
private void StartProcess2(object o) { try { ProcessorArgs processorArgs = (ProcessorArgs)o; ConfigurationMain mainCfg = processorArgs.ConfigurationMain; // FilePreparation.PrepareTreat(processorArgs.FilesDds, mainCfg, processorArgs.Orders, processorArgs.DiscardedOrders, processorArgs.SearchResults, false); // if (mainCfg.IsMergeActivated) { if (mainCfg.IsUnmergeActivated) { FilePreparation.PrepareUnmerge(mainCfg, processorArgs.DeleteOrders); } else { FilePreparation.PrepareMerge(mainCfg, processorArgs.CopyOrders); } } // OnProcessorEnded(3); } catch (AggregateException e) { Logger.Log(e); foreach (Exception innerException in e.InnerExceptions) { Logger.Log(innerException); } OnProcessorEnded(-1); } catch (Exception e) { Logger.Log(e); OnProcessorEnded(-1); } }
internal void ExecuteTreat(List <InformationOrder> orders, ConfigurationMain mainCfg, bool isBsa) { var eventName = isBsa ? ProgressExecuteOrderArchives : ProgressExecuteOrderTextures; Progresser.EventStart(eventName); // if (mainCfg.IsUseMultithreading) { Parallel.ForEach(orders, order => { ExecuteOrder(orders, mainCfg, order, eventName); }); } else { foreach (var order in orders) { ExecuteOrder(orders, mainCfg, order, eventName); } } // Logger.Log("Files processing complete. {0} operations done ", orders.Count); Progresser.EventEnd(eventName); }
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); } } }
private void StartProcess3(object o) { try { ProcessorArgs processorArgs = (ProcessorArgs)o; ConfigurationMain mainCfg = processorArgs.ConfigurationMain; // FileExecution.ExecuteTreat(processorArgs.Orders, mainCfg, false); // if (mainCfg.PassBsa.Enabled) { if (mainCfg.PassBsa.MustRepack()) { FileExecution.RepackBsa(processorArgs.BsaOrders, mainCfg.PassBsa.GameParameter, mainCfg.IsUseMultithreading, mainCfg.IsVerbose); } if (mainCfg.PassBsa.MustClean()) { FileExecution.CleanBsa(processorArgs.BsaOrders, mainCfg.IsVerbose); } } // if (mainCfg.IsMergeActivated) { if (mainCfg.IsUnmergeActivated) { FileExecution.DeleteFiles(mainCfg, processorArgs.DeleteOrders); } else { FileExecution.Merge(mainCfg, processorArgs.CopyOrders); } } // if (mainCfg.PassBsa.Enabled && mainCfg.PassBsa.IsRepackLooseFilesInBsa) { var bsaToProcess = mainCfg.PassBsa.IsIntelligentPacking ? FileUtils.GetIntelligentPacking(mainCfg.Selection, mainCfg.PathSource, mainCfg.PassBsa.GameParameter, mainCfg.PassBsa.IsRepackCreateDummy, mainCfg.IsVerbose) : FileUtils.PrepareForPacking(mainCfg.PassBsa.Repacks, mainCfg.PathSource, mainCfg.PassBsa.GameParameter, true, mainCfg.IsVerbose); List <DirectoryInfo> dirToDeleteIfFail = new List <DirectoryInfo>(); foreach (InformationRepackBsa informationRepackBsa in bsaToProcess) { ExternalTools.CallBsaPack(Path.Combine(informationRepackBsa.Source.FullName, informationRepackBsa.CurrentBsaName), informationRepackBsa.CurrentTarget.FullName, informationRepackBsa.IsCompressed, informationRepackBsa.GameParameter, mainCfg.IsUseMultithreading, mainCfg.IsVerbose); // informationRepackBsa.CurrentTarget.Refresh(); if (informationRepackBsa.CurrentTarget.Exists) { try { FileUtils.DeleteCompleteDirectory(informationRepackBsa.CurrentTarget); } catch { dirToDeleteIfFail.Add(informationRepackBsa.CurrentTarget); } } } // foreach (DirectoryInfo directoryInfo in dirToDeleteIfFail) { FileUtils.DeleteCompleteDirectory(directoryInfo); } } //Cleaning empty subdir if (mainCfg.IsBackupActivated && mainCfg.IsRefreshBackup) { FileInformation.CleanEmptySubdir(mainCfg.PathBackup); } //Cleaning no present source subdir if (mainCfg.IsBackupActivated && mainCfg.IsCleanBackup) { FileInformation.CleanBackupFromSource(mainCfg.PathSource, mainCfg.PathBackup); } // if (mainCfg.IsShowResults) { var infoTextures = new DirectoryInfo(mainCfg.PathSource); // foreach (var directoryInfo in infoTextures.GetDirectories()) { processorArgs.Folders[directoryInfo.Name].NewSize = FileUtils.CalculateDirectorySizeMo(directoryInfo, mainCfg.PassBsa.Enabled); } processorArgs.Folders[infoTextures.Name].NewSize = FileUtils.CalculateDirectorySizeMo(infoTextures, mainCfg.PassBsa.Enabled); // Show sizes before/after resizes Logger.Log("Results: (Size before resize in Mo => current size in Mo)"); foreach (var keyValuePair in processorArgs.Folders.OrderBy(e => e.Value.Size)) { Logger.Log("{0,15:F2} Mo => {1,15:F2} Mo {2}", keyValuePair.Value.Size, keyValuePair.Value.NewSize, keyValuePair.Key); } } OnProcessorEnded(-1); } catch (AggregateException e) { Logger.Log(e); foreach (Exception innerException in e.InnerExceptions) { Logger.Log(innerException); } OnProcessorEnded(-1); } catch (Exception e) { Logger.Log(e); OnProcessorEnded(-1); } }
private void StartProcess1(object o) { try { ProcessorArgs processorArgs = (ProcessorArgs)o; ConfigurationMain mainCfg = processorArgs.ConfigurationMain; // if (mainCfg.IsShowResults) { Logger.Log("Preparing futur results data"); var infoTextures = new DirectoryInfo(mainCfg.PathSource); // foreach (var directoryInfo in infoTextures.GetDirectories()) { processorArgs.Folders.Add(directoryInfo.Name, new InformationDirectory { Size = FileUtils.CalculateDirectorySizeMo(directoryInfo, mainCfg.PassBsa.Enabled) }); } processorArgs.Folders.Add(infoTextures.Name, new InformationDirectory { Size = FileUtils.CalculateDirectorySizeMo(infoTextures, mainCfg.PassBsa.Enabled) }); } // if (mainCfg.PassBsa.Enabled) { FileInformation.GetFileInfos(mainCfg.PathSource, mainCfg.PathBackup, processorArgs.FilesBsa, true, mainCfg); FilePreparation.PrepareTreat(processorArgs.FilesBsa, mainCfg, processorArgs.BsaOrders, null, null, true); FileExecution.ExecuteTreat(processorArgs.BsaOrders, mainCfg, true); if (mainCfg.PassBsa.MustUnpack()) { FileExecution.UnpackBsa(processorArgs.BsaOrders, mainCfg); } if (mainCfg.PassBsa.IsCopyAsLoose) { if (mainCfg.PassBsa.IsCopyAsLooseIfDummy) { List <InformationOrder> confirmedBsaUnpack = new List <InformationOrder>(); List <InformationCopy> confirmedDeletes = new List <InformationCopy>(); foreach (InformationOrder bsaOrder in processorArgs.BsaOrders) { var bsaName = Path.GetFileNameWithoutExtension(bsaOrder.FileSource.FullName); var espName = bsaName.ToUpper().Replace(" - TEXTURES", "").Replace("- TEXTURES", ""); var espFile = Path.Combine(bsaOrder.FileSource.Directory.FullName, string.Format("{0}.esp", espName)); FileInfo dummy = new FileInfo("dummy.esp"); if (!dummy.Exists) { throw new Exception("No dummy esp to compare from. A dummy.esp file must be present in Octagon directory."); } FileInfo esp = new FileInfo(espFile); if (esp.Exists && dummy.Length == esp.Length) { confirmedBsaUnpack.Add(bsaOrder); if (!confirmedDeletes.Any(e => string.Equals(e.Target, espFile, StringComparison.OrdinalIgnoreCase))) { confirmedDeletes.Add(new InformationCopy(null, espFile, false, false)); } } } FileExecution.CopyBsaAsLooseSimplified(confirmedBsaUnpack, mainCfg); foreach (InformationCopy confirmedDelete in confirmedDeletes) { FileUtils.ExecuteCopyOrDelete(confirmedDelete); } } else { FileExecution.CopyBsaAsLooseSimplified(processorArgs.BsaOrders, mainCfg); } } } // if (mainCfg.HasTextureOperation() || (mainCfg.IsBackupActivated && mainCfg.IsRecopyOriginal)) { FileInformation.GetFileInfos(mainCfg.PathSource, mainCfg.PathBackup, processorArgs.FilesDds, false, mainCfg); } OnProcessorEnded(2); } catch (AggregateException e) { Logger.Log(e); foreach (Exception innerException in e.InnerExceptions) { Logger.Log(innerException); } OnProcessorEnded(-1); } catch (Exception e) { Logger.Log(e); OnProcessorEnded(-1); } }
private void StartProcess0(object o) { try { ProcessorArgs processorArgs = (ProcessorArgs)o; ConfigurationMain mainCfg = processorArgs.ConfigurationMain; // Logger.Log("Checking configuration..."); // Progresser.EventStart(ProgressChecking); Progresser.ChangeProgress(ProgressChecking, 0); // if (mainCfg.Passes.Any()) { if (!File.Exists(mainCfg.Paths.PathTexconv)) { throw new FileNotFoundException("Texconv.exe not found. Check your exe paths in tool paths !"); } // if (!File.Exists(mainCfg.Paths.PathTexdiag)) { throw new FileNotFoundException("Texdiag.exe not found. Check your exe paths in tool paths !"); } // if (mainCfg.Passes.Any(p => p.TypePass == TypePass.ApplyGmic) && !File.Exists(mainCfg.Paths.PathGmic)) { throw new FileNotFoundException("Gmic.exe used and not found. Check your exe paths in tool paths !"); } // if (mainCfg.Passes.Any(p => p.TypePass == TypePass.ApplyCustom) && !File.Exists(mainCfg.Paths.PathCustomTool)) { throw new FileNotFoundException("Custom tool used and not found. Check your exe paths in tool paths !"); } } // if (mainCfg.PassBsa.Enabled && !File.Exists(mainCfg.Paths.PathBsarch)) { throw new FileNotFoundException("Bsarch.exe not found. Check your exe paths in tool paths !"); } // Logger.Log("Needed tools are found: ok"); // if (string.IsNullOrEmpty(mainCfg.PathSource)) { throw new ArgumentException("Source folder path is mandatory."); } // if (!(new DirectoryInfo(mainCfg.PathSource).Exists)) { throw new DirectoryNotFoundException("Source folder don't exist."); } // if (mainCfg.IsBackupActivated && string.IsNullOrEmpty(mainCfg.PathBackup)) { throw new ArgumentException("Backup folder path is mandatory when using backup functions."); } // if (mainCfg.IsBackupActivated && !(new DirectoryInfo(mainCfg.PathBackup).Exists)) { throw new DirectoryNotFoundException("Backup folder don't exist."); } // if (mainCfg.IsBackupActivated && Equals(mainCfg.PathSource, mainCfg.PathBackup)) { throw new ArgumentException("Source folder and backup folder cannot be the same."); } // Logger.Log("Configuration: ok"); // mainCfg.Selection.CalculateStartFileValidation(); mainCfg.PassBsa.Selection.CalculateStartFileValidation(); foreach (ConfigurationPass configurationPass in mainCfg.Passes) { configurationPass.Selection.CalculateStartFileValidation(); } // Logger.Log("Initializing validations ok"); // Progresser.ChangeProgress(ProgressChecking, 1); Progresser.EventEnd(ProgressChecking); // OnProcessorEnded(1); } catch (AggregateException e) { Logger.Log(e); foreach (Exception innerException in e.InnerExceptions) { Logger.Log(innerException); } OnProcessorEnded(-1); } catch (Exception e) { Logger.Log(e); OnProcessorEnded(-1); } }
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 GetFileInfos(string sourceDirectory, string targetDirectory, List<InformationFile> result, bool isBsa, ConfigurationMain main) { var eventName = isBsa ? ProgressSearchingArchives : ProgressSearchingTextures; var extension = isBsa ? ArchiveExtensionList.List : TextureExtensionList.List; // Progresser.EventStart(eventName); int fileCount = 0; foreach (var ext in extension) { fileCount += Directory.GetFiles(sourceDirectory, string.Format("*{0}", ext), SearchOption.AllDirectories).Length; } // DirectoryInfo diSource = new DirectoryInfo(sourceDirectory); if (string.IsNullOrEmpty(targetDirectory) || !main.IsBackupActivated) { GetFileInfos(diSource, result, isBsa, eventName, main, fileCount, true); } else { DirectoryInfo diTarget = new DirectoryInfo(targetDirectory); GetFileInfos(diSource, diTarget, result, isBsa, eventName, main, fileCount, true); } // // Logger.Log("Files scan complete: {0} {1} files found", result.Count, extension.Aggregate((i, j) => string.Format("{0}|{1}", i, j))); Progresser.EventEnd(eventName); }
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); } } } } }