private bool ValidateInstalledInternal(string name, string version)
        {
            var allInstalled = InstalledPackage.GetAllInstalledPackages();
            var found        = allInstalled.FirstOrDefault(x =>
            {
                if (x.Data.Name != name)
                {
                    return(false);
                }
                //match the exact version
                if (x.Data.Version == version)
                {
                    return(true);
                }
                //now try to compare the versions
                Version installed;
                Version selected;
                if (Version.TryParse(x.Data.Version, out installed) && Version.TryParse(version, out selected))
                {
                    if (installed >= selected)
                    {
                        return(true);
                    }
                }
                return(false);
            });

            if (found != null)
            {
                //this package is already installed
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// Returns all installed packages - only shows their latest versions
 /// </summary>
 /// <returns></returns>
 public IEnumerable <InstalledPackageModel> GetInstalled()
 {
     return(InstalledPackage.GetAllInstalledPackages()
            .GroupBy(
                //group by name
                x => x.Data.Name,
                //select the package with a parsed version
                pck =>
     {
         Version pckVersion;
         return Version.TryParse(pck.Data.Version, out pckVersion)
                     ? new { package = pck, version = pckVersion }
                     : new { package = pck, version = new Version(0, 0, 0) };
     })
            .Select(grouping =>
     {
         //get the max version for the package
         var maxVersion = grouping.Max(x => x.version);
         //only return the first package with this version
         return grouping.First(x => x.version == maxVersion).package;
     })
            .Select(pack => new InstalledPackageModel
     {
         Name = pack.Data.Name,
         Id = pack.Data.Id,
         Author = pack.Data.Author,
         Version = pack.Data.Version,
         Url = pack.Data.Url,
         License = pack.Data.License,
         LicenseUrl = pack.Data.LicenseUrl,
         Files = pack.Data.Files,
         IconUrl = pack.Data.IconUrl
     })
            .ToList());
 }
    private void VerifyStartsWithVersion(string versionString)
    {
        var prefix = new string(versionString.TakeWhile(x => char.IsDigit(x) || x == '.').ToArray());

        if (!Version.TryParse(prefix, out _))
        {
            throw new WeavingException("The version string must be prefixed with a valid Version. The following string does not: " + versionString);
        }
    }
Exemplo n.º 4
0
 private static IEnumerable <Tuple <string, OverrideVersion> > CreateOverriddenPackages(string overriddenPackagesString)
 {
     if (!string.IsNullOrEmpty(overriddenPackagesString))
     {
         overriddenPackagesString = overriddenPackagesString.Trim();
         string[] overriddenPackagesAndVersions = overriddenPackagesString.Split(new char[] { ';', '\r', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (string overriddenPackagesAndVersion in overriddenPackagesAndVersions)
         {
             string trimmedOverriddenPackagesAndVersion = overriddenPackagesAndVersion.Trim();
             int    separatorIndex = trimmedOverriddenPackagesAndVersion.IndexOf('|');
             if (separatorIndex != -1)
             {
                 string versionString     = trimmedOverriddenPackagesAndVersion.Substring(separatorIndex + 1);
                 string overriddenPackage = trimmedOverriddenPackagesAndVersion.Substring(0, separatorIndex);
                 if (OverrideVersion.TryParse(versionString, out OverrideVersion version))
                 {
                     yield return(Tuple.Create(overriddenPackage, version));
                 }
             }
         }
     }
 }
        internal static bool TryGetVersionComponents(
            string packageVersion,
            out Version version,
            out float prerelease)
        {
            char[] trimChars = new char[] { ' ', '\"', ',' };

            // Note: The version is in the following format Major.Minor.Revision[-Date.Build]

            // Attempt to split the version string into version and float components
            string[] versionComponents = packageVersion.Split(new char[] { '-' }, 2);

            // Parse the version component.
            string versionString = versionComponents[0].Trim(trimChars);

            if (Version.TryParse(versionString, out version))
            {
                if (versionComponents.Length == 2)
                {
                    // Parse the float component
                    string prereleaseString = versionComponents[1].Trim(trimChars);
                    if (float.TryParse(prereleaseString, NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo, out prerelease))
                    {
                        return(true);
                    }
                }
                else
                {
                    prerelease = 0f;
                    return(true);
                }
            }

            version    = null;
            prerelease = float.NaN;
            return(false);
        }
        private string?RetrieveEdgeChromiumInstallerPath()
        {
            string edgeChromiumBaseFolder = $@"{GetFolderPath(SpecialFolder.ProgramFilesX86)}\Microsoft\Edge\Application";

            if (!Directory.Exists(edgeChromiumBaseFolder))
            {
                return(null);
            }

            Version?edgeChromiumVersion         = null;
            string? folderOfSpecificEdgeVersion = Directory.EnumerateDirectories(edgeChromiumBaseFolder)
                                                  .FirstOrDefault(folder => Version.TryParse(new DirectoryInfo(folder).Name, out edgeChromiumVersion));

            if (folderOfSpecificEdgeVersion != null)
            {
                string installerPath = $@"{folderOfSpecificEdgeVersion}\Installer\setup.exe";
                if (File.Exists(installerPath))
                {
                    ui.PrintMessage($"Detected Edge Chromium version {edgeChromiumVersion}.");
                    return(installerPath);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        public Mod(string path)
        {
            if (!Directory.Exists(path))
            {
                throw new Exception($"path '{path}' not found.");
            }

            var about = PathCombine(path, "About", "About.xml");

            if (!File.Exists(about))
            {
                throw new Exception($"About.xml not found at ({about})");
            }

            ContentFolder = path;
            ModBytes      = GetFolderSize(ContentFolder);

            Tags = new List <string>
            {
                "Mod"
            };

            // open About.xml
            var aboutXml = new XmlDocument();

            aboutXml.Load(about);
            foreach (XmlNode node in aboutXml.ChildNodes)
            {
                if (node.Name == "ModMetaData")
                {
                    foreach (XmlNode metaNode in node.ChildNodes)
                    {
                        if (metaNode.Name.ToLower() == "name")
                        {
                            Name = metaNode.InnerText;
                        }
                        if (metaNode.Name.ToLower() == "description")
                        {
                            Description = metaNode.InnerText;
                        }
                        if (metaNode.Name == "supportedVersions")
                        {
                            foreach (XmlNode tagNode in metaNode.ChildNodes)
                            {
                                Version.TryParse(tagNode.InnerText, out Version version);
                                Tags.Add(version.Major + "." + version.Minor);
                            }
                        }
                    }
                }
            }

            // get preview image
            var preview = PathCombine(path, "About", "Preview.png");

            if (File.Exists(preview))
            {
                Preview      = preview;
                PreviewBytes = (new FileInfo(preview)).Length;
            }

            // get publishedFileId
            var pubfileIdPath = PathCombine(path, "About", "PublishedFileId.txt");

            if (File.Exists(pubfileIdPath) && uint.TryParse(File.ReadAllText(pubfileIdPath), out uint id))
            {
                PublishedFileId = new PublishedFileId_t(id);
            }
            else
            {
                PublishedFileId = PublishedFileId_t.Invalid;
            }
        }
Exemplo n.º 8
0
        private bool UpdateResolvedTicketsToVersion(ProjectMeta projectMeta)
        {
            _logger.Info("Getting all versions which have the fix version of <{0}>", _jiraOptions.FixVersion);
            string allClosedTicketsWithoutAnAvailableVersion =
                $"project={projectMeta.key} and status in (Resolved, \"Under Test\", Closed, Done) and fixVersion = {_jiraOptions.FixVersion} order by key";

            var    client = new JiraClient(Account);
            Issues issues = client.GetIssuesByJql(allClosedTicketsWithoutAnAvailableVersion, 0, 500);

            if (!issues.issues.Any())
            {
                _logger.Info("No tickets found to update");
                return(true);
            }
            AnotherJiraRestClient.JiraModel.Version addedVersion = AddOrGetExistingVersion(projectMeta);

            _logger.Info(
                $"Found <{issues.issues.Count}> issues for this release, will be updated to 'Available Version' <{addedVersion.name}>");

            var expando = new ExpandoObject();
            var asDict  = (IDictionary <string, object>)expando;

            asDict.Add(_jiraOptions.CustomFieldName, addedVersion);

            var updateIssue = new
            {
                fields = expando
            };

            _logger.Info($"Found <{issues.issues.Count}> issues to process");

            foreach (var issue in issues.issues)
            {
                _logger.Info($"Processing <{issue.key}>");

                var request = new RestRequest
                {
                    Resource = $"{ResourceUrls.IssueByKey(issue.key)}?fields={_jiraOptions.CustomFieldName}",
                    Method   = Method.GET
                };

                // TODO: custom logic to handle some version information specific to Promapp's needs
                var promappIssue = client.Execute <PromappReleaseIssue>(request, HttpStatusCode.OK);

                if (promappIssue.fields == null)
                {
                    throw new InvalidOperationException("Fields is empty, has the Jira API changed?");
                }

                bool updateVersion = false;
                if (promappIssue.fields.customfield_11520 == null)
                {
                    updateVersion = true;
                }
                else
                {
                    Version customFieldAsVersion;
                    if (!Version.TryParse(promappIssue.fields.customfield_11520.name, out customFieldAsVersion))
                    {
                        throw new InvalidOperationException($"Couldn't parse custom field value for ticket <{issue.key}> of <{promappIssue.fields.customfield_11520.name}> to a version");
                    }

                    // e.g. we have moved from dev->staging
                    if (_jiraOptions.FixVersion >= Version.Parse("1.0.0.0") && customFieldAsVersion < Version.Parse("1.0.0.0") && _jiraOptions.AvailableFromVersion >= Version.Parse("1.0.0"))
                    {
                        updateVersion = true;
                    }
                    else
                    {
                        _logger.Info($"Issue <{issue.key}> won't get updated as it is already stamped with version <{customFieldAsVersion}>");
                    }
                }

                if (updateVersion)
                {
                    _logger.Info($"Update issue <{issue.key}> with version <{_jiraOptions.AvailableFromVersion}>");
                    client.UpdateIssueFields(issue.key, updateIssue);
                }
            }
            return(true);
        }