public int Compare(object x, object y)
            {
                PdnVersionInfo info  = (PdnVersionInfo)x;
                PdnVersionInfo info2 = (PdnVersionInfo)y;

                if (info.Version < info2.Version)
                {
                    return(-1);
                }
                if (info.Version == info2.Version)
                {
                    return(0);
                }
                return(1);
            }
Beispiel #2
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 #3
0
 public ExtractingState(string extractMe, PdnVersionInfo newVersionInfo)
     : base(false, false, MarqueeStyle.Smooth)
 {
     this.extractMe      = extractMe;
     this.newVersionInfo = newVersionInfo;
 }
 public ReadyToInstallState(string installerPath, PdnVersionInfo newVersionInfo)
     : base(false, true, MarqueeStyle.None)
 {
     this.installerPath  = installerPath;
     this.newVersionInfo = newVersionInfo;
 }
Beispiel #5
0
 public UpdateAvailableState(PdnVersionInfo newVersionInfo)
     : base(false, true, MarqueeStyle.None)
 {
     this.newVersionInfo = newVersionInfo;
 }
Beispiel #6
0
        private void ShowUpdatesDialog(bool calledFromExit)
        {
            if (!calledFromExit)
            {
                if (this.installOnExit && ShellUtil.IsActivityQueuedForRestart)
                {
                    ShellUtil.IsActivityQueuedForRestart = false;
                }
                this.installOnExit = false;
            }
            IUpdatesMainFormSite site = this.host.FindMainForm();

            if (site != null)
            {
                site.FormClosing -= new FormClosingEventHandler(this.OnMainFormFormClosing);
            }
            if (this.retryDialogTimer != null)
            {
                this.retryDialogTimer.Enabled = false;
                this.retryDialogTimer.Dispose();
                this.retryDialogTimer = null;
            }
            bool flag = true;
            UpdateAvailableState currentState = this.stateMachineExecutor.CurrentState as UpdateAvailableState;

            if (currentState != null)
            {
                PdnVersionInfo newVersionInfo = currentState.NewVersionInfo;
                string         friendlyName   = newVersionInfo.FriendlyName;
                string         infoUrl        = newVersionInfo.InfoUrl;
                switch (this.AskInstallNowOrOnExit(this.host.UISite.Win32Window, friendlyName, infoUrl))
                {
                case DialogResult.Yes:
                    this.stateMachineExecutor.ProcessInput(UpdatesAction.Continue);
                    flag = true;
                    goto Label_0134;

                case DialogResult.OK:
                {
                    this.stateMachineExecutor.ProcessInput(UpdatesAction.Continue);
                    flag = false;
                    this.installOnExit = true;
                    ShellUtil.IsActivityQueuedForRestart = true;
                    IUpdatesMainFormSite site2 = this.host.FindMainForm();
                    if (site2 != null)
                    {
                        site2.FormClosing += new FormClosingEventHandler(this.OnMainFormFormClosing);
                    }
                    else
                    {
                        flag = true;
                    }
                    goto Label_0134;
                }
                }
                this.stateMachineExecutor.ProcessInput(UpdatesAction.Cancel);
                flag = false;
                this.DisposeUpdates();
            }
Label_0134:
            if (flag)
            {
                IWin32Window window;
                if (this.updatesDialog != null)
                {
                    this.updatesDialog.Close();
                    this.updatesDialog = null;
                }
                this.updatesDialog = new UpdatesDialog();
                this.updatesDialog.InstallingOnExit    = calledFromExit;
                this.updatesDialog.UpdatesStateMachine = this.stateMachineExecutor;
                if (!this.stateMachineExecutor.IsStarted)
                {
                    this.stateMachineExecutor.Start();
                }
                try
                {
                    IntPtr handle = this.host.UISite.Win32Window.Handle;
                    window = this.host.UISite.Win32Window;
                }
                catch (Exception)
                {
                    window = null;
                }
                this.updatesDialog.StartPosition = calledFromExit ? FormStartPosition.CenterScreen : this.updatesDialog.StartPosition;
                this.updatesDialog.ShowInTaskbar = calledFromExit;
                this.updatesDialog.Shown        += (s, e) => UIUtil.FlashForm(this.updatesDialog);
                this.updatesDialog.ShowDialog(window);
                DialogResult dialogResult = this.updatesDialog.DialogResult;
                this.updatesDialog.Dispose();
                this.updatesDialog = null;
                if (((this.stateMachineExecutor != null) && (dialogResult == DialogResult.Yes)) && (this.stateMachineExecutor.CurrentState is ReadyToInstallState))
                {
                    this.stateMachineExecutor.ProcessInput(UpdatesAction.Continue);
                    while (!this.calledFinish)
                    {
                        Application.DoEvents();
                        Thread.Sleep(10);
                    }
                }
            }
        }
 public DownloadingState(PdnVersionInfo downloadMe)
     : base(false, false, MarqueeStyle.Smooth)
 {
     this.downloadMe = downloadMe;
 }
Beispiel #8
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);
     }
 }