Esempio n. 1
0
        /// <summary>
        /// Displays the character exportation window and then exports it.
        /// </summary>
        /// <param name="character"></param>
        public static void ExportCharacter(Character character)
        {
            // Open the dialog box
            using (var characterSaveDialog = new SaveFileDialog())
            {
                characterSaveDialog.Title       = "Save Character Info";
                characterSaveDialog.Filter      = "Text Format|*.txt|CHR Format (EFT)|*.chr|HTML Format|*.html|XML Format (EVEMon)|*.xml|XML Format (CCP API)|*.xml|PNG Image|*.png";
                characterSaveDialog.FileName    = character.Name;
                characterSaveDialog.FilterIndex = (int)CharacterSaveFormat.CCPXML;

                var result = characterSaveDialog.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;
                    // Save character with the chosen format to our file
                    FileHelper.OverwriteOrWarnTheUser(characterSaveDialog.FileName, fs =>
                    {
                        if (format == CharacterSaveFormat.PNG)
                        {
                            var monitor = Program.MainWindow.GetCurrentMonitor();
                            var bmp     = monitor.GetCharacterScreenshot();
                            bmp.Save(fs, ImageFormat.Png);
                            return(true);
                        }

                        var content = CharacterExporter.Export(format, character, null);
                        if ((format == CharacterSaveFormat.CCPXML) && string.IsNullOrEmpty(content))
                        {
                            MessageBox.Show("This character has never been downloaded from CCP, cannot find it in the XML cache.", "Cannot export the character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return(false);
                        }

                        using (var sw = new StreamWriter(fs, Encoding.UTF8))
                        {
                            sw.Write(content);
                            sw.Flush();
                            sw.Close();
                        }
                        return(true);
                    });
                }
                // Handle exception
                catch (IOException exc)
                {
                    ExceptionHandler.LogException(exc, true);
                    MessageBox.Show("A problem occurred during exportation. The operation has not been completed.");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Displays the character exportation window and then exports it as it would be after the plan finish.
        /// </summary>
        /// <param name="character"></param>
        public static void ExportAfterPlanCharacter(Character character, Plan plan)
        {
            // Open the dialog box
            using (var characterSaveDialog = new SaveFileDialog())
            {
                characterSaveDialog.Title       = "Save After Plan Character Info";
                characterSaveDialog.Filter      = "Text Format|*.txt|CHR Format (EFT)|*.chr|HTML Format|*.html|XML Format (EVEMon)|*.xml";
                characterSaveDialog.FileName    = String.Format(CultureConstants.DefaultCulture, " {0} (after plan {1})", character.Name, plan.Name);
                characterSaveDialog.FilterIndex = (int)CharacterSaveFormat.EVEMonXML;

                var result = characterSaveDialog.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    // Save character to string with the chosen format
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;
                    var content = CharacterExporter.Export(format, character, plan);
                    // Save character with the chosen format to our file
                    FileHelper.OverwriteOrWarnTheUser(characterSaveDialog.FileName, fs =>
                    {
                        using (var sw = new StreamWriter(fs, Encoding.UTF8))
                        {
                            sw.Write(content);
                            sw.Flush();
                            sw.Close();
                        }
                        return(true);
                    });
                }
                // Handle exception
                catch (IOException ex)
                {
                    ExceptionHandler.LogException(ex, true);
                    MessageBox.Show("A problem occurred during exportation. The operation has not been completed.");
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Displays the character exportation window and then exports it.
        /// </summary>
        /// <param name="character"></param>
        public static void ExportCharacter(Character character)
        {
            // Open the dialog box
            using (var characterSaveDialog = new System.Windows.Forms.SaveFileDialog())
            {
                characterSaveDialog.Title       = "Save Character Info";
                characterSaveDialog.Filter      = "Text Format|*.txt|HTML Format|*.html|XML Format (CCP API)|*.xml|XML Format (EVEMon)|*.xml|PNG Image|*.png";
                characterSaveDialog.FileName    = character.Name;
                characterSaveDialog.FilterIndex = (int)CharacterSaveFormat.CCPXML;

                var result = characterSaveDialog.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    // Save file to the chosen format and to a temp file
                    string tempFileName        = Path.GetTempFileName();
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;
                    switch (format)
                    {
                    case CharacterSaveFormat.HTML:
                        File.WriteAllText(tempFileName, CharacterExporter.ExportAsHTML(character), Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.CCPXML:
                        var content = CharacterExporter.ExportAsCCPXML(character);
                        if (content == null)
                        {
                            MessageBox.Show("This character has never been downloaded from CCP, cannot find it in the XML cache.", "Cannot export the character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        File.WriteAllText(tempFileName, content, Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.EVEMonXML:
                        File.WriteAllText(tempFileName, CharacterExporter.ExportAsEVEMonXML(character), Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.Text:
                        File.WriteAllText(tempFileName, CharacterExporter.ExportAsText(character), Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.PNG:
                        var monitor = Program.MainWindow.GetCurrentMonitor();
                        var bmp     = monitor.GetCharacterScreenshot();
                        bmp.Save(tempFileName, System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    // Writes to our file
                    FileHelper.OverwriteOrWarnTheUser(tempFileName, characterSaveDialog.FileName, OverwriteOperation.Move);
                }
                // Handle exception
                catch (IOException exc)
                {
                    ExceptionHandler.LogException(exc, true);
                    MessageBox.Show("A problem occured during exportation. The operation has not been completed.");
                }
            }
        }