Bläddra i källkod

implement VCMIDirs

Andrey Filipenkov 4 år sedan
förälder
incheckning
8249171066
4 ändrade filer med 94 tillägg och 10 borttagningar
  1. 15 0
      lib/CIOSUtils.h
  2. 24 0
      lib/CIOSUtils.m
  3. 5 0
      lib/CMakeLists.txt
  4. 50 10
      lib/VCMIDirs.cpp

+ 15 - 0
lib/CIOSUtils.h

@@ -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 - 0
lib/CIOSUtils.m

@@ -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?

+ 5 - 0
lib/CMakeLists.txt

@@ -439,6 +439,11 @@ set(lib_HEADERS
 		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})
 
 add_library(vcmi SHARED ${lib_SRCS} ${lib_HEADERS})

+ 50 - 10
lib/VCMIDirs.cpp

@@ -349,7 +349,7 @@ class IVCMIDirsUNIX : public IVCMIDirs
 		boost::filesystem::path clientPath() const override;
 		boost::filesystem::path serverPath() const override;
 
-		bool developmentMode() const;
+		virtual bool 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"; }
 
 #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:
 		boost::filesystem::path userDataPath() const override;
 		boost::filesystem::path userCachePath() const override;
-		boost::filesystem::path userConfigPath() const override;
 		boost::filesystem::path userLogsPath() 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 binaryPath() const override;
 
-		std::string libraryName(const std::string& basename) const override;
-
 		void init() override;
 };
 
@@ -436,7 +476,6 @@ bfs::path VCMIDirsOSX::userDataPath() const
 	return bfs::path(homeDir) / "Library" / "Application Support" / "vcmi";
 }
 bfs::path VCMIDirsOSX::userCachePath() const { return userDataPath(); }
-bfs::path VCMIDirsOSX::userConfigPath() const { return userDataPath() / "config"; }
 
 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::binaryPath() const { return "."; }
-
-std::string VCMIDirsOSX::libraryName(const std::string& basename) const { return "lib" + basename + ".dylib"; }
+#endif // VCMI_IOS, VCMI_MAC
 #elif defined(VCMI_XDG)
 class VCMIDirsXDG : public IVCMIDirsUNIX
 {
@@ -635,9 +673,11 @@ namespace VCMIDirs
 			static VCMIDirsAndroid singleton;
 		#elif defined(VCMI_XDG)
 			static VCMIDirsXDG singleton;
-		#elif defined(VCMI_APPLE)
+		#elif defined(VCMI_MAC)
 			static VCMIDirsOSX singleton;
-        #endif
+		#elif defined(VCMI_IOS)
+			static VCMIDirsIOS singleton;
+		#endif
 
 		static bool initialized = false;
 		if (!initialized)