Skip to content

Commit

Permalink
Store: Implement progress bar for homebrew installs
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 22, 2024
1 parent bd388fc commit c2850ff
Show file tree
Hide file tree
Showing 45 changed files with 72 additions and 51 deletions.
29 changes: 25 additions & 4 deletions Core/Util/GameManager.cpp
Expand Up @@ -302,15 +302,12 @@ bool GameManager::InstallGame(const Path &url, const Path &fileName, bool delete
auto di = GetI18NCategory(I18NCat::DIALOG);
auto sy = GetI18NCategory(I18NCat::SYSTEM);

g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, 0.0f, 0.0f, 0.1f);

std::string extension = url.GetFileExtension();
// Examine the URL to guess out what we're installing.
if (extension == ".cso" || extension == ".iso") {
// It's a raw ISO or CSO file. We just copy it to the destination.
std::string shortFilename = url.GetFilename();
bool success = InstallRawISO(fileName, shortFilename, deleteAfter);
g_OSD.RemoveProgressBar("install", success, 0.5f);
return success;
}

Expand Down Expand Up @@ -569,9 +566,12 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
return true;
};

auto di = GetI18NCategory(I18NCat::DIALOG);

// Create all the directories first in one pass
std::set<Path> createdDirs;
for (int i = 0; i < info.numFiles; i++) {
// Let's count the directories as the first 10%.
const char *fn = zip_get_name(z, i, 0);
std::string zippedName = fn;
if (zippedName.length() < (size_t)info.stripChars) {
Expand All @@ -597,6 +597,7 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
allBytes += zstat.size;
}
}
g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, info.numFiles, (i + 1) * 0.1f, 0.1f);
}

// Now, loop through again in a second pass, writing files.
Expand All @@ -620,7 +621,9 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
createdFiles.push_back(outFilename);
}
}
g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, 1.0f, 0.1f + (i + 1) / (float)info.numFiles * 0.9f, 0.1f);
}

INFO_LOG(HLE, "Extracted %d files from zip (%d bytes / %d).", info.numFiles, (int)bytesCopied, (int)allBytes);
zip_close(z);
z = nullptr;
Expand All @@ -631,6 +634,7 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
}
InstallDone();
ResetInstallError();
g_OSD.RemoveProgressBar("install", true, 0.5f);
return true;

bail:
Expand All @@ -644,6 +648,7 @@ bool GameManager::InstallMemstickGame(struct zip *z, const Path &zipfile, const
File::DeleteDir(iter);
}
SetInstallError(sy->T("Storage full"));
g_OSD.RemoveProgressBar("install", false, 0.5f);
return false;
}

Expand All @@ -670,6 +675,8 @@ bool GameManager::InstallMemstickZip(struct zip *z, const Path &zipfile, const P
return false;
}

auto di = GetI18NCategory(I18NCat::DIALOG);

const size_t blockSize = 1024 * 128;
u8 *buffer = new u8[blockSize];
while (bytesCopied < allBytes) {
Expand All @@ -680,6 +687,7 @@ bool GameManager::InstallMemstickZip(struct zip *z, const Path &zipfile, const P
break;
bytesCopied += readSize;
installProgress_ = (float)bytesCopied / (float)allBytes;
g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, 1.0f, installProgress_, 0.1f);
}

delete[] buffer;
Expand All @@ -688,6 +696,7 @@ bool GameManager::InstallMemstickZip(struct zip *z, const Path &zipfile, const P

if (bytesCopied < allBytes) {
File::Delete(dest);
g_OSD.RemoveProgressBar("install", false, 0.5f);
SetInstallError(sy->T("Storage full"));
return false;
}
Expand All @@ -698,6 +707,7 @@ bool GameManager::InstallMemstickZip(struct zip *z, const Path &zipfile, const P
}
InstallDone();
ResetInstallError();
g_OSD.RemoveProgressBar("install", true, 0.5f);
return true;
}

