using_system_physfs
authorDebian Games Team <pkg-games-devel@lists.alioth.debian.org>
Fri, 17 Oct 2014 16:00:32 +0000 (17:00 +0100)
committerGianfranco Costamagna <costamagnagianfranco@yahoo.it>
Fri, 17 Oct 2014 16:00:32 +0000 (17:00 +0100)
# HG changeset patch
# User sheepluva
# Date 1390060550 -3600
#      Sat Jan 18 16:55:50 2014 +0100
# Branch 0.9.20
# Node ID f74ae7ee358599195c8e646f1f8e8652d0d38a24
# Parent  9d79a52c5586b3f2350c3d9dea6b9906b011c3ab
Description:
backport of PhysicsFS 2.0 compatibility patches

Gbp-Pq: Name using_system_physfs.patch

CMakeLists.txt
INSTALL
hedgewars/CMakeLists.txt
misc/libphyslayer/CMakeLists.txt
misc/libphyslayer/hwpacksmounter.h
misc/libphyslayer/physfscompat.c [new file with mode: 0644]
misc/libphyslayer/physfscompat.h [new file with mode: 0644]
misc/libphyslayer/physfslualoader.c
misc/libphyslayer/physfsrwops.h

index 20ab9b70e9f77addf207a534a137dcfe3474fe0b..725e1a44629044ce9b1f34f6d8ced31ebf22b83d 100644 (file)
@@ -18,12 +18,12 @@ option(NOVIDEOREC "Disable video recording (off)" OFF)
 
 #libraries are built shared unless explicitly added as a static
 option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON)
-#set this to ON when 2.1.0 becomes more widespread (and only for linux)
-option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
 
 if(WIN32 OR APPLE)
+    option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
     option(LUA_SYSTEM "Use system lua (off)" OFF)
 else()
+    option(PHYSFS_SYSTEM "Use system physfs (on)" ON)
     option(LUA_SYSTEM "Use system lua (on)" ON)
 endif()
 
@@ -152,8 +152,9 @@ if (${PHYSFS_SYSTEM})
         string(REGEX MATCH "([0-9]+)" physfs_patchversion "${physfs_patchversion}")
         set(physfs_detected_ver "${physfs_majorversion}.${physfs_minorversion}.${physfs_patchversion}")
 
