Esempio n. 1
0
        public void Delete(LocalScheme resource)
        {
            var gameInfo = _wormsLocator.Find();
            var path     = _fileSystem.Path.Combine(gameInfo.SchemesFolder, resource.Name + ".wsc");

            _fileSystem.File.Delete(path);
        }
Esempio n. 2
0
        private string ValidateOutputFolder(string outputFolder)
        {
            if (string.IsNullOrWhiteSpace(ResourceFolder))
            {
                var gameInfo = _wormsLocator.Find();

                if (!gameInfo.IsInstalled)
                {
                    throw new ConfigurationException(
                              "Worms is not installed. Use the --resource-folder option to specify where the Scheme should be created");
                }

                outputFolder = gameInfo.SchemesFolder;
            }

            if (_fileSystem.Directory.Exists(outputFolder))
            {
                return(outputFolder);
            }

            Logger.Information($"Output folder ({outputFolder}) does not exit. It will be created.");
            _fileSystem.Directory.CreateDirectory(outputFolder);

            return(outputFolder);
        }
Esempio n. 3
0
        public Task RunWorms(params string[] wormsArgs)
        {
            return(Task.Factory.StartNew(
                       () =>
            {
                var gameInfo = _wormsLocator.Find();

                var args = string.Join(" ", wormsArgs);
                using (var process = Process.Start(gameInfo.ExeLocation, args))
                {
                    if (process == null)
                    {
                        return;
                    }

                    process.WaitForExit();
                    if (process.ExitCode == 0)
                    {
                        return;
                    }
                }

                _steamService.WaitForSteamPrompt();

                var wormsProcess = Process.GetProcessesByName(gameInfo.ProcessName).FirstOrDefault();
                wormsProcess?.WaitForExit();
            }));
        }
Esempio n. 4
0
        public IReadOnlyCollection <string> GetReplayPaths(string pattern)
        {
            var gameInfo = _wormsLocator.Find();

            if (!gameInfo.IsInstalled)
            {
                return(new List <string>(0));
            }

            return(_fileSystem.Directory.GetFiles(gameInfo.ReplayFolder, $"{pattern}*.WAgame"));
        }
Esempio n. 5
0
        public Task <int> OnExecuteAsync()
        {
            var cliInfo = _cliInfoRetriever.Get();

            Logger.Information($"Worms CLI: {cliInfo.Version.ToString(3)}");

            var gameInfo    = _wormsLocator.Find();
            var gameVersion = gameInfo.IsInstalled ? gameInfo.Version.ToString(4) : "Not Installed";

            Logger.Information($"Worms Armageddon: {gameVersion}");
            return(Task.FromResult(0));
        }
Esempio n. 6
0
        public IReadOnlyCollection <ReplayPaths> GetReplayPaths(string pattern)
        {
            var gameInfo = _wormsLocator.Find();

            if (!gameInfo.IsInstalled)
            {
                return(new List <ReplayPaths>(0));
            }

            var waGamePaths = _fileSystem.Directory.GetFiles(gameInfo.ReplayFolder, $"{pattern}*.WAgame");

            return(waGamePaths.Select(x => new ReplayPaths(x, GetLogPath(x))).ToList());
        }
Esempio n. 7
0
        public Task RunWorms(params string[] wormsArgs)
        {
            return(Task.Factory.StartNew(
                       () =>
            {
                var gameInfo = _wormsLocator.Find();

                var args = string.Join(" ", wormsArgs);
                using var process = Process.Start("wine", gameInfo.ExeLocation + " " + args);
                if (process == null)
                {
                    return;
                }
                process.WaitForExit();
            }));
        }
Esempio n. 8
0
        public async Task <int> OnExecuteAsync()
        {
            Logger.Verbose("Loading configuration");
            var config = _configManager.Load();

            string hostIp;

            try
            {
                const string domain = "red-gate.com";
                hostIp = GetIpAddress(domain);
            }
            catch (Exception e)
            {
                Logger.Error($"IP address could not be found. {e.Message}");
                return(1);
            }

            var gameInfo = _wormsLocator.Find();

            if (!gameInfo.IsInstalled)
            {
                Logger.Error("Worms Armageddon is not installed");
                return(1);
            }

            Logger.Information("Downloading the latest options");
            if (!DryRun)
            {
                await _leagueUpdater.Update(config, Logger).ConfigureAwait(false);
            }

            Logger.Information("Starting Worms Armageddon");
            var runGame = !DryRun?_wormsRunner.RunWorms("wa://") : Task.CompletedTask;

            Logger.Information("Announcing game on Slack");
            Logger.Verbose($"Host name: {hostIp}");
            if (!DryRun)
            {
                await _slackAnnouncer.AnnounceGameStarting(hostIp, config.SlackWebHook, Logger).ConfigureAwait(false);
            }

            await runGame;

            return(0);
        }
