Beispiel #1
0
        /// <summary>
        /// Import the last imported savegame.
        /// </summary>
        private void TsbImportLastSaveGame_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Properties.Settings.Default.LastImportedSaveGame))
            {
                MessageBox.Show(
                    "First import a savegame via the menu, after that you can import the last imported file with this button.",
                    "First import manual.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            RunSavegameImport(ATImportFileLocation.CreateFromString(Properties.Settings.Default.LastImportedSaveGame));
        }
        /// <summary>
        /// Import the last imported savegame.
        /// </summary>
        private void TsbImportLastSaveGame_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Properties.Settings.Default.LastImportedSaveGame))
            {
                MessageBoxes.ShowMessageBox(
                    "First import a savegame via the menu. After that you can import the last imported file with this button.",
                    "First import a save file manually", MessageBoxIcon.Information);
                return;
            }

            var importFile = ATImportFileLocation.CreateFromString(Properties.Settings.Default.LastImportedSaveGame);

            if (string.IsNullOrEmpty(importFile.FileLocation) || !File.Exists(importFile.FileLocation))
            {
                MessageBoxes.ShowMessageBox(
                    $"The file that was imported last time does not exist anymore:\n{importFile.FileLocation}\nImport the file you want to import at least once via the menu. After that you can import the last imported file with this button.",
                    "File not existing");
                return;
            }

            RunSavegameImport(importFile);
        }