-        if (physfs_detected_ver VERSION_LESS "2.1.0")
-            message(FATAL_ERROR "PhysFS version is too old (dected ${physfs_detected_ver}, required 2.1.0)")
+        if (physfs_detected_ver VERSION_LESS "2.0.0")
+            message(FATAL_ERROR "PhysFS version is too old (detected ${physfs_detected_ver}, required 2.0.0)\n"
+                                "Perform an update or rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
             set(physfs_too_old true)
         endif()
     endif()
diff --git a/INSTALL b/INSTALL
index 898c5192f89ebeb1377a21ec5555b64251f08a8e..ad8977dad64d35a541c861af9f6b8d8a5d4baae1 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -8,7 +8,7 @@ To compile and install you need:
  - SDL_image >= 1.2
  - SDL_ttf >= 2.0
  - Lua >= 5.1.0
- - Physfs >= 2.1.0
+ - Physfs >= 2.0.0
 For server:
  - Glasgow Haskell Compiler >= 6.10
  - bytestring-show package
index f7a5983c8a138dbd5a19744469c0c2501e0c2681..6f31669ac14084f6b14286a0f4ea13671aebd2f8 100644 (file)
@@ -141,7 +141,7 @@ else()
     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
 endif()
 
-if(PHYSFS_FOUND)
+if(PHYSFS_SYSTEM)
     get_filename_component(PHYSFS_LIBRARY_DIR ${PHYSFS_LIBRARY} PATH)
     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${PHYSFS_LIBRARY}")
 else()
index 46559fee12c061708d8b938213f750ddc4e37781..a134df9c1bea66bfe600e05856840d7376e6182c 100644 (file)
@@ -7,6 +7,7 @@ include_directories(${LUA_INCLUDE_DIR})
 ## extra functions needed by Hedgewars
 ## TODO: maybe it's better to have them in a separate library?
 set(PHYSLAYER_SRCS
+    physfscompat.c
     physfsrwops.c
     physfslualoader.c
     hwpacksmounter.c
index 9d7180dc4f9401e3022a985141dc53c847eaf008..5159a96c00515f058efeb5851c5b49739950467c 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "physfs.h"
 
+#include "physfscompat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/misc/libphyslayer/physfscompat.c b/misc/libphyslayer/physfscompat.c
new file mode 100644 (file)
index 0000000..063ae26
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "physfscompat.h"
+
+#ifdef HW_PHYSFS_COMPAT
+
+PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
+{
+    PHYSFS_File * handle;
+
+    if (PHYSFS_exists(fname))
+    {
+        handle = PHYSFS_openRead(fname);
+        if (handle)
+        {
+            stat->filesize = PHYSFS_fileLength(handle);
+            PHYSFS_close(handle);
+            handle = 0;
+        }
+        else
+            stat->filesize = -1;
+
+        stat->modtime = PHYSFS_getLastModTime(fname);
+        stat->createtime = -1;
+        stat->accesstime = -1;
+
+        if (PHYSFS_isSymbolicLink(fname))
+            stat->filetype = PHYSFS_FILETYPE_SYMLINK;
+        else if (PHYSFS_isDirectory(fname))
+            stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
+        else stat->filetype = PHYSFS_FILETYPE_REGULAR;
+
+        stat->readonly = 0; /* not supported */
+
+        /* success */
+        return 1;
+    }
+
+    /* does not exist, can't stat */
+    return 0;
+}
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
+                                           PHYSFS_uint64 len)
+{
+    return PHYSFS_read(handle, buffer, 1, len);
+}
+
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
+                                            const void *buffer,
+                                            PHYSFS_uint64 len)
+{
+    return PHYSFS_write(handle, buffer, 1, len);
+}
+
+#endif /* HW_PHYSFS_COMPAT */
diff --git a/misc/libphyslayer/physfscompat.h b/misc/libphyslayer/physfscompat.h
new file mode 100644 (file)
index 0000000..bab372a
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef _HEDGEWARS_PHYSFSCOMPAT_C_
+#define _HEDGEWARS_PHYSFSCOMPAT_C_
+
+#include "physfs.h"
+
+#if PHYSFS_VER_MAJOR == 2
+#if PHYSFS_VER_MINOR == 0
+
+#define HW_PHYSFS_COMPAT
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PHYSFS_DECL __EXPORT__
+
+typedef enum PHYSFS_FileType
+{
+       PHYSFS_FILETYPE_REGULAR,
+       PHYSFS_FILETYPE_DIRECTORY,
+       PHYSFS_FILETYPE_SYMLINK,
+       PHYSFS_FILETYPE_OTHER
+} PHYSFS_FileType;
+
+typedef struct PHYSFS_Stat
+{
+       PHYSFS_sint64 filesize;
+       PHYSFS_sint64 modtime;
+       PHYSFS_sint64 createtime;
+       PHYSFS_sint64 accesstime;
+       PHYSFS_FileType filetype;
+       int readonly;
+} PHYSFS_Stat;
+
+PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
+                                           PHYSFS_uint64 len);
+
+
+PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
+                                            const void *buffer,
+                                            PHYSFS_uint64 len);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PHYSFS_VER_MAJOR == 2 */
+#endif /* PHYSFS_VER_MINOR == 0 */
+
+#endif /* _HEDGEWARS_PHYSFSCOMPAT_C_ */
index eda92da880799d53b522f9df67fbfbb772c45858..c415b7ea56029409498561f1478aa358d542b3c0 100644 (file)
@@ -1,6 +1,8 @@
 #include "lua.h"
 #include "physfs.h"
 
+#include "physfscompat.h"
+
 #define BUFSIZE 1024
 
 void *physfsReaderBuffer;
index e44ec83d9a364e21ee73c9e9bff77b11896358c6..05637cc3e1ffa2570f48c8e443aab851c2dd1c95 100644 (file)
@@ -26,6 +26,8 @@
 #include "physfs.h"
 #include "SDL.h"
 
+#include "physfscompat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif