aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkOSFile_stdio.cpp
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2017-11-29 11:42:33 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-29 17:06:25 +0000
commit329c5a6d826b7b90e5e75ec0a7824c75ed5f8077 (patch)
treecdc91f8575ad0f6b210d3df484bacdf439320dec /src/ports/SkOSFile_stdio.cpp
parent19ea45ef538b0cbcd2088e85fa7e88384d6932e3 (diff)
Bundle resources and skps directories into iOS app.
Will bundle resources/ for viewer (and skps/ if that directory exists in the main Skia directory). Also updates file code on iOS to fall back to bundle directory. Docs-Preview: https://skia.org/?cl=76803 Bug: skia:7339 Change-Id: I244f67559c866451a6d02c3f1c4948d89457ec84 Reviewed-on: https://skia-review.googlesource.com/76803 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/ports/SkOSFile_stdio.cpp')
-rw-r--r--src/ports/SkOSFile_stdio.cpp56
1 files changed, 19 insertions, 37 deletions
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index 501d275c0f..7cdc549df6 100644
--- a/src/ports/SkOSFile_stdio.cpp
+++ b/src/ports/SkOSFile_stdio.cpp
@@ -22,36 +22,9 @@
#endif
#ifdef SK_BUILD_FOR_IOS
-#import <CoreFoundation/CoreFoundation.h>
-
-static FILE* ios_open_from_bundle(const char path[], const char* perm) {
- // Get a reference to the main bundle
- CFBundleRef mainBundle = CFBundleGetMainBundle();
-
- // Get a reference to the file's URL
- CFStringRef pathRef = CFStringCreateWithCString(nullptr, path, kCFStringEncodingUTF8);
- CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, nullptr, nullptr);
- CFRelease(pathRef);
- if (!imageURL) {
- return nullptr;
- }
-
- // Convert the URL reference into a string reference
- CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle);
- CFRelease(imageURL);
-
- // Get the system encoding method
- CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
-
- // Convert the string reference into a C string
- const char *finalPath = CFStringGetCStringPtr(imagePath, encodingMethod);
- FILE* fileHandle = fopen(finalPath, perm);
- CFRelease(imagePath);
- return fileHandle;
-}
+#include "SkOSFile_ios.h"
#endif
-
FILE* sk_fopen(const char path[], SkFILE_Flags flags) {
char perm[4];
char* p = perm;
@@ -68,18 +41,17 @@ FILE* sk_fopen(const char path[], SkFILE_Flags flags) {
//TODO: on Windows fopen is just ASCII or the current code page,
//convert to utf16 and use _wfopen
FILE* file = nullptr;
+ file = fopen(path, perm);
#ifdef SK_BUILD_FOR_IOS
- // if read-only, try to open from bundle first
- if (kRead_SkFILE_Flag == flags) {
- file = ios_open_from_bundle(path, perm);
- }
- // otherwise just read from the Documents directory (default)
- if (!file) {
-#endif
- file = fopen(path, perm);
-#ifdef SK_BUILD_FOR_IOS
+ // if not found in default path and read-only, try to open from bundle
+ if (!file && kRead_SkFILE_Flag == flags) {
+ SkString bundlePath;
+ if (ios_get_path_in_bundle(path, &bundlePath)) {
+ file = fopen(bundlePath.c_str(), perm);
+ }
}
#endif
+
if (nullptr == file && (flags & kWrite_SkFILE_Flag)) {
SkDEBUGF(("sk_fopen: fopen(\"%s\", \"%s\") returned nullptr (errno:%d): %s\n",
path, perm, errno, strerror(errno)));
@@ -140,7 +112,17 @@ void sk_fclose(FILE* f) {
bool sk_isdir(const char *path) {
struct stat status;
if (0 != stat(path, &status)) {
+#ifdef SK_BUILD_FOR_IOS
+ // check the bundle directory if not in default path
+ SkString bundlePath;
+ if (ios_get_path_in_bundle(path, &bundlePath)) {
+ if (0 != stat(bundlePath.c_str(), &status)) {
+ return false;
+ }
+ }
+#else
return false;
+#endif
}
return SkToBool(status.st_mode & S_IFDIR);
}