/// <summary> /// This will save the state of a game/tester /// </summary> /// <remarks> /// Folder Structure: /// baseFolder /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner" /// Only one file per tester here. Each file is "testername Options.xml" /// Each tester gets one child folder off of base /// /// Game Folder /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans" /// This folder holds custom files for this game. It will also hold session subfolders (each session would be a different state) /// /// Session Folders /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247" /// /// Save Folders /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247\Save 2016-10-09 09.11.35.247 (auto)" /// This is where all the save folders go. Each save folder is for the parent session (there are many because backups should occur often) /// When saving, it shouldn't overwrite an existing save, it should create a new save folder, then delete old ones as needed /// If zipped is true, this will be a zip file instead of a folder /// </remarks> /// <param name="baseFolder"> /// Use UtilityCore.GetOptionsFolder() /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner" /// </param> /// <param name="name"> /// This is the name of the tester/game /// </param> /// <param name="session"> /// This is the class that goes in the root folder /// NOTE: This method will set the LatestSessionFolder property /// </param> /// <param name="saveFiles"> /// A set of files to put into the save folder (or zip file) /// Item1=Name of file (this method will ensure it ends in .xml) /// Item2=Object to serialize /// </param> /// <param name="zipped"> /// This only affects the leaf save folder /// True: The save folder will be a zip file instead /// False: The save folder will be a standard folder containing files /// </param> public static void Save(string baseFolder, string name, ISessionOptions session, IEnumerable<Tuple<string, object>> saveFiles, bool zipped) { if (string.IsNullOrEmpty(session.LatestSessionFolder) || !Directory.Exists(session.LatestSessionFolder)) { session.LatestSessionFolder = GetNewSessionFolderName(baseFolder, name); } #region root session file string rootSessionFilename = GetRootOptionsFilename(baseFolder, name); using (FileStream stream = new FileStream(rootSessionFilename, FileMode.Create)) { XamlServices.Save(stream, session); } #endregion // Session Folder //NOTE: This will also create the game folder if it doesn't exist Directory.CreateDirectory(session.LatestSessionFolder); // Save Folder (or zip file) string saveFolder = GetNewSaveFolderName(session.LatestSessionFolder); if (zipped) { // Just tack on a .zip to the save folder name to turn it into a zip filename throw new ApplicationException("finish saving to zip file"); } else { Save_Folder(saveFolder, saveFiles); } }
/// <summary> /// This will save the state of a game/tester /// </summary> /// <remarks> /// Folder Structure: /// baseFolder /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner" /// Only one file per tester here. Each file is "testername Options.xml" /// Each tester gets one child folder off of base /// /// Game Folder /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans" /// This folder holds custom files for this game. It will also hold session subfolders (each session would be a different state) /// /// Session Folders /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247" /// /// Save Folders /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247\Save 2016-10-09 09.11.35.247 (auto)" /// This is where all the save folders go. Each save folder is for the parent session (there are many because backups should occur often) /// When saving, it shouldn't overwrite an existing save, it should create a new save folder, then delete old ones as needed /// If zipped is true, this will be a zip file instead of a folder /// </remarks> /// <param name="baseFolder"> /// Use UtilityCore.GetOptionsFolder() /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner" /// </param> /// <param name="name"> /// This is the name of the tester/game /// </param> /// <param name="session"> /// This is the class that goes in the root folder /// NOTE: This method will set the LatestSessionFolder property /// </param> /// <param name="saveFiles"> /// A set of files to put into the save folder (or zip file) /// Item1=Name of file (this method will ensure it ends in .xml) /// Item2=Object to serialize /// </param> /// <param name="zipped"> /// This only affects the leaf save folder /// True: The save folder will be a zip file instead /// False: The save folder will be a standard folder containing files /// </param> public static void Save(string baseFolder, string name, ISessionOptions session, IEnumerable <Tuple <string, object> > saveFiles, bool zipped) { if (string.IsNullOrEmpty(session.LatestSessionFolder) || !Directory.Exists(session.LatestSessionFolder)) { session.LatestSessionFolder = GetNewSessionFolderName(baseFolder, name); } #region root session file string rootSessionFilename = GetRootOptionsFilename(baseFolder, name); UtilityCore.SerializeToFile(rootSessionFilename, session); #endregion // Session Folder //NOTE: This will also create the game folder if it doesn't exist Directory.CreateDirectory(session.LatestSessionFolder); // Save Folder (or zip file) string saveFolder = GetNewSaveFolderName(session.LatestSessionFolder); if (zipped) { // Just tack on a .zip to the save folder name to turn it into a zip filename throw new ApplicationException("finish saving to zip file"); } else { Save_Folder(saveFolder, saveFiles); } }
/// <summary> /// This will load files from a saved game /// </summary> /// <param name="baseFolder"> /// This can be one of 4 folders: /// baseFolder /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner" /// May contain a session file that points to the latest save /// Or contains the Game subfolder that then contains sessions (will load the latest session) /// /// Game Folder /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans" /// Will load the latest session subfolder /// /// Session Folders /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247" /// Will load the latest save subfolder /// /// Save Folders /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247\Save 2016-10-09 09.11.35.247 (auto)" /// Will load this exact save (and point the session file to this folder's parent) /// If this save folder isn't sitting in the standard hierarchy (ex: folder copied to the desktop), the session file will point directly to this location /// </param> /// <param name="name">This is the name of the tester/game</param> /// <param name="getSession"> /// If the folder pointed isn't the root folder, the session file won't be found. This delegate gives the caller a chance to create a session file that /// will be returned in the result object. This method will then populate the LatestSessionFolder with sessionFolder ?? saveFolder /// </param> public static SessionFolderResults Load(string baseFolder, string name, Func <ISessionOptions> getSession = null) { // Find session file. Else walk folders to get session folder and save folder/zip string sessionFolder = null; string saveFolder = null; ISessionOptions session = AttemptBaseFolder(baseFolder, name); if (session != null) { #region has session file if (session.LatestSessionFolder == null || !AttemptSessionSaveFolder(out sessionFolder, out saveFolder, session.LatestSessionFolder)) { // The session file exists, so baseFolder is expected to be pointing to the folder returned by UtilityCore.GetOptionsFolder() // See if the name folder is there (and contains a session folder) string nameFolder = Path.Combine(baseFolder, name); if (!AttemptNameFolder(out sessionFolder, out saveFolder, nameFolder)) { return(null); } } #endregion } else { #region no session file if (!AttemptNameFolder(out sessionFolder, out saveFolder, baseFolder)) { if (!AttemptSessionSaveFolder(out sessionFolder, out saveFolder, baseFolder)) { return(null); } } #endregion } // Deserialize the files in this save folder Tuple <string, object>[] saveFiles = Load_Specific(saveFolder); if (saveFiles == null || saveFiles.Length == 0) { return(null); } if (session == null && getSession != null) { session = getSession(); if (session != null) { session.LatestSessionFolder = sessionFolder ?? saveFolder; } } return(new SessionFolderResults(session, baseFolder, sessionFolder, saveFolder, saveFiles)); }
public SessionFolderResults(ISessionOptions sessionFile, string passedInFolder, string sessionFolder, string saveFolder_Zip, Tuple <string, object>[] savedFiles) { this.SessionFile = sessionFile; this.PassedInFolder = passedInFolder; this.SessionFolder = sessionFolder; this.SaveFolder_Zip = saveFolder_Zip; this.SavedFiles = savedFiles; }
public ISession Create() { ISessionOptions sessionOptions = _sessionOptions ?? new SessionOptions(); IConfig config = new Config(_configOptions ?? new ConfigOptions()); ISessionReflection sessionReflection = new SessionReflection(); return(new Session(sessionOptions, config, sessionReflection)); }
public SessionFolderResults(ISessionOptions sessionFile, string passedInFolder, string sessionFolder, string saveFolder_Zip, Tuple<string, object>[] savedFiles) { this.SessionFile = sessionFile; this.PassedInFolder = passedInFolder; this.SessionFolder = sessionFolder; this.SaveFolder_Zip = saveFolder_Zip; this.SavedFiles = savedFiles; }
/// <summary> /// This overload uses the standard base folder /// </summary> public static void Save(string name, ISessionOptions session, IEnumerable<Tuple<string, object>> saveFiles, bool zipped) { string baseFolder = UtilityCore.GetOptionsFolder(); Save(baseFolder, name, session, saveFiles, zipped); }
public Session(ISessionOptions sessionOptions, IConfig config, ISessionReflection sessionReflection) { _sessionOptions = sessionOptions; _config = config; _sessionReflection = sessionReflection; }
/// <summary> /// This overload uses the standard base folder /// </summary> public static void Save(string name, ISessionOptions session, IEnumerable <Tuple <string, object> > saveFiles, bool zipped) { string baseFolder = UtilityCore.GetOptionsFolder(); Save(baseFolder, name, session, saveFiles, zipped); }
public ISessionStandalone WithSessionOptions(ISessionOptions sessionOptions) { _sessionOptions = sessionOptions; return(this); }