Minor cleanup. Fix file handle leak when opening zip files from the main screen.

This commit is contained in:
Henrik Rydgård
2025-04-07 15:42:51 +02:00
parent 0dec3526a5
commit 605daf879b
5 changed files with 25 additions and 8 deletions
+1
View File
@@ -45,6 +45,7 @@ FileLoader *ConstructFileLoader(const Path &filename) {
}
// TODO : improve, look in the file more
// Does not take ownership.
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString) {
errorString->clear();
if (fileLoader == nullptr) {
+3 -1
View File
@@ -52,6 +52,7 @@
GameManager g_GameManager;
// Close the return value with ZipClose (if non-null, of course).
struct zip *ZipOpenPath(Path fileName) {
int error = 0;
// Need to special case for content URI here, similar to OpenCFile.
@@ -73,7 +74,8 @@ struct zip *ZipOpenPath(Path fileName) {
}
void ZipClose(struct zip *z) {
zip_close(z);
if (z)
zip_close(z);
}
GameManager::GameManager() {
+14
View File
@@ -63,6 +63,18 @@ enum class OpType {
Done,
};
static const char *OpTypeToString(OpType type) {
switch (type) {
case OpType::None: return "None";
case OpType::UpdateStallAddr: return "UpdateStallAddr";
case OpType::EnqueueList: return "EnqueueList";
case OpType::ListSync: return "ListSync";
case OpType::ReapplyGfxState: return "ReapplyGfxState";
case OpType::Done: return "Done";
default: return "N/A";
}
}
struct Operation {
OpType type;
u32 listID; // also listPC in EnqueueList
@@ -888,6 +900,8 @@ static u32 LoadReplay(const std::string &filename) {
}
void Replay_Unload() {
// TODO: Hm, we have a problem here. We might be paused inside a replay and exiting - in this case, the thread is still running.
_dbg_assert_(!replayThread.joinable());
lastExecFilename.clear();
+5 -4
View File
@@ -59,7 +59,7 @@ void InstallZipScreen::CreateViews() {
std::string shortFilename = zipPath_.GetFilename();
// TODO: Do in the background?
struct zip *z = ZipOpenPath(zipPath_);
struct zip *zipFile = ZipOpenPath(zipPath_);
bool showDeleteCheckbox = false;
returnToHomebrew_ = false;
@@ -71,8 +71,8 @@ void InstallZipScreen::CreateViews() {
std::vector<Path> destOptions;
if (z) {
DetectZipFileContents(z, &zipFileInfo_); // Even if this fails, it sets zipInfo->contents.
if (zipFile) {
DetectZipFileContents(zipFile, &zipFileInfo_); // Even if this fails, it sets zipInfo->contents.
if (zipFileInfo_.contents == ZipFileContents::ISO_FILE || zipFileInfo_.contents == ZipFileContents::PSP_GAME_DIR) {
std::string_view question = iz->T("Install game from ZIP file?");
@@ -120,7 +120,7 @@ void InstallZipScreen::CreateViews() {
leftColumn->Add(new TextView(zipFileInfo_.gameTitle + ": " + zipFileInfo_.savedataDir));
Path savedataDir = GetSysDirectory(DIRECTORY_SAVEDATA);
bool overwrite = !CanExtractWithoutOverwrite(z, savedataDir, 50);
bool overwrite = !CanExtractWithoutOverwrite(zipFile, savedataDir, 50);
destFolders_.push_back(savedataDir);
@@ -163,6 +163,7 @@ void InstallZipScreen::CreateViews() {
} else {
leftColumn->Add(new TextView(iz->T("Zip file does not contain PSP software"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
}
ZipClose(zipFile);
} else {
leftColumn->Add(new TextView(er->T("The file is not a valid zip file"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
}
+2 -3
View File
@@ -77,14 +77,13 @@ bool MainScreen::showHomebrewTab = false;
bool LaunchFile(ScreenManager *screenManager, const Path &path) {
// Depending on the file type, we don't want to launch EmuScreen at all.
auto loader = ConstructFileLoader(path);
std::unique_ptr<FileLoader> loader(ConstructFileLoader(path));
if (!loader) {
return false;
}
std::string errorString;
IdentifiedFileType type = Identify_File(loader, &errorString);
delete loader;
IdentifiedFileType type = Identify_File(loader.get(), &errorString);
switch (type) {
case IdentifiedFileType::ARCHIVE_ZIP: