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));