Handle error case for std::filesystem::space.

This commit is contained in:
Dario 2024-12-08 14:35:54 -03:00
parent 7dfeb8eca9
commit 26dbd7c697
2 changed files with 13 additions and 15 deletions

View file

@ -167,13 +167,13 @@ inline static std::unordered_map<std::string, std::unordered_map<ELanguage, std:
{
"Installer_Step_RequiredSpace",
{
{ ELanguage::English, "Required space:" }
{ ELanguage::English, "Required space: %2.2f GiB" }
}
},
{
"Installer_Step_AvailableSpace",
{
{ ELanguage::English, "Available space:" }
{ ELanguage::English, "Available space: %2.2f GiB" }
}
},
{

View file

@ -626,6 +626,8 @@ static void DrawDescriptionContainer()
DrawContainer(descriptionMin, descriptionMax, true);
char descriptionText[512];
char requiredSpaceText[128];
char availableSpaceText[128];
strncpy(descriptionText, GetWizardText(g_currentPage).c_str(), sizeof(descriptionText) - 1);
if (g_currentPage == WizardPage::CheckSpace)
@ -633,17 +635,9 @@ static void DrawDescriptionContainer()
constexpr double DivisorGiB = (1024.0 * 1024.0 * 1024.0);
double requiredGiB = double(g_installerSources.totalSize) / DivisorGiB;
double availableGiB = double(g_installerAvailableSize) / DivisorGiB;
// TODO: the format for where the numbers are (%2.2f GiB) should be moved to the localised string.
snprintf
(
descriptionText,
sizeof(descriptionText),
"%s%s %2.2f GiB\n%s %2.2f GiB",
GetWizardText(g_currentPage).c_str(),
Localise("Installer_Step_RequiredSpace").c_str(), requiredGiB,
Localise("Installer_Step_AvailableSpace").c_str(), availableGiB
);
snprintf(requiredSpaceText, sizeof(requiredSpaceText), Localise("Installer_Step_RequiredSpace").c_str(), requiredGiB);
snprintf(availableSpaceText, sizeof(availableSpaceText), (g_installerAvailableSize > 0) ? Localise("Installer_Step_AvailableSpace").c_str() : "", availableGiB);
snprintf(descriptionText, sizeof(descriptionText), "%s%s\n%s", GetWizardText(g_currentPage).c_str(), requiredSpaceText, availableSpaceText);
}
else if (g_currentPage == WizardPage::InstallSucceeded)
{
@ -1109,8 +1103,12 @@ static void InstallerStart()
static bool InstallerParseSources()
{
std::filesystem::space_info spaceInfo = std::filesystem::space(g_installPath);
g_installerAvailableSize = spaceInfo.available;
std::error_code spaceErrorCode;
std::filesystem::space_info spaceInfo = std::filesystem::space(g_installPath, spaceErrorCode);
if (!spaceErrorCode)
{
g_installerAvailableSize = spaceInfo.available;
}
Installer::Input installerInput;
installerInput.gameSource = g_gameSourcePath;