Rework commandline arguments && Add Exceptions

This commit is contained in:
ProfessionalUwU 2023-06-03 14:50:13 +02:00
parent 04048c4cb9
commit 888df20cc9
Signed by: ProfessionalUwU
GPG Key ID: 013AD77C0A9DD3F2
2 changed files with 9 additions and 2 deletions

View File

@ -7,9 +7,12 @@
} else {
switch (args[0]) {
case "determinePacmanCacheDirectory":
Pacserver.determinePacmanCacheDirectory();
Console.WriteLine(Pacserver.determinePacmanCacheDirectory());
break;
default:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
Console.ResetColor();
break;
}
}

View File

@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
public class Pacserver {
public static string pacmanCacheDirectory { get; set; } = string.Empty;
public static string determinePacmanCacheDirectory() {
// string defaultPacmanCacheDirectory = "/var/cache/pacman/pkg/";
string defaultPacmanCacheDirectory = "/var/cache/pacman/pkg/";
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
string? line;
@ -13,7 +13,11 @@ public class Pacserver {
Match match = regex.Match(line);
if (match.Success) {
pacmanCacheDirectory = match.ToString();
} else {
throw new Exception("Could not determine where pacman cache is! Would normally be found here " + defaultPacmanCacheDirectory);
}
} else {
throw new Exception("Pacman config has no CacheDir specified!");
}
}
file.Close();