Esempio n. 9
0
        public async Task Update(Config config, ILogger logger)
        {
            _packageManager.Connect("TheEadie", "WormsLeague", "schemes/v", config.GitHubPersonalAccessToken);

            var versions = (await _packageManager.GetAvailableVersions().ConfigureAwait(false)).ToList();

            logger.Verbose($"Available versions: {string.Join(", ", versions)}");

            var latestVersion = versions.OrderByDescending(x => x).FirstOrDefault();

            logger.Verbose($"Latest version: {latestVersion}");

            logger.Information($"Downloading Schemes: {latestVersion}");

            var schemesFolder = _wormsLocator.Find().SchemesFolder;

            await _packageManager.DownloadVersion(latestVersion, schemesFolder).ConfigureAwait(false);
        }
Esempio n. 10
0
        private string GetFilePath(string name)
        {
            var gameInfo = _wormsLocator.Find();

            if (!gameInfo.IsInstalled)
            {
                throw new ConfigurationException(
                          "Worms is not installed.");
            }

            var filePath = _fileSystem.Path.Combine(gameInfo.SchemesFolder, name + ".wsc");

            if (!_fileSystem.File.Exists(filePath))
            {
                throw new ConfigurationException($"No Scheme file found with name: {name}");
            }

            return(filePath);
        }
Esempio n. 11
0
        public IReadOnlyCollection <SchemeResource> Get(string pattern = "*")
        {
            var gameInfo = _wormsLocator.Find();

            if (!gameInfo.IsInstalled)
            {
                return(new List <SchemeResource>(0));
            }

            var schemes = new List <SchemeResource>();

            foreach (var scheme in _fileSystem.Directory.GetFiles(gameInfo.SchemesFolder, $"{pattern}.wsc"))
            {
                var fileName = _fileSystem.Path.GetFileNameWithoutExtension(scheme);
                var details  = _wscReader.Read(scheme);
                schemes.Add(new SchemeResource(fileName, "local", details));
            }

            return(schemes);
        }
Esempio n. 12
0
        public Task RunWorms(params string[] wormsArgs)
        {
            return(Task.Factory.StartNew(
                       () =>
            {
                var gameInfo = _wormsLocator.Find();

                var args = string.Join(" ", wormsArgs);
                var processStartInfo = new ProcessStartInfo
                {
                    FileName = "wine",
                    Arguments = gameInfo.ExeLocation + " " + args,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true
                };

                using var process = Process.Start(processStartInfo);
                if (process == null)
                {
                    return;
                }
                process.WaitForExit();
            }));
        }
Esempio n. 13
0
        public async Task <LocalGif> Create(LocalGifCreateParameters parameters)
        {
            var replayPath = parameters.Replay.Paths.WAgamePath;
            var turn       = parameters.Replay.Details.Turns.ElementAt((int)parameters.Turn - 1);

            var replayName     = _fileSystem.Path.GetFileNameWithoutExtension(replayPath);
            var worms          = _wormsLocator.Find();
            var framesFolder   = _fileSystem.Path.Combine(worms.CaptureFolder, replayName);
            var outputFileName = _fileSystem.Path.Combine(worms.CaptureFolder, replayName + " - " + parameters.Turn + ".gif");

            var animationDelay = 100 / parameters.FramesPerSecond / parameters.SpeedMultiplier;

            DeleteFrames(framesFolder);
            await _replayFrameExtractor.ExtractReplayFrames(
                replayPath,
                parameters.FramesPerSecond,
                turn.Start + parameters.StartOffset,
                turn.End - parameters.EndOffset);

            CreateGifFromFiles(framesFolder, outputFileName, animationDelay, 640, 480);
            DeleteFrames(framesFolder);

            return(new LocalGif(outputFileName));
        }