From e4582597b09db7d1e18959b67b2641be3feebd8f Mon Sep 17 00:00:00 2001 From: Debian Games Team Date: Fri, 17 Oct 2014 17:00:32 +0100 Subject: [PATCH] using_system_physfs # 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 | 9 ++-- INSTALL | 2 +- hedgewars/CMakeLists.txt | 2 +- misc/libphyslayer/CMakeLists.txt | 1 + misc/libphyslayer/hwpacksmounter.h | 2 + misc/libphyslayer/physfscompat.c | 73 +++++++++++++++++++++++++++++ misc/libphyslayer/physfscompat.h | 71 ++++++++++++++++++++++++++++ misc/libphyslayer/physfslualoader.c | 2 + misc/libphyslayer/physfsrwops.h | 2 + 9 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 misc/libphyslayer/physfscompat.c create mode 100644 misc/libphyslayer/physfscompat.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 20ab9b7..725e1a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 898c519..ad8977d 100644 --- 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 diff --git a/hedgewars/CMakeLists.txt b/hedgewars/CMakeLists.txt index f7a5983..6f31669 100644 --- a/hedgewars/CMakeLists.txt +++ b/hedgewars/CMakeLists.txt @@ -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() diff --git a/misc/libphyslayer/CMakeLists.txt b/misc/libphyslayer/CMakeLists.txt index 46559fe..a134df9 100644 --- a/misc/libphyslayer/CMakeLists.txt +++ b/misc/libphyslayer/CMakeLists.txt @@ -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 diff --git a/misc/libphyslayer/hwpacksmounter.h b/misc/libphyslayer/hwpacksmounter.h index 9d7180d..5159a96 100644 --- a/misc/libphyslayer/hwpacksmounter.h +++ b/misc/libphyslayer/hwpacksmounter.h @@ -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 index 0000000..063ae26 --- /dev/null +++ b/misc/libphyslayer/physfscompat.c @@ -0,0 +1,73 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2004-2014 Andrey Korotaev + * + * 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 index 0000000..bab372a --- /dev/null +++ b/misc/libphyslayer/physfscompat.h @@ -0,0 +1,71 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2004-2014 Andrey Korotaev + * + * 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_ */ diff --git a/misc/libphyslayer/physfslualoader.c b/misc/libphyslayer/physfslualoader.c index eda92da..c415b7e 100644 --- a/misc/libphyslayer/physfslualoader.c +++ b/misc/libphyslayer/physfslualoader.c @@ -1,6 +1,8 @@ #include "lua.h" #include "physfs.h" +#include "physfscompat.h" + #define BUFSIZE 1024 void *physfsReaderBuffer; diff --git a/misc/libphyslayer/physfsrwops.h b/misc/libphyslayer/physfsrwops.h index e44ec83..05637cc 100644 --- a/misc/libphyslayer/physfsrwops.h +++ b/misc/libphyslayer/physfsrwops.h @@ -26,6 +26,8 @@ #include "physfs.h" #include "SDL.h" +#include "physfscompat.h" + #ifdef __cplusplus extern "C" { #endif -- 2.30.2