added storing state of checked zip file
authorHolger Schemel <holger.schemel@virtion.de>
Fri, 20 Dec 2024 18:33:23 +0000 (19:33 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Fri, 20 Dec 2024 12:34:21 +0000 (13:34 +0100)
src/libgame/setup.c
src/libgame/system.c
src/libgame/system.h

index aa0a44f54d19cb42a6024dfdc0290c7f5dad0f33..1cad240d900b825e252d6798e8a39a4fb6db0ac6 100644 (file)
@@ -3738,8 +3738,7 @@ int GetZipFileTreeType(char *zip_filename)
   return tree_type;
 }
 
-static boolean CheckZipFileForDirectory(char *zip_filename, char *directory,
-                                       int tree_type)
+static int CheckZipFileForDirectoryExt(char *zip_filename, char *directory, int tree_type)
 {
   static char *top_dir_path = NULL;
   static char *top_dir_conf_filename = NULL;
@@ -3755,20 +3754,20 @@ static boolean CheckZipFileForDirectory(char *zip_filename, char *directory,
 
   // check if valid configuration filename determined
   if (conf_basename == NULL || strEqual(conf_basename, ""))
-    return FALSE;
+    return ZIP_FILE_ERROR_CONF_INVALID;
 
   char **zip_entries = zip_list(zip_filename);
 
   // check if zip file successfully opened
   if (zip_entries == NULL || zip_entries[0] == NULL)
-    return FALSE;
+    return ZIP_FILE_ERROR_CANNOT_OPEN;
 
   // first zip file entry is expected to be top level directory
   char *top_dir = zip_entries[0];
 
   // check if valid top level directory found in zip file
   if (!strSuffix(top_dir, "/"))
-    return FALSE;
+    return ZIP_FILE_ERROR_DIR_NOT_FOUND;
 
   // get path of extracted top level directory
   top_dir_path = getPath2(directory, top_dir);
@@ -3779,7 +3778,7 @@ static boolean CheckZipFileForDirectory(char *zip_filename, char *directory,
 
   // check if zip file's top level directory already exists in target directory
   if (fileExists(top_dir_path))                // (checks for file and directory)
-    return FALSE;
+    return ZIP_FILE_ERROR_DIR_EXISTS;
 
   // get filename of configuration file in top level directory
   top_dir_conf_filename = getStringCat2(top_dir, conf_basename);
@@ -3791,7 +3790,7 @@ static boolean CheckZipFileForDirectory(char *zip_filename, char *directory,
   {
     // check if every zip file entry is below top level directory
     if (!strPrefix(zip_entries[i], top_dir))
-      return FALSE;
+      return ZIP_FILE_ERROR_FILE_INVALID;
 
     // check if this zip file entry is the configuration filename
     if (strEqual(zip_entries[i], top_dir_conf_filename))
@@ -3802,9 +3801,16 @@ static boolean CheckZipFileForDirectory(char *zip_filename, char *directory,
 
   // check if valid configuration filename was found in zip file
   if (!found_top_dir_conf_filename)
-    return FALSE;
+    return ZIP_FILE_ERROR_CONF_NOT_FOUND;
 
-  return TRUE;
+  return ZIP_FILE_OK;
+}
+
+static boolean CheckZipFileForDirectory(char *zip_filename, char *directory, int tree_type)
+{
+  zip_file.state = CheckZipFileForDirectoryExt(zip_filename, directory, tree_type);
+
+  return (zip_file.state == ZIP_FILE_OK);
 }
 
 char *ExtractZipFileIntoDirectory(char *zip_filename, char *directory,
index ae76f6f063c1ff6cd3b038d73580e14aead38c04..c9a72bbedbd6c54db0fc37388e39f4a94f39eae6 100644 (file)
@@ -41,6 +41,7 @@ struct ArtworkInfo    artwork;
 struct JoystickInfo    joystick;
 struct SetupInfo       setup;
 struct UserInfo                user;
+struct ZipFileInfo     zip_file;
 
 LevelDirTree          *leveldir_first_all = NULL;
 LevelDirTree          *leveldir_first = NULL;
index 4a332d0ff64ee6b475fc0e9e6da970bbf192070a..df29a2666bfab58e0833a6518257440d20ab7f17 100644 (file)
@@ -1643,6 +1643,20 @@ struct UserInfo
   int nr;
 };
 
+#define ZIP_FILE_OK                            0
+#define ZIP_FILE_ERROR_CANNOT_OPEN             1
+#define ZIP_FILE_ERROR_DIR_NOT_FOUND           2
+#define ZIP_FILE_ERROR_DIR_EXISTS              3
+#define ZIP_FILE_ERROR_FILE_INVALID            4
+#define ZIP_FILE_ERROR_CONF_INVALID            5
+#define ZIP_FILE_ERROR_CONF_NOT_FOUND          6
+#define ZIP_FILE_ERROR_UNKNOWN                 9
+
+struct ZipFileInfo
+{
+  int state;
+};
+
 struct TreeInfo
 {
   struct TreeInfo **node_top;  // topmost node in tree
@@ -1973,6 +1987,7 @@ extern struct ArtworkInfo artwork;
 extern struct JoystickInfo     joystick;
 extern struct SetupInfo                setup;
 extern struct UserInfo         user;
+extern struct ZipFileInfo      zip_file;
 
 extern LevelDirTree           *leveldir_first_all;
 extern LevelDirTree           *leveldir_first;