Esempio n. 1
0
        protected override async Task ExecuteImplAsync(GetArguments args)
        {
            ValidateArguments(args.Packages);
            Controller.HealthCheck();

            var packages = args.Packages ?? new string[0];

            if (args.All && packages.Length > 0)
            {
                throw new UserInputException("You cannot specify --all and an item to get at the same time");
            }
            else if (!args.All && packages.Length == 0)
            {
                throw new UserInputException("You must specify what to get, or pass --all to get everything");
            }

            var registry = await Controller.AcquireRegistryAsync().ConfigureAwait(false);

            if (args.All)
            {
                foreach (var package in registry.Get(RegistryPackageType.Scripts))
                {
                    await GetOneAsync(args, new RegistryPackageVersionContext(registry, package, package.GetLatestVersion()));
                }
            }
            else
            {
                foreach (var p in packages)
                {
                    if (!PackageFullName.TryParsePackage(p, out var packageName))
                    {
                        throw new UserInputException("Invalid package name. Example: 'scripts/my-script'");
                    }

                    var package = registry.GetPackage(packageName);
                    if (package == null)
                    {
                        throw new RegistryException($"Package not found: '{packageName}'");
                    }

                    var version = packageName.Version != null
                        ? package.GetVersion(packageName.Version)
                        : package.GetLatestVersion();

                    if (version == null)
                    {
                        throw new RegistryException($"Package version not found: '{packageName}'");
                    }

                    var context = new RegistryPackageVersionContext(registry, package, version);

                    await GetOneAsync(args, context);
                }
            }
        }
Esempio n. 2
0
        public string GetDirectory(RegistryPackageVersionContext context)
        {
            var(_, package, version) = context;
            string author         = package.Author ?? "Anonymous";
            var    relativeFolder = package.Type switch
            {
                RegistryPackageType.Scripts => _fs.Path.Combine(author, package.Name, version.Version),
                RegistryPackageType.Clothing => _fs.Path.Combine(author, package.Name),
                RegistryPackageType.Scenes => _fs.Path.Combine(author, package.Name),
                RegistryPackageType.Textures => _fs.Path.Combine(author, package.Name),
                RegistryPackageType.Assets => _fs.Path.Combine(author, package.Name),
                RegistryPackageType.FemaleMorphs => _fs.Path.Combine(package.Name),
                RegistryPackageType.MaleMorphs => _fs.Path.Combine(package.Name),
                _ => throw new NotImplementedException($"Type {package.Type} is not currently handled by the folders helper."),
            };

            return(_fs.Path.Combine(GetDirectory(package.Type), relativeFolder));
        }
Esempio n. 3
0
        public async Task <LocalPackageInfo> GetInstalledPackageInfoAsync(RegistryPackageVersionContext context)
        {
            var(registry, package, version) = context;
            var packagePath = _folders.GetDirectory(context);
            var files       = new List <InstalledFileInfo>();

            foreach (var file in version.Files.Where(f => !f.Ignore && f.Filename != null))
            {
                files.Add(await GetPackageFileInfo(packagePath, file).ConfigureAwait(false));
            }
            if (version.Dependencies != null)
            {
                foreach (var dependency in version.Dependencies)
                {
                    if (!registry.TryGetDependency(dependency, out var depContext))
                    {
                        throw new RegistryException($"Could not find dependency {dependency}");
                    }
                    if (depContext.Version.Dependencies != null && depContext.Version.Dependencies.Count > 0)
                    {
                        throw new RegistryException($"Nesting of dependencies is not yet supported. {context} -> {depContext} -> {depContext.Version.Dependencies.FirstOrDefault()}");
                    }
                    var depPath  = _folders.GetDirectory(depContext);
                    var depFiles = dependency.Files != null && dependency.Files.Count > 0
                        ? dependency.Files.Select(df => depContext.Version.Files.FirstOrDefault(vf => df == vf.Filename) ?? throw new RegistryException($"Could not find dependency file '{df}' in package '{depContext.Package}@{depContext.Version.Version}'"))
                        : depContext.Version.Files;
                    foreach (var depFile in depFiles)
                    {
                        files.Add(await GetPackageFileInfo(depPath, depFile).ConfigureAwait(false));
                    }
                }
            }

            return(new LocalPackageInfo
            {
                PackageFolder = packagePath,
                Files = files.ToArray(),
                Corrupted = files.Any(f => f.Status == FileStatus.HashMismatch),
                Installed = files.All(f => f.Status == FileStatus.Installed),
                Installable = files.All(f => f.Status != FileStatus.NotDownloadable && f.Status != FileStatus.HashMismatch)
            });
        }
Esempio n. 4
0
        private async Task GetOneAsync(GetArguments args, RegistryPackageVersionContext context)
        {
            Renderer.Write($"Installing package ");
            Renderer.Write($"{context.Package.Name} v{context.Version.Version}", ConsoleColor.Cyan);
            Renderer.WriteLine("...");

            var installedStatus = await Controller.GetInstalledPackageInfoAsync(context);

            if (installedStatus.Installed && !args.Force)
            {
                Renderer.WriteLine($"  Plugin already installed at {installedStatus.PackageFolder}", ConsoleColor.Yellow);
                PrintInstalledFiles(installedStatus);
                return;
            }

            if (installedStatus.Installable || args.Force)
            {
                if (!args.Noop)
                {
                    var installResult = await Controller.InstallPackageAsync(installedStatus, args.Force);

                    Renderer.WriteLine($"  Files downloaded in {installedStatus.PackageFolder}:");
                    PrintInstalledFiles(installResult, "  ");
                }
                else
                {
                    Renderer.WriteLine($"  Noop has been used, skipping install. Files would have been downloaded in {installedStatus.PackageFolder}:");
                    foreach (var file in installedStatus.Files.Where(f => f.Status == FileStatus.NotInstalled))
                    {
                        Renderer.WriteLine($"    Path: {Controller.GetDisplayPath(file.FullPath)}");
                        Renderer.WriteLine($"    Hash: {file.RegistryFile.Hash.Value} ({file.RegistryFile.Hash.Type})");
                        Renderer.WriteLine($"    Url:  {file.RegistryFile.Url}");
                    }
                }
                return;
            }

            Renderer.WriteLine($"  Some files are not available for download or invalid, you can instead download at {context.Version.DownloadUrl ?? context.Package.Homepage ?? context.Package.Repository ?? "(no link provided)"}", ConsoleColor.Yellow);
            PrintInstalledFiles(installedStatus, "  ");
            return;
        }
Esempio n. 5
0
        protected override async Task ExecuteImplAsync(ShowArguments args)
        {
            ValidateArguments(args.Package);
            Controller.HealthCheck();

            if (!PackageFullName.TryParsePackage(args.Package, out var packageName))
            {
                throw new UserInputException("Invalid package name. Example: 'scripts/my-script'");
            }

            var registry = await Controller.AcquireRegistryAsync().ConfigureAwait(false);

            var package = registry.GetPackage(packageName);

            if (package == null)
            {
                throw new UserInputException($"Could not find package {args.Package}");
            }
            var version = package.GetLatestVersion();

            if (version?.Files == null)
            {
                throw new RegistryException("Package does not have any versions");
            }
            var context = new RegistryPackageVersionContext(registry, package, version);

            var packageTitle = $"{package.Name} v{version.Version} ({package.Type.ToString().ToLowerInvariant()})";

            Renderer.WriteLine(packageTitle, ConsoleColor.Cyan);
            Renderer.WriteLine(new string('=', packageTitle.Length));

            Renderer.WriteLine("Info:", ConsoleColor.Blue);
            if (package.Description != null)
            {
                Renderer.WriteLine($"  Description: {package.Description}");
            }
            if (package.Tags != null)
            {
                Renderer.WriteLine($"  Tags: {string.Join(", ", package.Tags)}");
            }
            if (package.Repository != null)
            {
                Renderer.WriteLine($"  Repository: {package.Repository}");
            }
            if (package.Homepage != null)
            {
                Renderer.WriteLine($"  Homepage: {package.Homepage}");
            }

            Renderer.WriteLine("Author:", ConsoleColor.Blue);
            Renderer.WriteLine($"  {package.Author}");
            var registryAuthor = registry.Authors?.FirstOrDefault(a => a.Name == package.Author);

            if (registryAuthor != null)
            {
                if (registryAuthor.Github != null)
                {
                    Renderer.WriteLine($"  Github: {registryAuthor.Github}");
                }
                if (registryAuthor.Reddit != null)
                {
                    Renderer.WriteLine($"  Reddit: {registryAuthor.Reddit}");
                }
            }

            Renderer.WriteLine("Versions:", ConsoleColor.Blue);
            foreach (var v in package.Versions)
            {
                Renderer.WriteLine($"  v{v.Version}, {v.Created.ToLocalTime().ToString("d")}: {v.Notes ?? "(none)"}");
                if (version.DownloadUrl != null)
                {
                    Renderer.WriteLine($"  Download: {v.DownloadUrl}");
                }
            }

            if ((version.Dependencies?.Count ?? 0) > 0)
            {
                Renderer.WriteLine("Dependencies:", ConsoleColor.Blue);
                foreach (var dependency in version.Dependencies)
                {
                    if (registry.TryGetDependency(dependency, out var depContext))
                    {
                        Renderer.WriteLine($"  {depContext.Package.Name} v{depContext.Version.Version} by {depContext.Package.Author} ({depContext.Version.Files.Count} files)");
                    }
                    else
                    {
                        Renderer.WriteLine($"  Dependency {dependency} was not found in the registry");
                    }
                }
            }

            Renderer.WriteLine($"Files (for v{version.Version}):", ConsoleColor.Blue);
            Renderer.WriteLine("Note: This only checks for the expected location. To see other locations, use party status.");
            var info = await Controller.GetInstalledPackageInfoAsync(context);

            PrintInstalledFiles(info, "");
        }
        private static void GivenContext(string path, string content, RegistryFile[] files, out GetInstalledPackageInfoHandler handler, out RegistryPackageVersionContext context)
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { path, new MockFileData(content) },
            });

            var folders = new FoldersHelper(fileSystem, @"C:\VaM", new[] { "Saves", "Custom" }, true);

            handler = new GetInstalledPackageInfoHandler(fileSystem, folders);

            var registry = TestFactory.Reg(
                TestFactory.RegScript("my-script", "some-author",
                                      TestFactory.RegVer("1.0.0", files)));

            context = registry.TryGetPackageVersion(RegistryPackageType.Scripts, "my-script", "1.0.0", out var x) ? x : throw new Exception("Could not get package context");
        }
Esempio n. 7
0
 public RegistryPackageFileContext(RegistryPackageVersionContext context, RegistryFile file)
     : this(context.Registry, context.Package, context.Version, file)
 {
 }