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; } }
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"; } } }
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; } }
void SetState(EUpdateState state) { Debug.Log($"KVUpdate ====>SetState({state})"); curState = state; }
public static void CancelUpdate() { _updateState = EUpdateState.Cancelled; // TODO: Cancel whichever state is currently happening. }
static void ReadyToInstall() { _updateState = EUpdateState.ReadyToInstall; _updaterWindow.UpdateFinished = true; _updaterWindow.StatusLabel.Content = "Ready to install. Press close to install and restart."; }