Improved error message text

This commit is contained in:
Caelan Sayler
2022-04-08 16:01:22 +01:00
parent bafc994a40
commit 95b0f0a1d9
3 changed files with 9 additions and 17 deletions

View File

@@ -47,7 +47,7 @@ void unzipSingleFile(BYTE* zipBuf, DWORD cZipBuf, wstring fileLocation, std::fun
CloseZip(zipFile);
if (!unzipSuccess) throw wstring(L"Unable to extract embedded package (predicate not found).");
if (!unzipSuccess) throw wstring(L"Unable to extract embedded package (Squirrel.exe not found).");
}
// Prints to the provided buffer a nice number of bytes (KB, MB, GB, etc)
@@ -91,24 +91,24 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
// locate bundled package and map to memory
memAddr = util::mmap_read(util::get_current_process_path(), 0);
if (!memAddr) {
throw wstring(L"Unable to map executable to memory");
throw wstring(L"Unable to memmap current executable. Is there enough available system memory?");
}
int64_t packageOffset, packageLength;
bundle_marker_t::header_offset(&packageOffset, &packageLength);
uint8_t* pkgStart = memAddr + packageOffset;
if (packageOffset == 0 || packageLength == 0) {
throw wstring(L"The embedded package was not found");
throw wstring(L"The embedded package containing the application to install was not found. Please contact the application author.");
}
// rough check for sufficient disk space before extracting anything
// required space is size of compressed nupkg, size of extracted app,
// and squirrel overheads (incl temp files). the constant 0.38 is a
// aggressive estimate on what the compression ratio might be.
int64_t squirrelOverhead = 50 * 1000 * 1000;
int64_t squirrelOverhead = 50 * 1000 * 1000;
int64_t requiredSpace = squirrelOverhead + (packageLength * 3) + (packageLength / (double)0.38);
if (!util::check_diskspace(requiredSpace)) {
throw wstring(L"Insufficient disk space. This application requires at least " + pretty_bytes(requiredSpace) + L" free space to be installed");
throw wstring(L"Insufficient disk space. This application requires at least " + pretty_bytes(requiredSpace) + L" free space to be installed.");
}
// extract Squirrel installer from package
@@ -125,21 +125,14 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
util::wexec(cmd.c_str());
}
catch (wstring wsx) {
util::show_error_dialog(L"An error occurred while running setup. " + wsx + L". Please contact the application author.");
}
catch (std::exception ex) {
// nasty shit to convert from ascii to wide-char. this will fail if there are multi-byte characters.
// hopefully we remember to throw 'wstring' everywhere instead of 'exception' and it doesn't matter.
string msg = ex.what();
wstring wsTmp(msg.begin(), msg.end());
util::show_error_dialog(L"An error occurred while running setup. " + wsTmp + L". Please contact the application author.");
util::show_error_dialog(L"An error occurred while running setup. " + wsx);
}
catch (...) {
util::show_error_dialog(L"An unknown error occurred while running setup. Please contact the application author.");
}
// clean-up resources
if(memAddr) util::munmap(memAddr);
if (memAddr) util::munmap(memAddr);
DeleteFile(updaterPath.c_str());
DeleteFile(packagePath.c_str());
return 0;

View File

@@ -113,7 +113,7 @@ void util::wexec(const wchar_t* cmd)
if (dwExitCode != 0) {
throw wstring(L"Process exited with error code: "
+ to_wstring((int32_t)dwExitCode)
+ L". There may be additional logs available at '%localappdata%\\SquirrelClowdTemp\\Squirrel.log'.");
+ L". There may be more detailed information in '%localappdata%\\SquirrelClowdTemp\\Squirrel.log'.");
}
}

View File

@@ -91,8 +91,7 @@ namespace Squirrel.Update
Windows.User32MessageBox.Show(
IntPtr.Zero,
"Setup encountered fatal error: " + ex.Message + Environment.NewLine
+ "There may be more detailed information in '%localappdata%\\SquirrelClowdTemp\\Squirrel.log'. "
+ "Please contact the application author.",
+ "There may be more detailed information in '%localappdata%\\SquirrelClowdTemp\\Squirrel.log'.",
"Setup Error",
Windows.User32MessageBox.MessageBoxButtons.OK,
Windows.User32MessageBox.MessageBoxIcon.Error);