Skip to content

Commit

Permalink
Add missing DLL/Dependency error message for Database Handler
Browse files Browse the repository at this point in the history
This way, user will be asked to download and install the missing VCRedist

#607
  • Loading branch information
bagusnl committed Nov 19, 2024
1 parent 2a5c375 commit 2bb13d9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CollapseLauncher/Classes/Helper/Database/DBHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ public static async Task Init(bool redirectThrow = false, bool bypassEnableFlag
}
else LogWriteLine("[DbHandler::Init] Reinitializing database system...");
}
catch (DllNotFoundException e)
{
LogWriteLine("[DbHandler::Init] Error when connecting to database system! Probably missing Visual C/C++ redist!\r\n" + e,
LogType.Error, true);
if (redirectThrow) throw;
}
// No need to handle all these error catcher with sentry
// The error should be handled in the method caller instead
catch (LibsqlException e) when (e.Message.Contains("`api error: `{\"error\":\"Unauthorized: `The JWT is invalid`\"}``",
Expand Down
44 changes: 39 additions & 5 deletions CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if !DISABLEDISCORD
using CollapseLauncher.DiscordPresence;
#endif
using CollapseLauncher.CustomControls;
using CollapseLauncher.Dialogs;
using CollapseLauncher.Extension;
using CollapseLauncher.Helper;
Expand Down Expand Up @@ -1493,18 +1494,20 @@ private async void ValidateAndSaveDbButton_Click(object sender, RoutedEventArgs
{
// Show checking bar status
ShowChecking();

// Set the value from prop
DbHandler.Uri = _dbUrl;
DbHandler.Token = _dbToken;
DbHandler.UserId = _dbUserId;

var r = Random.Shared.Next(100); // Generate random int for data verification

await DbHandler.Init(true, true); // Initialize database
await DbHandler.StoreKeyValue("TestKey", r.ToString(), true); // Store random number in TestKey
if (Convert.ToInt32(await DbHandler.QueryKey("TestKey", true)) != r) // Query key and check if value is correct
throw new InvalidDataException("Data validation failed!"); // Throw if value does not match (then catch), unlikely but maybe for really unstable db server
if (Convert.ToInt32(await DbHandler.QueryKey("TestKey", true)) !=
r) // Query key and check if value is correct
throw
new InvalidDataException("Data validation failed!"); // Throw if value does not match (then catch), unlikely but maybe for really unstable db server

// Show success bar status
ShowSuccess();
Expand All @@ -1516,9 +1519,40 @@ await SpawnDialog(
null,
null,
ContentDialogButton.Close,
CustomControls.ContentDialogTheme.Success
ContentDialogTheme.Success
); // Show success dialog
}
catch (DllNotFoundException ex)
{
// No need to revert the value if fail, user is asked to restart the app
ShowFailed(ex);
var res = await SpawnDialog(
Lang._Misc.MissingVcRedist,
Lang._Misc.MissingVcRedistSubtitle,
sender as UIElement,
Lang._Misc.Close,
Lang._Misc.Yes,
null,
ContentDialogButton.Primary,
ContentDialogTheme.Error);
if (res == ContentDialogResult.Primary)
{
await Task.Run(() =>
{
var uri =
"https://github.com/abbodi1406/vcredist/releases/latest/download/VisualCppRedist_AIO_x86_x64.exe";
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = uri,
UseShellExecute = true,
Verb = "runas"
};
Process.Start(psi);
});
}
else { await SentryHelper.ExceptionHandlerAsync(ex); }
}
catch (Exception ex)
{
// Revert value if fail
Expand Down
8 changes: 5 additions & 3 deletions Hi3Helper.Core/Lang/Locale/LangMisc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ public sealed partial class LangMisc

public string ImageCropperTitle { get; set; } = LangFallback?._Misc.ImageCropperTitle;

public string IsBytesMoreThanBytes { get; set; } = LangFallback?._Misc.IsBytesMoreThanBytes;
public string IsBytesUnlimited { get; set; } = LangFallback?._Misc.IsBytesUnlimited;
public string IsBytesNotANumber { get; set; } = LangFallback?._Misc.IsBytesNotANumber;
public string IsBytesMoreThanBytes { get; set; } = LangFallback?._Misc.IsBytesMoreThanBytes;
public string IsBytesUnlimited { get; set; } = LangFallback?._Misc.IsBytesUnlimited;
public string IsBytesNotANumber { get; set; } = LangFallback?._Misc.IsBytesNotANumber;
public string MissingVcRedist { get; set; } = LangFallback?._Misc.MissingVcRedist;
public string MissingVcRedistSubtitle { get; set; } = LangFallback?._Misc.MissingVcRedistSubtitle;
}
}
#endregion
Expand Down
5 changes: 4 additions & 1 deletion Hi3Helper.Core/Lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,10 @@

"IsBytesMoreThanBytes": "= {0} bytes (-/+ {1})",
"IsBytesUnlimited": "= Unlimited",
"IsBytesNotANumber": "= NaN"
"IsBytesNotANumber": "= NaN",

"MissingVcRedist": "Missing Visual C/C++ Redistributable",
"MissingVcRedistSubtitle": "You need to install the Visual C/C++ Redistributable to run this function. Do you want to download it now?\r\nNote: This will open a browser window and download a file from abbodi1406 GitHub repository. Please run the installer after downloading it then restart Collapse and try again.\r\nIf you have already installed it but the error remains, please send a issue ticket to us."
},

"_BackgroundNotification": {
Expand Down

0 comments on commit 2bb13d9

Please sign in to comment.