Esempio n. 1
0
bool Shell::Initialise(const Rocket::Core::String& path)
{
	gettimeofday(&start_time, NULL);

	InputMacOSX::Initialise();

	// Find the location of the executable.
	CFBundleRef bundle = CFBundleGetMainBundle();
	CFURLRef executable_url = CFBundleCopyExecutableURL(bundle);
	CFStringRef executable_posix_file_name = CFURLCopyFileSystemPath(executable_url, kCFURLPOSIXPathStyle);
	CFIndex max_length = CFStringGetMaximumSizeOfFileSystemRepresentation(executable_posix_file_name);
	char* executable_file_name = new char[max_length];
	if (!CFStringGetFileSystemRepresentation(executable_posix_file_name, executable_file_name, max_length))
		executable_file_name[0] = 0;

	executable_path = Rocket::Core::String(executable_file_name);
	executable_path = executable_path.Substring(0, executable_path.RFind("/") + 1);

	delete[] executable_file_name;
	CFRelease(executable_posix_file_name);
	CFRelease(executable_url);

	file_interface = new ShellFileInterface(executable_path + "../../../" + path);
	Rocket::Core::SetFileInterface(file_interface);

	return true;
}
Esempio n. 2
0
File: bs.c Progetto: MSch/MacRuby
static inline const char *
_bs_main_bundle_bs_path(void)
{
  static bool done = false;
  static char *path = NULL;
  /* XXX not thread-safe */
  if (!done) {
    CFBundleRef bundle;

    done = true;
    bundle = CFBundleGetMainBundle();
    if (bundle != NULL) {
      CFURLRef url;

      url = CFBundleCopyResourceURL(bundle, CFSTR("BridgeSupport"), 
                                    NULL, NULL);
      if (url != NULL) {
        CFStringRef str = CFURLCopyPath(url);
        path = (char *)malloc(sizeof(char) * PATH_MAX);
	ASSERT_ALLOC(path);
        CFStringGetFileSystemRepresentation(str, path, PATH_MAX);
        CFRelease(str);
        CFRelease(url);
      }
    }
  }
  return path;
}
Esempio n. 3
0
std::string GetBundleDirectory() 
{
	CFURLRef BundleRef;
	char AppBundlePath[MAXPATHLEN];
	// Get the main bundle for the app
	BundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	CFStringRef BundlePath = CFURLCopyFileSystemPath(BundleRef, kCFURLPOSIXPathStyle);
	CFStringGetFileSystemRepresentation(BundlePath, AppBundlePath, sizeof(AppBundlePath));
	CFRelease(BundleRef);
	CFRelease(BundlePath);

	return AppBundlePath;
}
Esempio n. 4
0
void get_my_path(char s[PATH_MAX])
{
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef executableURL = CFBundleCopyExecutableURL(mainBundle);
    CFStringRef executablePathString = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
    CFRelease(executableURL);

    CFStringGetFileSystemRepresentation(executablePathString, s, PATH_MAX-1);
    CFRelease(executablePathString);

	char *x;
    x = strrchr(s, '/');
    if(x) x[1] = 0;
}
Esempio n. 5
0
/**
 * 実行している自身のディレクトリパス取得
 * @return 実行ディレクトリフルパス
 */
