Пример #1
0
        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);
            }
        }
Пример #2
0
 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);
     }
 }