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
 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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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);
        }