add file_path.mm for bundle resource path
This commit is contained in:
6
src/app/core/platform/file_path.h
Normal file
6
src/app/core/platform/file_path.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef YAZE_APP_CORE_PLATFORM_FILE_PATH_H
|
||||
#define YAZE_APP_CORE_PLATFORM_FILE_PATH_H
|
||||
|
||||
std::string GetBundleResourcePath();
|
||||
|
||||
#endif // YAZE_APP_CORE_PLATFORM_FILE_PATH_H
|
||||
26
src/app/core/platform/file_path.mm
Normal file
26
src/app/core/platform/file_path.mm
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <TargetConditionals.h>
|
||||
|
||||
#if TARGET_IPHONE_SIMULATOR == 1
|
||||
std::string GetBundleResourcePath() {}
|
||||
#elif TARGET_OS_IPHONE == 1
|
||||
std::string GetBundleResourcePath() {
|
||||
NSBundle* bundle = [NSBundle mainBundle];
|
||||
NSString* resourceDirectoryPath = [bundle bundlePath];
|
||||
NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"];
|
||||
return [path UTF8String];
|
||||
}
|
||||
#elif TARGET_OS_MAC == 1
|
||||
std::string GetBundleResourcePath() {
|
||||
NSBundle* bundle = [NSBundle mainBundle];
|
||||
NSString* resourceDirectoryPath = [bundle bundlePath];
|
||||
NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"];
|
||||
return [path UTF8String];
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "app/gui/canvas.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "app/core/platform/file_path.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
@@ -590,7 +591,18 @@ void BindSelectable(Node* node, bool* selected,
|
||||
std::string LoadFile(const std::string& filename) {
|
||||
std::string fileContents;
|
||||
const std::string kPath = "assets/layouts/";
|
||||
std::ifstream file(kPath + filename);
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef TARGET_OS_IOS
|
||||
|
||||
const std::string kBundlePath = GetBundleResourcePath();
|
||||
std::ifstream file(kBundlePath + filename);
|
||||
#else
|
||||
std::ifstream file(kPath + filename);
|
||||
#endif
|
||||
#else
|
||||
std::ifstream file(kPath + filename);
|
||||
#endif
|
||||
|
||||
if (file.is_open()) {
|
||||
std::string line;
|
||||
|
||||
Reference in New Issue
Block a user