예제 #1
0
        private bool FetchData(Version version)
        {
            try
            {
                if (Config.GetDevReleases || !String.IsNullOrWhiteSpace(version.PreRelease))
                {
                    LatestRelease = gClient.Repository.Release.GetAll("antonpup", "Aurora", new ApiOptions {
                        PageCount = 1, PageSize = 1
                    }).Result[0];
                }
                else
                {
                    LatestRelease = gClient.Repository.Release.GetLatest("antonpup", "Aurora").Result;
                }

                //Console.WriteLine(reply);
            }
            catch (Exception exc)
            {
                updateState = UpdateStatus.Error;
                return(false);
            }

            return(true);
        }
        public async Task Login(string user, string password)
        {
            Version v;

            switch (_loginBehavior)
            {
            case LoginBehavior.Probe:
                Log.Debug("Detecting Harbor Version");
                try
                {
                    v = await ProbeVersion();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Unable to detect the version of harbor. If your deployment blocks /api/systeminfo or you are running a non-release version you may need to adjust the --login-behavior depending on your version of harbor");
                    throw;
                }
                break;

            case LoginBehavior.ForcePost17:
                Log.Debug("Forcing Post 1.7.0 Login Route");
                v = new Version(1, 7, 0);
                break;

            case LoginBehavior.ForcePre17:
                Log.Debug("Forcing Pre 1.7.0 Login Route");
                v = new Version(1, 6, 0);
                break;

            default:
                throw new ArgumentException("Unknown Login Behavior");
            }

            await DoLoginFor(v, user, password);
        }
예제 #3
0
        public void VerifyPlugin(string pluginName, string requestedVersion)
        {
            var plugin = Db.QueryPlugins(p => p.Name == pluginName).FirstOrDefault();

            if (plugin == null)
            {
                throw new ValidationException($"Plugin {pluginName} not found");
            }

            try
            {
                var requestedVersionRange = new Range(requestedVersion);
                var foundGoodVersion      = false;
                foreach (var pluginVersion in plugin.Versions)
                {
                    var ver = new SemVer.Version(pluginVersion.Version);
                    if (requestedVersionRange.IsSatisfied(ver))
                    {
                        foundGoodVersion = true;
                        break;
                    }
                }

                if (!foundGoodVersion)
                {
                    throw new ValidationException($"Could not find matching version for plugin {pluginName}. Requested version: {requestedVersion}");
                }
            }
            catch (ArgumentException ae)
            {
                throw new ValidationException($"Error processing requested version: {requestedVersion}: {ae.Message}");
            }
        }
예제 #4
0
        public IEnumerator CheckVersion()
        {
            UnityWebRequest www = UnityWebRequest.Get("https://api.github.com/repos/ToniMacaroni/TrickSaber/releases");

            www.SetRequestHeader("User-Agent", "TrickSaber-" + Version.GetVersionString());
            www.timeout = 10;
            yield return(www.SendWebRequest());

            try
            {
                if (!www.isNetworkError && !www.isHttpError)
                {
                    JSONNode releases      = JSON.Parse(www.downloadHandler.text);
                    JSONNode latestRelease = releases[0];
                    JSONNode jsonnode      = latestRelease["tag_name"];
                    string   githubVerStr  = (jsonnode != null) ? jsonnode.Value : null;
                    RemoteVersion   = new Version(githubVerStr);
                    IsNewestVersion = new Range($"<={Version}").IsSatisfied(RemoteVersion);
                }
            }
            catch (Exception ex)
            {
                Plugin.Log.Error("couldn't get version: " + ex.Message);
            }
        }
예제 #5
0
        private void CreateRelease(ReleaseInfo release)
        {
            if (release.gameVersion != selectedGameVersion.value)
            {
                return;
            }

            ReleaseInfo current = releases.Find(x => x.name == release.name);

            if (current == null)
            {
                releases.Add(release);
                return;
            }

            Version currentVersion = new Version(current.version);
            Version newVersion     = new Version(release.version);

            if (release.platform == Platform.Default)
            {
                releases.Remove(current);
                releases.Add(release);
            }
            else
            {
                if (currentVersion < newVersion)
                {
                    releases.Remove(current);
                }
                releases.Add(release);
            }
        }
예제 #6
0
        IEnumerator Start()
        {
            var ver = Assembly.GetExecutingAssembly().GetName().Version;

            Version = new Version(ver.Major, ver.Minor, ver.Build);
            yield return(StartCoroutine(CheckVersion()));

            ControllerModel = GetControllerName();
            Initialized     = true;
            Plugin.Log.Debug($"TrickSaber version {Version.GetVersionString()} started");
        }
예제 #7
0
        public async void Initialize()
        {
            var ver = Assembly.GetExecutingAssembly().GetName().Version;

            Version = new Version(ver.Major, ver.Minor, ver.Build);
            await CheckVersion();

            ControllerModel = GetControllerName();
            Initialized     = true;

            _logger.Debug($"TrickSaber version {Version.GetVersionString()} started");
        }
예제 #8
0
 internal UpdateInfoNode(string JSON)
     : base(JSON)
 {
     ID          = GetInt("id");
     Version     = new Version(GetString("vnr"), true);
     Title       = GetString("title");
     Description = GetString("desc").Replace("\\r\\n", "\r\n");
     Changelog   = GetString("clog").Replace("\\r\\n", "\r\n");
     File        = GetString("file");
     Type        = GetEnum <UpdateType>("type");
     FileSize    = GetLong("size");
     PreRelease  = GetInt("prerelease") == 1 ? true : false;
 }
예제 #9
0
        public async Task <List <ChangeLogCommit> > CalculateChangeLogAsync(string beginningVersionString, string endingVersionString)
        {
            var beginningVersion = new SemVer.Version(beginningVersionString);
            var endingVersion    = new SemVer.Version(endingVersionString);

            if (beginningVersion >= endingVersion)
            {
                throw new ArgumentException($"{nameof(beginningVersion)} ({beginningVersion}) greater than {nameof(endingVersion)} ({endingVersion})");
            }

            var allCommits = await _repository.GetAllCommitsAsync();

            return(allCommits
                   .Where(c => c.Versions.All(t => t > beginningVersion))
                   .Where(c => c.Versions.Any(t => t <= endingVersion))
                   .ToList());
        }
예제 #10
0
        private async Task CheckVersion()
        {
            try
            {
                var response = await _webClient.GetAsync("https://api.github.com/repos/ToniMacaroni/TrickSaber/releases",
                                                         CancellationToken.None);

                var releases = response.ContentToJson <Release[]>();

                RemoteVersion   = new Version(releases[0].TagName);
                IsNewestVersion = new Range($"<={Version}").IsSatisfied(RemoteVersion);

                _logger.Info($"Retrieved remote version ({RemoteVersion})");
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
            }
        }
예제 #11
0
        protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
        {
            var classOfMethod = Type.GetType(testMethod.TestClass.Class.Name, true, true);

#if !DOTNETCORE
            var attributes = Attribute.GetCustomAttributes(classOfMethod, typeof(SkipVersionAttribute));
#else
            var attributes = classOfMethod.GetTypeInfo().GetCustomAttributes(typeof(SkipVersionAttribute), false);
#endif
            if (!attributes.Any())
            {
                return(false);
            }

            var version = new SemVer.Version(TestClient.Configuration.ElasticsearchVersion);
            var ranges  = attributes.Cast <SkipVersionAttribute>()
                          .SelectMany(a => a.Ranges);

            return(ranges.Any(range => range.IsSatisfied(version)));
        }
        private async Task DoLoginFor(Version v, string user, string password)
        {
            Url path;

            if (_loginRefactorVersion.IsSatisfied(v))
            {
                Log.Debug("Newer version of harbor found, using 1.7.0+ login route");
                path             = Endpoint.AppendPathSegments("c", "login");
                sessionTokenName = NEW_SESSION_COOKIE_KEY;
            }
            else
            {
                Log.Debug("Older version of harbor found, using pre-1.7.0 login route");
                path             = Endpoint.AppendPathSegment("login");
                sessionTokenName = SESSION_COOKIE_KEY;
            }

            var client   = path.AllowAnyHttpStatus().EnableCookies();
            var response = await client.PostUrlEncodedAsync(new { principal = user, password = password });

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    throw new ArgumentException("Invalid username or password");
                }
                else
                {
                    throw;
                }
            }

            sessionToken = client.Cookies[sessionTokenName] ?? throw new Exception("Failed to parse session token");
        }
예제 #13
0
        public override async Task <FetchedVersion> GetLatestVersion(Mod.ModVersion mod)
        {
            string[] split  = mod.SourceUrl.Split("/");
            Release  latest = await _client.Repository.Release.GetLatest(split[3], split[4]);

            Version version = SanitizeVersionString(latest.TagName);

            // Do some filtering to determine the asset to use if there is more than one
            ReleaseAsset asset;

            if (latest.Assets.Count > 1)
            {
                ReleaseAsset[] assets = latest.Assets
                                        .Where(x =>
                                               Regex.IsMatch(
                                                   mod.DownloadUrl,
                                                   Regex.Replace(Regex.Escape(x.Name), @"\d(?:\\\.\d)+", ".*")
                                                   )
                                               ).ToArray();

                if (assets.Length > 1)
                {
                    throw new Exception("There was more than one asset and the correct one could not be determined.");
                }

                asset = assets[0];
            }
            else
            {
                asset = latest.Assets[0];
            }

            return(new FetchedVersion {
                Version = version, DownloadUrl = asset.BrowserDownloadUrl
            });
        }
