Ejemplo n.º 1
0
        private bool CreatePatch()
        {
            //remove failed patches
            FileBackup.CleanupBackups(Configs.PatchPath);

            using (var oldPatch = new FileBackup(Configs.PatchPath))
            {
                var patcher = new Patcher();

                var patch = patcher.StartPatch();
                foreach (var module in Plugins)
                {
                    IoC.Notif.ShowStatus($"Generating patch ({module.PluginName})...");
                    module.ApplyChanges(patch);
                }

                IoC.Notif.ShowStatus("Generating plugin patches...");
                patcher.ApplyCustomPatches(patch, PluginManager);

                IoC.Notif.ShowStatus("Generating patch (rebuild prefetch)...");

                var p = Prefetch.Load(patch);
                if (p.Rebuild(patch))
                {
                    p.Save();
                }

                if (!Directory.Exists(patch.WorkingDir))
                {
                    IoC.Notif.ShowStatus("No changes found, aborting pack creation.");

                    return(false);
                }

                IoC.Notif.ShowStatus("Generating patch (packing)...");
                patcher.PackPatch(patch);

                IoC.Notif.ShowStatus("Copying patch...");
                patcher.InstallPatch(patch);

                oldPatch.Delete();

#if !DEBUG
                Paths.Cleanup(IoC.Config.TempPath);
#endif
            }

            return(true);
        }
Ejemplo n.º 2
0
        private List <CharacterModel> LoadCharacterModels(bool unique)
        {
            if (_cache.TryLoadCache(out var cached))
            {
                var validCached = cached.Where(x => x.UniqueCharacter == unique).ToList();
                if (validCached.Any())
                {
                    return(validCached);
                }
            }
            else
            {
                cached = new List <CharacterModel>();
            }

            var files = Prefetch.Load().Files.Keys;

            var modelBag = new ConcurrentBag <CharacterModel>();

            var tasks = new ParallelTasks <string>(
                Environment.ProcessorCount, file =>
            {
                if (IsValid(file, unique))
                {
                    foreach (var model in GetCharacterModels(file))
                    {
                        modelBag.Add(model);
                    }
                }
            });

            tasks.Start();
            tasks.AddItems(files);
            tasks.WaitForComplete();

            GC.Collect();

            var modelList = modelBag.ToList();

            cached.AddRange(modelList);
            _cache.Save(cached);

            return(modelList);
        }
Ejemplo n.º 3
0
        private List <T> LoadInternal()
        {
            if (_cache.TryLoadCache(out var cached))
            {
                if (cached.Any())
                {
                    return(cached);
                }
            }
            else
            {
                cached = new List <T>();
            }

            var files = Prefetch.Load().Files.Keys;
            var bag   = new ConcurrentBag <T>();

            var parallels = IoC.Debug.SingleThread ? 1 : Environment.ProcessorCount;
            var tasks     = new ParallelTasks <string>(
                parallels, file =>
            {
                if (_fileNameValidator(file) && !Ignored.Any(x => x.IsMatch(file)))
                {
                    foreach (var item in _itemGetter(file))
                    {
                        bag.Add(item);
                    }
                }
            });

            tasks.Start();
            tasks.AddItems(files);
            tasks.WaitForComplete();

            GC.Collect();

            var itemList = bag.ToList();

            cached.AddRange(itemList);
            _cache.Save(cached);

            return(itemList);
        }