From 969cb8ac180127cd4aedc0ca33f7240b87b3a4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 14 Dec 2023 16:26:12 +0100 Subject: [PATCH] Driver choice: Add error message for wrong file type --- Common/File/FileUtil.cpp | 5 ++--- Common/File/FileUtil.h | 2 +- UI/GameSettingsScreen.cpp | 10 +++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index d41e49f68c..184f45ebfd 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -1209,12 +1209,11 @@ bool WriteStringToFile(bool text_file, const std::string &str, const Path &filen return true; } -bool WriteDataToFile(bool text_file, const void* data, const unsigned int size, const Path &filename) { +bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path &filename) { FILE *f = File::OpenCFile(filename, text_file ? "w" : "wb"); if (!f) return false; - size_t len = size; - if (len != fwrite(data, 1, len, f)) + if (size != fwrite(data, 1, size, f)) { fclose(f); return false; diff --git a/Common/File/FileUtil.h b/Common/File/FileUtil.h index 9f9c549111..e25b93521b 100644 --- a/Common/File/FileUtil.h +++ b/Common/File/FileUtil.h @@ -201,7 +201,7 @@ private: // Whole-file reading/writing bool WriteStringToFile(bool text_file, const std::string &str, const Path &filename); -bool WriteDataToFile(bool text_file, const void* data, const unsigned int size, const Path &filename); +bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path &filename); bool ReadFileToString(bool text_file, const Path &filename, std::string &str); // Return value must be delete[]-d. diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index c164d93e05..369b53e1ee 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1269,6 +1269,8 @@ UI::EventReturn GameSettingsScreen::OnCustomDriverInstall(UI::EventParams &e) { if (!value.empty()) { Path zipPath = Path(value); + bool success = false; + if (zipPath.GetFileExtension() == ".zip") { ZipFileReader *zipFileReader = ZipFileReader::Create(zipPath, ""); @@ -1304,9 +1306,15 @@ UI::EventReturn GameSettingsScreen::OnCustomDriverInstall(UI::EventParams &e) { File::Delete(tempMeta); + success = true; + RecreateViews(); } - } + } + if (!success) { + auto gr = GetI18NCategory(I18NCat::GRAPHICS); + g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The selected file is not a ZIP file with a compatible driver.")); + } } }); return UI::EVENT_DONE;