internal static string StoreCountry(EM_UI_MainForm mainForm, bool storeChanges = true) { CleanBackupFolder(); //delete all folders which are older than 3 days to avoid that the backup folder gets too big //outcommented as it is probably more confusing to inform the user than that one cannot undo actions before this (probably big) action ... //if (undoManager.HasChanges() && Tools.UserInfoHandler.GetInfo("Please note that the action generates a backup and therefore must reset the undo list. That means no undoing of actions up until now will be possible.", // MessageBoxButtons.OKCancel) == DialogResult.Cancel) // return false; //... instead pose this easier to understand question (i.e. only ask for saving unsaved changes, but not for any undo-stuff) if (storeChanges && mainForm.HasChanges() && Tools.UserInfoHandler.GetInfo("Do you want to save changes?", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return(string.Empty); } try { //the action will directly operate the XML-files therefore changes need to be commited and saved, unless explicitly not wished if (storeChanges) { SaveDirectXMLAction(mainForm); } //create a backup by copying files from Countries-folder to a dated folder (see below) in BackUps-folder if (!Directory.Exists(EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles))) { Directory.CreateDirectory(EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles)); } string countryShortName = mainForm.GetCountryShortName(); string backUpFolder = countryShortName + "_" + DateTime.Now.ToString("yyyy-MM-dd_H-mm-ss"); //backup-folder is name e.g. uk_2013-12-08_10-30-23 if (!Directory.Exists(EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder)) //is actually rather unlikely { Directory.CreateDirectory(EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder); } //copy XML-files (e.g. uk.xml + uk_DataConfig.xml or LMA.xml) string errorMessage; if (!Country.CopyXMLFiles(countryShortName, out errorMessage, string.Empty, EMPath.AddSlash(EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder))) { throw new System.ArgumentException(errorMessage); } return(backUpFolder); } catch (Exception exception) { UserInfoHandler.ShowException(exception); return(string.Empty); } }