Exemplo n.º 1
0
 public ProductInfoHeaderValue(System.Net.Http.Headers.ProductInfoHeaderValue containedObject)
 {
     if ((containedObject == null))
     {
         throw new System.ArgumentNullException("containedObject");
     }
     this.containedObject = containedObject;
 }
Exemplo n.º 2
0
        static async Task <string> downloadReleasesIndex(Uri uri)
        {
            Console.WriteLine("Trying to download RELEASES index from {0}", uri);

            var userAgent = new System.Net.Http.Headers.ProductInfoHeaderValue("Squirrel", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            using (HttpClient client = new HttpClient()) {
                client.DefaultRequestHeaders.UserAgent.Add(userAgent);
                return(await client.GetStringAsync(uri));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// FM Data Constructor with HttpClient and ConnectionInfo. Useful for Dependency Injection situations
        /// </summary>
        /// <param name="client">The HttpClient instance to use.</param>
        /// <param name="conn">The connection information for FMS.</param>
        public FileMakerXmlClient(HttpClient client, ConnectionInfo conn) : base(client, conn)
        {
#if NETSTANDARD1_3
            var header    = new System.Net.Http.Headers.ProductHeaderValue("FMData.Xml", "4");
            var userAgent = new System.Net.Http.Headers.ProductInfoHeaderValue(header);
#else
            var assembly  = Assembly.GetExecutingAssembly();
            var version   = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;
            var header    = new System.Net.Http.Headers.ProductHeaderValue(assembly.GetName().Name, version);
            var userAgent = new System.Net.Http.Headers.ProductInfoHeaderValue(header);
#endif
            Client.DefaultRequestHeaders.UserAgent.Add(userAgent);
        }
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try {
                Version semanticVersion    = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                string  semanticVersionStr = $"v{semanticVersion.Major}.{semanticVersion.Minor}.{semanticVersion.Build}";
                this.Title = $"Iwiwao's ToS Addon Manager {semanticVersionStr}";

                // Set initial HttpClient values as needed to connect to Github API.
                System.Net.Http.Headers.ProductHeaderValue     header    = new System.Net.Http.Headers.ProductHeaderValue("IwiwaoToSAddonManager", semanticVersionStr);
                System.Net.Http.Headers.ProductInfoHeaderValue userAgent = new System.Net.Http.Headers.ProductInfoHeaderValue(header);
                webConnector.DefaultRequestHeaders.UserAgent.Add(userAgent);

                if (System.IO.File.Exists("installedAddons.json"))
                {
                    listOfInstalledAddons = JsonConvert.DeserializeObject <List <installedAddons> >(System.IO.File.ReadAllText("installedAddons.json"));
                }                                                                                                                                                                                        // If there is saved installed addon list, load it.
                if (System.IO.File.Exists("completeAddonList.json"))
                {
                    listOfAllAddons = JsonConvert.DeserializeObject <List <addonDataFromRepo> >(System.IO.File.ReadAllText("completeAddonList.json"));
                }                                                                                                                                                                                        // If there is cache data, load it.
                if (System.IO.File.Exists("programSettings.json"))
                {
                    tosAMProgramSettings = JsonConvert.DeserializeObject <programSettings>(System.IO.File.ReadAllText("programSettings.json"));
                }                                                                                                                                                                                 // If there is a saved settings file, load it.
                if (System.IO.File.Exists("brokenAddonList.json"))
                {
                    listOfBrokenAddons = JsonConvert.DeserializeObject <List <brokenAddons> >(System.IO.File.ReadAllText("brokenAddonList.json"));
                }                                                                                                                                                                                  // You get the idea...
                if (System.IO.File.Exists("addonOverrides.json"))
                {
                    listOfAddonOverrides = JsonConvert.DeserializeObject <List <addonInstallerOverride> >(System.IO.File.ReadAllText("addonOverrides.json"));
                }
                displayActiveGrid();
                if (tosAMProgramSettings.checkForUpdates)
                {
                    AllowAutoCheck.IsChecked = true; checkForUpdates(null, null);
                }
            } catch (Exception ex) {
                Common.showError("Program Load Error", ex);
            }
        } // end MainWindow_Loaded
Exemplo n.º 5
0
 public static bool TryParse(string input, out System.Net.Http.Headers.ProductInfoHeaderValue parsedValue)
 {
     throw null;
 }
Exemplo n.º 6
0
        public static void CheckForUpdates()
        {
            //already checked recently
            DateTime nextCheckMinimum = GlobalConfig.Settings.Updates.UpdateLastCheckTime.AddMinutes(CONSTANTS.NETWORK.UpdateCheckMinimumDelayMinutes);

            if (nextCheckMinimum > DateTime.Now)
            {
                Logging.RecordLogEvent($"Not checking for updates, next check will be next time rgat is launched after {nextCheckMinimum.Humanize()}", Logging.LogFilterType.Debug);
                return;
            }

            if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                Logging.RecordLogEvent("Not checking for updates, no network connection available", Logging.LogFilterType.Debug);
                return;
            }

            //https://docs.github.com/en/rest/reference/repos#list-releases
            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
            System.Net.Http.Headers.ProductInfoHeaderValue versionHeader = new System.Net.Http.Headers.ProductInfoHeaderValue("rgat", CONSTANTS.PROGRAMVERSION.RGAT_VERSION_SEMANTIC.ToString());
            client.DefaultRequestHeaders.UserAgent.Add(versionHeader);
            client.DefaultRequestHeaders.Add("accept", "application/vnd.github.v3+json");
            client.DefaultRequestHeaders.Add("per_page", "1");
            client.DefaultRequestHeaders.Add("page", "0");

            try
            {
                //string releasesPath = $"https://api.github.com/repos/olivierlacan/keep-a-changelog/releases";
                string                     releasesPath = $"https://api.github.com/repos/ncatlin/rgat/releases";
                CancellationToken          exitToken    = rgatState.ExitToken;
                Task <HttpResponseMessage> response     = client.GetAsync(releasesPath, exitToken);
                response.Wait(exitToken);
                if (response.Result.IsSuccessStatusCode)
                {
                    Task <string> content = response.Result.Content.ReadAsStringAsync();
                    content.Wait(exitToken);
                    JArray  responseArr   = JArray.Parse(content.Result);
                    Version latestVersion = CONSTANTS.PROGRAMVERSION.RGAT_VERSION_SEMANTIC;
                    string  latestZip     = "";
                    bool    newVersion    = false;
                    foreach (JToken releaseTok in responseArr)
                    {
                        if (releaseTok.Type != JTokenType.Object)
                        {
                            continue;
                        }

                        if (((JObject)releaseTok).TryGetValue("tag_name", out JToken? releaseTagTok)
                            &&
                            ((JObject)releaseTok).TryGetValue("assets", out JToken? assetsTok) && assetsTok.Type is JTokenType.Array
                            )
                        {
                            string tagString = releaseTagTok.ToString();
                            if (tagString.StartsWith('v'))
                            {
                                tagString = tagString.Substring(1);
                            }

                            JArray?assets = assetsTok.ToObject <JArray>();
                            if (assets is null)
                            {
                                Logging.RecordError($"Bad assets entry in release {tagString}");
                                return;
                            }

                            string downloadLink = "";
                            foreach (JToken assetTok in assets)
                            {
                                JObject?asset = assetTok.ToObject <JObject>();
                                if (asset is not null && asset.TryGetValue("name", out JToken? nameTok) &&
                                    nameTok is not null && nameTok.ToString() == "rgat.zip")
                                {
                                    if (asset.TryGetValue("browser_download_url", out JToken? linkTok) && linkTok is not null)
                                    {
                                        downloadLink = linkTok.ToString();
                                        break;
                                    }
                                }
                            }

                            if (tagString.Count(x => x == '.') >= 2 && downloadLink.StartsWith("https:"))
                            {
                                Version releaseVersion = new Version(tagString);
                                //todo replace these lines when dev is done
                                if ((releaseVersion != null) && (releaseVersion > latestVersion))
                                {
                                    newVersion    = true;
                                    latestVersion = releaseVersion;
                                    latestZip     = downloadLink;
                                }
                            }
                        }
                    }

                    if (newVersion && latestVersion > GlobalConfig.Settings.Updates.UpdateLastCheckVersion)
                    {
                        client = new System.Net.Http.HttpClient();
                        client.DefaultRequestHeaders.UserAgent.Add(versionHeader);
                        client.DefaultRequestHeaders.Add("accept", "application/vnd.github.v3+json");

                        //string changelogPath = $"https://api.github.com/repos/olivierlacan/keep-a-changelog/contents/CHANGELOG.md";
                        string changelogPath = $"https://api.github.com/repos/ncatlin/rgat/contents/CHANGELOG.md";

                        response = client.GetAsync(changelogPath, exitToken);
                        response.Wait(exitToken);

                        if (response.Result.IsSuccessStatusCode)
                        {
                            content = response.Result.Content.ReadAsStringAsync();
                            content.Wait(exitToken);
                            JObject changelogObj = JObject.Parse(content.Result);
                            if (changelogObj.TryGetValue("content", out JToken? b64ChangelogTok) && b64ChangelogTok.Type == JTokenType.String)
                            {
                                string parsedChangelogChanges = ParseChangelogChanges(b64ChangelogTok.ToString());
                                GlobalConfig.RecordAvailableUpdateDetails(latestVersion, parsedChangelogChanges, latestZip);
                            }
                            else
                            {
                                Logging.RecordLogEvent("Update Check: No valid content in changelog content request", Logging.LogFilterType.Debug);
                            }
                        }
                    }
                    GlobalConfig.Settings.Updates.UpdateLastCheckTime = DateTime.Now;
                }
            }
            catch (Exception e)
            {
                if (!rgatState.rgatIsExiting)
                {
                    // not important enough to be an error display on the UI
                    Logging.RecordLogEvent($"Update check failed: {e.Message}");
                }
            }
        }