private void cmdCompress_Click(object sender, EventArgs e) { _lstFiles.Clear(); GetDirectories(txtFilePath.Text); OmaeHelper.CompressMutipleToFile(_lstFiles, txtDestination.Text); MessageBox.Show("Done"); }
private void cmdOK_Click(object sender, EventArgs e) { omaeSoapClient objService = OmaeHelper.GetOmaeService(); objService.SetEmailAddress(_strUserName, txtEmail.Text); DialogResult = DialogResult.OK; }
private void cmdLogin_Click(object sender, EventArgs e) { // Make sure User Name and Password are provided. if (string.IsNullOrWhiteSpace(txtUserName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_Omae_EnterUsername", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_ChooseUsername", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show(LanguageManager.GetString("Message_Omae_EnterPassword", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_ChoosePassword", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { bool blnResult = objService.Login(txtUserName.Text, OmaeHelper.Base64Encode(txtPassword.Text)); if (blnResult) { _strUserName = txtUserName.Text; _blnLoggedIn = true; lblLoggedIn.Text = LanguageManager.GetString("Label_Omae_LoggedInAs", GlobalOptions.Language).Replace("{0}", txtUserName.Text); panLogin.Visible = false; panLoggedIn.Visible = true; // Save the settings. RegistryKey objRegistry = Registry.CurrentUser.CreateSubKey("Software\\Chummer5"); GlobalOptions.OmaeUserName = txtUserName.Text; objRegistry.SetValue("omaeusername", txtUserName.Text); if (chkAutoLogin.Checked) { GlobalOptions.OmaePassword = OmaeHelper.Base64Encode(txtPassword.Text); objRegistry.SetValue("omaepassword", OmaeHelper.Base64Encode(txtPassword.Text)); GlobalOptions.OmaeAutoLogin = chkAutoLogin.Checked; objRegistry.SetValue("omaeautologin", chkAutoLogin.Checked.ToString()); } else { GlobalOptions.OmaePassword = string.Empty; objRegistry.SetValue("omaepassword", string.Empty); GlobalOptions.OmaeAutoLogin = chkAutoLogin.Checked; objRegistry.SetValue("omaeautologin", chkAutoLogin.Checked.ToString()); } objRegistry.Close(); } else { MessageBox.Show(LanguageManager.GetString("Message_Omae_CannotLogin", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_OmaeLogin", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); CheckUploadLanguagePermission(); }
private void frmOmae_Load(object sender, EventArgs e) { _strUserName = GlobalOptions.OmaeUserName; txtUserName.Text = _strUserName; if (!string.IsNullOrEmpty(txtUserName.Text)) txtPassword.Focus(); else txtUserName.Focus(); if (GlobalOptions.OmaeAutoLogin) { chkAutoLogin.Checked = true; txtPassword.Text = OmaeHelper.Base64Decode(GlobalOptions.OmaePassword); cmdLogin_Click(sender, e); } PopulateSortOrder(); PopulateMetatypes(); PopulateQualities(); PopulateMode(); GetCharacterTypes(); MoveControls(); if (txtUserName.Text == "Nebular" && _blnLoggedIn) { cmdCompress.Visible = true; cmdCompress.Text = "Compress Files"; cmdCompressData.Visible = true; cmdCompressData.Text = "Compress Data"; } CheckUploadLanguagePermission(); }
private void cmdPasswordReset_Click(object sender, EventArgs e) { omaeSoapClient objService = OmaeHelper.GetOmaeService(); if (!objService.ResetPassword(txtUserName.Text)) MessageBox.Show(LanguageManager.GetString("Message_Omae_PasswordNoEmail", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_PasswordReset", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); else MessageBox.Show(LanguageManager.GetString("Message_Omae_PasswordReset", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_PasswordReset", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void cmdCompressData_Click(object sender, EventArgs e) { foreach (string strFile in Directory.GetFiles(Path.Combine(Application.StartupPath, "data"), "*.xml")) { byte[] bytFile = File.ReadAllBytes(strFile); bytFile = OmaeHelper.Compress(bytFile); File.WriteAllBytes(strFile.Replace(".xml", ".zip"), bytFile); } MessageBox.Show("Done"); }
private void cmdCompressData_Click(object sender, EventArgs e) { OmaeHelper objHelper = new OmaeHelper(); foreach (string strFile in Directory.GetFiles(Path.Combine(GlobalOptions.ApplicationPath(), "data"), "*.xml")) { byte[] bytFile = File.ReadAllBytes(strFile); bytFile = objHelper.Compress(bytFile); File.WriteAllBytes(strFile.Replace(".xml", ".zip"), bytFile); } MessageBox.Show("Done"); }
private void objRecord_OmaeDeleteClicked(Object sender) { if (_objMode == OmaeMode.Character) { // Make sure the user wants to delete the character. if (MessageBox.Show(LanguageManager.GetString("Message_Omae_ConfirmDelete", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteCharacter", GlobalOptions.Language), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; // Delete the character. OmaeRecord objRecord = (OmaeRecord) sender; omaeSoapClient objService = OmaeHelper.GetOmaeService(); if (objService.DeleteCharacter(objRecord.CharacterID)) MessageBox.Show(LanguageManager.GetString("Message_Omae_CharacterDeleted", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteCharacter", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(LanguageManager.GetString("Message_Omae_CharacterDeleteError", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteCharacter", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (_objMode == OmaeMode.Data) { // Make sure the user wants to delete the data. if (MessageBox.Show(LanguageManager.GetString("Message_Omae_ConfirmData", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteData", GlobalOptions.Language), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; // Delete the data. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = OmaeHelper.GetOmaeService(); if (objService.DeleteDataFile(objRecord.CharacterID)) MessageBox.Show(LanguageManager.GetString("Message_Omae_DataDeleted", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteData", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(LanguageManager.GetString("Message_Omae_DataDeleteError", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteData", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (_objMode == OmaeMode.Sheets) { // Make sure the user wants to delete the character sheet. if (MessageBox.Show(LanguageManager.GetString("Message_Omae_ConfirmSheet", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteData", GlobalOptions.Language), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; // Delete the data. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = OmaeHelper.GetOmaeService(); if (objService.DeleteSheet(objRecord.CharacterID)) MessageBox.Show(LanguageManager.GetString("Message_Omae_SheetDeleted", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteData", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(LanguageManager.GetString("Message_Omae_SheetDeleteError", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DeleteData", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Show the Upload Language button if the user is allowed to upload languages. /// </summary> private void CheckUploadLanguagePermission() { if (!_blnLoggedIn) cmdUploadLanguage.Visible = false; else { translationSoapClient objService = OmaeHelper.GetTranslationService(); try { cmdUploadLanguage.Visible = objService.CanUploadLanguage(_strUserName); } catch { cmdUploadLanguage.Visible = false; } objService.Close(); } }
/// <summary> /// Attempt to get the list of character types. /// </summary> public bool GetCharacterTypes() { omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.GetCharacterTypes().WriteTo(objWriter); // Flush the output. objWriter.Flush(); XmlDocument objXmlDocument = OmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); // Stuff all of the items into a ListItem List. foreach (XmlNode objNode in objXmlDocument.SelectNodes("/types/type")) { _lstCharacterTypes.Add(new ListItem(objNode["id"].InnerText, objNode["name"].InnerText)); } _lstCharacterTypes.Add(new ListItem("4", "Official NPC Packs")); _lstCharacterTypes.Add(new ListItem("data", "Data")); _lstCharacterTypes.Add(new ListItem("sheets", "Character Sheets")); cboCharacterTypes.Items.Clear(); cboCharacterTypes.DataSource = _lstCharacterTypes; cboCharacterTypes.ValueMember = "Value"; cboCharacterTypes.DisplayMember = "Name"; } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); return(false); }
private void cmdRegister_Click(object sender, EventArgs e) { // Make sure User Name and Password are provided. if (string.IsNullOrWhiteSpace(txtUserName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_Omae_ChooseUsername", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_ChooseUsername", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show(LanguageManager.GetString("Message_Omae_ChoosePassword", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_ChoosePassword", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { int intResult = objService.RegisterUser(txtUserName.Text, OmaeHelper.Base64Encode(txtPassword.Text)); if (intResult == 0) { // Registered successfully. MessageBox.Show(LanguageManager.GetString("Message_Omae_AccountCreated", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_Registration", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if (intResult == -1) { // Username already exists. MessageBox.Show(LanguageManager.GetString("Message_Omae_AccountExists", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_Registration", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); }
private void cmdUpload_Click(object sender, EventArgs e) { // Make sure a file has been selected. if (string.IsNullOrEmpty(txtFilePath.Text)) { Program.MainForm.ShowMessageBox("Please select a language file to upload.", "No Language File Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } byte[] bytFile = File.ReadAllBytes(txtFilePath.Text); string strFileName = Path.GetFileName(txtFilePath.Text); translationSoapClient objService = OmaeHelper.GetTranslationService(); try { int intResult = objService.UploadLanguage(_strUserName, strFileName, bytFile); if (intResult == RESULT_SUCCESS) { Program.MainForm.ShowMessageBox(MESSAGE_SUCCESS, "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (intResult == RESULT_UNAUTHORIZED) { Program.MainForm.ShowMessageBox(MESSAGE_UNAUTHORIZED, "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (intResult == RESULT_INVALID_FILE) { Program.MainForm.ShowMessageBox(MESSAGE_INVALID_FILE, "File Upload", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException) { Program.MainForm.ShowMessageBox(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); }
private void cmdUpload_Click(object sender, EventArgs e) { // Make sure a name has been entered. if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_DataName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_DataName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure there is at least some sort of description. if (string.IsNullOrWhiteSpace(txtDescription.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OameUpload_DataDescription", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_DataDescription", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure at least 1 file is selected. int intCount = 0; foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { intCount++; } } if (intCount == 0) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_DataSelectFiles", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SelectFile", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool blnSuccess = false; string strFilePath = Path.Combine(Utils.GetStartupPath, "data", "books.xml"); XmlDocument objXmlBooks = new XmlDocument(); objXmlBooks.Load(strFilePath); List <string> lstSource = new List <string>(); // Run through all of the selected items. Create a list of the <source> items seen and make sure they're available in the core files or included in the user's selected item. foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(objNode.Tag.ToString()); XmlNodeList objRootList = objXmlDocument.SelectNodes("/chummer"); foreach (XmlNode objXmlGroup in objRootList[0]) { foreach (XmlNode objXmlNode in objXmlGroup.ChildNodes) { if (objXmlNode["source"] != null) { // Look to see if this sourcebook is already in the list. If not, add it. bool blnFound = false; foreach (string strSource in lstSource) { if (strSource == objXmlNode["source"].InnerText) { blnFound = true; break; } } if (!blnFound) { lstSource.Add(objXmlNode["source"].InnerText); } } } } } } // Now that we have the list of used sourcebooks, check the books file for the items. for (int i = 0; i <= lstSource.Count - 1; i++) { string strSource = lstSource[i]; if (!string.IsNullOrEmpty(strSource)) { XmlNode objNode = objXmlBooks.SelectSingleNode("/chummer/books/book[code = \"" + strSource + "\"]"); if (objNode != null) { lstSource[i] = string.Empty; } } } // Check any custom book files the user selected. foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked && objNode.Tag.ToString().EndsWith("books.xml")) { XmlDocument objXmlCustom = new XmlDocument(); objXmlCustom.Load(objNode.Tag.ToString()); for (int i = 0; i <= lstSource.Count - 1; i++) { string strSource = lstSource[i]; if (!string.IsNullOrEmpty(strSource)) { XmlNode objBookNode = objXmlCustom.SelectSingleNode("/chummer/books/book[code = \"" + strSource + "\"]"); if (objBookNode != null) { lstSource[i] = string.Empty; } } } } } // With all of the books checked, run through the list one more time and display an error if there are still any that were not found. string strMessage = string.Empty; foreach (string strSource in lstSource) { if (!string.IsNullOrEmpty(strSource)) { strMessage += Environment.NewLine + '\t' + strSource; } } if (!string.IsNullOrEmpty(strMessage)) { MessageBox.Show("The following sourcebooks could not be found in the core data files or any of the data files you have selected:" + strMessage); return; } // Everything is OK, so zip up the selected files. List <string> lstFiles = new List <string>(); string strFilesIncluded = string.Empty; foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { lstFiles.Add(objNode.Tag.ToString()); strFilesIncluded += objNode.Text + ","; } } byte[] bytFile = OmaeHelper.CompressMutiple(lstFiles); // Make sure the file doesn't exceed 250K in size (256,000 bytes). if (bytFile.Length > 256000) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_FileTooLarge", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_FileTooLarge", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Upload the file. omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { cmdUpload.Enabled = false; txtDescription.Enabled = false; txtName.Enabled = false; if (objService.UploadDataFile(_strUserName, _intDataID, txtName.Text, txtDescription.Text, strFilesIncluded, bytFile)) { blnSuccess = true; MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_UploadComplete", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadComplete", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_UploadFailed", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadFailed", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); cmdUpload.Enabled = true; txtDescription.Enabled = true; txtName.Enabled = true; if (blnSuccess) { DialogResult = DialogResult.OK; } //OmaeHelper.DecompressMultiple(bytFile); }
private void cmdUpload_Click(object sender, EventArgs e) { bool blnSuccess = false; // Make sure a file has been selected. if (string.IsNullOrWhiteSpace(txtFilePath.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_SelectFile", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SelectFile", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure there is at least some sort of description. if (string.IsNullOrWhiteSpace(txtDescription.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_CharacterDescription", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_CharacterDescription", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Read the contents of the file into a byte array, the compress it. byte[] bytFile = OmaeHelper.Compress(File.ReadAllBytes(txtFilePath.Text)); // Make sure the file doesn't exceed 500K in size (512,000 bytes). if (bytFile.Length > 512000) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_FileTooLarge", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_FileTooLarge", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { cmdUpload.Enabled = false; txtDescription.Enabled = false; string strCharacterName = cboCharacterName.Text; if (strCharacterName.Length > 100) { strCharacterName = strCharacterName.Substring(0, 100); } if (objService.UploadCharacter153(_strUserName, _intCharacterID, strCharacterName, txtDescription.Text, _strMetatype, _strMetavariant, _strQualities, Convert.ToInt32(cboCharacterTypes.SelectedValue), _intCreated, bytFile)) { blnSuccess = true; MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_UploadComplete", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadComplete", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_UploadFailed", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadFailed", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); cmdUpload.Enabled = true; txtDescription.Enabled = true; if (blnSuccess) { DialogResult = DialogResult.OK; } }
private void frmOmaeAccount_Load(object sender, EventArgs e) { omaeSoapClient objService = OmaeHelper.GetOmaeService(); txtEmail.Text = objService.GetEmailAddress(_strUserName); }
private void cmdSearch_Click(object sender, EventArgs e) { omaeSoapClient objService = OmaeHelper.GetOmaeService(); // Clear the current contents of the Omae Panel. Detach the events before clearing it. foreach (OmaeRecord objRecord in panOmae.Controls.OfType <OmaeRecord>()) { objRecord.OmaeDownloadClicked -= objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked -= objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked -= objRecord_OmaeDeleteClicked; } panOmae.Controls.Clear(); // Set the current operating mode. switch (cboCharacterTypes.SelectedValue.ToString()) { case "data": _objMode = OmaeMode.Data; break; case "sheets": _objMode = OmaeMode.Sheets; break; default: _objMode = OmaeMode.Character; break; } // Search for characters. if (_objMode == OmaeMode.Character) { try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.FetchCharacters153(Convert.ToInt32(cboCharacterTypes.SelectedValue), Convert.ToInt32(cboSortOrder.SelectedValue), cboFilterMetatype.Text, cboFilterMetavariant.Text, Convert.ToInt32(cboFilterMode.SelectedValue), txtFilterUser.Text, cboFilterQuality1.Text, cboFilterQuality2.Text, cboFilterQuality3.Text).WriteTo(objWriter); // Flush the output. objWriter.Flush(); XmlDocument objXmlDocument = OmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); if (objXmlDocument.SelectNodes("/characters/character").Count == 0) { Label lblResults = new Label { Text = LanguageManager.GetString("String_Omae_NoCharacters", GlobalOptions.Language), Width = 200 }; panOmae.Controls.Add(lblResults); } else { int intCounter = -1; foreach (XmlNode objNode in objXmlDocument.SelectNodes("/characters/character")) { intCounter++; OmaeRecord objRecord = new OmaeRecord(objNode, Convert.ToInt32(cboCharacterTypes.SelectedValue), OmaeMode.Character); objRecord.OmaeDownloadClicked += objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked += objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked += objRecord_OmaeDeleteClicked; if ((objRecord.UserName == txtUserName.Text || txtUserName.Text == "Nebular") && _blnLoggedIn) { objRecord.OwnedByUser = true; } objRecord.Top = intCounter * 88; panOmae.Controls.Add(objRecord); } } objService.Close(); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Search for data. else if (_objMode == OmaeMode.Data) { try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.FetchDataFiles(Convert.ToInt32(cboSortOrder.SelectedValue), string.Empty, txtFilterUser.Text).WriteTo(objWriter); // Flush the output. objWriter.Flush(); XmlDocument objXmlDocument = OmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); if (objXmlDocument.SelectNodes("/datas/data").Count == 0) { Label lblResults = new Label { Text = LanguageManager.GetString("String_Omae_NoData", GlobalOptions.Language), Width = 200 }; panOmae.Controls.Add(lblResults); } else { int intCounter = -1; foreach (XmlNode objNode in objXmlDocument.SelectNodes("/datas/data")) { intCounter++; OmaeRecord objRecord = new OmaeRecord(objNode, 0, OmaeMode.Data); objRecord.OmaeDownloadClicked += objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked += objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked += objRecord_OmaeDeleteClicked; if ((objRecord.UserName == txtUserName.Text || txtUserName.Text == "Nebular") && _blnLoggedIn) { objRecord.OwnedByUser = true; } objRecord.Top = intCounter * 88; panOmae.Controls.Add(objRecord); } } objService.Close(); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Search for character sheets. else if (_objMode == OmaeMode.Sheets) { try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.FetchSheets(Convert.ToInt32(cboSortOrder.SelectedValue), txtFilterUser.Text).WriteTo(objWriter); // Flush the output. objWriter.Flush(); XmlDocument objXmlDocument = OmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); if (objXmlDocument.SelectNodes("/sheets/sheet").Count == 0) { Label lblResults = new Label { Text = LanguageManager.GetString("String_Omae_NoSheets", GlobalOptions.Language), Width = 200 }; panOmae.Controls.Add(lblResults); } else { int intCounter = -1; foreach (XmlNode objNode in objXmlDocument.SelectNodes("/sheets/sheet")) { intCounter++; OmaeRecord objRecord = new OmaeRecord(objNode, 0, OmaeMode.Sheets); objRecord.OmaeDownloadClicked += objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked += objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked += objRecord_OmaeDeleteClicked; if ((objRecord.UserName == txtUserName.Text || txtUserName.Text == "Nebular") && _blnLoggedIn) { objRecord.OwnedByUser = true; } objRecord.Top = intCounter * 88; panOmae.Controls.Add(objRecord); } } objService.Close(); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <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 = OmaeHelper.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.GetString("Message_Omae_FileExists", GlobalOptions.Language).Replace("{0}", strFileName), LanguageManager.GetString("MessageTitle_Omae_FileExists", GlobalOptions.Language), 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.GetString("Message_Omae_CannotFindCharacter", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_CannotFindCharacter", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. bytFile = OmaeHelper.Decompress(bytFile); File.WriteAllBytes(strFullPath, bytFile); if (MessageBox.Show(LanguageManager.GetString("Message_Omae_CharacterDownloaded", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_CharacterDownloaded", GlobalOptions.Language), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Cursor = Cursors.WaitCursor; Character objOpenCharacter = Program.MainForm.LoadCharacter(strFullPath); Cursor = Cursors.Default; _frmMain.OpenCharacter(objOpenCharacter); } } 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.GetString("Message_Omae_CannotFindCharacter", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_CannotFindCharacter", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. OmaeHelper.DecompressNPCs(bytFile); MessageBox.Show(LanguageManager.GetString("Message_Omae_NPCPackDownloaded", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_CharacterDownloaded", GlobalOptions.Language), 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.GetString("Message_Omae_CannotFindData", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_CannotFindData", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. OmaeHelper.DecompressDataFile(bytFile, objRecord.CharacterID.ToString()); // Show a message saying everything is done. MessageBox.Show(LanguageManager.GetString("Message_Omae_DataDownloaded", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_DataDownloaded", GlobalOptions.Language), 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.GetString("Message_Omae_CannotFindSheet", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_CannotFindSheet", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. OmaeHelper.DecompressCharacterSheet(bytFile); // Show a message saying everything is done. MessageBox.Show(LanguageManager.GetString("Message_Omae_SheetDownloaded", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_Omae_SheetDownloaded", GlobalOptions.Language), 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); } } } }
private void cmdUpload_Click(object sender, EventArgs e) { // Make sure a name has been entered. if (string.IsNullOrWhiteSpace(txtName.Text)) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_OmaeUpload_SheetName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SheetName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure there is at least some sort of description. if (string.IsNullOrWhiteSpace(txtDescription.Text)) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_OameUpload_SheetDescription", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SheetDescription", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure at least 1 file was selected. if (string.IsNullOrEmpty(txtFilePath.Text)) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_OmaeUpload_SheetSelectFiles", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SelectFile", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool blnSuccess = false; // Compress the files. byte[] bytFile = OmaeHelper.CompressMutiple(_lstFiles); // Make sure the file doesn't exceed 250K in size (256,000 bytes). if (bytFile.Length > 256000) { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_OmaeUpload_FileTooLarge", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_FileTooLarge", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Upload the file. omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { cmdUpload.Enabled = false; txtDescription.Enabled = false; txtName.Enabled = false; if (objService.UploadSheet(_strUserName, _intSheetID, txtName.Text, txtDescription.Text, bytFile)) { blnSuccess = true; Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_OmaeUpload_UploadComplete", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadComplete", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_OmaeUpload_UploadFailed", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadFailed", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException) { Program.MainForm.ShowMessageBox(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); cmdUpload.Enabled = true; txtDescription.Enabled = true; txtName.Enabled = true; if (blnSuccess) { DialogResult = DialogResult.OK; } }
private void cmdCompressData_Click(object sender, EventArgs e) { OmaeHelper objHelper = new OmaeHelper(); foreach (string strFile in Directory.GetFiles(Path.Combine(Application.StartupPath, "data"), "*.xml")) { byte[] bytFile = File.ReadAllBytes(strFile); bytFile = objHelper.Compress(bytFile); File.WriteAllBytes(strFile.Replace(".xml", ".zip"), bytFile); } MessageBox.Show("Done"); }