Пример #1
0
        public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName)
        {
            string[] rafts = { "Raft_BP_C", "MotorRaft_BP_C", "Barge_BP_C" };
            (GameObjectContainer gameObjectContainer, float gameTime) = await readSavegameFile(filename);

            IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer
                                                            .Where(o => o.IsCreature() && o.IsTamed() && !o.IsUnclaimedBaby() && !rafts.Contains(o.ClassString));

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter))
            {
                string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',')
                                   .Select(s => s.Trim())
                                   .Where(s => !string.IsNullOrEmpty(s))
                                   .ToArray();

                tamedCreatureObjects = tamedCreatureObjects.Where(o =>
                {
                    string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty);
                    return(filters.Any(filter => tribeName.Contains(filter)));
                });
            }

            ImportSavegame  importSavegame = new ImportSavegame(gameTime);
            int?            wildLevelStep  = creatureCollection.getWildLevelStep();
            List <Creature> creatures      = tamedCreatureObjects.Select(o => importSavegame.convertGameObject(o, wildLevelStep)).ToList();

            importCollection(creatureCollection, creatures, serverName);
        }
Пример #2
0
        public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName)
        {
            (GameObjectContainer gameObjectContainer, float gameTime) = await Task.Run(() => ReadSavegameFile(filename));

            var ignoreClasses         = Values.V.IgnoreSpeciesClassesOnImport;
            var importUnclaimedBabies = Properties.Settings.Default.SaveFileImportUnclaimedBabies;

            IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer
                                                            .Where(o => o.IsCreature() &&
                                                                   o.IsTamed() &&
                                                                   (importUnclaimedBabies || (o.IsCryo && Properties.Settings.Default.SaveImportCryo) || !o.IsUnclaimedBaby()) &&
                                                                   !ignoreClasses.Contains(o.ClassString));

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter))
            {
                string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',')
                                   .Select(s => s.Trim())
                                   .Where(s => !string.IsNullOrEmpty(s))
                                   .ToArray();

                if (filters.Any())
                {
                    tamedCreatureObjects = tamedCreatureObjects.Where(o =>
                    {
                        string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty);
                        return(filters.Any(filter => tribeName.Contains(filter)));
                    });
                }
            }

            ImportSavegame importSavegame = new ImportSavegame(gameTime);
            int?           wildLevelStep  = creatureCollection.getWildLevelStep();
            var            creatures      = tamedCreatureObjects.Select(o => importSavegame.ConvertGameObject(o, wildLevelStep)).Where(c => c != null).ToArray();

            ArkName.ClearCache();

            // if there are creatures with unknown species, check if the according mod-file is available
            var unknownSpeciesCreatures = creatures.Where(c => c.Species == null).ToArray();

            if (!unknownSpeciesCreatures.Any() ||
                Properties.Settings.Default.IgnoreUnknownBlueprintsOnSaveImport ||
                MessageBox.Show("The species of " + unknownSpeciesCreatures.Length + " creature" + (unknownSpeciesCreatures.Length != 1 ? "s" : "") + " is not recognized, probably because they are from a mod that is not loaded.\n"
                                + "The unrecognized species-classes are as follows, all the according creatures cannot be imported:\n\n" + string.Join("\n", unknownSpeciesCreatures.Select(c => c.name).Distinct().ToArray())
                                + "\n\nTo import the unrecognized creatures, you first need mod values-files, see Settings - Mod value manager… if the mod value is available\n\n"
                                + "Do you want to import the recognized creatures? If you click no, nothing is imported.",
                                "Unrecognized species while importing savegame", MessageBoxButtons.YesNo, MessageBoxIcon.Question
                                ) == DialogResult.Yes
                )
            {
                ImportCollection(creatureCollection, creatures.Where(c => c.Species != null).ToList(), serverName);
            }
        }
Пример #3
0
        public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName)
        {
            if (Values.V.ignoreSpeciesClassesOnImport == null)
            {
                Values.V.LoadIgnoreSpeciesClassesFile();
            }

            (GameObjectContainer gameObjectContainer, float gameTime) = await readSavegameFile(filename);

            IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer
                                                            .Where(o => o.IsCreature() && o.IsTamed() && !o.IsUnclaimedBaby() && !Values.V.ignoreSpeciesClassesOnImport.Contains(o.ClassString));

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter))
            {
                string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',')
                                   .Select(s => s.Trim())
                                   .Where(s => !string.IsNullOrEmpty(s))
                                   .ToArray();

                tamedCreatureObjects = tamedCreatureObjects.Where(o =>
                {
                    string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty);
                    return(filters.Any(filter => tribeName.Contains(filter)));
                });
            }

            ImportSavegame  importSavegame = new ImportSavegame(gameTime);
            int?            wildLevelStep  = creatureCollection.getWildLevelStep();
            List <Creature> creatures      = tamedCreatureObjects.Select(o => importSavegame.convertGameObject(o, wildLevelStep)).ToList();

            // if there are creatures with unknown species, check if the according mod-file is available
            var unknownSpeciesCreatures = creatures.Where(c => c.Species == null).ToList();

            if (!unknownSpeciesCreatures.Any() ||
                MessageBox.Show("The species of " + unknownSpeciesCreatures.Count.ToString() + " creature" + (unknownSpeciesCreatures.Count != 1 ? "s" : "") + " is not recognized, probably because they are from a mod that is not loaded.\n"
                                + "The unrecognized species-classes are as follows, all the according creatures cannot be imported: " + string.Join(", ", unknownSpeciesCreatures.Select(c => c.name).Distinct().ToArray())
                                + "\n(To import the unrecognized creatures, you first need additional values-files.)\n\n"
                                + "Do you want to import the recognized creatures? If you click no, nothing is imported.",
                                "Unrecognized species while importing savegame", MessageBoxButtons.YesNo, MessageBoxIcon.Question
                                ) == DialogResult.Yes
                )
            {
                importCollection(creatureCollection, creatures.Where(c => c.Species != null).ToList(), serverName);
            }
        }
Пример #4
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);
            }
        }
Пример #5
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
        }
Пример #6
0
        /// <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;
            }
        }