1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

implement VCMIDirs

This commit is contained in:
Andrey Filipenkov
2021-03-02 06:23:00 +03:00
parent d6a92f23aa
commit 8249171066
4 changed files with 94 additions and 10 deletions

15
lib/CIOSUtils.h Normal file
View File

@@ -0,0 +1,15 @@
/*
* CIOSUtils.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
extern const char *ios_documentsPath();
extern const char *ios_cachesPath();
extern const char *ios_bundlePath();
extern const char *ios_frameworksPath();

24
lib/CIOSUtils.m Normal file
View File

@@ -0,0 +1,24 @@
/*
* CIOSUtils.m, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#import "CIOSUtils.h"
@import Foundation;
static const char *standardPath(NSSearchPathDirectory directory)
{
return [NSFileManager.defaultManager URLForDirectory:directory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL].path.UTF8String;
}
const char *ios_documentsPath() { return standardPath(NSDocumentDirectory); }
const char *ios_cachesPath() { return standardPath(NSCachesDirectory); }
const char *ios_bundlePath() { return NSBundle.mainBundle.bundlePath.UTF8String; }
const char *ios_frameworksPath() { return [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:@"Frameworks"].UTF8String; } // TODO: sharedFrameworksPath?

View File

@@ -439,6 +439,11 @@ set(lib_HEADERS
VCMI_Lib.h VCMI_Lib.h
) )
if(APPLE_IOS)
set(lib_SRCS ${lib_SRCS} CIOSUtils.m)
set(lib_HEADERS ${lib_HEADERS} CIOSUtils.h)
endif(APPLE_IOS)
assign_source_group(${lib_SRCS} ${lib_HEADERS}) assign_source_group(${lib_SRCS} ${lib_HEADERS})
add_library(vcmi SHARED ${lib_SRCS} ${lib_HEADERS}) add_library(vcmi SHARED ${lib_SRCS} ${lib_HEADERS})

View File

@@ -349,7 +349,7 @@ class IVCMIDirsUNIX : public IVCMIDirs
boost::filesystem::path clientPath() const override; boost::filesystem::path clientPath() const override;
boost::filesystem::path serverPath() const override; boost::filesystem::path serverPath() const override;
bool developmentMode() const; virtual bool developmentMode() const;
}; };
bool IVCMIDirsUNIX::developmentMode() const bool IVCMIDirsUNIX::developmentMode() const
@@ -362,12 +362,54 @@ bfs::path IVCMIDirsUNIX::clientPath() const { return binaryPath() / "vcmiclient"
bfs::path IVCMIDirsUNIX::serverPath() const { return binaryPath() / "vcmiserver"; } bfs::path IVCMIDirsUNIX::serverPath() const { return binaryPath() / "vcmiserver"; }
#ifdef VCMI_APPLE #ifdef VCMI_APPLE
class VCMIDirsOSX final : public IVCMIDirsUNIX class VCMIDirsApple : public IVCMIDirsUNIX
{
public:
bfs::path userConfigPath() const override;
std::string libraryName(const std::string& basename) const override;
};
bfs::path VCMIDirsApple::userConfigPath() const { return userDataPath() / "config"; }
std::string VCMIDirsApple::libraryName(const std::string& basename) const { return "lib" + basename + ".dylib"; }
#ifdef VCMI_IOS
extern "C" {
#import "CIOSUtils.h"
}
class VCMIDirsIOS final : public VCMIDirsApple
{
public:
bfs::path userDataPath() const override;
bfs::path userCachePath() const override;
bfs::path userLogsPath() const override;
std::vector<bfs::path> dataPaths() const override;
bfs::path libraryPath() const override;
bfs::path binaryPath() const override;
bool developmentMode() const override;
};
bfs::path VCMIDirsIOS::userDataPath() const { return {ios_documentsPath()}; }
bfs::path VCMIDirsIOS::userCachePath() const { return {ios_cachesPath()}; }
bfs::path VCMIDirsIOS::userLogsPath() const { return {ios_documentsPath()}; }
std::vector<bfs::path> VCMIDirsIOS::dataPaths() const { return {userDataPath()}; }
bfs::path VCMIDirsIOS::libraryPath() const { return {ios_frameworksPath()}; }
bfs::path VCMIDirsIOS::binaryPath() const { return {ios_bundlePath()}; }
bool VCMIDirsIOS::developmentMode() const { return false; }
#elif defined(VCMI_MAC)
class VCMIDirsOSX final : public VCMIDirsApple
{ {
public: public:
boost::filesystem::path userDataPath() const override; boost::filesystem::path userDataPath() const override;
boost::filesystem::path userCachePath() const override; boost::filesystem::path userCachePath() const override;
boost::filesystem::path userConfigPath() const override;
boost::filesystem::path userLogsPath() const override; boost::filesystem::path userLogsPath() const override;
std::vector<boost::filesystem::path> dataPaths() const override; std::vector<boost::filesystem::path> dataPaths() const override;
@@ -375,8 +417,6 @@ class VCMIDirsOSX final : public IVCMIDirsUNIX
boost::filesystem::path libraryPath() const override; boost::filesystem::path libraryPath() const override;
boost::filesystem::path binaryPath() const override; boost::filesystem::path binaryPath() const override;
std::string libraryName(const std::string& basename) const override;
void init() override; void init() override;
}; };
@@ -436,7 +476,6 @@ bfs::path VCMIDirsOSX::userDataPath() const
return bfs::path(homeDir) / "Library" / "Application Support" / "vcmi"; return bfs::path(homeDir) / "Library" / "Application Support" / "vcmi";
} }
bfs::path VCMIDirsOSX::userCachePath() const { return userDataPath(); } bfs::path VCMIDirsOSX::userCachePath() const { return userDataPath(); }
bfs::path VCMIDirsOSX::userConfigPath() const { return userDataPath() / "config"; }
bfs::path VCMIDirsOSX::userLogsPath() const bfs::path VCMIDirsOSX::userLogsPath() const
{ {
@@ -463,8 +502,7 @@ std::vector<bfs::path> VCMIDirsOSX::dataPaths() const
bfs::path VCMIDirsOSX::libraryPath() const { return "."; } bfs::path VCMIDirsOSX::libraryPath() const { return "."; }
bfs::path VCMIDirsOSX::binaryPath() const { return "."; } bfs::path VCMIDirsOSX::binaryPath() const { return "."; }
#endif // VCMI_IOS, VCMI_MAC
std::string VCMIDirsOSX::libraryName(const std::string& basename) const { return "lib" + basename + ".dylib"; }
#elif defined(VCMI_XDG) #elif defined(VCMI_XDG)
class VCMIDirsXDG : public IVCMIDirsUNIX class VCMIDirsXDG : public IVCMIDirsUNIX
{ {
@@ -635,9 +673,11 @@ namespace VCMIDirs
static VCMIDirsAndroid singleton; static VCMIDirsAndroid singleton;
#elif defined(VCMI_XDG) #elif defined(VCMI_XDG)
static VCMIDirsXDG singleton; static VCMIDirsXDG singleton;
#elif defined(VCMI_APPLE) #elif defined(VCMI_MAC)
static VCMIDirsOSX singleton; static VCMIDirsOSX singleton;
#endif #elif defined(VCMI_IOS)
static VCMIDirsIOS singleton;
#endif
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)