Beispiel #1
0
        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();
        }