diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-11-01 20:24:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-11-01 21:33:37 +0300 |
commit | 23b307ad13024134908849b53b756dd6073f8d56 (patch) | |
tree | 29b02c624c07e49a29ed44962282f61de946324d | |
parent | e9ddc70c0202c04535c83753bad2d01a92527b15 (diff) | |
download | plus-23b307ad13024134908849b53b756dd6073f8d56.tar.gz plus-23b307ad13024134908849b53b756dd6073f8d56.tar.bz2 plus-23b307ad13024134908849b53b756dd6073f8d56.tar.xz plus-23b307ad13024134908849b53b756dd6073f8d56.zip |
move physfs initialisation code in physfstools.
-rw-r--r-- | src/main.cpp | 19 | ||||
-rw-r--r-- | src/utils/physfstools.cpp | 21 | ||||
-rw-r--r-- | src/utils/physfstools.h | 1 |
3 files changed, 24 insertions, 17 deletions
diff --git a/src/main.cpp b/src/main.cpp index f9ee5d5d7..765d0d11c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -304,26 +304,11 @@ int main(int argc, char *argv[]) _exit(0); } - // Initialize PhysicsFS -#if defined(__native_client__) - if (!PHYSFS_init("/fakebinary")) -#elif defined(ANDROID) +#ifdef ANDROID mkdir_r(getSdStoragePath().c_str()); - - if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) -#else - if (!PHYSFS_init(argv[0])) #endif - { - std::cout << "Error while initializing PhysFS: " - << PHYSFS_getLastError() << std::endl; - return 1; - } - - PhysFs::updateDirSeparator(); - - atexit((void(*)()) PHYSFS_deinit); + PhysFs::init(argv[0]); XML::initXML(); #if SDL_IMAGE_VERSION_ATLEAST(1, 2, 11) IMG_Init(IMG_INIT_PNG); diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp index cf87fa9ab..36131759b 100644 --- a/src/utils/physfstools.cpp +++ b/src/utils/physfstools.cpp @@ -20,12 +20,33 @@ #include "utils/physfstools.h" +#include <iostream> +#include <unistd.h> + #include "localconsts.h" const char *dirSeparator = nullptr; namespace PhysFs { + void init(const char *const name) + { +#if defined(__native_client__) + if (!PHYSFS_init("/fakebinary")) +#elif defined(ANDROID) + if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) +#else + if (!PHYSFS_init(name)) +#endif + { + std::cout << "Error while initializing PhysFS: " + << PHYSFS_getLastError() << std::endl; + _exit(1); + } + updateDirSeparator(); + atexit((void(*)()) PHYSFS_deinit); + } + void updateDirSeparator() { dirSeparator = PHYSFS_getDirSeparator(); diff --git a/src/utils/physfstools.h b/src/utils/physfstools.h index cb64a981b..fd760f287 100644 --- a/src/utils/physfstools.h +++ b/src/utils/physfstools.h @@ -25,6 +25,7 @@ namespace PhysFs { + void init(const char *const name); void updateDirSeparator(); const char *getDirSeparator(); const char *getBaseDir(); |