From 7b12b793288471275964e55b000f5a8ca0fb1e01 Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Mon, 7 Oct 2024 16:35:58 +0100 Subject: [PATCH] Verify the entered Imperator documents path after reading the configuration (#2248) #patch Sentry event ID: 586e6a384e1446f2b8a6036429aec830 --- ImperatorToCK3/Configuration.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ImperatorToCK3/Configuration.cs b/ImperatorToCK3/Configuration.cs index df0bde04a..33ef2e92a 100644 --- a/ImperatorToCK3/Configuration.cs +++ b/ImperatorToCK3/Configuration.cs @@ -47,6 +47,7 @@ public Configuration(ConverterVersion converterVersion) { VerifyImperatorVersion(converterVersion); VerifyCK3Path(); VerifyCK3Version(converterVersion); + VerifyImperatorDocPath(); Logger.IncrementProgress(); } @@ -212,6 +213,30 @@ private void VerifyCK3Path() { } } + private void VerifyImperatorDocPath() { + if (!Directory.Exists(ImperatorDocPath)) { + throw new UserErrorException($"{ImperatorDocPath} does not exist!"); + } + + string[] dirsInDocFolder = ["mod/", "logs/", "save_games/", "cache/"]; + string[] filesInDocFolder = [ + "continue_game.json", "dlc_load.json", "dlc_signature", "game_data.json", "pdx_settings.txt" + ]; + // If at least one of the paths exists, we consider the folder to be valid. + bool docFolderVerified = dirsInDocFolder.Any(dir => Directory.Exists(Path.Combine(ImperatorDocPath, dir))); + if (!docFolderVerified) { + docFolderVerified = filesInDocFolder.Any(file => File.Exists(Path.Combine(ImperatorDocPath, file))); + } + + if (!docFolderVerified) { + throw new UserErrorException($"{ImperatorDocPath} is not a valid I:R documents path!\n" + + $"It should contain one of the following files: " + + $"{string.Join(", ", filesInDocFolder)}"); + } + + Logger.Debug($"I:R documents path {ImperatorPath} is valid."); + } + private void SetOutputName() { if (string.IsNullOrWhiteSpace(OutputModName)) { OutputModName = CommonFunctions.TrimExtension(CommonFunctions.TrimPath(SaveGamePath));