From f8f499901ff69a1ed9b92582e15cdab0cb23ecaf Mon Sep 17 00:00:00 2001 From: SpyDev14 Date: Wed, 26 Mar 2025 10:24:15 +0400 Subject: [PATCH] Now arguments 4 and 5 (the author and what to do if there is already such a file) have been swapped, as well as the text of error messages has been slightly changed and the error output method in Program.cs has been added. (cherry picked from commit e561166337e44e1f2df030b57914ec90d2ef823d) --- Content.Core/Assembly/BaseAssembler.cs | 2 +- Content.Core/Program.cs | 60 +++++++++++++-------- Content.Core/Properties/launchSettings.json | 2 +- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Content.Core/Assembly/BaseAssembler.cs b/Content.Core/Assembly/BaseAssembler.cs index 55e44a1..9aa70ee 100644 --- a/Content.Core/Assembly/BaseAssembler.cs +++ b/Content.Core/Assembly/BaseAssembler.cs @@ -31,7 +31,7 @@ public AssembledFile AssembleFiles() stringBuilder.AppendLine($@" # Prototype assembled with Prototype Assembler by SpyDev14 # github: https://github.com/SpyDev14/PrototypeAssembler -# Thank's for using! +# Thanks for using! "); // combining files diff --git a/Content.Core/Program.cs b/Content.Core/Program.cs index 801b597..3c30574 100644 --- a/Content.Core/Program.cs +++ b/Content.Core/Program.cs @@ -7,14 +7,25 @@ namespace Content.Core; public class Program { + private const string wrongArgumentsErrorMessage +=@"At least 3 arguments are needed! + arg[0] - workFolderPath* + arg[1] - assembledFileSavePath* + arg[2] - assembledFileName* + arg[3] - (optional) OnFileExistOperation: int or string = 1 (CreateWithIndex) + ├─ 0 - Overwrite + ├─ 1 - CreateWithIndex + └─ 2 - ThrowException + arg[4] - (optional) author = null"; + static void Main(string[] args) { /* arg[0] - workFolderPath arg[1] - assembledFileSavePath arg[2] - assembledFileName - arg[3] - author (optional) - arg[4] - OnFileExistOperation: int (optional) + arg[3] - OnFileExistOperation: int or string (optional) + arg[4] - author (optional) */ string workFolderPath, assembledFileSavePath, assembledFileName; @@ -29,37 +40,33 @@ static void Main(string[] args) if (args.Length >= 4) { - author = args[3]; + try { + onFileAlreadyExist = Enum.Parse(args[3]); } + + catch { + WriteError("Unknow on file already exsist operation!"); + throw new ArgumentException("this OnFileExistOperation not exsist"); + } if (args.Length >= 5) { - Enum.TryParse(args[4], out onFileAlreadyExist); + author = args[4]; } } } else { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(@"At least 3 arguments are needed! - arg[0] - workFolderPath - arg[1] - assembledFileSavePath - arg[2] - assembledFileName - arg[3] - (optional) author = null - arg[4] - (optional) OnFileExistOperation: int or string = 1 (CreateWithIndex) - ├─ 0 - Overwrite - ├─ 1 - CreateWithIndex - └─ 2 - ThrowException"); - - Console.ResetColor(); + WriteError(wrongArgumentsErrorMessage); throw new ArgumentException("At least 3 arguments are needed"); } - Console.WriteLine($"Work folder path: {workFolderPath}"); - Console.WriteLine($"Assembled file path: {assembledFileSavePath}"); - Console.WriteLine($"Assembled file name: {assembledFileName}"); - Console.WriteLine($"Author: {author}"); - Console.WriteLine($"On file already exst operation: {onFileAlreadyExist}\n"); + Console.WriteLine($"Work folder path: {workFolderPath}"); + Console.WriteLine($"Assembled file path: {assembledFileSavePath}"); + Console.WriteLine($"Assembled file name: {assembledFileName}"); + Console.WriteLine($"On file already exst: {onFileAlreadyExist}"); + Console.WriteLine($"Author: {author}"); + Console.WriteLine(); AssemblyData assemblyData = new(workFolderPath) { @@ -81,4 +88,15 @@ static void Main(string[] args) Console.WriteLine("\nУспешно!"); Console.ResetColor(); } + + private static void WriteError(string msg, bool addErrorPrefix = true, string endsWith = "\n") + { + const string errorPrefix = "ERROR:"; + ConsoleColor beforeColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + + Console.Write($"{(addErrorPrefix? errorPrefix : null)} {msg}{endsWith}"); + + Console.ForegroundColor = beforeColor; + } } \ No newline at end of file diff --git a/Content.Core/Properties/launchSettings.json b/Content.Core/Properties/launchSettings.json index 613eb2f..4de46fd 100644 --- a/Content.Core/Properties/launchSettings.json +++ b/Content.Core/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Content.Core": { "commandName": "Project", - "commandLineArgs": "C:\\Users\\User\\Desktop\\_b.VV()\\prototypes\r\nC:\\Users\\User\\Desktop\\_b.VV()\r\nTest_25.03.25\r\nSpyDev14\r\nOverwrite" + "commandLineArgs": "C:\\Users\\User\\Desktop\\_b.VV()\\prototypes\r\nC:\\Users\\User\\Desktop\\_b.VV()\r\nTest_26.03.25\r\nOverwrite\r\nSpyDev14" } } } \ No newline at end of file