public override async Task <ISaveGame> CreateSave(ISaveGame saveGame) { var oldLatestFile = this.ProfileRoot.OpenFile("latest"); // todo decide on some way to organize these saves. var newGuid = Guid.NewGuid(); var saveName = $"{DateTimeOffset.UtcNow.ToString(DateFormat)}-{newGuid}"; var saveDirectory = this.ProfileRoot.OpenDirectory(saveName); var contentDirectory = saveDirectory.OpenDirectory("content"); // Copy it twice, once for backup, once for head. await saveGame.ExtractSave(contentDirectory); // Delete the old head if (oldLatestFile.Created) { var oldLatestName = oldLatestFile.ReadAllText(); var oldLatest = this.ProfileRoot.OpenDirectory(oldLatestName); // Delete the old head oldLatest.Delete(); } this.ProfileRoot.OpenFile("latest").WriteAllText(saveName, Encoding.UTF8); return(this.GetSave(saveDirectory)); }
public override async Task <ISaveGame> CreateSave(ISaveGame saveGame) { var newGuid = Guid.NewGuid(); var saveName = $"{DateTimeOffset.UtcNow.ToString(DateFormat)}-{newGuid}"; var saveDirectory = this.ProfileRoot.OpenDirectory(saveName); var contentDirectory = saveDirectory.OpenDirectory("content"); await saveGame.ExtractSave(contentDirectory); this.ProfileRoot.OpenFile("latest").WriteAllText(saveName, Encoding.UTF8); return(this.GetSave(saveDirectory) !); }