From a23a4cbbd082448d6e0cafbe71d287e565071b75 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 17 May 2022 11:52:45 -0700 Subject: [PATCH] Improve vlog statements when `PHYSFS_openRead` fails There are three different places where we call PHYSFS_openRead. This commit makes sure all of them print a statement upon failure along with the PhysFS reason for failure, and assigns the log level of each print as so: - FILESYSTEM_loadFileToMemory: Debug print (previously no print existed in the first place), because some files (such as font.txt) may or may not be needed, but if it isn't then no need to print and worry the user. The game will error anyway if a critical file like a graphics file is missing. - FILESYSTEM_loadBinaryBlob: Debug print (previously info print), because sometimes it's not needed, such as mmmmmm.vvv. I remember one user being worried that the game printed "Unable to open file mmmmmm.vvv" when it's not critical unlike vvvvvvmusic.vvv (and that file is assumed to exist if data.zip exists anyways). Though maybe we should move to loose-leaf files to save on memory usage (and so we don't have to use special tools to modify a binary blob)... - FILESYSTEM_loadZip: Error print. If we're calling this function, we really do expect the zip to be loaded, and if it fails because we can't open the file in the first place, then it would be good to know why. --- desktop_version/src/FileSystemUtils.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index ea87ef89..ab516972 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -355,6 +355,14 @@ static bool FILESYSTEM_mountAssetsFrom(const char *fname) void FILESYSTEM_loadZip(const char* filename) { PHYSFS_File* zip = PHYSFS_openRead(filename); + if (zip == NULL) + { + vlog_error( + "Could not read zip %s: %s", + filename, + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) + ); + } if (!PHYSFS_mountHandle(zip, filename, "levels", 1)) { @@ -589,6 +597,11 @@ void FILESYSTEM_loadFileToMemory( handle = PHYSFS_openRead(name); if (handle == NULL) { + vlog_debug( + "Could not read file %s: %s", + name, + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) + ); goto fail; } length = PHYSFS_fileLength(handle); @@ -673,7 +686,11 @@ bool FILESYSTEM_loadBinaryBlob(binaryBlob* blob, const char* filename) handle = PHYSFS_openRead(path); if (handle == NULL) { - vlog_info("Unable to open file %s", filename); + vlog_debug( + "Could not read binary blob %s: %s", + filename, + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) + ); return false; }