Exemple #1
0
        private List <BikeyFile> GetKeysFromMod(IMod mod)
        {
            _logger.LogDebug("Looking for standard keys for {Mod}", mod.ToShortString());

            return(_keysFinder.GetKeysFromDirectory(mod.Directory)
                   .Select(path => new BikeyFile(path, mod.ToShortString()))
                   .ToList());
        }
        /// <summary>
        /// Checks if <paramref name="foundDirectory"/> equals to main arma server directory and throws an exception then.
        /// This prevents any f**k ups in server directory.
        /// This is just a failsafe, it should never be called actually.
        /// Might be removed when 100% sure it won't happen again.
        /// </summary>
        /// <param name="mod">Mod for which the <paramref name="foundDirectory"/> was found.</param>
        /// <param name="foundDirectory">Directory path to mod.</param>
        /// <returns>Mod directory path.</returns>
        /// <exception cref="ModNotFoundException">Thrown when <paramref name="foundDirectory"/> equals to server directory.</exception>
        private Result <string> AssertFoundDirectoryIsNotServerDirectory(IMod mod, string foundDirectory)
        {
            if (foundDirectory != _serverPath)
            {
                return(Result.Success(foundDirectory));
            }

            _logger.LogError("Directory for mod {@Mod} equals server directory while it should not!", mod);

            throw new ModNotFoundException(mod.ToShortString(), $"Directory for {mod.ToShortString()} equals server directory while it should not!");
        }
Exemple #3
0
        private void LogKeysCopyError(IMod mod, string error)
        {
            _logger.LogWarning(
                "Copying keys for mod {Mod} failed with error: {Error}",
                mod.ToShortString(),
                error);

            _logger.LogTrace("Copying keys failed for mod {@Mod}", mod);
        }
Exemple #4
0
        private List <BikeyFile> GetExternalKeys(IMod mod)
        {
            var result = _modDirectoryFinder.TryFindModDirectory(mod, _externalKeysDirectoryPath)
                         .Tap(_ => _logger.LogDebug("Looking for external keys for {Mod}", mod.ToShortString()));

            return(result.IsSuccess
                ? _keysFinder.GetKeysFromDirectory(result.Value)
                   .Select(path => new BikeyFile(path, mod.ToShortString()))
                   .ToList()
                : new List <BikeyFile>());
        }
Exemple #5
0
        private Result <ModBikeys> CopyKeysForMod(IMod mod)
        {
            try
            {
                var keysForMod = GetAllKeysForMod(mod);

                _logger.LogTrace(
                    "Found {Count} keys for {@Mod}",
                    keysForMod.BikeyFiles.Count,
                    mod);

                return(_keysCopier.CopyKeys(_keysDirectory, keysForMod.BikeyFiles)
                       .Bind(() => Result.Success(keysForMod)));
            }
            // TODO: Remove if does not occur anymore
            catch (ArgumentNullException exception)
            {
                _logger.LogError(
                    exception,
                    "Error copying keys for {Mod}",
                    mod.ToShortString());
                throw;
            }
        }
 public Result <string> TryFindModDirectory(IMod mod, string directoryToSearch)
 => TryFindModDirectoryByDirectory(mod, directoryToSearch)
 .OnFailureCompensate(() => TryFindModDirectoryByWorkshopId(mod, directoryToSearch))
 .OnFailureCompensate(() => TryFindModDirectoryByName(mod, directoryToSearch))
 .OnFailureCompensate(() => TryFindModDirectoryByNamePrefixedWithAtSign(mod, directoryToSearch))
 .OnFailureCompensate(() => TryFindCdlcDirectory(mod))
 .OnFailureCompensate(() => Result.Failure <string>($"Directory not found for {mod.ToShortString()}."))
 .Bind(directory => AssertFoundDirectoryIsNotServerDirectory(mod, directory));