private void LoadStage() { string texoDataFolder = PathExtensions.GetAndCreateDataDirectoryPath(FileManagerConstants.STORAGE_DIRECTORY_NAME); string filePath = texoDataFolder.CombinePathWith(FileManagerConstants.STORAGE_STAGE_FILE_NAME); if (!File.Exists(filePath)) { return; } using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { IStashEntry stage = serialisation.DeserializeFromStream <StashEntry>(file); if (stage == null) { return; } lobby = stage.GetLobby() ?? string.Empty; var pathsBuilder = ImmutableSortedSet.CreateBuilder(new InsensitiveFullPathComparer()); pathsBuilder.UnionWith(stage.GetPaths()); paths = pathsBuilder.ToImmutable(); } }
public void Add(IStashEntry stash) { if (stash == null) { return; } Add(stash.GetPaths()); }
private static Item BuildStashOverviewItem(IStashEntry stash, int index) { MarkdownBuilder builder = new MarkdownBuilder(); builder.Header(GetStashHeader(stash, index)); builder.Bullet(); builder.Italic(GetStashLobbyTitle(stash)); builder.WritePathOverview(stash.GetPaths(), stash.GetLobby()); return(Item.AsMarkdown(builder.ToString())); }
private void ApplyStashToStage(IStashEntry stash, bool replace) { if (replace) { stage.Clear(); } stage.SetLobby(stash.GetLobby()); stage.Add(stash); }
private static Item BuildStashDetailItem(IStashEntry stash, int index) { MarkdownBuilder builder = new MarkdownBuilder(); builder.Header(GetStashHeader(stash, index)); builder.Italic(GetStashLobbyTitle(stash)); builder.WriteLine(); builder.WritePathLists(stash.GetPaths(), stash.GetLobby()); return(Item.AsMarkdown(builder.ToString())); }
private ICommandResult Peek(CommandContext context) { IStashEntry stash = stashes.GetStash(0); if (stash == null) { return(new TextResult("The stash stack is empty.")); } ApplyStashToStage(stash, !context.HasOption(StashOptions.ADD)); return(new ItemsResult($"{GetStashHeader(stash, 0)} has been applied to stage.")); }
private ICommandResult Pop(CommandContext context) { IStashEntry stash = stashes.GetStash(0); if (stash == null) { return(new TextResult("The stash stack is empty.")); } ApplyStashToStage(stash, !context.HasOption(StashOptions.ADD)); stashes.RemoveStash(stash); return(new TextResult($"{GetStashHeader(stash, 0)} has been applied to stage and removed from top of the stack.")); }
private ICommandResult Push(CommandContext context) { IImmutableList <string> paths = stage.GetPaths(); if (paths == null || paths.Count < 1) { return(new ErrorTextResult("The stage is empty.")); } string name = context.GetParameterValue(ParameterKeys.NAME); IStashEntry stash = stashes.CreateStash(stage.GetLobby(), paths, name); return(new ItemsResult(BuildStashDetailItem(stash, 0))); }
private ICommandResult Show(CommandContext context) { string id = context.GetParameterValue(StashParameters.IDENTIFIER); IStashEntry stash = int.TryParse(id, out int index) ? stashes.GetStash(index) : stashes.GetStash(id); if (stash == null) { return(new ErrorTextResult($"No stash @{id} found.")); } return(new ItemsResult(BuildStashDetailItem(stash, index))); }
private ICommandResult Drop(CommandContext context) { string id = context.GetParameterValue(StashParameters.IDENTIFIER); IStashEntry stash = int.TryParse(id, out int index) ? stashes.GetStash(index) : stashes.GetStash(id); if (stash == null) { return(new ErrorTextResult($"No stash @{id} found.")); } stashes.RemoveStash(stash); return(new TextResult($"{GetStashHeader(stash, index)} has been dropped.")); }
private ICommandResult List(CommandContext context) { var allStashes = stashes.GetStashes(); if (allStashes.Count < 1) { return(new TextResult("The stash stack is empty.")); } var result = ImmutableList <Item> .Empty.ToBuilder(); for (int i = 0; i < allStashes.Count; i++) { IStashEntry stash = allStashes[i]; result.Add(BuildStashOverviewItem(stash, i)); } return(new ItemsResult(result.ToImmutable())); }
private ICommandResult Apply(CommandContext context) { if (!context.HasParameter(StashParameters.IDENTIFIER)) { return(Peek(context)); } string id = context.GetParameterValue(StashParameters.IDENTIFIER); IStashEntry stash = int.TryParse(id, out int index) ? stashes.GetStash(index) : stashes.GetStash(id); if (stash == null) { return(new ErrorTextResult($"No stash @{id} found.")); } ApplyStashToStage(stash, !context.HasOption(StashOptions.ADD)); return(new TextResult($"{GetStashHeader(stash, index)} has been applied to stage.")); }
public void RemoveStash(int index) { if (stashes.Count == 0 && index == 0) { return; } if (index < 0 || index >= stashes.Count) { throw new IndexOutOfRangeException(); } IStashEntry stash = stashes[index]; if (!string.IsNullOrWhiteSpace(stash.Name)) { nameMap.Remove(stash.Name); } stashes.RemoveAt(index); }
public void RemoveStash(IStashEntry stash) { int index = -1; if (string.IsNullOrWhiteSpace(stash.Name)) { if (nameMap.TryGetValue(stash.Name, out int nameIndex)) { index = nameIndex; nameMap.Remove(stash.Name); } } else { index = stashes.IndexOf(stash); } if (index < 0) { return; } stashes.RemoveAt(index); }
private static string GetStashHeader(IStashEntry stash, int index) { return(string.IsNullOrWhiteSpace(stash.Name) ? $"Stash @{index}" : $"Stash @{stash.Name}"); }
private static string GetStashLobbyTitle(IStashEntry stash) { return(string.IsNullOrEmpty(stash.GetLobby()) ? "No lobby directory." : stash.GetLobby()); }