Beispiel #3
0
        private async void RunSavegameImport(object sender, EventArgs e)
        {
            try
            {
                ATImportFileLocation atImportFileLocation = (ATImportFileLocation)((ToolStripMenuItem)sender).Tag;

                string workingCopyfilename = Properties.Settings.Default.savegameExtractionPath;

                // working dir not configured? use temp dir
                // luser configured savegame folder as working dir? use temp dir instead
                if (string.IsNullOrWhiteSpace(workingCopyfilename) ||
                    Path.GetDirectoryName(atImportFileLocation.FileLocation) == workingCopyfilename)
                {
                    workingCopyfilename = Path.GetTempPath();
                }


                if (Uri.TryCreate(atImportFileLocation.FileLocation, UriKind.Absolute, out var uri) &&
                    uri.Scheme != "file")
                {
                    switch (uri.Scheme)
                    {
                    case "ftp":
                        workingCopyfilename = await CopyFtpFileAsync(uri, atImportFileLocation.ConvenientName, workingCopyfilename);

                        if (workingCopyfilename == null)
                        {
                            // the user didn't enter credentials
                            return;
                        }
                        break;

                    default:
                        throw new Exception($"Unsuppoerted uri scheme: {uri.Scheme}");
                    }
                }
                else
                {
                    workingCopyfilename = Path.Combine(workingCopyfilename, Path.GetFileName(atImportFileLocation.FileLocation));
                    File.Copy(atImportFileLocation.FileLocation, workingCopyfilename, true);
                }

                await ImportSavegame.ImportCollectionFromSavegame(creatureCollection, workingCopyfilename, atImportFileLocation.ServerName);

                UpdateParents(creatureCollection.creatures);

                foreach (var creature in creatureCollection.creatures)
                {
                    creature.RecalculateAncestorGenerations();
                }

                UpdateIncubationParents(creatureCollection);

                // update UI
                SetCollectionChanged(true);
                UpdateCreatureListings();

                if (creatureCollection.creatures.Any())
                {
                    tabControlMain.SelectedTab = tabPageLibrary;
                }

                // reapply last sorting
                listViewLibrary.Sort();

                UpdateTempCreatureDropDown();

                // if unknown mods are used in the savegame-file and the user wants to load the missing mod-files, do it
                if (creatureCollection.ModValueReloadNeeded &&
                    LoadModValuesOfCollection(creatureCollection, true, true))
                {
                    SetCollectionChanged(true);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message
                                 + "\n\nException in " + ex.Source
                                 + "\n\nMethod throwing the error: " + ex.TargetSite.DeclaringType.FullName + "." + ex.TargetSite.Name
                                 + "\n\nStackTrace:\n" + ex.StackTrace
                                 + (ex.InnerException != null ? "\n\nInner Exception:\n" + ex.InnerException.Message : string.Empty)
                ;
                MessageBox.Show($"An error occured while importing. Message: \n\n{message}",
                                "Import Error", MessageBoxButtons.OK);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Imports the creatures from the given saveGame. ftp is possible.
        /// </summary>
        /// <returns>null on success, else an error message to show, or an empty string if the error was already displayed.</returns>
        private async Task <string> RunSavegameImport(ATImportFileLocation atImportFileLocation)
        {
            TsbQuickSaveGameImport.Enabled     = false;
            TsbQuickSaveGameImport.BackColor   = Color.Yellow;
            ToolStripStatusLabelImport.Text    = $"{Loc.S("ImportingSavegame")} {atImportFileLocation.ConvenientName}";
            ToolStripStatusLabelImport.Visible = true;

            try
            {
                string workingCopyFolderPath = Properties.Settings.Default.savegameExtractionPath;
                string workingCopyFilePath;

                // working dir not configured? use temp dir
                // luser configured savegame folder as working dir? use temp dir instead
                if (string.IsNullOrWhiteSpace(workingCopyFolderPath) ||
                    Path.GetDirectoryName(atImportFileLocation.FileLocation) == workingCopyFolderPath)
                {
                    workingCopyFolderPath = Path.GetTempPath();
                }


                if (Uri.TryCreate(atImportFileLocation.FileLocation, UriKind.Absolute, out var uri) &&
                    uri.Scheme != "file")
                {
                    switch (uri.Scheme)
                    {
                    case "ftp":
                        workingCopyFilePath = await CopyFtpFileAsync(uri, atImportFileLocation.ConvenientName,
                                                                     workingCopyFolderPath);

                        if (workingCopyFilePath == null)
                        {
                            // the user didn't enter credentials
                            return("no credentials");
                        }
                        break;

                    default:
                        throw new Exception($"Unsupported uri scheme: {uri.Scheme}");
                    }
                }
                else
                {
                    if (!File.Exists(atImportFileLocation.FileLocation))
                    {
                        return($"File not found: {atImportFileLocation.FileLocation}");
                    }

                    workingCopyFilePath = Path.Combine(workingCopyFolderPath,
                                                       Path.GetFileName(atImportFileLocation.FileLocation));
                    try
                    {
                        File.Copy(atImportFileLocation.FileLocation, workingCopyFilePath, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBoxes.ExceptionMessageBox(ex, $"Error while copying the save game file to the working directory\n{workingCopyFolderPath}\nIt's recommended to leave the setting for the working folder empty.");
                        return(string.Empty);
                    }
                }

                await ImportSavegame.ImportCollectionFromSavegame(_creatureCollection, workingCopyFilePath,
                                                                  atImportFileLocation.ServerName);

                FileService.TryDeleteFile(workingCopyFilePath);

                UpdateParents(_creatureCollection.creatures);

                foreach (var creature in _creatureCollection.creatures)
                {
                    creature.RecalculateAncestorGenerations();
                }

                UpdateIncubationParents(_creatureCollection);

                // update UI
                SetCollectionChanged(true);
                UpdateCreatureListings();

                if (_creatureCollection.creatures.Any())
                {
                    tabControlMain.SelectedTab = tabPageLibrary;
                }

                // reapply last sorting
                listViewLibrary.Sort();

                UpdateTempCreatureDropDown();

                // if unknown mods are used in the savegame-file and the user wants to load the missing mod-files, do it
                if (_creatureCollection.ModValueReloadNeeded &&
                    LoadModValuesOfCollection(_creatureCollection, true, true))
                {
                    SetCollectionChanged(true);
                }
            }
            catch (Exception ex)
            {
                MessageBoxes.ExceptionMessageBox(ex, $"An error occurred while importing the file {atImportFileLocation.FileLocation}.", "Save file import error");
                return(string.Empty);
            }
            finally
            {
                TsbQuickSaveGameImport.Enabled     = true;
                TsbQuickSaveGameImport.BackColor   = SystemColors.Control;
                ToolStripStatusLabelImport.Visible = false;
            }

            return(null); // no error
        }
        /// <summary>
        /// Imports the creatures from the given savegame. ftp is possible.
        /// </summary>
        /// <param name="atImportFileLocation"></param>
        private async void RunSavegameImport(ATImportFileLocation atImportFileLocation)
        {
            TsbImportLastSaveGame.Enabled      = false;
            TsbImportLastSaveGame.BackColor    = Color.Yellow;
            ToolStripStatusLabelImport.Text    = $"{Loc.S("ImportingSavegame")} {atImportFileLocation.ConvenientName}";
            ToolStripStatusLabelImport.Visible = true;
            try
            {
                string workingCopyfilename = Properties.Settings.Default.savegameExtractionPath;

                // working dir not configured? use temp dir
                // luser configured savegame folder as working dir? use temp dir instead
                if (string.IsNullOrWhiteSpace(workingCopyfilename) ||
                    Path.GetDirectoryName(atImportFileLocation.FileLocation) == workingCopyfilename)
                {
                    workingCopyfilename = Path.GetTempPath();
                }


                if (Uri.TryCreate(atImportFileLocation.FileLocation, UriKind.Absolute, out var uri) &&
                    uri.Scheme != "file")
                {
                    switch (uri.Scheme)
                    {
                    case "ftp":
                        workingCopyfilename = await CopyFtpFileAsync(uri, atImportFileLocation.ConvenientName,
                                                                     workingCopyfilename);

                        if (workingCopyfilename == null)
                        {
                            // the user didn't enter credentials
                            return;
                        }
                        break;

                    default:
                        throw new Exception($"Unsupported uri scheme: {uri.Scheme}");
                    }
                }
                else
                {
                    workingCopyfilename = Path.Combine(workingCopyfilename,
                                                       Path.GetFileName(atImportFileLocation.FileLocation));
                    File.Copy(atImportFileLocation.FileLocation, workingCopyfilename, true);
                }

                await ImportSavegame.ImportCollectionFromSavegame(_creatureCollection, workingCopyfilename,
                                                                  atImportFileLocation.ServerName);

                UpdateParents(_creatureCollection.creatures);

                foreach (var creature in _creatureCollection.creatures)
                {
                    creature.RecalculateAncestorGenerations();
                }

                UpdateIncubationParents(_creatureCollection);

                // update UI
                SetCollectionChanged(true);
                UpdateCreatureListings();

                if (_creatureCollection.creatures.Any())
                {
                    tabControlMain.SelectedTab = tabPageLibrary;
                }

                // reapply last sorting
                listViewLibrary.Sort();

                UpdateTempCreatureDropDown();

                // if unknown mods are used in the savegame-file and the user wants to load the missing mod-files, do it
                if (_creatureCollection.ModValueReloadNeeded &&
                    LoadModValuesOfCollection(_creatureCollection, true, true))
                {
                    SetCollectionChanged(true);
                }

                Properties.Settings.Default.LastImportedSaveGame = atImportFileLocation.ToString();
                TsbImportLastSaveGame.ToolTipText = $"Import savegame {atImportFileLocation.ConvenientName}";
            }
            catch (Exception ex)
            {
                string message = ex.Message
                                 + "\n\nException in " + ex.Source
                                 + "\n\nMethod throwing the error: " + ex.TargetSite.DeclaringType.FullName + "." +
                                 ex.TargetSite.Name
                                 + "\n\nStackTrace:\n" + ex.StackTrace
                                 + (ex.InnerException != null
                                     ? "\n\nInner Exception:\n" + ex.InnerException.Message
                                     : string.Empty)
                ;
                MessageBoxes.ShowMessageBox($"An error occurred while importing. Message:\n\n{message}", "Save file import error");
            }
            finally
            {
                TsbImportLastSaveGame.Enabled      = true;
                TsbImportLastSaveGame.BackColor    = SystemColors.Control;
                ToolStripStatusLabelImport.Visible = false;
            }
        }