예제 #14
0
        private void listViewMods_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            ReleaseInfo release = (ReleaseInfo)e.Item.Tag;

            if (release.disabled)
            {
                e.Item.Checked = release.install;
                return;
            }
            else
            {
                release.install = e.Item.Checked;
            }

            IEnumerable <ListViewItem> lv = listViewMods.Items.Cast <ListViewItem>();

            List <ListViewItem> changedConflicts = new List <ListViewItem>();

            if (release.conflictsWith.Count > 0)
            {
                List <ListViewItem> filtered = lv.Where(lvi =>
                {
                    ReleaseInfo info = (ReleaseInfo)lvi.Tag;

                    bool exists = release.conflictsWith.Exists(l => l.name == info.name);
                    if (!exists)
                    {
                        return(false);
                    }

                    ModLink link = release.conflictsWith.Find(l => l.name == info.name);

                    Version version = new Version(info.version);
                    Range range     = new Range(link.semver);

                    return(range.IsSatisfied(version));
                }).ToList();

                foreach (var x in filtered)
                {
                    changedConflicts.Add(x);
                    ReleaseInfo info = (ReleaseInfo)x.Tag;
                    info.disabled = e.Item.Checked;
                    info.install  = !e.Item.Checked;

                    if (e.Item.Checked)
                    {
                        x.Checked = false;
                    }
                }
            }

            if (release.dependsOn.Count > 0)
            {
                List <ListViewItem> filtered = lv.Where(lvi =>
                {
                    ReleaseInfo info = (ReleaseInfo)lvi.Tag;
                    if (info.disabled && !info.install)
                    {
                        return(false);
                    }

                    bool exists = release.dependsOn.Exists(l => l.name == info.name);
                    if (!exists)
                    {
                        return(false);
                    }

                    ModLink link = release.dependsOn.Find(l => l.name == info.name);

                    Version version = new Version(info.version);
                    Range range     = new Range(link.semver);

                    return(range.IsSatisfied(version));
                }).ToList();

                if (filtered.Count != release.dependsOn.Count)
                {
                    release.install  = false;
                    release.disabled = true;

                    foreach (var x in changedConflicts)
                    {
                        ReleaseInfo info = (ReleaseInfo)x.Tag;
                        info.disabled = !e.Item.Checked;
                        info.install  = e.Item.Checked;
                    }
                }
                else
                {
                    foreach (var x in filtered)
                    {
                        ReleaseInfo info = (ReleaseInfo)x.Tag;
                        info.disabled = e.Item.Checked;
                        info.install  = e.Item.Checked;
                        x.Checked     = e.Item.Checked;
                    }
                }
            }

            ReRenderListView();
        }
예제 #15
0
        public static bool TryResolve(Product product, Version version, OSPlatform os, string filters, out Artifact artifact)
        {
            artifact = null;
            var p     = product.SubProduct?.SubProductName ?? product.ProductName;
            var query = p;

            if (product.PlatformDependent && version > product.PlatformSuffixAfter)
            {
                query += $",{OsMonikers.From(os)}";
            }
            else if (product.PlatformDependent)
            {
                query += $",{OsMonikers.CurrentPlatformSearchFilter()}";
            }
            if (!string.IsNullOrWhiteSpace(filters))
            {
                query += $",{filters}";
            }

            var packages = new Dictionary <string, SearchPackage>();

            try
            {
                var json = ApiResolver.FetchJson($"search/{version}/{query}");
                // if packages is empty it turns into an array[] otherwise its a dictionary :/
                packages = JsonSerializer.Deserialize <ArtifactsSearchResponse>(json).Packages;
            }
            catch { }

            if (packages == null || packages.Count == 0)
            {
                return(false);
            }
            var list = packages
                       .OrderByDescending(k => k.Value.Classifier == null ? 1 : 0)
                       .ToArray();

            var ext           = OsMonikers.CurrentPlatformArchiveExtension();
            var shouldEndWith = $"{version}.{ext}";

            if (product.PlatformDependent && version > product.PlatformSuffixAfter)
            {
                shouldEndWith = $"{version}-{OsMonikers.CurrentPlatformPackageSuffix()}.{ext}";
            }
            foreach (var kv in list)
            {
                if (product.PlatformDependent && !kv.Key.EndsWith(shouldEndWith))
                {
                    continue;
                }


                var tokens = PackageProductRegex.Split(kv.Key).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
                if (tokens.Length < 2)
                {
                    continue;
                }

                if (!tokens[0].Equals(p, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                if (!tokens[1].Equals(version.ToString(), StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                // https://snapshots.elastic.co/7.4.0-677857dd/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-7.4.0-SNAPSHOT.zip
                var buildHash = ApiResolver.GetBuildHash(kv.Value.DownloadUrl);
                artifact = new Artifact(product, version, kv.Value, buildHash);
            }
            return(false);
        }
예제 #16
0
 public bool IsSatisfied(SemVer.Version version) => version?.Parsed == this._range;
예제 #17
0
 public UpdateManager(Version version)
 {
     LoadSettings();
     PerformCleanup();
     FetchData(version);
 }