std::string getBinaryDir()
{
    const int MAXPATHLEN = 4096;
    char exepath[MAXPATHLEN] = {};
#if _WIN32
	wchar_t app_full_path[1024];
	DWORD length = GetModuleFileNameW(NULL, app_full_path, sizeof(app_full_path) / sizeof(wchar_t));
	std::wstring str(app_full_path, length);
	const char16_t* p = reinterpret_cast<const char16_t*>(str.c_str());
	std::u16string u16str(p);
	// utf16 to utf8
	std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
	std::string stdstr = convert.to_bytes(u16str);

	std::string::size_type pos = stdstr.find_last_of("\\");
	if (pos != std::string::npos) {
		std::string basepath = stdstr.substr(0, pos + 1);
		return basepath;
	}
	return stdstr;
    
#elif __APPLE__
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1012
    uint32_t size = sizeof(exepath);
    int ret = _NSGetExecutablePath(exepath, &size);
    if (0 != ret) {
        return ""; // FIXME(IDS): 
    } 
#else
    CFBundleRef bundle         = CFBundleGetMainBundle();
    CFURLRef    executableURL  = CFBundleCopyExecutableURL(bundle);
    CFStringRef executablePath = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
    CFStringGetMaximumSizeOfFileSystemRepresentation(executablePath);
    CFStringGetFileSystemRepresentation(executablePath, exepath, MAXPATHLEN);
    CFRelease(executablePath);
    CFRelease(executableURL);
#endif
#else // Linux
    readlink("/proc/self/exe", exepath, sizeof(exepath));
#endif
    // for Mac & Linux
    std::string fullpath(exepath);
    size_t t = fullpath.rfind("/");
    if (t != std::string::npos) {
        fullpath = fullpath.substr(0, t + 1);
    }
    return fullpath;
}
Esempio n. 6
0
char* _CFFSCreateRepresentation(CFStringRef path) {
    if (!path) {
        errno = EINVAL;
        return NULL;
    }
    CFIndex length = CFStringGetMaximumSizeOfFileSystemRepresentation(path);
    char* buffer = (char*)malloc(length);
    if (!buffer) {
        return NULL;
    }
    if (!CFStringGetFileSystemRepresentation(path, buffer, length)) {
        free(buffer);
        errno = ENAMETOOLONG;
        return NULL;
    }
    return buffer;
}
Esempio n. 7
0
CString fileSystemRepresentation(const String& path)
{
    RetainPtr<CFStringRef> cfString = path.createCFString();

    if (!cfString)
        return CString();

    CFIndex size = CFStringGetMaximumSizeOfFileSystemRepresentation(cfString.get());

    Vector<char> buffer(size);

    if (!CFStringGetFileSystemRepresentation(cfString.get(), buffer.data(), buffer.size())) {
        LOG_ERROR("Failed to get filesystem representation to create CString from cfString");
        return CString();
    }

    return CString(buffer.data(), strlen(buffer.data()));
}
Esempio n. 8
0
static CFIndex CFURLEnumeratorPushURL(CFURLEnumeratorRef enumerator, CFURLRef url, CFErrorRef *error) {
    char path[PATH_MAX] = { 0 };
    CFStringRef urlPath = CFURLCopyPath(url);
    Boolean success = CFStringGetFileSystemRepresentation(urlPath, path, PATH_MAX);
    
    if (!success) {
        cocoaError(error, -1, url, urlPath);
        CFRelease(urlPath);
        return kCFNotFound;
    }

    DIR *dir = opendir(path);
    if (dir == NULL) {
        posixError(error, url, urlPath);
        CFRelease(urlPath);
        return kCFNotFound;
    }

    CFMutableArrayRef fileInfos = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);

    struct dirent *current = NULL;
    while ((current = readdir(dir)) != NULL) {
        if (strcmp(current->d_name, ".") == 0 || strcmp(current->d_name, "..") == 0) {
            continue;
        }
        CFMutableDictionaryRef fileInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        CFStringRef fileName = CFStringCreateWithBytes(kCFAllocatorDefault, current->d_name, strlen(current->d_name), kCFStringEncodingUTF8, false);
        CFDictionarySetValue(fileInfo, fileInfoNameKey, fileName);
        CFDictionarySetValue(fileInfo, fileInfoIsDirKey, current->d_type == DT_DIR ? kCFBooleanTrue : kCFBooleanFalse);
        CFArrayAppendValue(fileInfos, fileInfo);
        CFRelease(fileName);
        CFRelease(fileInfo);
    }

    CFArraySortValues(fileInfos, CFRangeMake(0, CFArrayGetCount(fileInfos)), _compareFileInfo, nil);
    CFArrayAppendValue(enumerator->urlStack, url);
    CFArrayAppendValue(enumerator->dirFileInfos, fileInfos);
    CFRelease(urlPath);
    CFRelease(fileInfos);
    closedir(dir);
    return CFArrayGetCount(enumerator->urlStack);
}
/* Return the string value suitable for use with posix file system calls for
   KEY found in PLIST. NULL will be returned if KEY does not have a valid value
   in the the property list, if the value is not a string, or if there were
   errors extracting the value for KEY.  */
