Example #1
0
        static void StartDownload(string url)
        {
            try
            {
                _updateState = EUpdateState.Downloading;
                _updaterWindow.StatusLabel.Content = "Starting Download...";

                if (File.Exists(GetSavePath()))
                {
                    File.Delete(GetSavePath());
                }
                if (!Directory.Exists(GetTempDirectory()))
                {
                    Directory.CreateDirectory(GetTempDirectory());
                }

                _client = new WebClient();
                _client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
                _client.DownloadFileCompleted   += new System.ComponentModel.AsyncCompletedEventHandler(DownloadCompletedCallback);

                Uri uri = new Uri(url);
                _client.DownloadFileAsync(uri, GetSavePath());
            }
            catch (Exception e)
            {
                _updaterWindow.StatusLabel.Content = "Error Downloading: " + e.Message;
            }
        }
Example #2
0
        private static void DownloadCompletedCallback(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                _updateState = EUpdateState.Error;
                _updaterWindow.StatusLabel.Content = "Download was interrupted";
            }
            else if (e.Error != null)
            {
                _updateState = EUpdateState.Error;
                _updaterWindow.StatusLabel.Content = e.Error.Message;
            }
            else
            {
                _updaterWindow.StatusLabel.Content = "Download Finished; verifying...";

                // Verify the hash of the download
                if (_patchHash == "" || _patchHash == RXPatchLib.Sha256.GetFileHash(GetSavePath()))
                {
                    // Download valid; begin extraction
                    StartExtract();
                }
                else
                {
                    // Hash mismatch; set an error
                    _updateState = EUpdateState.Error;
                    _updaterWindow.StatusLabel.Content = "Hash mismatch";
                }
            }
        }
Example #3
0
        static void StartExtract()
        {
            try
            {
                if (Directory.Exists(GetExtractDirectory()))
                {
                    Directory.Delete(GetExtractDirectory(), true);
                }

                _updateState = EUpdateState.Extracting;
                _updaterWindow.StatusLabel.Content = "Extracting...";
                ZipFile.ExtractToDirectory(GetSavePath(), GetExtractDirectory());
                ReadyToInstall();
            }
            catch (Exception e)
            {
                _updaterWindow.StatusLabel.Content = "Error Extracting: " + e.Message;
            }
        }
Example #4
0
 void SetState(EUpdateState state)
 {
     Debug.Log($"KVUpdate ====>SetState({state})");
     curState = state;
 }
Example #5
0
 public static void CancelUpdate()
 {
     _updateState = EUpdateState.Cancelled;
     // TODO: Cancel whichever state is currently happening.
 }
Example #6
0
 static void ReadyToInstall()
 {
     _updateState = EUpdateState.ReadyToInstall;
     _updaterWindow.UpdateFinished      = true;
     _updaterWindow.StatusLabel.Content = "Ready to install. Press close to install and restart.";
 }