/// <summary>
 /// Maps the import result.
 /// </summary>
 /// <param name="modCollection">The mod collection.</param>
 /// <param name="importResult">The import result.</param>
 protected virtual void MapImportResult(IModCollection modCollection, ICollectionImportResult importResult)
 {
     if (!string.IsNullOrWhiteSpace(importResult.Game))
     {
         var collectionGame = GameService.Get().FirstOrDefault(p => p.Type.Equals(importResult.Game));
         if (collectionGame == null)
         {
             collectionGame = GameService.Get().FirstOrDefault(p => p.ParadoxGameId.Equals(importResult.Game));
         }
         if (collectionGame != null)
         {
             modCollection.Game = collectionGame.Type;
         }
     }
     modCollection.IsSelected       = importResult.IsSelected;
     modCollection.MergedFolderName = importResult.MergedFolderName;
     modCollection.ModNames         = importResult.ModNames;
     modCollection.Mods             = importResult.Descriptors;
     modCollection.Name             = importResult.Name;
     modCollection.PatchModEnabled  = importResult.PatchModEnabled;
     if (importResult.ModIds != null && importResult.ModIds.Any())
     {
         var mods = GetInstalledModsInternal(modCollection.Game, false);
         if (mods.Any())
         {
             var collectionMods = mods.Where(p => importResult.ModIds.Contains(p.RemoteId.ToString()));
             modCollection.Mods     = collectionMods.Select(p => p.DescriptorFile).ToList();
             modCollection.ModNames = collectionMods.Select(p => p.Name).ToList();
         }
     }
 }
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Customs the mod directory empty asynchronous.
        /// </summary>
        /// <param name="gameType">Type of the game.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> CustomModDirectoryEmptyAsync(string gameType)
        {
            var game = GameService.Get().FirstOrDefault(p => p.Type.Equals(gameType));

            if (game == null)
            {
                return(true);
            }
            if (string.IsNullOrWhiteSpace(game.CustomModDirectory))
            {
                return(true);
            }
            var path   = GetModDirectoryRootPath(game);
            var result = await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = path
            });

            return(!result);
        }
示例#4
0
 /// <summary>
 /// Gets the installed mods internal.
 /// </summary>
 /// <param name="game">The game.</param>
 /// <param name="ignorePatchMods">if set to <c>true</c> [ignore patch mods].</param>
 /// <returns>IEnumerable&lt;IMod&gt;.</returns>
 protected virtual IEnumerable <IMod> GetInstalledModsInternal(string game, bool ignorePatchMods)
 {
     return(GetInstalledModsInternal(GameService.Get().FirstOrDefault(p => p.Type.Equals(game)), ignorePatchMods));
 }