internal static bool RestoreCountry(EM_UI_MainForm mainForm, string backUpFolder = "") { bool reportSuccess = false; if (backUpFolder == string.Empty) //called via button in MainForm { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); folderBrowserDialog.SelectedPath = EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles); folderBrowserDialog.Description = "Please select the back-up folder"; if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return(true); } backUpFolder = folderBrowserDialog.SelectedPath; reportSuccess = true; } else //called from a catch-branch, i.e. using just generated back-up in Temp/BackUp { backUpFolder = EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder; } string countryShortName = mainForm.GetCountryShortName(); bool isAddOn = CountryAdministrator.IsAddOn(countryShortName); try { //check if backUpFolder contains the necessary files and if the files actually contain a backup of the loaded country/add-on ... string errorMessage; if (!Country.DoesFolderContainValidXMLFiles(countryShortName, out errorMessage, backUpFolder, isAddOn, true)) //check if countryShortName corresponds to country's short name as stored in the XML-file { throw new System.ArgumentException(errorMessage); } //... if yes, copy files form backup-folder to Countries-folder if (!Country.CopyXMLFiles(countryShortName, out errorMessage, backUpFolder)) { throw new System.ArgumentException(errorMessage); } mainForm.ReloadCountry(); if (reportSuccess) //report success only if called via button (and not if called by a failed function) { UserInfoHandler.ShowSuccess("Successfully restored using back-up stored in" + Environment.NewLine + backUpFolder + "."); } return(true); } catch (Exception exception) { UserInfoHandler.ShowError("Restore failed because of the error stated below." + Environment.NewLine + "You may want to try a manual restore via the button in the ribbon 'Country Tools'." + Environment.NewLine + Environment.NewLine + exception.Message); return(false); } }