Exemplo n.º 1
0
        public Language(List <Translation> prioritizedTranslationList, decimal percentTranslated)
        {
            translations      = prioritizedTranslationList;
            mainWindow        = null;
            setupWizardWindow = null;
            setupWizardProxySettingsWindowLocalizator = null;
            searchTab = null;
            nonFictionSearchResultsTab = null;
            fictionSearchResultsTab    = null;
            sciMagSearchResultsTab     = null;
            commonDetailsTab           = null;
            nonFictionDetailsTab       = null;
            fictionDetailsTab          = null;
            sciMagDetailsTab           = null;
            import             = null;
            exportPanel        = null;
            nonFictionExporter = null;
            fictionExporter    = null;
            sciMagExporter     = null;
            synchronization    = null;
            database           = null;
            databaseError      = null;
            sqlDebugger        = null;
            downloadManager    = null;
            applicationUpdate  = null;
            settings           = null;
            about       = null;
            messageBox  = null;
            errorWindow = null;
            Translation mainTranslation = prioritizedTranslationList.First();

            Name          = mainTranslation.General?.Name?.Trim() ?? String.Empty;
            LocalizedName = mainTranslation.General?.LocalizedName?.Trim() ?? String.Empty;
            if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(LocalizedName))
            {
                DisplayName = $"{Name} ({LocalizedName})";
            }
            else
            {
                DisplayName = "Error";
            }
            CultureCode       = mainTranslation.General?.CultureCode?.Trim() ?? String.Empty;
            TranslatorName    = mainTranslation.General?.TranslatorName ?? "unknown";
            PercentTranslated = percentTranslated;
            Formatter         = new LanguageFormatter(prioritizedTranslationList);
        }
        public static OpenFileDialogResult SelectDatabaseFile(MainModel mainModel)
        {
            DatabaseWindowLocalizator databaseLocalizator = mainModel.Localization.CurrentLanguage.Database;
            StringBuilder             filterBuilder       = new StringBuilder();

            filterBuilder.Append(databaseLocalizator.Databases);
            filterBuilder.Append(" (*.db)|*.db|");
            filterBuilder.Append(databaseLocalizator.AllFiles);
            filterBuilder.Append(" (*.*)|*.*");
            OpenFileDialogParameters openFileDialogParameters = new OpenFileDialogParameters
            {
                DialogTitle = databaseLocalizator.BrowseDatabaseDialogTitle,
                Filter      = filterBuilder.ToString(),
                Multiselect = false
            };

            return(WindowManager.ShowOpenFileDialog(openFileDialogParameters));
        }
        public static async Task <bool> OpenDatabase(MainModel mainModel, IWindowContext parentWindowContext)
        {
            DatabaseWindowLocalizator databaseLocalizator   = mainModel.Localization.CurrentLanguage.Database;
            MessageBoxLocalizator     messageBoxLocalizator = mainModel.Localization.CurrentLanguage.MessageBox;
            OpenFileDialogResult      openFileDialogResult  = SelectDatabaseFile(mainModel);

            if (openFileDialogResult.DialogResult)
            {
                string databaseFilePath = openFileDialogResult.SelectedFilePaths.First();
                MainModel.OpenDatabaseOptions openDatabaseOptions = MainModel.OpenDatabaseOptions.NONE;
                MainModel.DatabaseStatus      databaseStatus;
                bool stopOpenAttempts   = false;
                bool openedSuccessfully = false;
                while (!stopOpenAttempts)
                {
                    databaseStatus = await mainModel.OpenDatabase(databaseFilePath, openDatabaseOptions);

                    switch (databaseStatus)
                    {
                    case MainModel.DatabaseStatus.OPENED:
                        mainModel.AppSettings.DatabaseFileName = MainModel.GetDatabaseNormalizedPath(databaseFilePath);
                        mainModel.SaveSettings();
                        openedSuccessfully = true;
                        stopOpenAttempts   = true;
                        break;

                    case MainModel.DatabaseStatus.POSSIBLE_DUMP_FILE:
                        WindowManager.ShowMessage(databaseLocalizator.Error, databaseLocalizator.GetDatabaseDumpFileText(databaseFilePath),
                                                  messageBoxLocalizator.Ok, parentWindowContext);
                        stopOpenAttempts = true;
                        break;

                    case MainModel.DatabaseStatus.OLD_FICTION_SCHEMA:
                        if (WindowManager.ShowPrompt(databaseLocalizator.OldFictionSchemaTitle, databaseLocalizator.GetOldFictionSchemaText(databaseFilePath),
                                                     messageBoxLocalizator.Yes, messageBoxLocalizator.No, parentWindowContext))
                        {
                            openDatabaseOptions = MainModel.OpenDatabaseOptions.MIGRATE_FICTION;
                        }
                        else
                        {
                            stopOpenAttempts = true;
                        }
                        break;

                    case MainModel.DatabaseStatus.CORRUPTED:
                        WindowManager.ShowMessage(databaseLocalizator.Error, databaseLocalizator.GetDatabaseNotValidText(databaseFilePath),
                                                  messageBoxLocalizator.Ok, parentWindowContext);
                        stopOpenAttempts = true;
                        break;

                    case MainModel.DatabaseStatus.SERVER_DATABASE:
                        WindowManager.ShowMessage(databaseLocalizator.Error, databaseLocalizator.GetLibgenServerDatabaseText(databaseFilePath),
                                                  messageBoxLocalizator.Ok, parentWindowContext);
                        stopOpenAttempts = true;
                        break;

                    default:
                        throw new Exception($"Unexpected database status: {databaseStatus}.");
                    }
                }
                if (openedSuccessfully)
                {
                    return(true);
                }
                else
                {
                    await mainModel.OpenDatabase(mainModel.AppSettings.DatabaseFileName);

                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }