mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Store: Implement progress bar for homebrew installs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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.
|
||||
@@ -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;
|
||||
@@ -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:
|
||||
@@ -644,6 +648,7 @@ bail:
|
||||
File::DeleteDir(iter);
|
||||
}
|
||||
SetInstallError(sy->T("Storage full"));
|
||||
g_OSD.RemoveProgressBar("install", false, 0.5f);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user