Beispiel #1
0
        private static void CheckForUpdates(out PdnVersionManifest manifestResult, out int latestVersionIndexResult, out Exception exception)
        {
            exception = null;
            PdnVersionManifest updatesManifest = null;

            manifestResult           = null;
            latestVersionIndexResult = -1;
            int num = 2;

            while (num > 0)
            {
                try
                {
                    updatesManifest = GetUpdatesManifest(out exception);
                    num             = 0;
                    continue;
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    num--;
                    if (num == 0)
                    {
                        updatesManifest = null;
                    }
                    continue;
                }
            }
            if (updatesManifest != null)
            {
                int  latestStableVersionIndex = updatesManifest.GetLatestStableVersionIndex();
                int  latestBetaVersionIndex   = updatesManifest.GetLatestBetaVersionIndex();
                bool flag2 = AppSettings.Instance.Updates.AutoCheckForPrerelease.Value || PdnInfo.IsPrereleaseBuild;
                int  index = latestStableVersionIndex;
                if ((flag2 && (latestBetaVersionIndex != -1)) && ((latestStableVersionIndex == -1) || (updatesManifest.VersionInfos[latestBetaVersionIndex].Version >= updatesManifest.VersionInfos[latestStableVersionIndex].Version)))
                {
                    index = latestBetaVersionIndex;
                }
                if ((index != -1) && (PdnInfo.IsTestMode || (updatesManifest.VersionInfos[index].Version > PdnInfo.Version)))
                {
                    manifestResult           = updatesManifest;
                    latestVersionIndexResult = index;
                }
            }
        }
