Skip to content

Commit

Permalink
Verify the entered Imperator documents path after reading the configu…
Browse files Browse the repository at this point in the history
…ration (#2248) #patch

Sentry event ID: 586e6a384e1446f2b8a6036429aec830
  • Loading branch information
IhateTrains authored Oct 7, 2024
1 parent 6b8aad2 commit 7b12b79
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ImperatorToCK3/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Configuration(ConverterVersion converterVersion) {
VerifyImperatorVersion(converterVersion);
VerifyCK3Path();
VerifyCK3Version(converterVersion);
VerifyImperatorDocPath();

Logger.IncrementProgress();
}
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 7b12b79

Please sign in to comment.