Exemplo n.º 1
0
        private bool UpdateRequired()
        {
            // Get local revision number
            int localrev = -1;

            if (File.Exists(appFileName))
            {
                var info = FileVersionInfo.GetVersionInfo(appFileName);
                localrev = info.ProductPrivatePart;
            }

            // Get remote revision number
            int remoterev;

            using (MemoryStream stream = Webdata.DownloadWebFile(Path.Combine(URL, "Versions.txt")))
            {
                if (stream == null)
                {
                    if (string.IsNullOrEmpty(ErrorDescription))
                    {
                        ErrorDescription = "Failed to retrieve remote revision info.";
                    }
                    return(false);
                }

                string s;
                using (StreamReader reader = new StreamReader(stream))
                {
                    s = reader.ReadLine();                     // First line should be editor revision
                }

                if (!int.TryParse(s, out remoterev))
                {
                    ErrorDescription = "Failed to retrieve remote revision number.";
                    return(false);
                }
            }

            // Replace wildcard with remoterev
            downloadFile = downloadFile.Replace(revisionwildcard, remoterev.ToString());
            downloadFile = downloadFile.Replace(platformwildcard, platform.ToString());

            if (remoterev > 0 && remoterev <= localrev)
            {
                URL = string.Empty;
                ErrorDescription = "Your version is up to date!";
            }
            return(remoterev > localrev);
        }
Exemplo n.º 2
0
        private void BackgroundWorker(object sender, DoWorkEventArgs e)
        {
            UpdateLabel(label1, "1/6: Checking revisions...");
            if (!UpdateRequired())
            {
                e.Cancel = true;
                return;
            }
            PreDownload();

            UpdateLabel(label1, "2/6: Downloading Update...");
            Webdata.BytesDownloaded += WebdataOnBytesDownloaded;
            if (!Webdata.SaveWebFile(URL, downloadFile, updateFolder))
            {
                e.Cancel = true;
                Webdata.BytesDownloaded -= WebdataOnBytesDownloaded;
                return;
            }

            // Check if the editor is running...
            if (!EditorClosed())
            {
                // Error or user canceled
                e.Cancel = true;
                return;
            }

            UpdateLabel(label1, "4/6: Decompressing package...");
            Thread.Sleep(500);
            if (!Unpack(updateFolder + downloadFile, Application.StartupPath))
            {
                e.Cancel = true;
                return;
            }

            UpdateLabel(label1, "5/6: Moving files...");
            Thread.Sleep(500);
            MoveFiles();

            UpdateLabel(label1, "6/6: Wrapping up...");
            Thread.Sleep(500);
            PostDownload();
        }