Add proper checks for file type when picking a background image

Should fix some confusion, and also issues picking files from the
Download folder on Android where the filenames we get don't always have
extensions.
This commit is contained in:
Henrik Rydgård 2024-01-27 12:03:01 +01:00
parent cb89dff10f
commit a811cbac80
48 changed files with 75 additions and 6 deletions

View File

@ -70,7 +70,7 @@ static Draw::DataFormat ZimToT3DFormat(int zim) {
}
}
static ImageFileType DetectImageFileType(const uint8_t *data, size_t size) {
ImageFileType DetectImageFileType(const uint8_t *data, size_t size) {
if (size < 4) {
return ImageFileType::UNKNOWN;
}

View File

@ -80,3 +80,5 @@ private:
Draw::Texture *CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name);
Draw::Texture *CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType type, bool generateMips);
Draw::Texture *CreateTextureFromTempImage(Draw::DrawContext *draw, const TempImage &image, bool generateMips, const char *name);
ImageFileType DetectImageFileType(const uint8_t *data, size_t size);

View File

@ -27,6 +27,7 @@
#include "Common/UI/View.h"
#include "Common/UI/ViewGroup.h"
#include "Common/UI/Context.h"
#include "Common/Render/ManagedTexture.h"
#include "Common/VR/PPSSPPVR.h"
#include "Common/System/Display.h" // Only to check screen aspect ratio with pixel_yres/pixel_xres
@ -1385,8 +1386,32 @@ UI::EventReturn GameSettingsScreen::OnChangeBackground(UI::EventParams &e) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
System_BrowseForImage(GetRequesterToken(), sy->T("Set UI background..."), [=](const std::string &value, int) {
if (!value.empty()) {
Path dest = GetSysDirectory(DIRECTORY_SYSTEM) / (endsWithNoCase(value, ".jpg") ? "background.jpg" : "background.png");
File::Copy(Path(value), dest);
Path path(value);
// Check the file format. Don't rely on the file extension here due to scoped storage URLs.
FILE *f = File::OpenCFile(path, "rb");
uint8_t buffer[8];
ImageFileType type = ImageFileType::UNKNOWN;
if (8 == fread(buffer, 1, ARRAY_SIZE(buffer), f)) {
type = DetectImageFileType(buffer, ARRAY_SIZE(buffer));
}
std::string filename;
switch (type) {
case ImageFileType::JPEG:
filename = "background.jpg";
break;
case ImageFileType::PNG:
filename = "background.png";
break;
}
if (!filename.empty()) {
Path dest = GetSysDirectory(DIRECTORY_SYSTEM) / filename;
File::Copy(Path(value), dest);
} else {
g_OSD.Show(OSDType::MESSAGE_ERROR, sy->T("Only JPG and PNG images are supported"), path.GetFilename(), 5.0);
}
}
// It will init again automatically. We can't init outside a frame on Vulkan.
UIBackgroundShutdown();

View File

@ -128,8 +128,7 @@ android {
'-DANDROID_PLATFORM=android-16',
'-DANDROID_TOOLCHAIN=clang',
'-DANDROID_CPP_FEATURES=',
'-DANDROID_STL=c++_static',
'-DANDROID_ARM_NEON=TRUE'
'-DANDROID_STL=c++_static'
}
}
ndk {

View File

@ -1316,6 +1316,7 @@ No animation = No animation
Not a PSP game = PSP ليست لعبة
Off = ‎مغلق
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP موديل

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP серия

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Toto není hra PSP
Off = Vypnuto
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Model PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Kein PSP Spiel
Off = Aus
Oldest Save = Ältester Spielstand
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP Modell

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1322,6 +1322,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1309,6 +1309,7 @@ No animation = Sin animación
Not a PSP game = No es un juego de PSP
Off = No
Oldest Save = Partida guardada más antigua
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = ¡La ruta no existe!
PSP Memory Stick = PSP Memory Stick
PSP Model = Modelo de PSP

View File

@ -1310,6 +1310,7 @@ No animation = Sin animación
Not a PSP game = No es un juego de PSP
Off = No
Oldest Save = Antiguos datos de guardado
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = La ruta no existe.
PSP Memory Stick = Memory Stick de PSP
PSP Model = Modelo de PSP

View File

@ -1308,6 +1308,7 @@ No animation = بدون انمیشین
Not a PSP game = ‎نیست PSP بازی
Off = ‎خاموش
Oldest Save = قدیمی ترین ذخیره
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = مسیر فایل پیدا نشد
PSP Memory Stick = حافظه psp
PSP Model = PSP مدل

View File

@ -1308,6 +1308,7 @@ No animation = Ei animaatiota
Not a PSP game = Ei PSP-peli
Off = Pois
Oldest Save = Vanhin tallennus
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Polkua ei ole olemassa!
PSP Memory Stick = PSP-muistikortti
PSP Model = PSP-malli

View File

@ -1299,6 +1299,7 @@ No animation = No animation
Not a PSP game = Ce n'est pas un jeu PSP.
Off = Désactivé
Oldest Save = Le plus ancien état
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Modèle de PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Modelo de PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Δεν είναι παιχνίδι PSP
Off = Off
Oldest Save = Παλαιότερο αρχείο αποθήκευσης
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Μοντέλο PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Nije PSP igra
Off = Isključeno
Oldest Save = Najstariji save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Nem egy PSP játék
Off = Ki
Oldest Save = Legrégebbi mentés
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP modell

View File

@ -1308,6 +1308,7 @@ No animation = Tanpa animasi
Not a PSP game = Bukan permainan PSP
Off = Mati
Oldest Save = Simpanan lawas
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Tidak ada jalur!
PSP Memory Stick = PSP Memory Stick
PSP Model = Model PSP

View File

@ -1291,6 +1291,7 @@ Fast Memory = Memoria Rapida (instabile)
Force real clock sync (slower, less lag) = Forza sincronizzazione con frequenza reale (lento, meno lag)
Moving background = Spostamento dello sfondo
No animation = Nessuna animazione
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Il percorso non esiste!
PSP Memory Stick = Memory Stick PSP
Recent games = Giochi recenti

View File

@ -1308,6 +1308,7 @@ No animation = アニメーションなし
Not a PSP game = PSPのゲームではありません
Off = オフ
Oldest Save = 最も古いセーブ
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = パスが存在しません
PSP Memory Stick = メモリースティックの設定
PSP Model = PSPのモデル

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Ora ana dolanan PSP
Off = Mati
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1298,6 +1298,7 @@ No animation = 애니메이션 없음
Not a PSP game = PSP 게임이 아님
Off =
Oldest Save = 가장 오래된 저장
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = 경로가 존재하지 않습니다!
PSP Memory Stick = PSP 메모리 스틱
PSP Model = PSP 모델

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = ອັນນີ້ບໍ່ແມ່ນເກມ PSP
Off = ປິດ
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = ໂມເດລ PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Emuliuojamo PSP modelis

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Model PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Geen PSP-game
Off = Uit
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP-model

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Not a PSP game
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1314,6 +1314,7 @@ No animation = Bez animacji
Not a PSP game = To nie jest gra PSP
Off = Wył.
Oldest Save = Najstarszy zapis
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Ta ścieżka nie istnieje!
PSP Memory Stick = Karta Pamięci PSP
PSP Model = Model PSP

View File

@ -1322,6 +1322,7 @@ No animation = Sem animação
Not a PSP game = Não é um jogo de PSP
Off = Desligado
Oldest Save = Save mais antigo
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = O caminho não existe!
PSP Memory Stick = Cartão de Memória do PSP
PSP Model = Modelo do PSP

View File

@ -1324,6 +1324,7 @@ No animation = Sem animação
Not a PSP game = Não é um jogo de PSP
Off = Desativado
Oldest Save = Salvamento mais antigo
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = O caminho não existe!
PSP Memory Stick = Cartão de memória da PSP
PSP Model = Modelo da PSP

View File

@ -1309,6 +1309,7 @@ No animation = No animation
Not a PSP game = Nu e joc PSP
Off = Off
Oldest Save = Oldest save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Model PSP

View File

@ -1308,6 +1308,7 @@ No animation = Нет анимации
Not a PSP game = Игра не для PSP
Off = Отключено
Oldest Save = Самое старое сохранение
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Путь не существует!
PSP Memory Stick = Карта памяти PSP
PSP Model = Модель PSP

View File

@ -1309,6 +1309,7 @@ No animation = Ingen animation
Not a PSP game = Inte ett PSP-spel
Off = Off
Oldest Save = Äldsta sparfilen
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP-modell

View File

@ -1308,6 +1308,7 @@ No animation = Walang animation
Not a PSP game = Hindi PSP game
Off = Off
Oldest Save = Pinakalumang na i-save
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Direksyon ay hindi na lumabas!
PSP Memory Stick = PSP Memory Stick
PSP Model = Modelo ng PSP

View File

@ -1330,6 +1330,7 @@ No animation = ไม่แสดงอนิเมชั่น
Not a PSP game = นี่ไม่ใช่เกม PSP นะจ้ะ
Off = ปิด
Oldest Save = เซฟอันเก่าสุด
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = ไม่มีเส้นทางนี้อยู่!
PSP Memory Stick = แหล่งเก็บข้อมูล PSP
PSP Model = โมเดลของ PSP

View File

@ -1309,6 +1309,7 @@ No animation = animasyon yok
Not a PSP game = Bir PSP oyunu değil
Off = Kapalı
Oldest Save = En eski kayıt
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Yol mevcut değil!
PSP Memory Stick = PSP Hafıza Kartı
PSP Model = PSP modeli

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Не є грою для PSP
Off = Вимкнено
Oldest Save = Найстаріші збереження
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = Модель PSP

View File

@ -1308,6 +1308,7 @@ No animation = No animation
Not a PSP game = Đây Không phải là game PSP
Off = Tắt
Oldest Save = Save cũ nhất
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = Path does not exist!
PSP Memory Stick = PSP Memory Stick
PSP Model = PSP model

View File

@ -1246,6 +1246,7 @@ AVI Dump stopped. = AVI转储停止
Cache ISO in RAM = 在内存中缓存完整ISO
Change CPU Clock = 修改PSP的CPU频率 (不稳定)
Loaded plugin: %1 = 已加载插件: %1
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Recording = Recording
RetroAchievements = RetroAchievements
Rewind Snapshot Interval = 倒带快照间隔

View File

@ -1298,6 +1298,7 @@ No animation = 靜態背景
Not a PSP game = 這不是 PSP 遊戲
Off = 關閉
Oldest Save = 最舊存檔
Only JPG and PNG images are supported = Only JPG and PNG images are supported
Path does not exist! = 路徑不存在!
PSP Memory Stick = PSP 記憶棒
PSP Model = PSP 型號

@ -1 +1 @@
Subproject commit c5f9a6412e55ef489c1769a52ee1d590e4abd64b
Subproject commit e7989c300280ba06d7621ae5b4e00ac7fe28d97a