mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
refactor VCMIDirs for Android
removes inheritance from VCMIDirsXDG to get rid of defining M_*_DIR variables
This commit is contained in:
109
lib/VCMIDirs.cpp
109
lib/VCMIDirs.cpp
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#ifdef VCMI_IOS
|
#ifdef VCMI_IOS
|
||||||
#include "iOS_utils.h"
|
#include "iOS_utils.h"
|
||||||
|
#elif defined(VCMI_ANDROID)
|
||||||
|
#include "CAndroidVMHelper.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
@@ -60,11 +62,6 @@ void IVCMIDirs::init()
|
|||||||
bfs::create_directories(userSavePath());
|
bfs::create_directories(userSavePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
|
||||||
#include "CAndroidVMHelper.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VCMI_WINDOWS
|
#ifdef VCMI_WINDOWS
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
@@ -529,6 +526,57 @@ 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
|
#endif // VCMI_IOS, VCMI_MAC
|
||||||
|
|
||||||
|
#elif defined(VCMI_ANDROID)
|
||||||
|
class VCMIDirsAndroid : public IVCMIDirsUNIX
|
||||||
|
{
|
||||||
|
std::string basePath;
|
||||||
|
std::string internalPath;
|
||||||
|
std::string nativePath;
|
||||||
|
public:
|
||||||
|
std::string libraryName(const std::string & basename) const override;
|
||||||
|
bfs::path fullLibraryPath(const std::string & desiredFolder, const std::string & baseLibName) const override;
|
||||||
|
bfs::path binaryPath() const override;
|
||||||
|
bfs::path libraryPath() const override;
|
||||||
|
bfs::path userDataPath() const override;
|
||||||
|
bfs::path userCachePath() const override;
|
||||||
|
bfs::path userConfigPath() const override;
|
||||||
|
|
||||||
|
std::vector<bfs::path> dataPaths() const override;
|
||||||
|
|
||||||
|
void init() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string VCMIDirsAndroid::libraryName(const std::string & basename) const { return "lib" + basename + ".so"; }
|
||||||
|
bfs::path VCMIDirsAndroid::binaryPath() const { return "."; }
|
||||||
|
bfs::path VCMIDirsAndroid::libraryPath() const { return nativePath; }
|
||||||
|
bfs::path VCMIDirsAndroid::userDataPath() const { return basePath; }
|
||||||
|
bfs::path VCMIDirsAndroid::userCachePath() const { return userDataPath() / "cache"; }
|
||||||
|
bfs::path VCMIDirsAndroid::userConfigPath() const { return userDataPath() / "config"; }
|
||||||
|
|
||||||
|
bfs::path VCMIDirsAndroid::fullLibraryPath(const std::string & desiredFolder, const std::string & baseLibName) const
|
||||||
|
{
|
||||||
|
// ignore passed folder (all libraries in android are dumped into a single folder)
|
||||||
|
return libraryPath() / libraryName(baseLibName);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<bfs::path> VCMIDirsAndroid::dataPaths() const
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
internalPath,
|
||||||
|
userDataPath(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void VCMIDirsAndroid::init()
|
||||||
|
{
|
||||||
|
// asks java code to retrieve needed paths from environment
|
||||||
|
CAndroidVMHelper envHelper;
|
||||||
|
basePath = envHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "dataRoot");
|
||||||
|
internalPath = envHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "internalDataRoot");
|
||||||
|
nativePath = envHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "nativePath");
|
||||||
|
IVCMIDirsUNIX::init();
|
||||||
|
}
|
||||||
#elif defined(VCMI_XDG)
|
#elif defined(VCMI_XDG)
|
||||||
class VCMIDirsXDG : public IVCMIDirsUNIX
|
class VCMIDirsXDG : public IVCMIDirsUNIX
|
||||||
{
|
{
|
||||||
@@ -636,56 +684,7 @@ bfs::path VCMIDirsXDG::binaryPath() const
|
|||||||
|
|
||||||
std::string VCMIDirsXDG::libraryName(const std::string& basename) const { return "lib" + basename + ".so"; }
|
std::string VCMIDirsXDG::libraryName(const std::string& basename) const { return "lib" + basename + ".so"; }
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
#endif // VCMI_APPLE, VCMI_ANDROID, VCMI_XDG
|
||||||
|
|
||||||
class VCMIDirsAndroid : public VCMIDirsXDG
|
|
||||||
{
|
|
||||||
std::string basePath;
|
|
||||||
std::string internalPath;
|
|
||||||
std::string nativePath;
|
|
||||||
public:
|
|
||||||
bfs::path fullLibraryPath(const std::string & desiredFolder, const std::string & baseLibName) const override;
|
|
||||||
bfs::path libraryPath() const override;
|
|
||||||
bfs::path userDataPath() const override;
|
|
||||||
bfs::path userCachePath() const override;
|
|
||||||
bfs::path userConfigPath() const override;
|
|
||||||
|
|
||||||
std::vector<bfs::path> dataPaths() const override;
|
|
||||||
|
|
||||||
void init() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
bfs::path VCMIDirsAndroid::libraryPath() const { return nativePath; }
|
|
||||||
bfs::path VCMIDirsAndroid::userDataPath() const { return basePath; }
|
|
||||||
bfs::path VCMIDirsAndroid::userCachePath() const { return userDataPath() / "cache"; }
|
|
||||||
bfs::path VCMIDirsAndroid::userConfigPath() const { return userDataPath() / "config"; }
|
|
||||||
|
|
||||||
bfs::path VCMIDirsAndroid::fullLibraryPath(const std::string & desiredFolder, const std::string & baseLibName) const
|
|
||||||
{
|
|
||||||
// ignore passed folder (all libraries in android are dumped into a single folder)
|
|
||||||
return libraryPath() / libraryName(baseLibName);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<bfs::path> VCMIDirsAndroid::dataPaths() const
|
|
||||||
{
|
|
||||||
std::vector<bfs::path> paths(2);
|
|
||||||
paths.push_back(internalPath);
|
|
||||||
paths.push_back(userDataPath());
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VCMIDirsAndroid::init()
|
|
||||||
{
|
|
||||||
// asks java code to retrieve needed paths from environment
|
|
||||||
CAndroidVMHelper envHelper;
|
|
||||||
basePath = envHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "dataRoot");
|
|
||||||
internalPath = envHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "internalDataRoot");
|
|
||||||
nativePath = envHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "nativePath");
|
|
||||||
IVCMIDirs::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VCMI_ANDROID
|
|
||||||
#endif // VCMI_APPLE, VCMI_XDG
|
|
||||||
#endif // VCMI_WINDOWS, VCMI_UNIX
|
#endif // VCMI_WINDOWS, VCMI_UNIX
|
||||||
|
|
||||||
// Getters for interfaces are separated for clarity.
|
// Getters for interfaces are separated for clarity.
|
||||||
|
|||||||
Reference in New Issue
Block a user