Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
    private void btnDoSomething_Click(object sender0, RoutedEventArgs e0)
    {
        _progressDialogue = new Progresser {
            Owner = _owner, StartPosition = FormStartPosition.CenterParent
        };
        _progressDialogue.Closed += ProgressDialogueClosed;
        _progressDialogue.Show();

        BackgroundWorker worker = new BackgroundWorker();

        worker.WorkerReportsProgress = true;
        worker.DoWork += delegate(object sender, DoWorkEventArgs e) {
            DoSomething();
            e.Result = result;
        };
        worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e) {
            progressDialogue.Update()
        };
        worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) {
            progressDialogue.Close()
        };
        worker.RunWorkerAsync(new CustomArgs()
        {
            SomeValue = txtValue.Text,
        });
    }
}
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        public async Task <string> UploadFile(Stream fileStream, string name, Action <int> onProgress = null)
        {
            var bucket     = storageClient.ListBuckets(projectId).First();
            var progresser = new Progresser(onProgress, L => (int)((double)L / fileStream.Length * 100));
            await storageClient.UploadObjectAsync(bucket.Name, name, "audio/wav", fileStream, progress : progresser);

            return($"gs://{bucket.Name}/{name}");
        }
Exemplo n.º 5
0
 private void Awake()
 {
     progress1      = p1.GetComponent <ProgressHub>();
     progress2      = p2.GetComponent <ProgressHub>();
     progresser1    = programer1.GetComponent <Progresser>();
     progresser2    = programer2.GetComponent <Progresser>();
     fadeAnim       = Fade.GetComponent <Animator>();
     transitionTime = new WaitForSeconds(1f);
 }
Exemplo n.º 6
0
    public override void UseItem(GameObject target)
    {
        Progresser progresserChecker = target.GetComponent <Progresser>();

        if (progresserChecker != null)
        {
            progresserChecker.progressHub.totalProgress -= 10;
        }
        Destroy(this.gameObject, 0.5f);
    }
Exemplo n.º 7
0
 private async void LoadingBtn2_Click(object sender, RoutedEventArgs e)
 {
     using (var progresser = new Progresser(ctrl: new CustomLoading()))
     {
         await Task.Run(() =>
         {
             Thread.Sleep(3000);
         });
     }
 }
Exemplo n.º 8
0
    public override void UseItem(GameObject target)
    {
        Progresser progress = target.GetComponent <Progresser>();

        if (progress.itemRequest == type)
        {
            progress.sendTranmission();
        }
        else
        {
            progress.setStatus(false, 1, 3f);
        }
    }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
    public override void UseItem(GameObject target)
    {
        Progresser progresserChecker = target.GetComponent <Progresser>();

        if (progresserChecker.itemRequest == type)
        {
            print("use");
            progresserChecker.sendTranmission();
            Destroy(this.gameObject, 0.5f);
        }
        else
        {
            progresserChecker.setStatus(false, 1, EffectDuration);
            Destroy(this.gameObject, 0.5f);
        }
    }
Exemplo n.º 11
0
    public override void UseItem(GameObject target)
    {
        Player     playerChecker     = target.GetComponent <Player>();
        Progresser progresserChecker = target.GetComponent <Progresser>();

        if (playerChecker != null)
        {
            //Effect on Player
            playerChecker.setStatus(false, -3f, EffectDuration);
        }
        else if (progresserChecker != null)
        {
            //Effect on Progresser
            progresserChecker.setStatus(true, 4, EffectDuration * 2);
        }
        Destroy(this.gameObject, 0.5f);
    }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
        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);
            //
        }
Exemplo n.º 14
0
 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);
 }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 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);
 }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 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);
         }
     }
 }
Exemplo n.º 20
0
        private List <string> CallBsarch(string eventName, string arg, bool verbose)
        {
            var startInfo = new ProcessStartInfo
            {
                WindowStyle            = ProcessWindowStyle.Hidden,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                FileName  = ConfigurationPath.PathBsarch,
                Arguments = arg
            };
            //
            var process = new Process {
                StartInfo = startInfo
            };

            process.Start();
            Progresser.EventStart(eventName);
            List <string> result = new List <string>();
            string        error  = null;

            process.OutputDataReceived += (sender, args) =>
            {
                result.Add(args.Data);
                var data = args.Data;
                if (!string.IsNullOrWhiteSpace(data))
                {
                    data = data.Trim();
                    if (data.StartsWith("[") && data.EndsWith("%]"))
                    {
                        data = data.Replace("[", string.Empty);
                        data = data.Replace("%]", string.Empty);
                        int i;
                        if (int.TryParse(data, out i))
                        {
                            Progresser.ChangeProgressPct(eventName, i / 100d);
                        }
                    }
                    else if (data.StartsWith("EFCreateError", StringComparison.OrdinalIgnoreCase))
                    {
                        error = string.Format("File system error, file name not ASCII ? {0}", data);
                    }
                    else if (data.ToLower().Contains("exception"))
                    {
                        error = data;
                    }
                    else
                    {
                        if (verbose)
                        {
                            Logger.Log(data);
                        }
                    }
                }
            };
            process.BeginOutputReadLine();
            process.WaitForExit();
            Progresser.EventEnd(eventName);
            if (error != null)
            {
                throw new Exception(error);
            }
            return(result);
        }
Exemplo n.º 21
0
      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);
         }

      }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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);
                        }
                    }
                }
            }
        }