add compatibility for physicsfs 2.0
authorsheepluva
Wed, 15 Jan 2014 23:48:18 +0100
changeset 9991 3858d99476f5
parent 9990 c8443c53eb33
child 9992 1773ef634b78
add compatibility for physicsfs 2.0
CMakeLists.txt
INSTALL
hedgewars/CMakeLists.txt
misc/libphyslayer/CMakeLists.txt
misc/libphyslayer/hwpacksmounter.h
misc/libphyslayer/physfscompat.c
misc/libphyslayer/physfscompat.h
misc/libphyslayer/physfslualoader.c
misc/libphyslayer/physfsrwops.h
--- a/CMakeLists.txt	Thu Jan 16 01:27:44 2014 +0400
+++ b/CMakeLists.txt	Wed Jan 15 23:48:18 2014 +0100
@@ -153,8 +153,8 @@
         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)")
             set(physfs_too_old true)
         endif()
     endif()
--- a/INSTALL	Thu Jan 16 01:27:44 2014 +0400
+++ b/INSTALL	Wed Jan 15 23:48:18 2014 +0100
@@ -8,7 +8,7 @@
  - SDL_image >= 1.2
  - SDL_ttf >= 2.0
  - Lua >= 5.1.0
- - Physfs >= 2.1.0
+ - Physfs >= 2.0.3
 For server:
  - Glasgow Haskell Compiler >= 6.10
  - bytestring-show package
--- a/hedgewars/CMakeLists.txt	Thu Jan 16 01:27:44 2014 +0400
+++ b/hedgewars/CMakeLists.txt	Wed Jan 15 23:48:18 2014 +0100
@@ -141,7 +141,7 @@
     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()
--- a/misc/libphyslayer/CMakeLists.txt	Thu Jan 16 01:27:44 2014 +0400
+++ b/misc/libphyslayer/CMakeLists.txt	Wed Jan 15 23:48:18 2014 +0100
@@ -7,6 +7,7 @@
 ## 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
--- a/misc/libphyslayer/hwpacksmounter.h	Thu Jan 16 01:27:44 2014 +0400
+++ b/misc/libphyslayer/hwpacksmounter.h	Wed Jan 15 23:48:18 2014 +0100
@@ -3,6 +3,8 @@
 
 #include "physfs.h"
 
+#include "physfscompat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/libphyslayer/physfscompat.c	Wed Jan 15 23:48:18 2014 +0100
@@ -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 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/libphyslayer/physfscompat.h	Wed Jan 15 23:48:18 2014 +0100
@@ -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_ */
--- a/misc/libphyslayer/physfslualoader.c	Thu Jan 16 01:27:44 2014 +0400
+++ b/misc/libphyslayer/physfslualoader.c	Wed Jan 15 23:48:18 2014 +0100
@@ -1,6 +1,8 @@
 #include "lua.h"
 #include "physfs.h"
 
+#include "physfscompat.h"
+
 #define BUFSIZE 1024
 
 void *physfsReaderBuffer;
--- a/misc/libphyslayer/physfsrwops.h	Thu Jan 16 01:27:44 2014 +0400
+++ b/misc/libphyslayer/physfsrwops.h	Wed Jan 15 23:48:18 2014 +0100
@@ -26,6 +26,8 @@
 #include "physfs.h"
 #include "SDL.h"
 
+#include "physfscompat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif