internal RemoteUniversalPackage(JObject obj)
        {
            var group = (string)obj["group"];
            var name  = (string)obj["name"];

            if (string.IsNullOrEmpty(name))
            {
                throw new FormatException("Missing \"name\" property.");
            }

            this.FullName = new UniversalPackageId(group, name);

            var latestVersion = (string)obj["latestVersion"];

            if (string.IsNullOrEmpty(latestVersion))
            {
                throw new FormatException("Missing \"latestVersion\" property.");
            }

            this.LatestVersion = UniversalPackageVersion.Parse(latestVersion);

            this.Title       = (string)obj["title"];
            this.Icon        = (string)obj["icon"];
            this.Description = (string)obj["description"];
            this.Downloads   = (int?)obj["downloads"] ?? 0;

            this.AllVersions   = Array.AsReadOnly(((JArray)obj["versions"]).Select(t => UniversalPackageVersion.Parse((string)t)).ToArray());
            this.AllProperties = new ReadOnlyDictionary <string, object>((IDictionary <string, object>)obj.ToObject(typeof(Dictionary <string, object>)));
        }
Exemplo n.º 2
0
        internal RemoteUniversalPackageVersion(JObject obj)
        {
            var group = (string)obj["group"];
            var name  = (string)obj["name"];

            if (string.IsNullOrEmpty(name))
            {
                throw new FormatException("Missing \"name\" property.");
            }

            this.FullName = new UniversalPackageId(group, name);

            var version = (string)obj["version"];

            if (string.IsNullOrEmpty(version))
            {
                throw new FormatException("Missing \"version\" property.");
            }

            this.Version       = UniversalPackageVersion.Parse(version);
            this.Title         = (string)obj["title"];
            this.Icon          = (string)obj["icon"];
            this.Description   = (string)obj["description"];
            this.Size          = (long?)obj["size"] ?? 0;
            this.PublishedDate = (DateTimeOffset)obj["published"];
            this.Downloads     = (int?)obj["downloads"] ?? 0;
            var sha1String = (string)obj["sha1"];

            if (!string.IsNullOrEmpty(sha1String))
            {
                this.SHA1 = HexString.Parse(sha1String);
            }

            this.AllProperties = new ReadOnlyDictionary <string, object>((IDictionary <string, object>)obj.ToObject(typeof(Dictionary <string, object>)));
        }
Exemplo n.º 3
0
        private bool ParseOption(ArgOption o)
        {
            if (string.Equals("source", o.Key, StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrWhiteSpace(o.Value))
                {
                    throw new RompException("Expected source name or URL after --source=");
                }

                if (o.Value.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || o.Value.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                {
                    this.Source = new UniversalFeedEndpoint(o.Value, true);
                }
                else
                {
                    var source = RompDb.GetPackageSources()
                                 .FirstOrDefault(s => string.Equals(s.Name, o.Value, StringComparison.OrdinalIgnoreCase));

                    if (source == null)
                    {
                        throw new RompException($"Package source \"{o.Value}\" not found.");
                    }

                    if (string.IsNullOrEmpty(source.UserName) || source.Password == null)
                    {
                        this.Source = new UniversalFeedEndpoint(source.FeedUrl, true);
                    }
                    else
                    {
                        this.Source = new UniversalFeedEndpoint(new Uri(source.FeedUrl), source.UserName, source.Password);
                    }
                }

                return(true);
            }
            else if (string.Equals("version", o.Key, StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrWhiteSpace(o.Value))
                {
                    throw new RompException("Expected package version after --version=");
                }

                try
                {
                    this.PackageVersion = UniversalPackageVersion.Parse(o.Value);
                }
                catch (Exception ex)
                {
                    throw new RompException("Invalid version: " + o.Value, ex);
                }

                return(true);
            }

            return(false);
        }
        private static JObject GetMungedPackage(IEnumerable <PackageFile> packageVersions)
        {
            var sorted = (from p in packageVersions
                          let v = UniversalPackageVersion.Parse((string)p.JObject["version"])
                                  orderby v descending
                                  select p).ToList();

            var latest = (JObject)sorted.First().JObject.DeepClone();

            latest["latestVersion"] = latest["version"];
            latest.Remove("version");
            latest["versions"] = new JArray(sorted.Select(v => (string)v.JObject["version"]));
            return(latest);
        }
        public Stream GetPackageStream(UniversalPackageId id, UniversalPackageVersion version)
        {
            var packageVersions = this.allPackages.Value[new PackageKey(id.Group, id.Name)];
            var match           = default(PackageFile);

            if (version == null)
            {
                match = packageVersions.OrderByDescending(p => UniversalPackageVersion.Parse((string)p.JObject["version"])).FirstOrDefault();
            }
            else
            {
                var s = version.ToString();
                match = packageVersions.FirstOrDefault(p => string.Equals((string)p.JObject["version"], s, StringComparison.OrdinalIgnoreCase));
            }

            if (match.IsNull)
            {
                return(null);
            }

            return(new FileStream(match.FileName, FileMode.Open, FileAccess.Read, FileShare.Read));
        }
Exemplo n.º 6
0
        private static async Task Uninstall(ArgList args)
        {
            var spec = PackageSpecifier.FromArgs(args);

            if (spec == null)
            {
                throw new RompException("Usage: romp uninstall <package> [-Vvar=value...]");
            }

            Console.WriteLine("Package: " + spec);
            Console.WriteLine();

            var registeredPackage = await GetRegisteredPackageAsync(spec.PackageId);

            if (registeredPackage == null)
            {
                throw new RompException("Package is not installed.");
            }

            spec.PackageVersion = UniversalPackageVersion.Parse(registeredPackage.Version);

            await ExtensionsManager.WaitForInitializationAsync();

            var vars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            using (var package = await spec.FetchPackageAsync(args, default))
            {
                args.ProcessOptions(parseOption);

                foreach (var var in vars)
                {
                    RompSessionVariable.SetSessionVariable(var.Key, var.Value);
                }

                var packageInfo = RompPackInfo.Load(package);
                if (packageInfo.WriteScriptErrors())
                {
                    throw new RompException("Error compiling uninstall script.");
                }

                PackageInstaller.TargetDirectory = registeredPackage.InstallPath;
                RompSessionVariable.SetSessionVariable("TargetDirectory", registeredPackage.InstallPath);

                await PackageInstaller.RunAsync(package, "uninstall.otter", false);

                using (var registry = PackageRegistry.GetRegistry(RompConfig.UserMode))
                {
                    await registry.LockAsync();

                    await registry.UnregisterPackageAsync(registeredPackage);

                    await registry.DeleteFromCacheAsync(spec.PackageId, package.Version);

                    await registry.UnlockAsync();
                }
            }

            bool parseOption(ArgOption o)
            {
                if (o.Key.StartsWith("V") && o.Key.Length > 1)
                {
                    vars[o.Key.Substring(1)] = o.Value ?? string.Empty;
                    return(true);
                }

                return(false);
            }
        }