Skip to content

Commit

Permalink
Added a try catch to patching since for the few people who do patch a…
Browse files Browse the repository at this point in the history
… small percent of them might have MM crash on them.

also removed a duplicate if statement in setup wizard
  • Loading branch information
shananas committed Feb 6, 2025
1 parent 9e38dbb commit 08ed25d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 49 deletions.
16 changes: 12 additions & 4 deletions OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,18 @@ await ModsService.InstallMod(name, isZipFile, isLuaFile, progress =>

PatchCommand = new RelayCommand(async (fastMode) =>
{
ResetLogWindow();
await BuildPatches(Convert.ToBoolean(fastMode));
await PatchGame(Convert.ToBoolean(fastMode));
CloseAllWindows();
try
{
ResetLogWindow();
await BuildPatches(Convert.ToBoolean(fastMode));
await PatchGame(Convert.ToBoolean(fastMode));
CloseAllWindows();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}, _ => !IsBuilding);

RunCommand = new RelayCommand(async _ =>
Expand Down
94 changes: 49 additions & 45 deletions OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,73 +884,77 @@ public SetupWizardViewModel()
return;
}

if (!Directory.Exists(directoryPath))
{
MessageBox.Show("No Game Install Locations Found\nPlease Manually Browse To Your Game Install Directory", "Failure", MessageBoxButton.OK);
return;
}

bool installLocationFoundRemix = false;
bool installLocationFound3D = false;
// Read the entire content of the VDF file
string vdfContent;
try
{
vdfContent = File.ReadAllText(Path.Combine(directoryPath, "libraryfolders.vdf"));

}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\nPlease Manually Browse To Your Game Install Directory");
return;
}
// Define a regular expression to match "path" values
Regex regex = new Regex(@"""path""\s*""([^""]*)""", RegexOptions.IgnoreCase);
// MatchCollection to store all matches found
MatchCollection matches = regex.Matches(vdfContent);
// Iterate through matches and print out the "path" values
if (Directory.Exists(directoryPath))
try
{
foreach (Match match in matches)
// Define a regular expression to match "path" values
Regex regex = new Regex(@"""path""\s*""([^""]*)""", RegexOptions.IgnoreCase);
// MatchCollection to store all matches found
MatchCollection matches = regex.Matches(vdfContent);
// Iterate through matches and print out the "path" values
if (Directory.Exists(directoryPath))
{
string pathValue = match.Groups[1].Value; // Group 1 is the path raw, without the key
Console.WriteLine($"Path: {pathValue}");
string parsedText = pathValue.Replace(@"\\", @"\");
string commonGamesDirectory = Path.Combine(parsedText, "steamapps\\common");
if (Directory.Exists(commonGamesDirectory))
foreach (Match match in matches)
{
string kH1525Path = Path.Combine(commonGamesDirectory, @"KINGDOM HEARTS -HD 1.5+2.5 ReMIX-");
string kH28Path = Path.Combine(commonGamesDirectory, @"KINGDOM HEARTS HD 2.8 Final Chapter Prologue");
if (File.Exists(Path.Combine(kH1525Path, "steam_api64.dll")))
string pathValue = match.Groups[1].Value; // Group 1 is the path raw, without the key
Console.WriteLine($"Path: {pathValue}");
string parsedText = pathValue.Replace(@"\\", @"\");
string commonGamesDirectory = Path.Combine(parsedText, "steamapps\\common");
if (Directory.Exists(commonGamesDirectory))
{
installLocationFoundRemix = true;
PcReleaseLocation = kH1525Path;
}
if (File.Exists(Path.Combine(kH28Path, "steam_api64.dll")))
{
installLocationFound3D = true;
PcReleaseLocationKH3D = kH28Path;
string kH1525Path = Path.Combine(commonGamesDirectory, @"KINGDOM HEARTS -HD 1.5+2.5 ReMIX-");
string kH28Path = Path.Combine(commonGamesDirectory, @"KINGDOM HEARTS HD 2.8 Final Chapter Prologue");
if (File.Exists(Path.Combine(kH1525Path, "steam_api64.dll")))
{
installLocationFoundRemix = true;
PcReleaseLocation = kH1525Path;
}
if (File.Exists(Path.Combine(kH28Path, "steam_api64.dll")))
{
installLocationFound3D = true;
PcReleaseLocationKH3D = kH28Path;
}
}
}
}
if (!installLocationFoundRemix && !installLocationFound3D)
{
MessageBox.Show("No Game Install Locations Found\nThis may be caused by missing files in the game install folder. If you have an installation verify your game files through Steam to get the missing files and try again." +
"\nPlease Manually Browse To Your Game Install Directory", "Failure", MessageBoxButton.OK);
}
else if (!installLocationFoundRemix && installLocationFound3D)
{
MessageBox.Show("Kingdom Hearts HD 1.5+2.5: MISSING (This may be caused by missing files in the game install folder. If you have an installation verify your game files through Steam to get the missing files and try again.)" +
"\nKingdom Hearts HD 2.8: FOUND", "Success", MessageBoxButton.OK);
}
else if (installLocationFoundRemix && !installLocationFound3D)
{
MessageBox.Show("Kingdom Hearts HD 1.5+2.5: FOUND\nKingdom Hearts HD 2.8: MISSING" +
"(This may be caused by missing files in the game install folder. If you have an installation verify your game files through Steam to get the missing files and try again.)", "Success", MessageBoxButton.OK);
}
else
{
MessageBox.Show("Kingdom Hearts HD 1.5+2.5: FOUND\nKingdom Hearts HD 2.8: FOUND", "Success", MessageBoxButton.OK);
}

}
if (!installLocationFoundRemix && !installLocationFound3D)
{
MessageBox.Show("No Game Install Locations Found\nThis may be caused by missing files in the game install folder. If you have an installation verify your game files through Steam to get the missing files and try again." +
"\nPlease Manually Browse To Your Game Install Directory", "Failure", MessageBoxButton.OK);
}
else if (!installLocationFoundRemix && installLocationFound3D)
{
MessageBox.Show("Kingdom Hearts HD 1.5+2.5: MISSING (This may be caused by missing files in the game install folder. If you have an installation verify your game files through Steam to get the missing files and try again.)" +
"\nKingdom Hearts HD 2.8: FOUND", "Success", MessageBoxButton.OK);
}
else if (installLocationFoundRemix && !installLocationFound3D)
{
MessageBox.Show("Kingdom Hearts HD 1.5+2.5: FOUND\nKingdom Hearts HD 2.8: MISSING" +
"(This may be caused by missing files in the game install folder. If you have an installation verify your game files through Steam to get the missing files and try again.)", "Success", MessageBoxButton.OK);
}
else
catch (Exception ex)
{
MessageBox.Show("Kingdom Hearts HD 1.5+2.5: FOUND\nKingdom Hearts HD 2.8: FOUND", "Success", MessageBoxButton.OK);
MessageBox.Show(ex.Message);
return;
}
}
else
Expand Down

0 comments on commit 08ed25d

Please sign in to comment.