const char *
macosx_get_plist_posix_value(const void *plist, const char* key)
{
  char *value = NULL;
  CFStringRef cf_key;
  CFStringRef cf_value;

  if (plist == NULL)
    return NULL;
  cf_key = (CFStringRef)CFStringCreateWithCString(kCFAllocatorDefault, key,
                                                  kCFStringEncodingUTF8);
  cf_value = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)plist,
                                               cf_key);
  if ((cf_value != NULL) && (CFGetTypeID(cf_value) == CFStringGetTypeID()))
    {
      CFIndex max_value_len;
      max_value_len = CFStringGetMaximumSizeOfFileSystemRepresentation(cf_value);
      if (max_value_len > 0)
	{
	  value = (char *)xmalloc(max_value_len + 1);
	  if (value)
	    {
	      if (!CFStringGetFileSystemRepresentation(cf_value, value,
                                                       max_value_len))
		{
		  /* We failed to get a file system representation
		     of the bundle executable, just free the buffer
		     we malloc'ed.  */
		  xfree(value);
		  value = NULL;
		}
	    }
	}
    }
  if (cf_key) {
    CFRelease(cf_key);
  }
  return value;
}
Esempio n. 10
0
int prFileRealPath(struct VMGlobals* g, int numArgsPushed )
{
	PyrSlot *a = g->sp - 1, *b = g->sp;
	char ipath[PATH_MAX];
	char opath[PATH_MAX];
	int err;

	err = slotStrVal(b, ipath, PATH_MAX);
	if (err) return err;

	bool isAlias = false;
	if(sc_ResolveIfAlias(ipath, opath, isAlias, PATH_MAX)!=0) {
		return errFailed;
	}

	boost::system::error_code error_code;
	boost::filesystem::path p = boost::filesystem::canonical(opath,error_code);
	if(error_code) {
		SetNil(a);
		return errNone;
	}
	strcpy(opath,p.string().c_str());

#if SC_DARWIN
	CFStringRef cfstring =
		CFStringCreateWithCString(NULL,
								  opath,
								  kCFStringEncodingUTF8);
	err = !CFStringGetFileSystemRepresentation(cfstring, opath, PATH_MAX);
	CFRelease(cfstring);
	if (err) return errFailed;
#endif // SC_DARWIN

	PyrString* pyrString = newPyrString(g->gc, opath, 0, true);
	SetObject(a, pyrString);

	return errNone;
}
sdmmd_return_t SDMMD_stream_image(SDMMD_AMConnectionRef connection, CFStringRef path, CFStringRef image_type)
{
	sdmmd_return_t result = kAMDSuccess;
	char fspath[0x400] = {0};
	Boolean fsRep = CFStringGetFileSystemRepresentation(path, fspath, 0x400);
	if (fsRep) {
		struct stat fileStat;
		lstat(fspath, &fileStat);
		CFNumberRef size = CFNumberCreate(kCFAllocatorDefault, 0xb, &fileStat.st_size);
		CFMutableDictionaryRef streamDict = SDMMD_create_dict();
		CFDictionarySetValue(streamDict, CFSTR("Command"), CFSTR("ReceiveBytes"));
		CFDictionarySetValue(streamDict, CFSTR("ImageType"), image_type);
		CFDictionarySetValue(streamDict, CFSTR("ImageSize"), size);
		result = SDMMD_ServiceSendMessage(SDMMD_TranslateConnectionToSocket(connection), streamDict, kCFPropertyListXMLFormat_v1_0);
		CFSafeRelease(streamDict);
		CFSafeRelease(size);

		CheckErrorAndReturn(result);

		CFDictionaryRef response;
		result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(connection), (CFPropertyListRef *)&response);

		CheckErrorAndReturn(result);

		if (response) {
			result = SDMMD__ErrorHandler(SDMMD_ImageMounterErrorConvert, response);

			CheckErrorAndReturn(result);

			CFTypeRef status = CFDictionaryGetValue(response, CFSTR("Status"));
			if (status) {
				if (CFStringCompare(status, CFSTR("ReceiveBytesAck"), 0) == 0) {
					// block code
					CFDataRef image_file = CFDataCreateFromPath(path);
					uint64_t offset = 0;
					uint64_t remainder = 0;
					while (offset < fileStat.st_size) {
						remainder = (fileStat.st_size - offset);
						remainder = (remainder > kDeveloperImageStreamSize ? kDeveloperImageStreamSize : remainder);
						CFRange current_read = CFRangeMake((CFIndex)offset, (CFIndex)remainder);
						CFDataRef image_stream = CFDataCreateFromSubrangeOfData(image_file, current_read);
						result = SDMMD_DirectServiceSend(SDMMD_TranslateConnectionToSocket(connection), image_stream);
						CheckErrorAndReturn(result);
						offset += remainder;
						CFSafeRelease(image_stream);
					}
					CFDictionaryRef getStatus;
					result = SDMMD_ServiceReceiveMessage(SDMMD_TranslateConnectionToSocket(connection), (CFPropertyListRef *)&getStatus);

					if (result == 0) {
						result = SDMMD__ErrorHandler(SDMMD_ImageMounterErrorConvert, response);

						CheckErrorAndReturn(result);

						CFTypeRef streamStatus = CFDictionaryGetValue(getStatus, CFSTR("Status"));
						if (streamStatus) {
							if (CFStringCompare(streamStatus, CFSTR("Complete"), 0x0) == 0) {
								result = kAMDSuccess;
							}
						}
					}
					CFSafeRelease(getStatus);
					CFSafeRelease(image_file);
				}
			}
			else {
				result = kAMDUndefinedError;
			}
		}
		else {
			result = kAMDReadError;
		}
	}
	else {
		result = kAMDNoResourcesError;
	}

	ExitLabelAndReturn(result);
}
Esempio n. 12
0
// Returns the current directory
std::string GetCurrentDir()
{
    // Get the current working directory (getcwd uses malloc)
#ifdef _WIN32
    wchar_t *dir;
    if (!(dir = _wgetcwd(nullptr, 0))) {
#else
    char *dir;
    if (!(dir = getcwd(nullptr, 0))) {
#endif
        LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s",
                GetLastErrorMsg());
        return nullptr;
    }
#ifdef _WIN32
    std::string strDir = Common::UTF16ToUTF8(dir);
#else
    std::string strDir = dir;
#endif
    free(dir);
    return strDir;
}

