diff --git a/publish.bat b/publish.bat index 5d63b94..7edf00d 100644 --- a/publish.bat +++ b/publish.bat @@ -15,7 +15,6 @@ exit /b :publish_and_zip dotnet publish -c Release -r %1 -p:PublishSingleFile=true -p:PublishTrimmed=%2 -p:DefineConstants=WINDOWS --self-contained=%2 -if exist slsk-batchdl\bin\Release\%FRAMEWORK%\%1\publish\*.pdb del /F /Q slsk-batchdl\bin\Release\%FRAMEWORK%\%1\publish\*.pdb if exist slsk-batchdl\bin\zips\%3 del /F /Q slsk-batchdl\bin\zips\%3 powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('slsk-batchdl\bin\Release\%FRAMEWORK%\%1\publish', 'slsk-batchdl\bin\zips\%3'); }" exit /b diff --git a/slsk-batchdl/Config.cs b/slsk-batchdl/Config.cs index 027a14e..73cc3c9 100644 --- a/slsk-batchdl/Config.cs +++ b/slsk-batchdl/Config.cs @@ -289,7 +289,7 @@ public class Config int idx = l.IndexOf('='); if (idx <= 0 || idx == l.Length - 1) - throw new ArgumentException($"Error parsing config '{path}' at line {i}"); + InputError($"Error parsing config '{path}' at line {i}"); var x = l.Split('=', 2, StringSplitOptions.TrimEntries); string key = x[0]; @@ -443,7 +443,7 @@ public class Config "interactive" => interactiveMode, "album" => album, "aggregate" => aggregate, - _ => throw new ArgumentException($"Unrecognized profile condition variable {var}") + _ => InputError($"Unrecognized profile condition variable {var}") }; } @@ -507,7 +507,7 @@ public class Config return !ParsePrimaryExpression(); if (token.StartsWith("\"")) - throw new ArgumentException("Invalid token at this position: " + token); + InputError("Invalid token at this position: " + token); if (tokens.Count > 0 && (tokens.Peek() == "==" || tokens.Peek() == "!=")) { @@ -633,7 +633,8 @@ public class Config UpdateMinMax2(value, condition, ref track.MinAlbumTrackCount, ref track.MaxAlbumTrackCount); break; default: - throw new ArgumentException($"Unknown condition '{condition}'"); + InputError($"Unknown condition '{condition}'"); + break; } } @@ -691,7 +692,7 @@ public class Config { i++; if (i < 0 || i >= args.Count) - throw new ArgumentException("Option requires parameter"); + InputError("Option requires parameter"); return args[i]; } @@ -718,7 +719,7 @@ public class Config "bandcamp" => InputType.Bandcamp, "string" => InputType.String, "list" => InputType.List, - _ => throw new ArgumentException($"Invalid input type '{args[i]}'"), + _ => InputError($"Invalid input type '{args[i]}'"), }; break; case "-p": @@ -846,7 +847,7 @@ public class Config "results" => PrintOption.Results, "tracks-full" => PrintOption.Tracks | PrintOption.Full, "results-full" => PrintOption.Results | PrintOption.Full, - _ => throw new ArgumentException($"Invalid print option '{args[i]}'"), + _ => InputError($"Invalid print option '{args[i]}'"), }; break; case "--pt": @@ -1037,7 +1038,7 @@ public class Config "default" => AlbumArtOption.Default, "largest" => AlbumArtOption.Largest, "most" => AlbumArtOption.Most, - _ => throw new ArgumentException($"Invalid album art download mode '{args[i]}'"), + _ => InputError($"Invalid album art download mode '{args[i]}'"), }; break; case "--aao": @@ -1195,7 +1196,7 @@ public class Config "name" => SkipMode.Name, "tag" => SkipMode.Tag, "index" => SkipMode.Index, - _ => throw new ArgumentException($"Invalid output dir skip mode '{args[i]}'"), + _ => InputError($"Invalid output dir skip mode '{args[i]}'"), }; break; case "--smmd": @@ -1204,7 +1205,7 @@ public class Config { "name" => SkipMode.Name, "tag" => SkipMode.Tag, - _ => throw new ArgumentException($"Invalid music dir skip mode '{args[i]}'"), + _ => InputError($"Invalid music dir skip mode '{args[i]}'"), }; break; case "--nrsc": @@ -1288,7 +1289,8 @@ public class Config parallelAlbumSearchProcesses = int.Parse(getParameter(ref i)); break; default: - throw new ArgumentException($"Unknown argument: {args[i]}"); + InputError($"Unknown argument: {args[i]}"); + break; } } else @@ -1299,7 +1301,7 @@ public class Config inputSet = true; } else - throw new ArgumentException($"Invalid argument \'{args[i]}\'. Input is already set to \'{input}\'"); + InputError($"Invalid argument \'{args[i]}\'. Input is already set to \'{input}\'"); } } } @@ -1340,4 +1342,18 @@ public class Config return args.ToArray(); } + + + public static void InputError(string message) + { + Printing.WriteLine($"Input error: {message}", ConsoleColor.Red); + Environment.Exit(1); + } + + + public static T InputError(string message) + { + InputError(message); + return default; + } } diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index 210e5c5..7d1b454 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -42,7 +42,7 @@ static partial class Program var config = new Config(args); if (config.input.Length == 0) - throw new ArgumentException($"No input provided"); + Config.InputError($"No input provided"); (config.inputType, extractor) = ExtractorRegistry.GetMatchingExtractor(config.input, config.inputType); @@ -90,7 +90,7 @@ static partial class Program client = new SoulseekClient(clientOptions); if (!config.useRandomLogin && (string.IsNullOrEmpty(config.username) || string.IsNullOrEmpty(config.password))) - throw new ArgumentException("No soulseek username or password"); + Config.InputError("No soulseek username or password"); await Login(config, config.useRandomLogin);