/// <summary> /// A file is done downloading, so increment the overall progress bar and check to see if all downloads are done. /// </summary> private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { // Detach the event handlers once they're done so they don't continue to fire and/or consume memory. WebClient wc = new WebClient(); wc = (WebClient)sender; wc.DownloadProgressChanged -= wc_DownloadProgressChanged; wc.DownloadFileCompleted -= wc_DownloadFileCompleted; _intDoneCount++; pgbOverallProgress.Value++; if (_intDoneCount == _intFileCount) { bool blnUnzipSuccess = true; // Unzip the data files that have been downloaded. OmaeHelper objHelper = new OmaeHelper(); foreach (string strFile in Directory.GetFiles(Path.Combine(Application.StartupPath, "data"), "*.zip")) { try { byte[] bytFile = File.ReadAllBytes(strFile); bytFile = objHelper.Decompress(bytFile); File.WriteAllBytes(strFile.Replace(".zip", ".xml"), bytFile); if (!strFile.Contains("\\Debug\\")) File.Delete(strFile); } catch { blnUnzipSuccess = false; } } if (!_blnSilentMode) { // If the update process is not running in silent mode, display a message informing the user that the update is done. pgbOverallProgress.Visible = false; pgbFileProgress.Visible = false; lblDone.Visible = true; } if (ValidateFiles() && blnUnzipSuccess) { if (_blnExeDownloaded) { cmdRestart.Visible = true; if (_blnSilentMode) { // The user is in silent mode, so restart the application. Application.Restart(); } } // Close the window when we're done in Silent Mode. if (_blnSilentMode) this.Close(); } else { // Show the progress bars again. pgbOverallProgress.Visible = true; pgbFileProgress.Visible = true; lblDone.Visible = false; // Something did not download properly. if (_blnSilentMode) FetchXML(); else { // Make a list of each item that is currently checked. List<string> lstStrings = new List<string>(); // Loop through all of the root-level nodes in the update tree. foreach (TreeNode nodRoot in treeUpdate.Nodes) { // Loop through each of the child nodes. foreach (TreeNode nodNode in nodRoot.Nodes) { if (nodNode.Checked) { lstStrings.Add(nodNode.Tag.ToString()); } } } FetchXML(); // Select all of the items that were selected before. // Loop through all of the root-level nodes in the update tree. foreach (string strString in lstStrings) { foreach (TreeNode nodRoot in treeUpdate.Nodes) { // Loop through each of the child nodes. foreach (TreeNode nodNode in nodRoot.Nodes) { if (nodNode.Tag.ToString() == strString) { nodNode.Checked = true; } } } } // Click the button to do it all again. cmdUpdate_Click(null, null); } } } }
private void objRecord_OmaeDownloadClicked(Object sender) { // Setup the web service. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); if (_objMode == OmaeMode.Character) { if (objRecord.CharacterType != 4) { // Download the selected character. string strFileName = objRecord.CharacterName + ".chum5"; strFileName = FileSafe(strFileName); // If the Omae save directory does not yet exist, create it. string strSavePath = Path.Combine(Application.StartupPath, "saves"); if (!Directory.Exists(strSavePath)) { Directory.CreateDirectory(strSavePath); } string omaeDirectoryPath = Path.Combine(strSavePath, "omae"); if (!Directory.Exists(omaeDirectoryPath)) { Directory.CreateDirectory(omaeDirectoryPath); } // See if there is already a file with the character's name in the Downloads directory. string strFullPath = Path.Combine(omaeDirectoryPath, strFileName); if (File.Exists(strFullPath)) { if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_FileExists").Replace("{0}", strFileName), LanguageManager.Instance.GetString("MessageTitle_Omae_FileExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } try { // Download the compressed file. byte[] bytFile = objService.DownloadCharacter(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindCharacter"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindCharacter"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. bytFile = _objOmaeHelper.Decompress(bytFile); File.WriteAllBytes(strFullPath, bytFile); if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CharacterDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_CharacterDownloaded"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _frmMain.LoadCharacter(strFullPath); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { // Download the selected NPC pack. string strFileName = objRecord.CharacterName + ".chum5"; strFileName = FileSafe(strFileName); // If the Omae save directory does not yet exist, create it. string strSavePath = Path.Combine(Application.StartupPath, "saves"); if (!Directory.Exists(strSavePath)) { Directory.CreateDirectory(strSavePath); } try { // Download the compressed file. byte[] bytFile = objService.DownloadCharacter(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindCharacter"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindCharacter"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. _objOmaeHelper.DecompressNPCs(bytFile); MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_NPCPackDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_CharacterDownloaded"), MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else if (_objMode == OmaeMode.Data) { try { // Download the compressed file. byte[] bytFile = objService.DownloadDataFile(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindData"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindData"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. _objOmaeHelper.DecompressDataFile(bytFile, objRecord.CharacterID.ToString()); // Show a message saying everything is done. MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_DataDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_DataDownloaded"), MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (_objMode == OmaeMode.Sheets) { // If the Omae sheets directory does not yet exist, create it. string strSheetsPath = Path.Combine(Application.StartupPath, "sheets", "omae"); if (!Directory.Exists(strSheetsPath)) { Directory.CreateDirectory(strSheetsPath); } try { // Download the compressed file. byte[] bytFile = objService.DownloadSheet(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindSheet"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindSheet"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. _objOmaeHelper.DecompressCharacterSheet(bytFile); // Show a message saying everything is done. MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_SheetDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_SheetDownloaded"), MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Close the service now that we're done with it. objService.Close(); }
/// <summary> /// A file is done downloading, so increment the overall progress bar and check to see if all downloads are done. /// </summary> private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { // Detach the event handlers once they're done so they don't continue to fire and/or consume memory. WebClient wc = new WebClient(); wc = (WebClient)sender; wc.DownloadProgressChanged -= wc_DownloadProgressChanged; wc.DownloadFileCompleted -= wc_DownloadFileCompleted; _intDoneCount++; pgbOverallProgress.Value++; if (_intDoneCount == _intFileCount) { bool blnUnzipSuccess = true; // Unzip the data files that have been downloaded. OmaeHelper objHelper = new OmaeHelper(); foreach (string strFile in Directory.GetFiles(Path.Combine(Application.StartupPath, "data"), "*.zip")) { try { byte[] bytFile = File.ReadAllBytes(strFile); bytFile = objHelper.Decompress(bytFile); File.WriteAllBytes(strFile.Replace(".zip", ".xml"), bytFile); if (!strFile.Contains("\\Debug\\")) { File.Delete(strFile); } } catch { blnUnzipSuccess = false; } } if (!_blnSilentMode) { // If the update process is not running in silent mode, display a message informing the user that the update is done. pgbOverallProgress.Visible = false; pgbFileProgress.Visible = false; lblDone.Visible = true; } if (ValidateFiles() && blnUnzipSuccess) { if (_blnExeDownloaded) { cmdRestart.Visible = true; if (_blnSilentMode) { // The user is in silent mode, so restart the application. Application.Restart(); } } // Close the window when we're done in Silent Mode. if (_blnSilentMode) { this.Close(); } } else { // Show the progress bars again. pgbOverallProgress.Visible = true; pgbFileProgress.Visible = true; lblDone.Visible = false; // Something did not download properly. if (_blnSilentMode) { FetchXML(); } else { // Make a list of each item that is currently checked. List <string> lstStrings = new List <string>(); // Loop through all of the root-level nodes in the update tree. foreach (TreeNode nodRoot in treeUpdate.Nodes) { // Loop through each of the child nodes. foreach (TreeNode nodNode in nodRoot.Nodes) { if (nodNode.Checked) { lstStrings.Add(nodNode.Tag.ToString()); } } } FetchXML(); // Select all of the items that were selected before. // Loop through all of the root-level nodes in the update tree. foreach (string strString in lstStrings) { foreach (TreeNode nodRoot in treeUpdate.Nodes) { // Loop through each of the child nodes. foreach (TreeNode nodNode in nodRoot.Nodes) { if (nodNode.Tag.ToString() == strString) { nodNode.Checked = true; } } } } // Click the button to do it all again. cmdUpdate_Click(null, null); } } } }