// Sets the current directory to the given directory
bool SetCurrentDir(const std::string &directory)
{
#ifdef _WIN32
    return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0;
#else
    return chdir(directory.c_str()) == 0;
#endif
}

#if defined(__APPLE__)
std::string GetBundleDirectory()
{
    CFURLRef BundleRef;
    char AppBundlePath[MAXPATHLEN];
    // Get the main bundle for the app
    BundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    CFStringRef BundlePath = CFURLCopyFileSystemPath(BundleRef, kCFURLPOSIXPathStyle);
    CFStringGetFileSystemRepresentation(BundlePath, AppBundlePath, sizeof(AppBundlePath));
    CFRelease(BundleRef);
    CFRelease(BundlePath);

    return AppBundlePath;
}
#endif

#ifdef _WIN32
std::string& GetExeDirectory()
{
    static std::string exe_path;
    if (exe_path.empty())
    {
        wchar_t wchar_exe_path[2048];
        GetModuleFileNameW(nullptr, wchar_exe_path, 2048);
        exe_path = Common::UTF16ToUTF8(wchar_exe_path);
        exe_path = exe_path.substr(0, exe_path.find_last_of('\\'));
    }
    return exe_path;
}
#else
/**
 * @return The user’s home directory on POSIX systems
 */
static const std::string& GetHomeDirectory() {
    static std::string home_path;
    if (home_path.empty()) {
        const char* envvar = getenv("HOME");
        if (envvar) {
            home_path = envvar;
        } else {
            auto pw = getpwuid(getuid());
            ASSERT_MSG(pw, "$HOME isn’t defined, and the current user can’t be found in /etc/passwd.");
            home_path = pw->pw_dir;
        }
    }
    return home_path;
}

/**
 * Follows the XDG Base Directory Specification to get a directory path
 * @param envvar The XDG environment variable to get the value from
 * @return The directory path
 * @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
 */
