Zip install: Minor refactoring, putting the content identifier in ZipFileInfo.

This commit is contained in:
Henrik Rydgård committed 2024-09-04 12:53:45 +02:00
1 parent 2694104531
commit 795c4c4262
3 files changed
+22 -20

No files matched your search

+15 -14
View File
@@ -199,14 +199,15 @@ static void countSlashes(const std::string &fileName, int *slashLocation, int *s
}
}
ZipFileContents DetectZipFileContents(const Path &fileName, ZipFileInfo *info) {
bool DetectZipFileContents(const Path &fileName, ZipFileInfo *info) {
struct zip *z = ZipOpenPath(fileName);
if (!z) {
return ZipFileContents::UNKNOWN;
info->contents = ZipFileContents::UNKNOWN;
return false;
}
ZipFileContents retVal = DetectZipFileContents(z, info);
DetectZipFileContents(z, info);
zip_close(z);
return retVal;
return true;
}
inline char asciitolower(char in) {
@@ -215,7 +216,7 @@ inline char asciitolower(char in) {
return in;
}
ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info) {
void DetectZipFileContents(struct zip *z, ZipFileInfo *info) {
int numFiles = zip_get_num_files(z);
// Verify that this is a PSP zip file with the correct layout. We also try
@@ -280,21 +281,21 @@ ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info) {
// If a ZIP is detected as both, let's let the memstick game interpretation prevail.
if (isPSPMemstickGame) {
return ZipFileContents::PSP_GAME_DIR;
info->contents = ZipFileContents::PSP_GAME_DIR;
} else if (isZippedISO) {
return ZipFileContents::ISO_FILE;
info->contents = ZipFileContents::ISO_FILE;
} else if (isTexturePack) {
info->stripChars = stripCharsTexturePack;
info->ignoreMetaFiles = true;
return ZipFileContents::TEXTURE_PACK;
info->contents = ZipFileContents::TEXTURE_PACK;
} else {
return ZipFileContents::UNKNOWN;
info->contents = ZipFileContents::UNKNOWN;
}
}
// Parameters need to be by value, since this is a thread func.
bool GameManager::InstallGame(const Path &url, const Path &fileName, bool deleteAfter) {
SetCurrentThreadName("InstallGame");
bool GameManager::InstallZipContents(const Path &url, const Path &fileName, bool deleteAfter) {
SetCurrentThreadName("InstallZipContents");
if (installDonePending_) {
ERROR_LOG(Log::HLE, "Cannot have two installs in progress at the same time");
@@ -332,9 +333,9 @@ bool GameManager::InstallGame(const Path &url, const Path &fileName, bool delete
}
ZipFileInfo info;
ZipFileContents contents = DetectZipFileContents(z, &info);
DetectZipFileContents(z, &info);
bool success = false;
switch (contents) {
switch (info.contents) {
case ZipFileContents::PSP_GAME_DIR:
INFO_LOG(Log::HLE, "Installing '%s' into '%s'", fileName.c_str(), pspGame.c_str());
// InstallMemstickGame contains code to close (and delete) z.
@@ -773,7 +774,7 @@ bool GameManager::InstallGameOnThread(const Path &url, const Path &fileName, boo
if (InstallInProgress() || installDonePending_) {
return false;
}
installThread_ = std::thread(std::bind(&GameManager::InstallGame, this, url, fileName, deleteAfter));
installThread_ = std::thread(std::bind(&GameManager::InstallZipContents, this, url, fileName, deleteAfter));
return true;
}
+4 -3
View File
@@ -79,7 +79,7 @@ public:
private:
// TODO: The return value on this is a bit pointless, we can't get at it.
bool InstallGame(const Path &url, const Path &tempFileName, bool deleteAfter);
bool InstallZipContents(const Path &url, const Path &tempFileName, bool deleteAfter);
bool InstallMemstickGame(struct zip *z, const Path &zipFile, const Path &dest, const ZipFileInfo &info, bool allowRoot, bool deleteAfter);
bool InstallMemstickZip(struct zip *z, const Path &zipFile, const Path &dest, const ZipFileInfo &info, bool deleteAfter);
bool InstallZippedISO(struct zip *z, int isoFileIndex, const Path &zipfile, bool deleteAfter);
@@ -117,6 +117,7 @@ enum class ZipFileContents {
};
struct ZipFileInfo {
ZipFileContents contents;
int numFiles;
int stripChars; // for PSP game
int isoFileIndex; // for ISO
@@ -124,5 +125,5 @@ struct ZipFileInfo {
bool ignoreMetaFiles;
};
ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info);
ZipFileContents DetectZipFileContents(const Path &fileName, ZipFileInfo *info);
void DetectZipFileContents(struct zip *z, ZipFileInfo *info);
bool DetectZipFileContents(const Path &fileName, ZipFileInfo *info);
+3 -3
View File
@@ -51,9 +51,9 @@ void InstallZipScreen::CreateViews() {
// TODO: Do in the background?
ZipFileInfo zipInfo{};
ZipFileContents contents = DetectZipFileContents(zipPath_, &zipInfo);
DetectZipFileContents(zipPath_, &zipInfo); // Even if this fails, it sets zipInfo->contents.
if (contents == ZipFileContents::ISO_FILE || contents == ZipFileContents::PSP_GAME_DIR) {
if (zipInfo.contents == ZipFileContents::ISO_FILE || zipInfo.contents == ZipFileContents::PSP_GAME_DIR) {
std::string_view question = iz->T("Install game from ZIP file?");
leftColumn->Add(new TextView(question, ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
leftColumn->Add(new TextView(shortFilename, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE)));
@@ -67,7 +67,7 @@ void InstallZipScreen::CreateViews() {
rightColumnItems->Add(new CheckBox(&deleteZipFile_, iz->T("Delete ZIP file")));
returnToHomebrew_ = true;
} else if (contents == ZipFileContents::TEXTURE_PACK) {
} else if (zipInfo.contents == ZipFileContents::TEXTURE_PACK) {
std::string_view question = iz->T("Install textures from ZIP file?");
leftColumn->Add(new TextView(question, ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
leftColumn->Add(new TextView(shortFilename, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE)));