Skip to content

Commit

Permalink
Merge pull request #18765 from hrydgard/background-image-file-type
Browse files Browse the repository at this point in the history
Add proper checks for file type when picking a background image
  • Loading branch information
hrydgard committed Jan 27, 2024
2 parents cb89dff + a811cba commit bb99409
Show file tree
Hide file tree
Showing 48 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Common/Render/ManagedTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Render/ManagedTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ class ManagedTexture {
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);
29 changes: 27 additions & 2 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 موديل
Expand Down
1 change: 1 addition & 0 deletions assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 серия
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ca_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/cz_CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/da_DK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/de_DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/dr_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_LA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fa_IR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 مدل
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fi_FI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fr_FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/gl_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/gr_EL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/he_IL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/he_IL_invert.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/hr_HR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/hu_HU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/id_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/it_IT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ja_JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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のモデル
Expand Down
1 change: 1 addition & 0 deletions assets/lang/jv_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ko_KR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 모델
Expand Down
1 change: 1 addition & 0 deletions assets/lang/lo_LA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/lt-LT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ms_MY.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/nl_NL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/no_NO.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/pl_PL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/pt_BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/pt_PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ro_RO.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ru_RU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/sv_SE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/tg_PH.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/th_TH.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/tr_TR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/uk_UA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions assets/lang/vi_VN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit bb99409

Please sign in to comment.