Beispiel #1
0
        private async Task ExecuteAsync(UpgradeArguments args)
        {
            Controller.HealthCheck();

            if (args.All && args.Filter != null)
            {
                throw new UserInputException("You cannot specify --all and an item to upgrade at the same time");
            }
            else if (!args.All && args.Filter == null)
            {
                throw new UserInputException("You must specify what to upgrade (a .cs, .cslist, .json or package name), or pass --all to upgrade everything");
            }

            // TODO: If the item is a package (no extension), resolve it to a path (if the plugin was not downloaded, throw)
            var(saves, registry) = await GetSavesAndRegistryAsync(args.Filter);

            var matches = Controller.MatchSavesToRegistry(saves, registry);

            PrintWarnings(args.Warnings, saves.Errors);

            foreach (var match in matches.HashMatches)
            {
                await HandleOne(match, args);
            }
        }
Beispiel #2
0
        private async Task HandleOne(RegistrySavesMatch match, UpgradeArguments args)
        {
            var latestVersion   = match.Script.GetLatestVersion();
            var updateToVersion = latestVersion.Version.Equals(match.Version.Version) ? null : latestVersion;

            if (match.Local.Scenes == null || (match.Local.Scenes.Count == 0 && updateToVersion == null))
            {
                if (args.Verbose)
                {
                    PrintScriptToPackage(match, null);
                    Renderer.WriteLine($"  Skipping because no updates are available and no scenes are using it", ConsoleColor.Yellow);
                }
                return;
            }

            PrintScriptToPackage(match, updateToVersion);

            var info = await Controller.GetInstalledPackageInfoAsync(match.Script.Name, updateToVersion ?? match.Version);

            var statuses = info.DistinctStatuses();

            if (statuses.Length != 1)
            {
                PrintCorruptedInstallInfo(info);
                if (!args.Force)
                {
                    return;
                }
            }

            var status = statuses[0];

            if (status == LocalPackageInfo.FileStatus.HashMismatch)
            {
                PrintCorruptedInstallInfo(info);
                if (!args.Force)
                {
                    return;
                }
            }

            if (status == LocalPackageInfo.FileStatus.NotInstalled)
            {
                if (args.Get)
                {
                    if (args.Noop)
                    {
                        Renderer.WriteLine("  Skipping install because the --noop option was specified", ConsoleColor.Yellow);
                    }
                    else if (!args.Force && latestVersion.Files.Where(f => f.Url == null && f.LocalPath != null).Any(f => !Controller.Exists(f.LocalPath)))
                    {
                        Renderer.WriteLine($"  Cannot upgrade automatically because some companion files must be downloaded. Get them from: {match.Script.Homepage ?? match.Script.Repository ?? "(no link provided)"}", ConsoleColor.Yellow);
                        return;
                    }
                    else
                    {
                        Renderer.Write($"  Installing...");
                        info = await Controller.InstallPackageAsync(info, args.Force);

                        Renderer.WriteLine($"  Downloaded in {info.InstallFolder}:", ConsoleColor.Green);
                        foreach (var file in info.Files)
                        {
                            Renderer.WriteLine($"  - {Controller.GetRelativePath(file.Path, info.InstallFolder)}");
                        }
                    }
                }
                else if (args.Verbose)
                {
                    Renderer.WriteLine($"  Skipping downloading to the party folder because this package is not installed (run again with --get to download it)", ConsoleColor.DarkYellow);
                }
            }
            else if (status != LocalPackageInfo.FileStatus.Installed)
            {
                throw new NotImplementedException($"Status {status} is not implemented");
            }

            if (updateToVersion == null && !(args.Fix && !match.Local.FullPath.StartsWith(info.InstallFolder)))
            {
                return;
            }

            foreach (var scene in match.Local.Scenes)
            {
                string scenePath = Controller.GetDisplayPath(scene.FullPath);
                if (args.Noop)
                {
                    Renderer.WriteLine($"  Skipping scene {scenePath} because --noop option was specified", ConsoleColor.Yellow);
                    continue;
                }
                Renderer.Write($"  Updating scene ");
                Renderer.Write(scenePath, ConsoleColor.Blue);
                Renderer.Write($"...");

                var changes = await Controller.UpdateScriptInSceneAsync(scene, match.Local, info);

                if (changes.Length > 0)
                {
                    Renderer.WriteLine(" updated", ConsoleColor.Green);
                }
                else
                {
                    Renderer.WriteLine(" already up to date", ConsoleColor.DarkGray);
                }

                if (args.Verbose)
                {
                    using (Renderer.WithColor(ConsoleColor.DarkGray))
                    {
                        foreach (var(before, after) in changes)
                        {
                            Renderer.WriteLine($"    {before} > {after}");
                        }
                    }
                }

                if (args.Clean && changes.Length > 0)
                {
                    if (args.Noop)
                    {
                        Renderer.WriteLine("  Skipping cleanup because the --noop option was specified", ConsoleColor.Yellow);
                    }
                    else
                    {
                        Controller.Delete(match.Local.FullPath);
                    }
                }
            }
        }