Mount .hwt files found in Data folder physfslayer
authorunc0rr
Sun, 18 Nov 2012 00:37:23 +0400
branchphysfslayer
changeset 8052 845b5ae03841
parent 8049 133e22b5c410
child 8055 04dd8b7fb605
Mount .hwt files found in Data folder
QTfrontend/CMakeLists.txt
QTfrontend/main.cpp
QTfrontend/util/FileEngine.cpp
QTfrontend/util/FileEngine.h
hedgewars/uPhysFSLayer.pas
misc/physfs/extras/CMakeLists.txt
misc/physfs/extras/hwpacksmounter.c
misc/physfs/extras/hwpacksmounter.h
project_files/hedgewars.pro
--- a/QTfrontend/CMakeLists.txt	Sat Nov 17 22:45:30 2012 +0400
+++ b/QTfrontend/CMakeLists.txt	Sun Nov 18 00:37:23 2012 +0400
@@ -45,6 +45,7 @@
 include_directories(${FFMPEG_INCLUDE_DIR})
 include_directories(${CMAKE_SOURCE_DIR}/misc/quazip)
 include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/src)
+include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/extras)
 if(UNIX)
     # HACK: in freebsd cannot find iconv.h included via SDL.h
     include_directories("/usr/local/include")
@@ -179,6 +180,7 @@
 set(HW_LINK_LIBS
     quazip
     physfs
+    physfsrwops
     ${QT_LIBRARIES}
     ${SDL_LIBRARY}
     ${SDLMIXER_LIBRARY}
--- a/QTfrontend/main.cpp	Sat Nov 17 22:45:30 2012 +0400
+++ b/QTfrontend/main.cpp	Sun Nov 18 00:37:23 2012 +0400
@@ -226,6 +226,7 @@
     engine.mount(cfgdir->absolutePath() + "/Data");
     engine.mount(cfgdir->absolutePath(), "/config");
     engine.setWriteDir(cfgdir->absolutePath());
+    engine.mountPacks();
 
     QTranslator Translator;
     {
--- a/QTfrontend/util/FileEngine.cpp	Sat Nov 17 22:45:30 2012 +0400
+++ b/QTfrontend/util/FileEngine.cpp	Sun Nov 18 00:37:23 2012 +0400
@@ -3,6 +3,7 @@
  */
 
 
+#include "hwpacksmounter.h"
 #include "FileEngine.h"
 
 
@@ -265,6 +266,10 @@
     PHYSFS_setWriteDir(path.toUtf8().constData());
 }
 
+void FileEngineHandler::mountPacks()
+{
+    hedgewarsMountPackages();
+}
 
 
 FileEngineIterator::FileEngineIterator(QDir::Filters filters, const QStringList &nameFilters, const QStringList &entries)
--- a/QTfrontend/util/FileEngine.h	Sat Nov 17 22:45:30 2012 +0400
+++ b/QTfrontend/util/FileEngine.h	Sun Nov 18 00:37:23 2012 +0400
@@ -66,6 +66,7 @@
         void mount(const QString & path);
         void mount(const QString & path, const QString & mountPoint);
         void setWriteDir(const QString & path);
+        void mountPacks();
 
 //    private:
         static const QString scheme;
--- a/hedgewars/uPhysFSLayer.pas	Sat Nov 17 22:45:30 2012 +0400
+++ b/hedgewars/uPhysFSLayer.pas	Sun Nov 18 00:37:23 2012 +0400
@@ -38,6 +38,8 @@
 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external;
 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external;
 
+procedure hedgewarsMountPackages(); cdecl; external;
+
 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
 begin
     exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
@@ -103,6 +105,8 @@
     AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
     i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true);
     AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
+
+    hedgewarsMountPackages;
 end;
 
 procedure freeModule;
--- a/misc/physfs/extras/CMakeLists.txt	Sat Nov 17 22:45:30 2012 +0400
+++ b/misc/physfs/extras/CMakeLists.txt	Sun Nov 18 00:37:23 2012 +0400
@@ -4,6 +4,6 @@
 include_directories(${CMAKE_SOURCE_DIR}/misc/liblua)
 include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/src)
 
-add_library(physfsrwops STATIC physfsrwops.c physfslualoader.c)
+add_library(physfsrwops STATIC physfsrwops.c physfslualoader.c hwpacksmounter.c)
 
 add_dependencies(physfsrwops lua)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/physfs/extras/hwpacksmounter.c	Sun Nov 18 00:37:23 2012 +0400
@@ -0,0 +1,36 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <physfs.h>
+
+#include "hwpacksmounter.h"
+
+void hedgewarsMountPackages()
+{
+    char ** filesList = PHYSFS_enumerateFiles("/");
+    char **i;
+
+    for (i = filesList; *i != NULL; i++)
+    {
+        char * fileName = *i;
+        int fileNameLength = strlen(fileName);
+        if (fileNameLength > 4)
+            if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
+            {
+                const char * dir = PHYSFS_getRealDir(fileName);
+                if(dir)
+                {
+                    char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
+                    strcpy(fullPath, dir);
+                    strcat(fullPath, "/");
+                    strcat(fullPath, fileName);
+
+                    PHYSFS_mount(fullPath, NULL, 1);
+
+                    free(fullPath);
+                }
+            }
+    }
+
+    PHYSFS_freeList(filesList);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/physfs/extras/hwpacksmounter.h	Sun Nov 18 00:37:23 2012 +0400
@@ -0,0 +1,15 @@
+#ifndef HEDGEWARS_PACKAGES_MOUNTER_H
+#define HEDGEWARS_PACKAGES_MOUNTER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void hedgewarsMountPackages();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- a/project_files/hedgewars.pro	Sat Nov 17 22:45:30 2012 +0400
+++ b/project_files/hedgewars.pro	Sun Nov 18 00:37:23 2012 +0400
@@ -1,7 +1,7 @@
 TEMPLATE = app
 TARGET = hedgewars
 DEPENDPATH += ../QTfrontend/
-INCLUDEPATH += ../QTfrontend/
+INCLUDEPATH += ../QTfrontend
 INCLUDEPATH += ../QTfrontend/model
 INCLUDEPATH += ../QTfrontend/ui
 INCLUDEPATH += ../QTfrontend/ui/widget
@@ -10,7 +10,8 @@
 INCLUDEPATH += ../QTfrontend/net
 INCLUDEPATH += ../QTfrontend/util
 INCLUDEPATH += ../misc/quazip/
-INCLUDEPATH += ../misc/physfs/src/
+INCLUDEPATH += ../misc/physfs/src
+INCLUDEPATH += ../misc/physfs/extras
 
 DESTDIR = ../bin
 
@@ -233,7 +234,7 @@
 
 RESOURCES += ../QTfrontend/hedgewars.qrc
 
-LIBS += -L../bin -lquazip -lphysfs
+LIBS += -L../bin -lquazip -lphysfs -lphysfsrwops
 
 macx {
     QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6