Driver choice: Add error message for wrong file type

This commit is contained in:
Henrik Rydgård 2023-12-14 16:26:12 +01:00
parent 7634eba083
commit 969cb8ac18
3 changed files with 12 additions and 5 deletions

View file

@ -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;

View file

@ -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.

View file

@ -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;