Пример #1
0
/**
 * Default directory fallback is:
 *   - (command line argument)
 *   - <platform dependent>
 */
void platform_resolve_user_data_path()
{
	const char separator[2] = { platform_get_path_separator(), 0 };

	if (gCustomUserDataPath[0] != 0) {
		if (realpath(gCustomUserDataPath, _userDataDirectoryPath) == NULL) {
			log_error("Could not resolve path \"%s\"", gCustomUserDataPath);
			return;
		}

		// Ensure path ends with separator
		int len = strlen(_userDataDirectoryPath);
		if (_userDataDirectoryPath[len - 1] != separator[0]) {
			strncat(_userDataDirectoryPath, separator, MAX_PATH - 1);
		}
		return;
	}

	char buffer[MAX_PATH];
	buffer[0] = '\0';
	log_verbose("buffer = '%s'", buffer);

	const char *homedir = getpwuid(getuid())->pw_dir;
	platform_posix_sub_user_data_path(buffer, homedir, separator);

	log_verbose("OpenRCT2 user data directory = '%s'", buffer);
	int len = strnlen(buffer, MAX_PATH);
	wchar_t *w_buffer = regular_to_wchar(buffer);
	w_buffer[len] = '\0';
	utf8 *path = widechar_to_utf8(w_buffer);
	free(w_buffer);
	safe_strcpy(_userDataDirectoryPath, path, MAX_PATH);
	free(path);
}
Пример #2
0
/**
 * Default directory fallback is:
 *   - (command line argument)
 *   - <platform dependent>
 */
void platform_resolve_user_data_path()
{

    if (gCustomUserDataPath[0] != 0) {
        if (!platform_ensure_directory_exists(gCustomUserDataPath)) {
            log_error("Failed to create directory \"%s\", make sure you have permissions.", gCustomUserDataPath);
            return;
        }
        char *path;
        if ((path = realpath(gCustomUserDataPath, NULL)) == NULL) {
            log_error("Could not resolve path \"%s\"", gCustomUserDataPath);
            return;
        }

        safe_strcpy(_userDataDirectoryPath, path, MAX_PATH);
        free(path);

        // Ensure path ends with separator
        path_end_with_separator(_userDataDirectoryPath, MAX_PATH);
        log_verbose("User data path resolved to: %s", _userDataDirectoryPath);
        if (!platform_directory_exists(_userDataDirectoryPath)) {
            log_error("Custom user data directory %s does not exist", _userDataDirectoryPath);
        }
        return;
    }

    char buffer[MAX_PATH];
    log_verbose("buffer = '%s'", buffer);

    const char *homedir = getpwuid(getuid())->pw_dir;
    platform_posix_sub_user_data_path(buffer, MAX_PATH, homedir);

    log_verbose("OpenRCT2 user data directory = '%s'", buffer);
    sint32 len = strnlen(buffer, MAX_PATH);
    wchar_t *w_buffer = regular_to_wchar(buffer);
    w_buffer[len] = '\0';
    utf8 *path = widechar_to_utf8(w_buffer);
    free(w_buffer);
    safe_strcpy(_userDataDirectoryPath, path, MAX_PATH);
    free(path);
    log_verbose("User data path resolved to: %s", _userDataDirectoryPath);
}