Beispiel #1
0
        private bool TryBatchImport()
        {
            if (string.IsNullOrWhiteSpace(PathToBatchFolderInput))
            {
                MessageDialogWindow.Show("Enter a path to a folder containing .iro files and/or mod folders.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (!Directory.Exists(PathToBatchFolderInput))
            {
                MessageDialogWindow.Show("Directory does not exist.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            ModImporter importer = null;

            try
            {
                importer = new ModImporter();
                importer.ImportProgressChanged += Importer_ImportProgressChanged;

                int modImportCount = 0;

                foreach (string iro in Directory.GetFiles(PathToBatchFolderInput, "*.iro"))
                {
                    string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(iro));
                    importer.Import(iro, modName, true, false);
                    modImportCount++;
                }

                foreach (string dir in Directory.GetDirectories(PathToBatchFolderInput))
                {
                    string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(dir));
                    importer.Import(dir, modName, false, false);
                    modImportCount++;
                }

                Sys.Message(new WMessage($"Successfully imported {modImportCount} mod(s)!", true));
                return(true);
            }
            catch (DuplicateModException de)
            {
                Logger.Error(de);
                MessageDialogWindow.Show($"Can not import mod(s). {de.Message}", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                MessageDialogWindow.Show("Failed to import mod(s). The error has been logged.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                importer.ImportProgressChanged -= Importer_ImportProgressChanged;
            }
        }
Beispiel #2
0
        private bool TryBatchImport()
        {
            if (string.IsNullOrWhiteSpace(PathToBatchFolderInput))
            {
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.EnterPathToFolderContainingIroFilesOrModFolders), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (!Directory.Exists(PathToBatchFolderInput))
            {
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.DirectoryDoesNotExist), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            ModImporter importer = null;

            try
            {
                importer = new ModImporter();
                importer.ImportProgressChanged += Importer_ImportProgressChanged;

                int modImportCount = 0;

                foreach (string iro in Directory.GetFiles(PathToBatchFolderInput, "*.iro"))
                {
                    string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(iro));
                    importer.Import(iro, modName, true, false);
                    modImportCount++;
                }

                foreach (string dir in Directory.GetDirectories(PathToBatchFolderInput))
                {
                    string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(dir));
                    importer.Import(dir, modName, false, false);
                    modImportCount++;
                }

                Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.SuccessfullyImported)} {modImportCount} mod(s)!", true));
                return(true);
            }
            catch (DuplicateModException de)
            {
                Logger.Error(de);
                MessageDialogWindow.Show($"{ResourceHelper.Get(StringKey.CanNotImportMod)}(s). {de.Message}", ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                importer.ImportProgressChanged -= Importer_ImportProgressChanged;
            }
        }
Beispiel #3
0
        private bool TryImportFromFolder()
        {
            if (string.IsNullOrWhiteSpace(PathToModFolderInput))
            {
                MessageDialogWindow.Show("Enter a path to a folder containing mod files.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (!Directory.Exists(PathToModFolderInput))
            {
                MessageDialogWindow.Show("Directory does not exist.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            ModImporter importer = null;

            try
            {
                string folderName = new DirectoryInfo(PathToModFolderInput).Name;

                importer = new ModImporter();
                importer.ImportProgressChanged += Importer_ImportProgressChanged;
                importer.Import(PathToModFolderInput, ModImporter.ParseNameFromFileOrFolder(folderName), false, false);

                Sys.Message(new WMessage($"Successfully imported {folderName}!", true));
                return(true);
            }
            catch (DuplicateModException de)
            {
                Logger.Error(de);
                MessageDialogWindow.Show($"Can not import mod. {de.Message}", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                MessageDialogWindow.Show("Failed to import mod. The error has been logged.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                importer.ImportProgressChanged -= Importer_ImportProgressChanged;
            }
        }
Beispiel #4
0
        private bool TryImportFromIroArchive()
        {
            if (string.IsNullOrWhiteSpace(PathToIroArchiveInput))
            {
                MessageDialogWindow.Show("Enter a path to an .iro file.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (!File.Exists(PathToIroArchiveInput))
            {
                MessageDialogWindow.Show(".iro file does not exist.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            ModImporter importer = null;

            try
            {
                string fileName = Path.GetFileNameWithoutExtension(PathToIroArchiveInput);

                importer = new ModImporter();
                importer.ImportProgressChanged += Importer_ImportProgressChanged;
                importer.Import(PathToIroArchiveInput, ModImporter.ParseNameFromFileOrFolder(fileName), true, false);

                Sys.Message(new WMessage($"Successfully imported {fileName}!"));
                return(true);
            }
            catch (DuplicateModException de)
            {
                Logger.Error(de);
                MessageDialogWindow.Show($"Can not import mod. {de.Message}", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                MessageDialogWindow.Show("Failed to import mod. The error has been logged.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                importer.ImportProgressChanged -= Importer_ImportProgressChanged;
            }
        }
Beispiel #5
0
        private bool TryImportFromFolder()
        {
            if (string.IsNullOrWhiteSpace(PathToModFolderInput))
            {
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.EnterPathToFolderContainingModFiles), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (!Directory.Exists(PathToModFolderInput))
            {
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.DirectoryDoesNotExist), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            ModImporter importer = null;

            try
            {
                string folderName = new DirectoryInfo(PathToModFolderInput).Name;

                importer = new ModImporter();
                importer.ImportProgressChanged += Importer_ImportProgressChanged;
                importer.Import(PathToModFolderInput, ModImporter.ParseNameFromFileOrFolder(folderName), false, false);

                Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.SuccessfullyImported)} {folderName}!", true));
                return(true);
            }
            catch (DuplicateModException de)
            {
                Logger.Error(de);
                MessageDialogWindow.Show($"{ResourceHelper.Get(StringKey.CanNotImportMod)} {de.Message}", ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                importer.ImportProgressChanged -= Importer_ImportProgressChanged;
            }
        }
Beispiel #6
0
        private bool TryImportFromIroArchive()
        {
            if (string.IsNullOrWhiteSpace(PathToIroArchiveInput))
            {
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.EnterPathToAnIroFile), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (!File.Exists(PathToIroArchiveInput))
            {
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.IroFileDoesNotExist), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            bool isPatchFile = Path.GetExtension(PathToIroArchiveInput) == ".irop";

            ModImporter importer = null;

            try
            {
                importer = new ModImporter();
                importer.ImportProgressChanged += Importer_ImportProgressChanged;

                string fileName = Path.GetFileNameWithoutExtension(PathToIroArchiveInput);

                if (isPatchFile)
                {
                    bool didPatch = importer.ImportModPatch(PathToIroArchiveInput);

                    if (!didPatch)
                    {
                        MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                        return(false);
                    }

                    Sys.Message(new WMessage($"Successfully applied patch {fileName}!"));
                }
                else
                {
                    importer.Import(PathToIroArchiveInput, ModImporter.ParseNameFromFileOrFolder(fileName), true, false);
                    Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.SuccessfullyImported)} {fileName}!"));
                }

                return(true);
            }
            catch (DuplicateModException de)
            {
                Logger.Error(de);
                MessageDialogWindow.Show($"{ResourceHelper.Get(StringKey.CanNotImportMod)} {de.Message}", ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                importer.ImportProgressChanged -= Importer_ImportProgressChanged;
            }
        }