static const std::string GetUserDirectory(const std::string& envvar) {
    const char* directory = getenv(envvar.c_str());

    std::string user_dir;
    if (directory) {
        user_dir = directory;
    } else {
        std::string subdirectory;
        if (envvar == "XDG_DATA_HOME")
            subdirectory = DIR_SEP ".local" DIR_SEP "share";
        else if (envvar == "XDG_CONFIG_HOME")
            subdirectory = DIR_SEP ".config";
        else if (envvar == "XDG_CACHE_HOME")
            subdirectory = DIR_SEP ".cache";
        else
            ASSERT_MSG(false, "Unknown XDG variable %s.", envvar.c_str());
        user_dir = GetHomeDirectory() + subdirectory;
    }

    ASSERT_MSG(!user_dir.empty(), "User directory %s musn’t be empty.", envvar.c_str());
    ASSERT_MSG(user_dir[0] == '/', "User directory %s must be absolute.", envvar.c_str());

    return user_dir;
}
#endif

std::string GetSysDirectory()
{
    std::string sysDir;

#if defined (__APPLE__)
    sysDir = GetBundleDirectory();
    sysDir += DIR_SEP;
    sysDir += SYSDATA_DIR;
#else
    sysDir = SYSDATA_DIR;
#endif
    sysDir += DIR_SEP;

    LOG_DEBUG(Common_Filesystem, "Setting to %s:", sysDir.c_str());
    return sysDir;
}

// Returns a string with a Citra data dir or file in the user's home
// directory. To be used in "multi-user" mode (that is, installed).
const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath)
{
    static std::string paths[NUM_PATH_INDICES];

    // Set up all paths and files on the first run
    if (paths[D_USER_IDX].empty())
    {
#ifdef _WIN32
        paths[D_USER_IDX]   = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
        paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
        paths[D_CACHE_IDX]  = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
#else
        if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
            paths[D_USER_IDX]   = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
            paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
            paths[D_CACHE_IDX]  = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
        } else {
            std::string data_dir   = GetUserDirectory("XDG_DATA_HOME");
            std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
            std::string cache_dir  = GetUserDirectory("XDG_CACHE_HOME");

            paths[D_USER_IDX]   = data_dir   + DIR_SEP EMU_DATA_DIR DIR_SEP;
            paths[D_CONFIG_IDX] = config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
            paths[D_CACHE_IDX]  = cache_dir  + DIR_SEP EMU_DATA_DIR DIR_SEP;
        }
#endif

        paths[D_GAMECONFIG_IDX]     = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
        paths[D_MAPS_IDX]           = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
        paths[D_SDMC_IDX]           = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
        paths[D_NAND_IDX]           = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
        paths[D_SYSDATA_IDX]        = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP;
        paths[D_SHADERCACHE_IDX]    = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
        paths[D_SHADERS_IDX]        = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
        paths[D_STATESAVES_IDX]     = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
        paths[D_SCREENSHOTS_IDX]    = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
        paths[D_DUMP_IDX]           = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
        paths[D_DUMPFRAMES_IDX]     = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
        paths[D_DUMPAUDIO_IDX]      = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
        paths[D_DUMPTEXTURES_IDX]   = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
        paths[D_LOGS_IDX]           = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
        paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
        paths[F_LOGGERCONFIG_IDX]   = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
        paths[F_MAINLOG_IDX]        = paths[D_LOGS_IDX] + MAIN_LOG;
    }

    if (!newPath.empty())
    {
        if (!FileUtil::IsDirectory(newPath))
        {
            LOG_ERROR(Common_Filesystem, "Invalid path specified %s", newPath.c_str());
            return paths[DirIDX];
        }
        else
        {
            paths[DirIDX] = newPath;
        }

        switch (DirIDX)
        {
        case D_ROOT_IDX:
            paths[D_USER_IDX]           = paths[D_ROOT_IDX] + DIR_SEP;
            paths[D_SYSCONF_IDX]        = paths[D_USER_IDX] + SYSCONF_DIR + DIR_SEP;
            paths[F_SYSCONF_IDX]        = paths[D_SYSCONF_IDX] + SYSCONF;
            break;

        case D_USER_IDX:
            paths[D_USER_IDX]           = paths[D_ROOT_IDX] + DIR_SEP;
            paths[D_CONFIG_IDX]         = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
            paths[D_GAMECONFIG_IDX]     = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
            paths[D_MAPS_IDX]           = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
            paths[D_CACHE_IDX]          = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
            paths[D_SDMC_IDX]           = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
            paths[D_NAND_IDX]           = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
            paths[D_SHADERCACHE_IDX]    = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
            paths[D_SHADERS_IDX]        = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
            paths[D_STATESAVES_IDX]     = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
            paths[D_SCREENSHOTS_IDX]    = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
            paths[D_DUMP_IDX]           = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
            paths[D_DUMPFRAMES_IDX]     = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
            paths[D_DUMPAUDIO_IDX]      = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
            paths[D_DUMPTEXTURES_IDX]   = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
            paths[D_LOGS_IDX]           = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
            paths[D_SYSCONF_IDX]        = paths[D_USER_IDX] + SYSCONF_DIR DIR_SEP;
            paths[F_EMUCONFIG_IDX]      = paths[D_CONFIG_IDX] + EMU_CONFIG;
            paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
            paths[F_LOGGERCONFIG_IDX]   = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
            paths[F_MAINLOG_IDX]        = paths[D_LOGS_IDX] + MAIN_LOG;
            break;

        case D_CONFIG_IDX:
            paths[F_EMUCONFIG_IDX]      = paths[D_CONFIG_IDX] + EMU_CONFIG;
            paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
            paths[F_LOGGERCONFIG_IDX]   = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
            break;

        case D_DUMP_IDX:
            paths[D_DUMPFRAMES_IDX]     = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
            paths[D_DUMPAUDIO_IDX]      = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
            paths[D_DUMPTEXTURES_IDX]   = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
            break;

        case D_LOGS_IDX:
            paths[F_MAINLOG_IDX]        = paths[D_LOGS_IDX] + MAIN_LOG;
        }
    }

    return paths[DirIDX];
}

