/// <summary>
        /// import mods as an asynchronous operation.
        /// </summary>
        /// <param name="importType">Type of the import.</param>
        /// <param name="file">The file.</param>
        /// <returns>IModCollection.</returns>
        protected virtual async Task <IModCollection> ImportModsAsync(ImportType importType, string file = Shared.Constants.EmptyParam)
        {
            async Task <IModCollection> performImport(IGame game)
            {
                var instance   = Create();
                var parameters = new ModCollectionExporterParams()
                {
                    ModDirectory = Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory),
                    File         = file,
                    Mod          = instance
                };
                ICollectionImportResult result = null;

                switch (importType)
                {
                case ImportType.Paradox:
                    result = await modCollectionExporter.ImportParadoxAsync(parameters);

                    break;

                case ImportType.ParadoxLauncher:
                    result = await modCollectionExporter.ImportParadoxLauncherAsync(parameters);

                    break;

                case ImportType.Paradoxos:
                    result = await modCollectionExporter.ImportParadoxosAsync(parameters);

                    break;

                case ImportType.ParadoxLauncherBeta:
                    result = await modCollectionExporter.ImportParadoxLauncherBetaAsync(parameters);

                    break;

                case ImportType.ParadoxLauncherJson:
                    result = await modCollectionExporter.ImportParadoxLauncherJsonAsync(parameters);

                    break;

                default:
                    break;
                }
                if (result != null)
                {
                    // Order of operations is very important here
                    MapImportResult(instance, result);
                    return(instance);
                }
                return(null);
            }

            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            return(await performImport(game));
        }
        /// <summary>
        /// import as an asynchronous operation.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>Task&lt;IModCollection&gt;.</returns>
        public async Task <IModCollection> ImportAsync(string file)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            var instance = await GetImportedCollectionDetailsAsync(file);

            if (instance != null)
            {
                // Incase selected game != imported collection game
                if (!game.Type.Equals(instance.Game))
                {
                    game = GameService.Get().FirstOrDefault(p => p.Type.Equals(instance.Game));
                }
                var path       = GetPatchModDirectory(game, instance);
                var exportPath = GetPatchModDirectory(game, !string.IsNullOrWhiteSpace(instance.MergedFolderName) ? instance.MergedFolderName : instance.Name);
                var result     = await modCollectionExporter.ImportModDirectoryAsync(new ModCollectionExporterParams()
                {
                    File               = file,
                    ModDirectory       = path,
                    Mod                = instance,
                    ExportModDirectory = exportPath
                });

                if (result)
                {
                    return(instance);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// export hash report as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="path">The path.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportHashReportAsync(IEnumerable <IMod> mods, string path)
        {
            if (!string.IsNullOrWhiteSpace(path) && mods?.Count() > 0)
            {
                var modExport    = mods.ToList();
                var collection   = GetAllModCollectionsInternal().FirstOrDefault(p => p.IsSelected);
                var patchModName = GenerateCollectionPatchName(collection.Name);
                var allMods      = GetInstalledModsInternal(GameService.GetSelected(), false);
                var patchMod     = allMods.FirstOrDefault(p => p.Name.Equals(patchModName));
                if (patchMod == null)
                {
                    var game = GameService.GetSelected();
                    if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
                    {
                        RootDirectory = GetPatchModDirectory(game, patchModName)
                    }))
                    {
                        patchMod = GeneratePatchModDescriptor(allMods, game, patchModName);
                    }
                }
                if (patchMod != null && collection.PatchModEnabled)
                {
                    if (patchMod.Files == null || !patchMod.Files.Any())
                    {
                        await PopulateModFilesInternalAsync(new List <IMod>() { patchMod });
                    }
                    modExport.Add(patchMod);
                }
                var reports = await ParseReportAsync(modExport);

                return(await exportService.ExportAsync(reports, path));
            }
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Purges the mod directory asynchronous.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> PurgeModDirectoryAsync(string folder)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(false);
            }
            var fullPath = Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory, folder);
            var result   = await ModWriter.PurgeModDirectoryAsync(new ModWriterParameters()
            {
                RootDirectory = game.UserDirectory,
                Path          = Path.Combine(Shared.Constants.ModDirectory, folder)
            }, true);

            var mods = GetInstalledModsInternal(game, false);

            if (mods.Any(p => !string.IsNullOrWhiteSpace(p.FullPath) && p.FullPath.Contains(fullPath)))
            {
                var mod = mods.Where(p => p.FullPath.Contains(fullPath));
                if (mod.Any())
                {
                    await DeleteDescriptorsInternalAsync(mod);
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// delete descriptors internal as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        protected virtual async Task <bool> DeleteDescriptorsInternalAsync(IEnumerable <IMod> mods)
        {
            var game = GameService.GetSelected();

            if (game != null && mods?.Count() > 0)
            {
                var tasks = new List <Task>();
                foreach (var item in mods)
                {
                    var task = ModWriter.DeleteDescriptorAsync(new ModWriterParameters()
                    {
                        Mod           = item,
                        RootDirectory = game.UserDirectory
                    });
                    tasks.Add(task);
                }
                await Task.WhenAll(tasks);

                Cache.Invalidate(new CacheInvalidateParameters()
                {
                    Region = ModsCacheRegion, Prefix = game.Type, Keys = new List <string> {
                        GetModsCacheKey(true), GetModsCacheKey(false)
                    }
                });
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// lock descriptors as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="isLocked">if set to <c>true</c> [is locked].</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> LockDescriptorsAsync(IEnumerable <IMod> mods, bool isLocked)
        {
            var game = GameService.GetSelected();

            if (game != null && mods?.Count() > 0)
            {
                var tasks = new List <Task>();
                foreach (var item in mods)
                {
                    // Cannot lock\unlock mandatory local zipped mods
                    if (!CheckIfModShouldBeLocked(game, item))
                    {
                        var task = ModWriter.SetDescriptorLockAsync(new ModWriterParameters()
                        {
                            Mod           = item,
                            RootDirectory = game.UserDirectory
                        }, isLocked);
                        item.IsLocked = isLocked;
                        tasks.Add(task);
                    }
                }
                await Task.WhenAll(tasks);

                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Saves the specified collection.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">collection</exception>
        public virtual bool Save(IModCollection collection)
        {
            if (collection == null || string.IsNullOrWhiteSpace(collection.Game))
            {
                throw new ArgumentNullException(nameof(collection));
            }
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(false);
            }
            lock (serviceLock)
            {
                var collections = StorageProvider.GetModCollections().ToList();
                if (collections.Count > 0)
                {
                    var existing = collections.FirstOrDefault(p => p.Name.Equals(collection.Name, StringComparison.OrdinalIgnoreCase) && p.Game.Equals(collection.Game));
                    if (existing != null)
                    {
                        collections.Remove(existing);
                    }
                    if (collection.IsSelected)
                    {
                        foreach (var item in collections.Where(p => p.Game.Equals(collection.Game) && p.IsSelected))
                        {
                            item.IsSelected = false;
                        }
                    }
                }
                collections.Add(collection);
                return(StorageProvider.SetModCollections(collections));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the collection mods.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="collectionName">Name of the collection.</param>
        /// <returns>IEnumerable&lt;IMod&gt;.</returns>
        protected virtual IEnumerable <IMod> GetCollectionMods(IEnumerable <IMod> mods = null, string collectionName = Shared.Constants.EmptyParam)
        {
            if (mods == null)
            {
                mods = GetInstalledModsInternal(GameService.GetSelected(), false);
            }
            var collectionMods = new List <IMod>();
            var collections    = GetAllModCollectionsInternal();

            if (collections?.Count() > 0)
            {
                IModCollection collection;
                if (!string.IsNullOrWhiteSpace(collectionName))
                {
                    collection = collections.FirstOrDefault(p => p.Name.Equals(collectionName, StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    collection = collections.FirstOrDefault(p => p.IsSelected);
                }

                if (collection != null)
                {
                    foreach (var item in collection.Mods)
                    {
                        var mod = mods.FirstOrDefault(p => p.DescriptorFile.Equals(item, StringComparison.OrdinalIgnoreCase));
                        if (mod != null)
                        {
                            collectionMods.Add(mod);
                        }
                    }
                }
            }
            return(collectionMods);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// import as an asynchronous operation.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>Task&lt;IModCollection&gt;.</returns>
        public async Task <IModCollection> ImportAsync(string file)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            var instance = await GetImportedCollectionDetailsAsync(file);

            if (instance != null)
            {
                var path = GetModDirectory(game, instance);
                if (await modCollectionExporter.ImportModDirectoryAsync(new ModCollectionExporterParams()
                {
                    File = file,
                    ModDirectory = path,
                    Mod = instance
                }))
                {
                    return(instance);
                }
            }
            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// import as an asynchronous operation.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>Task&lt;IModCollection&gt;.</returns>
        public async Task <IModCollection> ImportAsync(string file)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            var instance = await GetImportedCollectionDetailsAsync(file);

            if (instance != null)
            {
                var path       = GetPatchModDirectory(game, instance);
                var exportPath = GetPatchModDirectory(game, !string.IsNullOrWhiteSpace(instance.MergedFolderName) ? instance.MergedFolderName : instance.Name);
                if (await modCollectionExporter.ImportModDirectoryAsync(new ModCollectionExporterParams()
                {
                    File = file,
                    ModDirectory = path,
                    Mod = instance,
                    ExportModDirectory = exportPath
                }))
                {
                    return(instance);
                }
            }
            return(null);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Exports the asynchronous.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="modCollection">The mod collection.</param>
        /// <param name="exportOrderOnly">if set to <c>true</c> [export order only].</param>
        /// <param name="exportMods">if set to <c>true</c> [export mods].</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual Task <bool> ExportAsync(string file, IModCollection modCollection, bool exportOrderOnly = false, bool exportMods = false)
        {
            var game = GameService.GetSelected();

            if (game == null || modCollection == null)
            {
                return(Task.FromResult(false));
            }
            var collection = Mapper.Map <IModCollection>(modCollection);

            if (string.IsNullOrWhiteSpace(collection.MergedFolderName) && exportMods)
            {
                collection.MergedFolderName = collection.Name.GenerateValidFileName();
            }
            var path       = GetPatchModDirectory(game, modCollection);
            var parameters = new ModCollectionExporterParams()
            {
                File               = file,
                Mod                = collection,
                ModDirectory       = path,
                ExportModOrderOnly = exportOrderOnly
            };

            if (exportMods)
            {
                parameters.ExportMods = GetCollectionMods(collectionName: modCollection.Name);
            }
            return(modCollectionExporter.ExportAsync(parameters));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// install mods as an asynchronous operation.
        /// </summary>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> InstallModsAsync()
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(false);
            }
            var mods              = GetInstalledModsInternal(game, false);
            var descriptors       = new List <IMod>();
            var userDirectoryMods = GetAllModDescriptors(Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory), ModSource.Local);

            if (userDirectoryMods?.Count() > 0)
            {
                descriptors.AddRange(userDirectoryMods);
            }
            var workshopDirectoryMods = GetAllModDescriptors(game.WorkshopDirectory, ModSource.Steam);

            if (workshopDirectoryMods?.Count() > 0)
            {
                descriptors.AddRange(workshopDirectoryMods);
            }
            var diffs = descriptors.Where(p => !mods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile, StringComparison.OrdinalIgnoreCase))).ToList();

            if (diffs.Count > 0)
            {
                await ModWriter.CreateModDirectoryAsync(new ModWriterParameters()
                {
                    RootDirectory = game.UserDirectory,
                    Path          = Shared.Constants.ModDirectory
                });

                var tasks = new List <Task>();
                foreach (var diff in diffs)
                {
                    if (IsPatchModInternal(diff))
                    {
                        continue;
                    }
                    tasks.Add(ModWriter.WriteDescriptorAsync(new ModWriterParameters()
                    {
                        Mod           = diff,
                        RootDirectory = game.UserDirectory,
                        Path          = diff.DescriptorFile
                    }, IsPatchModInternal(diff)));
                }
                if (tasks.Count > 0)
                {
                    await Task.WhenAll(tasks);

                    Cache.Invalidate(ModsCachePrefix, ConstructModsCacheKey(game, true), ConstructModsCacheKey(game, false));
                }
                return(true);
            }

            return(false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Exports the mods asynchronous.
        /// </summary>
        /// <param name="enabledMods">The mods.</param>
        /// <param name="regularMods">The regular mods.</param>
        /// <param name="modCollection">The mod collection.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportModsAsync(IReadOnlyCollection <IMod> enabledMods, IReadOnlyCollection <IMod> regularMods, IModCollection modCollection)
        {
            var game = GameService.GetSelected();

            if (game == null || enabledMods == null || regularMods == null || modCollection == null)
            {
                return(false);
            }
            var allMods        = GetInstalledModsInternal(game, false);
            var mod            = GeneratePatchModDescriptor(allMods, game, GenerateCollectionPatchName(modCollection.Name));
            var applyModParams = new ModWriterParameters()
            {
                OtherMods     = regularMods.Where(p => !enabledMods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile))).ToList(),
                EnabledMods   = enabledMods,
                RootDirectory = game.UserDirectory
            };

            if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = mod.FullPath
            }))
            {
                if (modCollection.PatchModEnabled && enabledMods.Any())
                {
                    if (await ModWriter.WriteDescriptorAsync(new ModWriterParameters()
                    {
                        Mod = mod,
                        RootDirectory = game.UserDirectory,
                        Path = mod.DescriptorFile,
                        LockDescriptor = CheckIfModShouldBeLocked(game, mod)
                    }, IsPatchModInternal(mod)))
                    {
                        applyModParams.TopPriorityMods = new List <IMod>()
                        {
                            mod
                        };
                        Cache.Invalidate(new CacheInvalidateParameters()
                        {
                            Region = ModsCacheRegion, Prefix = game.Type, Keys = new List <string> {
                                GetModsCacheKey(true), GetModsCacheKey(false)
                            }
                        });
                    }
                }
            }
            else
            {
                // Remove left over descriptor
                if (allMods.Any(p => p.Name.Equals(mod.Name)))
                {
                    await DeleteDescriptorsInternalAsync(new List <IMod>() { mod });
                }
            }
            return(await ModWriter.ApplyModsAsync(applyModParams));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the image stream asynchronous.
        /// </summary>
        /// <param name="modName">Name of the mod.</param>
        /// <param name="path">The path.</param>
        /// <returns>Task&lt;MemoryStream&gt;.</returns>
        public virtual Task <MemoryStream> GetImageStreamAsync(string modName, string path)
        {
            var game = GameService.GetSelected();

            if (game == null || string.IsNullOrWhiteSpace(modName))
            {
                return(Task.FromResult((MemoryStream)null));
            }
            var mods = GetInstalledModsInternal(game, false);

            return(GetImageStreamAsync(mods.FirstOrDefault(p => p.Name.Equals(modName)), path));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns>IModCollection.</returns>
        public virtual IModCollection Create()
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            var instance = GetModelInstance <IModCollection>();

            instance.Game = game.Type;
            return(instance);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Mods the directory exists asynchronous.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual Task <bool> ModDirectoryExistsAsync(string folder)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(Task.FromResult(false));
            }
            return(ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = game.UserDirectory,
                Path = Path.Combine(Shared.Constants.ModDirectory, folder)
            }));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Evals the achievement compatibility.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public virtual bool EvalAchievementCompatibility(IEnumerable <IMod> mods)
        {
            var game = GameService.GetSelected();

            if (game != null && mods?.Count() > 0)
            {
                foreach (var item in mods.Where(p => p.IsValid))
                {
                    var isAchievementCompatible = !item.Files.Any(p => game.ChecksumFolders.Any(s => p.StartsWith(s, StringComparison.OrdinalIgnoreCase)));
                    item.AchievementStatus = isAchievementCompatible ? AchievementStatus.Compatible : AchievementStatus.NotCompatible;
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Gets the image stream asynchronous.
 /// </summary>
 /// <param name="mod">The mod.</param>
 /// <param name="path">The path.</param>
 /// <param name="isFromGame">if set to <c>true</c> [is from game].</param>
 /// <returns>Task&lt;MemoryStream&gt;.</returns>
 public virtual Task <MemoryStream> GetImageStreamAsync(IMod mod, string path, bool isFromGame = false)
 {
     if (!isFromGame)
     {
         if (mod != null && !string.IsNullOrWhiteSpace(path))
         {
             return(Reader.GetImageStreamAsync(mod.FullPath, path));
         }
     }
     else
     {
         return(Reader.GetImageStreamAsync(Path.GetDirectoryName(GameService.GetSelected().ExecutableLocation), path));
     }
     return(Task.FromResult((MemoryStream)null));
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Gets all mod collections internal.
        /// </summary>
        /// <returns>IEnumerable&lt;IModCollection&gt;.</returns>
        protected virtual IEnumerable <IModCollection> GetAllModCollectionsInternal()
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(new List <IModCollection>());
            }
            var collections = StorageProvider.GetModCollections().Where(s => s.Game.Equals(game.Type));

            if (collections.Count() > 0)
            {
                return(collections.OrderBy(p => p.Name));
            }
            return(new List <IModCollection>());
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>IModCollection.</returns>
        public virtual IModCollection Get(string name)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            var collections = StorageProvider.GetModCollections();

            if (collections?.Count() > 0)
            {
                var collection = collections.FirstOrDefault(c => c.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && c.Game.Equals(game.Type));
                return(collection);
            }
            return(null);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Exports the asynchronous.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="modCollection">The mod collection.</param>
        /// <param name="exportOrderOnly">if set to <c>true</c> [export order only].</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual Task <bool> ExportAsync(string file, IModCollection modCollection, bool exportOrderOnly = false)
        {
            var game = GameService.GetSelected();

            if (game == null || modCollection == null)
            {
                return(Task.FromResult(false));
            }
            var path = GetModDirectory(game, modCollection);

            return(modCollectionExporter.ExportAsync(new ModCollectionExporterParams()
            {
                File = file,
                Mod = modCollection,
                ModDirectory = path,
                ExportModOrderOnly = exportOrderOnly
            }));
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Populates the mod path.
 /// </summary>
 /// <param name="definitions">The definitions.</param>
 /// <param name="collectionMods">The collection mods.</param>
 /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
 protected virtual IEnumerable <IDefinition> PopulateModPath(IEnumerable <IDefinition> definitions, IEnumerable <IMod> collectionMods)
 {
     if (definitions?.Count() > 0)
     {
         foreach (var item in definitions)
         {
             if (IsPatchModInternal(item.ModName))
             {
                 item.ModPath = GetModDirectory(GameService.GetSelected(), item.ModName);
             }
             else
             {
                 item.ModPath = collectionMods.FirstOrDefault(p => p.Name.Equals(item.ModName)).FullPath;
             }
         }
     }
     return(definitions);
 }
        /// <summary>
        /// Exports the paradox launcher json asynchronous.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="modCollection">The mod collection.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual Task <bool> ExportParadoxLauncherJsonAsync(string file, IModCollection modCollection)
        {
            var game = GameService.GetSelected();

            if (game == null || modCollection == null)
            {
                return(Task.FromResult(false));
            }
            var collection = Mapper.Map <IModCollection>(modCollection);
            var parameters = new ModCollectionExporterParams()
            {
                File       = file,
                Mod        = collection,
                ExportMods = GetCollectionMods(collectionName: modCollection.Name),
                Game       = game
            };

            return(modCollectionExporter.ExportParadoxLauncherJsonAsync(parameters));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// get imported collection details as an asynchronous operation.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>Task&lt;IModCollection&gt;.</returns>
        public virtual async Task <IModCollection> GetImportedCollectionDetailsAsync(string file)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(null);
            }
            var instance = GetModelInstance <IModCollection>();
            var result   = await modCollectionExporter.ImportAsync(new ModCollectionExporterParams()
            {
                File = file,
                Mod  = instance
            });

            if (result)
            {
                return(instance);
            }
            return(null);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Imports the hash report asynchronous.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="path">The path.</param>
        /// <returns>Task&lt;IEnumerable&lt;IModHashReport&gt;&gt;.</returns>
        public virtual async Task <IEnumerable <IModHashReport> > ImportHashReportAsync(IEnumerable <IMod> mods, string path)
        {
            var modExport    = mods.ToList();
            var collection   = GetAllModCollectionsInternal().FirstOrDefault(p => p.IsSelected);
            var patchModName = GenerateCollectionPatchName(collection.Name);
            var allMods      = GetInstalledModsInternal(GameService.GetSelected(), false);
            var patchMod     = allMods.FirstOrDefault(p => p.Name.Equals(patchModName));

            if (patchMod != null)
            {
                if (patchMod.Files == null || !patchMod.Files.Any())
                {
                    await PopulateModFilesInternalAsync(new List <IMod>() { patchMod });
                }
                modExport.Add(patchMod);
            }
            var currentReports = await ParseReportAsync(modExport);

            var importedReports = await modReportExporter.ImportAsync(path);

            if (importedReports != null)
            {
Ejemplo n.º 26
0
        /// <summary>
        /// Exports the mods asynchronous.
        /// </summary>
        /// <param name="enabledMods">The mods.</param>
        /// <param name="regularMods">The regular mods.</param>
        /// <param name="collectionName">Name of the collection.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportModsAsync(IReadOnlyCollection <IMod> enabledMods, IReadOnlyCollection <IMod> regularMods, string collectionName)
        {
            var game = GameService.GetSelected();

            if (game == null || enabledMods == null || regularMods == null)
            {
                return(false);
            }
            var allMods        = GetInstalledModsInternal(game, false);
            var mod            = GeneratePatchModDescriptor(allMods, game, GenerateCollectionPatchName(collectionName));
            var applyModParams = new ModWriterParameters()
            {
                OtherMods     = regularMods.Where(p => !enabledMods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile))).ToList(),
                EnabledMods   = enabledMods,
                RootDirectory = game.UserDirectory
            };

            if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = game.UserDirectory,
                Path = mod.FileName
            }))
            {
                if (await ModWriter.WriteDescriptorAsync(new ModWriterParameters()
                {
                    Mod = mod,
                    RootDirectory = game.UserDirectory,
                    Path = mod.DescriptorFile
                }, IsPatchModInternal(mod)))
                {
                    applyModParams.TopPriorityMods = new List <IMod>()
                    {
                        mod
                    };
                    Cache.Invalidate(ModsCachePrefix, ConstructModsCacheKey(game, true), ConstructModsCacheKey(game, false));
                }
            }
            return(await ModWriter.ApplyModsAsync(applyModParams));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// lock descriptors as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="isLocked">if set to <c>true</c> [is locked].</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> LockDescriptorsAsync(IEnumerable <IMod> mods, bool isLocked)
        {
            var game = GameService.GetSelected();

            if (game != null && mods?.Count() > 0)
            {
                var tasks = new List <Task>();
                foreach (var item in mods)
                {
                    var task = ModWriter.SetDescriptorLockAsync(new ModWriterParameters()
                    {
                        Mod           = item,
                        RootDirectory = game.UserDirectory
                    }, isLocked);
                    tasks.Add(task);
                }
                await Task.WhenAll(tasks);

                return(true);
            }
            return(false);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Deletes the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public virtual bool Delete(string name)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(false);
            }
            lock (serviceLock)
            {
                var collections = StorageProvider.GetModCollections().ToList();
                if (collections.Count > 0)
                {
                    var existing = collections.FirstOrDefault(p => p.Game.Equals(game.Type) && p.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
                    if (existing != null)
                    {
                        collections.Remove(existing);
                        return(StorageProvider.SetModCollections(collections));
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// export hash report as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="path">The path.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportHashReportAsync(IEnumerable <IMod> mods, string path)
        {
            if (!string.IsNullOrWhiteSpace(path) && mods?.Count() > 0)
            {
                var modExport    = mods.ToList();
                var collection   = GetAllModCollectionsInternal().FirstOrDefault(p => p.IsSelected);
                var patchModName = GenerateCollectionPatchName(collection.Name);
                var allMods      = GetInstalledModsInternal(GameService.GetSelected(), false);
                var patchMod     = allMods.FirstOrDefault(p => p.Name.Equals(patchModName));
                if (patchMod != null)
                {
                    if (patchMod.Files == null || patchMod.Files.Count() == 0)
                    {
                        await PopulateModFilesInternalAsync(new List <IMod>() { patchMod });
                    }
                    modExport.Add(patchMod);
                }
                var reports = await ParseReportAsync(modExport);

                return(await modReportExporter.ExportAsync(reports, path));
            }
            return(false);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// parse report as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <returns>IEnumerable&lt;IModHashReport&gt;.</returns>
        protected virtual async Task <IEnumerable <IHashReport> > ParseReportAsync(IEnumerable <IMod> mods)
        {
            var    game           = GameService.GetSelected();
            var    reports        = new List <IHashReport>();
            var    total          = mods.SelectMany(p => p.Files).Count(p => game.GameFolders.Any(a => p.StartsWith(a)));
            var    progress       = 0;
            double lastPercentage = 0;

            foreach (var mod in mods)
            {
                var report = GetModelInstance <IHashReport>();
                report.Name       = mod.Name;
                report.ReportType = HashReportType.Collection;
                var hashReports = new List <IHashFileReport>();
                foreach (var item in mod.Files.Where(p => game.GameFolders.Any(a => p.StartsWith(a))))
                {
                    var info = Reader.GetFileInfo(mod.FullPath, item);
                    if (info != null)
                    {
                        var fileReport = GetModelInstance <IHashFileReport>();
                        fileReport.File = item;
                        fileReport.Hash = info.ContentSHA;
                        hashReports.Add(fileReport);
                    }
                    progress++;
                    var percentage = GetProgressPercentage(total, progress);
                    if (percentage != lastPercentage)
                    {
                        await messageBus.PublishAsync(new ModReportExportEvent(1, percentage));
                    }
                    lastPercentage = percentage;
                }
                report.Reports = hashReports;
                reports.Add(report);
            }
            return(reports);
        }