11#include <android/asset_manager.h>
12#include <android/asset_manager_jni.h>
13#include <android/log.h>
14#include <Manager/EngineCore.h>
15#include <Manager/ResMgr.h>
17#define LOG_TAG "SCENGINE"
20#include <CoreFoundation/CFURL.h>
21#include <CoreFoundation/CFURLAccess.h>
22#include <CoreFoundation/CFBundle.h>
23#include <CoreFoundation/CFPropertyList.h>
27 static std::string NativeAssetsPath() {
29#if defined(MSVC_CMAKE)
30 path.append(
"../../../../Assets/");
33#elif defined(_WIN32) || defined(__linux__) || defined(__APPLE_CC__)
34 path.append(
"../../../Assets/");
42 static std::string AssetsPath() {
45 if (Settings::IsAssetsPacked() ==
false)
46 path = NativeAssetsPath();
51 static std::string OpenNativeAssetsTxtFile(
const std::string& path) {
56 AAssetManager* assetManager = CORE->GetCore(ResMgr)->GetAssetManager();
57 AAsset* asset = AAssetManager_open(assetManager, path.c_str(), AASSET_MODE_STREAMING);
62 off_t fileSize = AAsset_getRemainingLength(asset);
67 char* strbuf =
new char[fileSize + 1]();
68 AAsset_read(asset, strbuf, fileSize);
70 buf = std::string(strbuf, fileSize);
72#elif defined (_WIN32) || defined(__linux__) || defined(__EMSCRIPTEN__) || defined(__APPLE_CC__)
74 auto path_split = split(path,
'.');
75 CFStringRef cf_name = CFStringCreateWithCString(kCFAllocatorDefault, path_split[0].c_str(), kCFStringEncodingUTF8);
76 CFStringRef cf_ext = CFStringCreateWithCString(kCFAllocatorDefault, path_split[1].c_str(), kCFStringEncodingUTF8);
78 CFURLRef manifest_url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cf_name, cf_ext, NULL);
79 char manifest_path[1024];
80 CFURLGetFileSystemRepresentation(manifest_url, TRUE, (UInt8*)manifest_path,
sizeof(manifest_path));
81 CFRelease(manifest_url);
85 std::ifstream fin(manifest_path, std::ios::binary);
87 std::ifstream fin(path, std::ios::binary);
89 if (!fin.is_open())
return "";
91 fin.seekg(0, std::ios::end);
92 size_t size = fin.tellg();
94 buf = std::string(size,
' ');
95 fin.read(&buf[0], size);
101 static bool SaveTxtFile(
const std::string& path, std::string data) {
102#if defined(__ANDROID__) || defined(IOS) || defined(__EMSCRIPTEN__)
105 std::ofstream fout(path, std::ios::binary | std::ios::trunc);