size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename)
{
    return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
}

size_t ReadFileToString(bool text_file, const char *filename, std::string &str)
{
    IOFile file(filename, text_file ? "r" : "rb");

    if (!file)
        return false;

    str.resize(static_cast<u32>(file.GetSize()));
    return file.ReadArray(&str[0], str.size());
}
Esempio n. 13
0
void mui_init(){
	#if TARGET_OS_IPHONE
	if( mui::MuiConfig::detectRetina ){
		ofAppiOSWindow * w = ofAppiOSWindow::getInstance();
		if( w->isRetinaEnabled() ){
			mui::MuiConfig::scaleFactor = 2;
			mui::MuiConfig::useRetinaAssets = true;
		}
	}
	#endif
	//TODO: allow retina in osx too!
	
	Poco::Path appPath;
	#if TARGET_OS_IPHONE
		// http://www.cocoabuilder.com/archive/cocoa/193451-finding-out-executable-location-from-c-program.html
		CFBundleRef bundle = CFBundleGetMainBundle();
		CFURLRef    url  = CFBundleCopyExecutableURL(bundle); // CFBundleCopyResourcesDirectoryURL(bundle);
		CFURLRef absolute = CFURLCopyAbsoluteURL(url);
		CFStringRef path  = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
		CFIndex    maxLength = CFStringGetMaximumSizeOfFileSystemRepresentation(path);
		char        *result = (char*)malloc(maxLength);
		
		if(result) {
			if(!CFStringGetFileSystemRepresentation(path,result, maxLength)) {
				free(result);
				result = NULL;
			}
		}
		
		CFRelease(path);
		CFRelease(url);
		CFRelease(absolute);
		appPath = Poco::Path(result);
		appPath = appPath.parent();
	#elif TARGET_OS_MAC
		// http://www.cocoabuilder.com/archive/cocoa/193451-finding-out-executable-location-from-c-program.html
		CFBundleRef bundle = CFBundleGetMainBundle();
		CFURLRef    url  = CFBundleCopyExecutableURL(bundle); // CFBundleCopyResourcesDirectoryURL(bundle);
		CFURLRef absolute = CFURLCopyAbsoluteURL(url);
		CFStringRef path  = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
		CFIndex    maxLength = CFStringGetMaximumSizeOfFileSystemRepresentation(path);
		char        *result = (char*)malloc(maxLength);
		
		if(result) {
			if(!CFStringGetFileSystemRepresentation(path,result, maxLength)) {
				free(result);
				result = NULL;
			}
		}
		
		CFRelease(path);
		CFRelease(url);
		CFRelease(absolute);
		appPath = Poco::Path(result);
		appPath = appPath.parent().parent().pushDirectory("Resources");
	
		if( mui::MuiConfig::detectRetina ){
			ofAppGLFWWindow * window = dynamic_cast<ofAppGLFWWindow*>(ofGetWindowPtr());
			if( window != NULL ){
				mui::MuiConfig::scaleFactor = window->getPixelScreenCoordScale();
			}
		}
	#else
		appPath = Poco::Path(ofToDataPath("", true));
	#endif
	
	mui::MuiConfig::dataPath = appPath.absolute();
}
Esempio n. 14
0
static char * vmd_get_vmddir(void) {
  OSErr rc = 0;
  FSSpec spec;
  FSRef ref;
  UInt8 *path = NULL;
  char *bundledir = NULL;
  char *vmddir = NULL;
  char *tmp = NULL;

  bundledir = (char *) malloc(2048 * sizeof(UInt8));
  memset(bundledir, 0, 2048 * sizeof(UInt8));

#if defined(ARCH_MACOSXX86_64)
  //
  // CoreFoundation/Cocoa-based application bundle path query code
  //
  CFBundleRef mainbundle = CFBundleGetMainBundle();
  if (mainbundle != NULL) {
#if 1
    CFURLRef appurl = CFBundleCopyBundleURL(mainbundle);
#else
    CFURLRef appurl = CFBundleCopyExecutableURL(mainbundle);
#endif
    CFStringRef cfpath = CFURLCopyFileSystemPath(appurl, kCFURLPOSIXPathStyle);
    if (CFStringGetFileSystemRepresentation(cfpath, bundledir, 2048 * sizeof(UInt8) - 1) == true) {
//      printf("MacOS X Bundle path: %s\n", bundledir);

      // Truncate bundle path to parent bundle directory, 
      // if needed, when the executable is launched by double clicking
      // the application bundle in the GUI.  When the application 
      // is launched directly via scripts etc, the main bundle path
      // returned from the previous calls already points to the parent
      // directory of the VMD executable.
      if (strstr(bundledir, "/Contents/Resources/VMD.app")) {
        if ((tmp = strrchr(bundledir, '/')) != NULL) {
          tmp[0] = '\0';
        }
        if ((tmp = strrchr(bundledir, '/')) != NULL) {
          tmp[0] = '\0';
        }
        if ((tmp = strrchr(bundledir, '/')) != NULL) {
          tmp[0] = '\0';
        }

        // add path to main VMD directory from the outermost bundle container
        strcat(bundledir, "/Contents/vmd");
      }


      vmddir = (char *) malloc(strlen(bundledir) + 1 + strlen("/vmd"));
      strcpy(vmddir, bundledir);
    }

    free(bundledir);
    CFRelease(appurl);
    CFRelease(cfpath);
  }

  if (!vmddir) {
    printf("WARNING: Failed to get path for main VMD application bundle...\n");
    vmddir = getenv("VMDDIR");
  }

#else

  //
  // Carbon-based application bundle path query code
  //
#if 0
  if (!(rc = GetApplicationPackageFSSpecFromBundle(&spec))) {
#else
  if (!(rc = GetApplicationBundleFSSpec(&spec))) {
#endif
    rc = FSpMakeFSRef(&spec, &ref);
    if (rc) printf("makefsref OSErr: %d\n", rc);
      
    rc = FSRefMakePath(&ref,(UInt8 *) bundledir, 2048);
    if (rc) printf("makepath OSErr: %d\n", rc);
  } else {
    printf("getappbundlepath OSErr: %d\n", rc);
  }

  if (rc) {
    free(bundledir);
    return NULL;
  } 

  // truncate bundle path to parent bundle directory
  if ((tmp = strrchr(bundledir, '/')) != NULL) {
    tmp[0] = '\0';
  }
  if ((tmp = strrchr(bundledir, '/')) != NULL) {
    tmp[0] = '\0';
  }

  // add "/vmd" to parent bundle directory
  vmddir = (char *) malloc(strlen(bundledir) + 1 + strlen("/vmd"));
  strcpy(vmddir, bundledir);
  strcat(vmddir, "/vmd");

  free(bundledir);
#endif

  return (char *) vmddir;
}


#if 1
int macosxvmdstart(int argc, char **argv) {
#else
int main(int argc, char **argv) {
#endif
  char tmp[8192];
  char * vmddir;
  int i;

  vmddir = vmd_get_vmddir();
  if (vmddir == NULL) {
    return -1; // fail and exit
  }

#if 0
  if (!getenv("MACOSXVMDSTARTUP")) {
    int startterminal=1; // be default, we start one...

    setenv("MACOSXVMDSTARTUP", "1", 1);
    // check for -dispdev text, in which case we don't start a terminal...
    for (i=0; i < argc; i++) {
      if (!strupcmp(argv[i], "-dispdev")) {
        if (argc > i+1) {
          if (!strupcmp(argv[i+1], "text")) {
            startterminal=0;
          }
        } 
      }
    }

    if (startterminal) {
      char cmdbuf[16384];
      sprintf(cmdbuf, "\"%s/vmd_MACOSX\"", vmddir);
      if (argc > 1) {
        for (i=1; i < argc; i++) {
          strcat(cmdbuf, " ");
          strcat(cmdbuf, argv[i]);
        }
      }
      strcat(cmdbuf, " &");

printf("Executing VMD startup command: %s\n", cmdbuf);
      exit(system(cmdbuf));
    }
  }
#endif

  if (!getenv("VMDDIR")) {
    setenv("VMDDIR", vmddir, 1);
  }

  if (!getenv("TCL_LIBRARY")) {
    strcpy(tmp, vmddir);
    strcat(tmp, "/scripts/tcl");
    setenv("TCL_LIBRARY", tmp, 1);
  }

  if (!getenv("TK_LIBRARY")) {
    strcpy(tmp, vmddir);
    strcat(tmp, "/scripts/tk");
    setenv("TK_LIBRARY", tmp, 1);
  }

  if (!getenv("PYTHONPATH")) {
    strcpy(tmp, vmddir);
    strcat(tmp, "/scripts/python");
    setenv("PYTHONPATH", tmp, 1);
  } else {
    strcpy(tmp, getenv("PYTHONPATH"));
    strcat(tmp, ":");
    strcat(tmp, vmddir);
    strcat(tmp, "/scripts/python");
    setenv("PYTHONPATH", tmp, 1);
  }

  if (!getenv("STRIDE_BIN")) {
    strcpy(tmp, vmddir);
#if defined(ARCH_MACOSXX86_64)
    strcat(tmp, "/stride_MACOSXX86_64");
#elif defined(ARCH_MACOSXX86)
    strcat(tmp, "/stride_MACOSXX86");
#else
    strcat(tmp, "/stride_MACOSX");
#endif
    setenv("STRIDE_BIN", tmp, 1);
  }

  if (!getenv("SURF_BIN")) {
    strcpy(tmp, vmddir);
#if defined(ARCH_MACOSXX86_64)
    strcat(tmp, "/surf_MACOSXX86_64");
#elif defined(ARCH_MACOSXX86)
    strcat(tmp, "/surf_MACOSXX86");
#else
    strcat(tmp, "/surf_MACOSX");
#endif
    setenv("SURF_BIN", tmp, 1);
  }

  if (!getenv("TACHYON_BIN")) {
    strcpy(tmp, vmddir);
#if defined(ARCH_MACOSXX86_64)
    strcat(tmp, "/tachyon_MACOSXX86_64");
#elif defined(ARCH_MACOSXX86)
    strcat(tmp, "/tachyon_MACOSXX86");
#else
    strcat(tmp, "/tachyon_MACOSX");
#endif
    setenv("TACHYON_BIN", tmp, 1);
  }

  return 0;
}