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(); }