public void SaveIsDoneMessage(SaveWork _save) //Done method is different for the launch option as we don't want to show unset save procedures. { if (_save.Type != SaveWorkType.unset) { Console.WriteLine("\nDone."); } }
//Can create a save work from simple parameters public void CreateWork(int _nb, string _name, string _sourcePath, string _destinationPath, SaveWorkType _type) { SaveWork tempSave = new SaveWork(_name, _sourcePath, _destinationPath, _type); WorkList[_nb - 1] = tempSave; UpdateSaveFile(_nb); CreateLogLine("Creation of a new save work in position " + _nb + ", name : " + tempSave.Name + ", source path : " + tempSave.SourcePath + ", destination path : " + tempSave.DestinationPath + ", type : " + tempSave.Type); }
//Shows a different message depending on save type. public void SaveInProgressMessage(SaveWork _save) { if (_save.Type == SaveWorkType.differencial) { Console.WriteLine("\nDifferential save " + _save.Name + " in progress..."); } else if (_save.Type == SaveWorkType.complete) { Console.WriteLine("\nComplete save " + _save.Name + " in progress..."); } }
//Can initiate a type of save from the numbers of the save work in workList. public void DoSave(int _nb) { SaveWork work = WorkList[_nb - 1]; if (Directory.Exists(WorkList[_nb - 1].SourcePath)) { if (work.Type == SaveWorkType.complete) { CompleteSave(_nb); } else if (work.Type == SaveWorkType.differencial) { DifferencialSave(_nb); } } }
private void ModifySave() { View.TerminalMessage("modify"); int saveProcedureIndex = View.SelectSaveProcedure(Model.WorkList); if (saveProcedureIndex != 9) { SaveWork saveProcedure = View.ModifySaveProcedure(Model.WorkList[saveProcedureIndex - 1]); if (saveProcedure != null) { Model.ChangeWork(saveProcedureIndex, saveProcedure.Name, saveProcedure.SourcePath, saveProcedure.DestinationPath, saveProcedure.Type); View.OperationDoneMessage(); } } ShowMenu(); return; }
//Model Class constructor, initiate Save Work in an array public Model() { //If the state file has not been initialized then create 5 SaveWork object from nothing if (!File.Exists("stateFile.json")) { WorkList = new SaveWork[5]; for (int i = 0; i < 5; i++) { WorkList[i] = new SaveWork("", "", "", SaveWorkType.unset); } } //Then if the State file already exist, use the objects in it to create the WorkList else { string stateFile = File.ReadAllText("stateFile.json"); var tempWorkList = JsonConvert.DeserializeObject <List <SaveWork> >(stateFile); WorkList = tempWorkList.ToArray(); } }
//Allows the user to modifiy an existing save procedure name, source path, destination path and/or type. public SaveWork ModifySaveProcedure(SaveWork _save) { if (_save.Type != SaveWorkType.unset) { SaveWork modifiedSave = _save; string choice = ""; while (choice != "5" && choice != "9") //While loop to allow the user to modify multiple values. { Console.WriteLine("\n\nPlease select a parameter to modify :\n" + "1. Name : " + modifiedSave.Name + "\n2. Source Path : " + modifiedSave.SourcePath + "\n3. Destination Path : " + modifiedSave.DestinationPath + "\n4. Save Type : " + modifiedSave.Type + "\n5. Confirm" + "\n9. Cancel.\n"); choice = Console.ReadLine(); switch (choice) { case "1": Console.WriteLine("\nPlease enter a new name\n"); string enteredName = Console.ReadLine(); while (!Regex.IsMatch(enteredName, @"^[a-zA-Z0-9 _]+$")) //Regex only allowing alphanumeric chars, spaces or underscores. { Console.WriteLine("\nPlease only make use of alphanumeric characters, spaces or underscores.\n"); enteredName = Console.ReadLine(); } modifiedSave.Name = enteredName; break; case "2": Console.WriteLine("Please enter a new source path to save (absolute) :\n"); string enteredSource = Console.ReadLine(); while (!Regex.IsMatch(enteredSource, @"^[a-zA-Z]:(?:\/[a-zA-Z0-9 _]+)*$")) //Regex for valid windows folder path. { Console.WriteLine("\nPlease enter a valid absolute path.\n"); enteredSource = Console.ReadLine(); } modifiedSave.SourcePath = enteredSource; break; case "3": Console.WriteLine("Please enter a new destination path to export the save (absolute) :\n"); string enteredDestination = Console.ReadLine(); while (!Regex.IsMatch(enteredDestination, @"^[a-zA-Z]:(?:\/[a-zA-Z0-9 _]+)*$")) //Regex for valid windows folder path. { Console.WriteLine("\nPlease enter a valid absolute path.\n"); enteredDestination = Console.ReadLine(); } modifiedSave.SourcePath = enteredDestination; break; case "4": Console.WriteLine("Please choose a new save type :\n" + "1. Complete\n" + "2. Differencial\n"); string enteredValue = Console.ReadLine(); //Check for valid value entered by the user (1 or 2). while (enteredValue != "1" && enteredValue != "2") { Console.WriteLine("\nPlease enter a correct value to proceed.\n"); enteredValue = Console.ReadLine(); } modifiedSave.Type = enteredValue == "1" ? SaveWorkType.complete : SaveWorkType.differencial; break; case "5": break; case "9": break; default: Console.WriteLine("\nPlease enter a correct value to proceed.\n"); break; } } return(choice == "5" ? modifiedSave : null); } else { Console.WriteLine("The Specified save work is currently empty, cannot modify it"); return(null); } }
//Can delete a save work (set to null) public void DeleteWork(int _nb) { workList[_nb - 1] = new SaveWork("", "", "", SaveWorkType.unset); UpdateSaveFile(_nb); CreateLogLine("Supression of save work in position" + _nb); }