Beispiel #2
0
        private static void CheckForUpdates(
            out PdnVersionManifest manifestResult,
            out int latestVersionIndexResult,
            out Exception exception)
        {
            exception = null;
            PdnVersionManifest manifest = null;

            manifestResult           = null;
            latestVersionIndexResult = -1;

            int retries = 2;

            while (retries > 0)
            {
                try
                {
                    manifest = GetUpdatesManifest(out exception);
                    retries  = 0;
                }

                catch (Exception ex)
                {
                    exception = ex;
                    --retries;

                    if (retries == 0)
                    {
                        manifest = null;
                    }
                }
            }

            if (manifest != null)
            {
                int stableIndex = manifest.GetLatestStableVersionIndex();
                int betaIndex   = manifest.GetLatestBetaVersionIndex();

                // Check for betas as well?
                bool checkForBetas = ("1" == Settings.SystemWide.GetString(PdnSettings.AlsoCheckForBetas, "0"));

                // Figure out which version we want to compare against the current version
                int latestIndex = stableIndex;

                if (checkForBetas)
                {
                    // If they like betas, and if the beta is newer than the latest stable release,
                    // then offer it to them.
                    if (betaIndex != -1 &&
                        (stableIndex == -1 || manifest.VersionInfos[betaIndex].Version >= manifest.VersionInfos[stableIndex].Version))
                    {
                        latestIndex = betaIndex;
                    }
                }

                // Now compare that version against the current version
                if (latestIndex != -1)
                {
                    if (PdnInfo.IsTestMode ||
                        manifest.VersionInfos[latestIndex].Version > PdnInfo.GetVersion())
                    {
                        manifestResult           = manifest;
                        latestVersionIndexResult = latestIndex;
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Downloads the latest updates manifest from the Paint.NET web server.
        /// </summary>
        /// <returns>The latest updates manifest, or null if there was an error in which case the exception argument will be non-null.</returns>
        // TODO: throw the exception, don't return it via an out parameter
        private static PdnVersionManifest GetUpdatesManifest(out Exception exception)
        {
            try
            {
                string versionsUrl = VersionManifestUrl;

                Uri                 versionsUri    = new Uri(versionsUrl);
                byte[]              manifestBuffer = Utility.DownloadSmallFile(versionsUri);
                string              manifestText   = System.Text.Encoding.UTF8.GetString(manifestBuffer);
                string[]            manifestLines  = BreakIntoLines(manifestText);
                NameValueCollection nameValues     = LinesToNameValues(manifestLines);

                string downloadPageUrl = nameValues[downloadPageUrlName];

                string    stableVersionsStrings = nameValues[stableVersionsName];
                Version[] stableVersions        = VersionStringToArray(stableVersionsStrings);
                string[]  stableNames           = BuildVersionValueMapping(nameValues, stableVersions, nameNameFormat);
                string[]  stableNetFxVersions   = BuildVersionValueMapping(nameValues, stableVersions, netFxVersionNameFormat);
                string[]  stableInfoUrls        = BuildVersionValueMapping(nameValues, stableVersions, infoUrlNameFormat);
                string[]  stableZipUrls         = BuildVersionValueMapping(nameValues, stableVersions, zipUrlListNameFormat);
                string[]  stableFullZipUrls     = BuildVersionValueMapping(nameValues, stableVersions, fullZipUrlListNameFormat);

                string    betaVersionsStrings = nameValues[betaVersionsName];
                Version[] betaVersions        = VersionStringToArray(betaVersionsStrings);
                string[]  betaNames           = BuildVersionValueMapping(nameValues, betaVersions, nameNameFormat);
                string[]  betaNetFxVersions   = BuildVersionValueMapping(nameValues, betaVersions, netFxVersionNameFormat);
                string[]  betaInfoUrls        = BuildVersionValueMapping(nameValues, betaVersions, infoUrlNameFormat);
                string[]  betaZipUrls         = BuildVersionValueMapping(nameValues, betaVersions, zipUrlListNameFormat);
                string[]  betaFullZipUrls     = BuildVersionValueMapping(nameValues, betaVersions, fullZipUrlListNameFormat);

                PdnVersionInfo[] versionInfos = new PdnVersionInfo[betaVersions.Length + stableVersions.Length];

                int cursor = 0;
                for (int i = 0; i < stableVersions.Length; ++i)
                {
                    List <string> zipUrlList = new List <string>();
                    SplitUrlList(stableZipUrls[i], zipUrlList);

                    List <string> fullZipUrlList = new List <string>();
                    SplitUrlList(stableFullZipUrls[i], fullZipUrlList);

                    PdnVersionInfo info = new PdnVersionInfo(stableVersions[i], stableNames[i], new Version(stableNetFxVersions[i]),
                                                             stableInfoUrls[i], zipUrlList.ToArray(), fullZipUrlList.ToArray(), true);

                    versionInfos[cursor] = info;
                    ++cursor;
                }

                for (int i = 0; i < betaVersions.Length; ++i)
                {
                    List <string> zipUrlList = new List <string>();
                    SplitUrlList(betaZipUrls[i], zipUrlList);

                    List <string> fullZipUrlList = new List <string>();
                    SplitUrlList(betaFullZipUrls[i], fullZipUrlList);

                    PdnVersionInfo info = new PdnVersionInfo(betaVersions[i], betaNames[i], new Version(betaNetFxVersions[i]),
                                                             betaInfoUrls[i], zipUrlList.ToArray(), fullZipUrlList.ToArray(), false);

                    versionInfos[cursor] = info;
                    ++cursor;
                }

                PdnVersionManifest manifest = new PdnVersionManifest(downloadPageUrl, versionInfos);
                exception = null;
                return(manifest);
            }

            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
Beispiel #4
0
 private static PdnVersionManifest GetUpdatesManifest(out Exception exception)
 {
     try
     {
         Uri    uri   = new Uri(VersionManifestUrl);
         byte[] bytes = WebHelpers.DownloadSmallFile(uri);
         NameValueCollection nameValues   = LinesToNameValues(BreakIntoLines(Encoding.UTF8.GetString(bytes)));
         string           downloadPageUrl = nameValues["DownloadPageUrl"];
         string           versions        = nameValues["StableVersions"];
         Version[]        versionArray    = VersionStringToArray(versions);
         string[]         strArray2       = BuildVersionValueMapping(nameValues, versionArray, "{0}_Name");
         string[]         strArray3       = BuildVersionValueMapping(nameValues, versionArray, "{0}_NetFxVersion");
         string[]         strArray4       = BuildVersionValueMapping(nameValues, versionArray, "{0}_InfoUrl");
         string[]         strArray5       = BuildVersionValueMapping(nameValues, versionArray, "{0}_ZipUrlList");
         string[]         strArray6       = BuildVersionValueMapping(nameValues, versionArray, "{0}_FullZipUrlList");
         string           str5            = nameValues["BetaVersions"];
         Version[]        versionArray2   = VersionStringToArray(str5);
         string[]         strArray7       = BuildVersionValueMapping(nameValues, versionArray2, "{0}_Name");
         string[]         strArray8       = BuildVersionValueMapping(nameValues, versionArray2, "{0}_NetFxVersion");
         string[]         strArray9       = BuildVersionValueMapping(nameValues, versionArray2, "{0}_InfoUrl");
         string[]         strArray10      = BuildVersionValueMapping(nameValues, versionArray2, "{0}_ZipUrlList");
         string[]         strArray11      = BuildVersionValueMapping(nameValues, versionArray2, "{0}_FullZipUrlList");
         PdnVersionInfo[] versionInfos    = new PdnVersionInfo[versionArray2.Length + versionArray.Length];
         int index = 0;
         for (int i = 0; i < versionArray.Length; i++)
         {
             List <string> urlsOutput = new List <string>();
             SplitUrlList(strArray5[i], urlsOutput);
             List <string> list2 = new List <string>();
             SplitUrlList(strArray6[i], list2);
             Version version = new Version(strArray3[i]);
             if ((version.Major == 2) && (version.Minor == 0))
             {
                 version = new Version(2, 0, 0);
             }
             versionInfos[index] = new PdnVersionInfo(versionArray[i], strArray2[i], version.Major, version.Minor, version.Build, strArray4[i], urlsOutput.ToArrayEx <string>(), list2.ToArrayEx <string>(), true);
             index++;
         }
         for (int j = 0; j < versionArray2.Length; j++)
         {
             List <string> list3 = new List <string>();
             SplitUrlList(strArray10[j], list3);
             List <string> list4 = new List <string>();
             SplitUrlList(strArray11[j], list4);
             Version version2 = new Version(strArray8[j]);
             if ((version2.Major == 2) && (version2.Minor == 0))
             {
                 version2 = new Version(2, 0, 0);
             }
             versionInfos[index] = new PdnVersionInfo(versionArray2[j], strArray7[j], version2.Major, version2.Minor, version2.Build, strArray9[j], list3.ToArrayEx <string>(), list4.ToArrayEx <string>(), false);
             index++;
         }
         PdnVersionManifest manifest = new PdnVersionManifest(downloadPageUrl, versionInfos);
         exception = null;
         return(manifest);
     }
     catch (Exception exception2)
     {
         exception = exception2;
         return(null);
     }
 }