From 0e3557f5967462b6eaf4148dc292ce45dbc51f5c Mon Sep 17 00:00:00 2001 From: Aaron Yarborough Date: Wed, 9 Sep 2020 10:30:56 +0200 Subject: [PATCH] Implement save directory --- .vscode/launch.json | 15 +++++--- .vscode/tasks.json | 36 ++++++++++++++----- GraalGmapGenerator/Program.cs | 29 ++++++++++++--- .../Validators/GmapPropertyValidators.cs | 17 +++++++++ 4 files changed, 78 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4e5916f..ce12779 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,12 +9,17 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/GraalGmapGenerator.dll", + "program": "${workspaceFolder}/GraalGmapGenerator/bin/Debug/netcoreapp3.1/GraalGmapGenerator.dll", "args": [], - "cwd": "${workspaceFolder}", - "stopAtEntry": false, - "console": "internalConsole" + "cwd": "${workspaceFolder}/GraalGmapGenerator", + "console": "externalTerminal", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" } - ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 31c32bd..7b9f919 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,23 +1,41 @@ { - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", - "type": "shell", + "type": "process", "args": [ "build", - // Ask dotnet build to generate full paths for file names. + "${workspaceFolder}/GraalGmapGenerator/GraalGmapGenerator.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/GraalGmapGenerator/GraalGmapGenerator.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/GraalGmapGenerator/GraalGmapGenerator.csproj", "/property:GenerateFullPaths=true", - // Do not generate summary otherwise it leads to duplicate errors in Problems panel "/consoleloggerparameters:NoSummary" ], - "group": "build", - "presentation": { - "reveal": "silent" - }, "problemMatcher": "$msCompile" } ] diff --git a/GraalGmapGenerator/Program.cs b/GraalGmapGenerator/Program.cs index 22fea92..d4f0ce5 100644 --- a/GraalGmapGenerator/Program.cs +++ b/GraalGmapGenerator/Program.cs @@ -1,9 +1,10 @@ using System; +using System.IO; using GraalGmapGenerator.Validators; namespace GraalGmapGenerator { - class Program + class Programfg { static void Main(string[] args) { @@ -65,7 +66,7 @@ namespace GraalGmapGenerator Console.WriteLine("Load full map? (y/n)..."); Console.WriteLine("INFO: Loads all map parts into memory on startup."); - var loadFullMapStr = GetInput( + string loadFullMapStr = GetInput( inputFunc: () => Console.ReadLine(), validator: (input) => { @@ -84,7 +85,7 @@ namespace GraalGmapGenerator Console.WriteLine("No automapping? (y/n)..."); Console.WriteLine("INFO: Disables the assembly of automagical screenshots into a map that is drawn over the MAPIMG image."); - var noAutoMappingStr = GetInput( + string noAutoMappingStr = GetInput( inputFunc: () => Console.ReadLine(), validator: (input) => { @@ -103,12 +104,30 @@ namespace GraalGmapGenerator Console.WriteLine("Save directory..."); Console.WriteLine($"INFO: If you do not wish to provide a save directory, you can leave this setting blank (hit ENTER) and the GMAP will be created under \"gmaps/\" in the application directory ({AppDomain.CurrentDomain.BaseDirectory}/gmaps/{gmapName}/)"); - // string saveDirectory = + string saveDirectory = GetInput( + () => Console.ReadLine(), + (input) => + { + if (input != "" && !GmapPropertyValidators.IsValidDirectory(input)) + { + Console.WriteLine("Please provide a valid directory path."); + return false; + } + + return true; + } + ); + + if (saveDirectory == "") + { + saveDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "gmaps", gmapName); + } + Console.WriteLine("Generating gmap..."); var gmap = mapBuilder.Build(); Console.WriteLine("Saving gmap..."); - GmapWriter.SaveGmap(gmap); + GmapWriter.SaveGmap(saveDirectory, gmap); Console.WriteLine("Done!"); Console.ReadLine(); diff --git a/GraalGmapGenerator/Validators/GmapPropertyValidators.cs b/GraalGmapGenerator/Validators/GmapPropertyValidators.cs index 5b8e0b2..611c300 100644 --- a/GraalGmapGenerator/Validators/GmapPropertyValidators.cs +++ b/GraalGmapGenerator/Validators/GmapPropertyValidators.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Linq; namespace GraalGmapGenerator.Validators { @@ -18,5 +20,20 @@ namespace GraalGmapGenerator.Validators return true; return false; } + + public static bool IsValidDirectory(string input) + { + char[] inputChars = input.ToCharArray(); + char[] fsInvalidPathChars = Path.GetInvalidPathChars(); + foreach (char inputChar in inputChars) + { + if (fsInvalidPathChars.Contains(inputChar)) + { + return false; + } + } + + return true; + } } } \ No newline at end of file