Expand All @@ -718,13 +728,19 @@ bool GameManager::InstallZippedISO(struct zip *z, int isoFileIndex, const Path &

Path outputISOFilename = Path(g_Config.currentDirectory) / fn.substr(nameOffset);
size_t bytesCopied = 0;
bool success = false;
auto di = GetI18NCategory(I18NCat::DIALOG);
g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, 0.0f, 0.0f, 0.1f);
if (ExtractFile(z, isoFileIndex, outputISOFilename, &bytesCopied, allBytes)) {
INFO_LOG(IO, "Successfully extracted ISO file to '%s'", outputISOFilename.c_str());
success = true;
}
zip_close(z);
if (deleteAfter) {
if (success && deleteAfter) {
File::Delete(zipfile);
g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, 0.0f, 0.0f, 0.1f);
}
g_OSD.RemoveProgressBar("install", success, 0.5f);

z = 0;
installProgress_ = 1.0f;
Expand Down Expand Up @@ -755,11 +771,16 @@ bool GameManager::UninstallGameOnThread(const std::string &name) {

bool GameManager::InstallRawISO(const Path &file, const std::string &originalName, bool deleteAfter) {
Path destPath = Path(g_Config.currentDirectory) / originalName;
auto di = GetI18NCategory(I18NCat::DIALOG);
g_OSD.SetProgressBar("install", di->T("Installing..."), 0.0f, 0.0f, 0.0f, 0.1f);
// TODO: To save disk space, we should probably attempt a move first.
if (File::Copy(file, destPath)) {
if (deleteAfter) {
File::Delete(file);
}
g_OSD.RemoveProgressBar("install", true, 0.5f);
} else {
g_OSD.RemoveProgressBar("install", false, 0.5f);
}
installProgress_ = 1.0f;
InstallDone();
Expand Down
8 changes: 4 additions & 4 deletions UI/Store.cpp
Expand Up @@ -311,15 +311,15 @@ void ProductView::CreateViews() {
} else {
installButton_ = nullptr;
speedView_ = nullptr;
Add(new TextView(st->T("Already Installed")));
launchButton_ = new Button(st->T("Launch Game"));
launchButton_->OnClick.Handle(this, &ProductView::OnLaunchClick);
Add(launchButton_);
uninstallButton_ = new Button(st->T("Uninstall"));
Add(uninstallButton_)->OnClick.Add([=](UI::EventParams &e) {
g_GameManager.UninstallGameOnThread(entry_.file);
return UI::EVENT_DONE;
});
launchButton_ = new Button(st->T("Launch Game"));
launchButton_->OnClick.Handle(this, &ProductView::OnLaunchClick);
Add(launchButton_);
Add(new TextView(st->T("Installed")));
}

cancelButton_ = Add(new Button(di->T("Cancel")));
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/ar_AE.ini
Expand Up @@ -1168,9 +1168,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = ‎مثبتة بالفعل
Connection Error = ‎خطأ في الإتصال
Install = ‎تثبيت
Installed = ‎مثبتة بالفعل
Launch Game = ‎إبدء اللعبة
Loading... = ‎تحميل...
MB = ‎ميجا
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/az_AZ.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Already installed
Connection Error = Connection error
Install = Install
Installed = Installed
Launch Game = Launch game
Loading... = Loading...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/bg_BG.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Вече е инсталирано
Connection Error = Грешка при свързването
Install = Инсталирай
Installed = Вече е инсталирано
Launch Game = Launch game
Loading... = Зареждане...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/ca_ES.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = Cap paràmetre coincideix '%1'
Search term = Search term
[Store]
Already Installed = Ja instal·lat
Connection Error = Error de connexió
Install = Instal·lar
Installed = Ja instal·lat
Launch Game = Iniciar joc
Loading... = Carregant...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/cz_CZ.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Již instalováno
Connection Error = Chyba připojení
Install = Nainstalovat
Installed = Již instalováno
Launch Game = Spustit hru
Loading... = Načítání...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/da_DK.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Allerede installeret
Connection Error = Forbindelsesfejl
Install = Installer
Installed = Allerede installeret
Launch Game = Start spil
Loading... = Henter...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/de_DE.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = Keine Übereinstimmungen mit '%1'
Search term = Suchbegriff
[Store]
Already Installed = Bereits installiert
Connection Error = Verbindungsfehler
Install = Installieren
Installed = Bereits installiert
Launch Game = Spiel starten
Loading... = Lade...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/dr_ID.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term
[Store]
Already Installed = Already installed
Connection Error = Connection error
Install = Install
Installed = Installed
Launch Game = Launch game
Loading... = Loading...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/en_US.ini
Expand Up @@ -1176,9 +1176,9 @@ State load undone = State load undone
Untitled PSP game = Untitled PSP game

[Store]
Already Installed = Already installed
Connection Error = Connection error
Install = Install
Installed = Installed
Launch Game = Launch game
Loading... = Loading...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/es_ES.ini
Expand Up @@ -1161,9 +1161,9 @@ No settings matched '%1' = Ningún ajuste coincide '%1'
Search term = Buscar término
[Store]
Already Installed = Ya instalado
Connection Error = Error de conexión
Install = Instalar
Installed = Ya instalado
Launch Game = Iniciar juego
Loading... = Cargando...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/es_LA.ini
Expand Up @@ -1162,9 +1162,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term
[Store]
Already Installed = Ya instalado
Connection Error = Error de conexión
Install = Instalar
Installed = Ya instalado
Launch Game = Lanzar juego
Loading... = Cargando...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/fa_IR.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Already installed
Connection Error = Connection error
Install = Install
Installed = Installed
Launch Game = Launch game
Loading... = Loading...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/fi_FI.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = Ei löytynyt asetuksia hakusanalla '%1'
Search term = Hakusana
[Store]
Already Installed = Jo asennettu
Connection Error = Yhteysvirhe
Install = Asenna
Installed = Jo asennettu
Launch Game = Käynnistä peli
Loading... = Ladataan...
MB = Mt
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/fr_FR.ini
Expand Up @@ -1151,9 +1151,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Déjà installé
Connection Error = Erreur de connexion
Install = Installer
Installed = Déjà installé
Launch Game = Lancer le jeu
Loading... = Chargement...
MB = Mo
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/gl_ES.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Xa instalado
Connection Error = Erro de conexión
Install = Instalar
Installed = Xa instalado
Launch Game = Launch game
Loading... = Cargando...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/gr_EL.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Ήδη εγκατεστημένο
Connection Error = Σφάλμα σύνδεσης
Install = Εγκατάσταση
Installed = Ήδη εγκατεστημένο
Launch Game = Έναρξη παιχνιδιού
Loading... = Φόρτωση...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/he_IL.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term
[Store]
Already Installed = Already installed
Connection Error = Connection error
Install = Install
Installed = Installed
Launch Game = Launch game
Loading... = Loading...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/he_IL_invert.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Already installed
Connection Error = Connection error
Install = Install
Installed = Installed
Launch Game = Launch game
Loading... = Loading...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/hr_HR.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term
[Store]
Already Installed = Već instalirano
Connection Error = Pogreška u spajanju
Install = Instaliraj
Installed = Već instalirano
Launch Game = Pokreni igru
Loading... = Učitavanje...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/hu_HU.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term
[Store]
Already Installed = Már telepítve
Connection Error = Kapcsolódási hiba
Install = Telepítés
Installed = Már telepítve
Launch Game = Játék indítása
Loading... = Töltés...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/id_ID.ini
Expand Up @@ -1160,9 +1160,9 @@ No settings matched '%1' = No settings matched '%1'
Search term = Search term

[Store]
Already Installed = Sudah terpasang
Connection Error = Kesalahan pada koneksi
Install = Pasang
Installed = Sudah terpasang
Launch Game = Jalankan permainan
Loading... = Memuat...
MB = MB
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/it_IT.ini
Expand Up @@ -1161,9 +1161,9 @@ No settings matched '%1' = Nessuna impostazione con corrispondenza: '%1'
Search term = Cerca termine
[Store]
Already Installed = Già installato
Connection Error = Errore di connessione
Install = Installa
Installed = Già installato
Launch Game = Avvia il gioco
Loading... = Caricamento...
MB = MB
Expand Down

0 comments on commit c2850ff

Please sign in to comment.