Skip to content

Commit

Permalink
Misc: Add missing error reporting to a couple of WriteBinaryFiles()
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 18, 2025
1 parent 227c249 commit 43e7be9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,10 @@ void Achievements::DownloadImage(std::string url, std::string cache_path)
return;
}

if (!FileSystem::WriteBinaryFile(cache_path.c_str(), data.data(), data.size()))
Error write_error;
if (!FileSystem::WriteBinaryFile(cache_path.c_str(), data, &write_error))
{
ERROR_LOG("Failed to write badge image to '{}'", cache_path);
ERROR_LOG("Failed to write badge image to '{}': {}", cache_path, write_error.GetDescription());
return;
}

Expand Down
9 changes: 6 additions & 3 deletions src/duckstation-qt/qthost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,15 @@ bool QtHost::DownloadFile(QWidget* parent, const QString& title, std::string url

// Directory may not exist. Create it.
const std::string directory(Path::GetDirectory(path));
Error error;
if ((!directory.empty() && !FileSystem::DirectoryExists(directory.c_str()) &&
!FileSystem::CreateDirectory(directory.c_str(), true)) ||
!FileSystem::WriteBinaryFile(path, data.data(), data.size()))
!FileSystem::CreateDirectory(directory.c_str(), true, &error)) ||
!FileSystem::WriteBinaryFile(path, data, &error))
{
QMessageBox::critical(parent, qApp->translate("QtHost", "Error"),
qApp->translate("QtHost", "Failed to write '%1'.").arg(QString::fromUtf8(path)));
qApp->translate("QtHost", "Failed to write '%1':\n%2")
.arg(QString::fromUtf8(path))
.arg(QString::fromUtf8(error.GetDescription())));
return false;
}

Expand Down

0 comments on commit 43e7be9

Please # to comment.