Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/appdir.c
| Show All 35 Lines | |||||
| #include "BKE_blender_version.h" | #include "BKE_blender_version.h" | ||||
| #include "BKE_appdir.h" /* own include */ | #include "BKE_appdir.h" /* own include */ | ||||
| #include "GHOST_Path-api.h" | #include "GHOST_Path-api.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "CLG_log.h" | |||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| # include "utf_winfunc.h" | # include "utf_winfunc.h" | ||||
| # include "utfconv.h" | # include "utfconv.h" | ||||
| # include <io.h> | # include <io.h> | ||||
| # ifdef _WIN32_IE | # ifdef _WIN32_IE | ||||
| # undef _WIN32_IE | # undef _WIN32_IE | ||||
| # endif | # endif | ||||
| # define _WIN32_IE 0x0501 | # define _WIN32_IE 0x0501 | ||||
| # include <windows.h> | # include <windows.h> | ||||
| # include <shlobj.h> | # include <shlobj.h> | ||||
| # include "BLI_winstuff.h" | # include "BLI_winstuff.h" | ||||
| #else /* non windows */ | #else /* non windows */ | ||||
| # ifdef WITH_BINRELOC | # ifdef WITH_BINRELOC | ||||
| # include "binreloc.h" | # include "binreloc.h" | ||||
| # endif | # endif | ||||
| # include <unistd.h> /* mkdtemp on OSX (and probably all *BSD?), not worth making specific check for this OS. */ | # include <unistd.h> /* mkdtemp on OSX (and probably all *BSD?), not worth making specific check for this OS. */ | ||||
| #endif /* WIN32 */ | #endif /* WIN32 */ | ||||
| /* local */ | /* local */ | ||||
| static CLG_LogRef LOG = {"bke.appdir"}; | |||||
| static char bprogname[FILE_MAX]; /* full path to program executable */ | static char bprogname[FILE_MAX]; /* full path to program executable */ | ||||
| static char bprogdir[FILE_MAX]; /* full path to directory in which executable is located */ | static char bprogdir[FILE_MAX]; /* full path to directory in which executable is located */ | ||||
| static char btempdir_base[FILE_MAX]; /* persistent temporary directory */ | static char btempdir_base[FILE_MAX]; /* persistent temporary directory */ | ||||
| static char btempdir_session[FILE_MAX] = ""; /* volatile temporary directory */ | static char btempdir_session[FILE_MAX] = ""; /* volatile temporary directory */ | ||||
| /* This is now only used to really get the user's default document folder */ | /* This is now only used to really get the user's default document folder */ | ||||
| /* On Windows I chose the 'Users/<MyUserName>/Documents' since it's used | /* On Windows I chose the 'Users/<MyUserName>/Documents' since it's used | ||||
| * as default location to save documents */ | * as default location to save documents */ | ||||
| ▲ Show 20 Lines • Show All 493 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| { | { | ||||
| wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath"); | wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath"); | ||||
| if (GetModuleFileNameW(0, fullname_16, maxlen)) { | if (GetModuleFileNameW(0, fullname_16, maxlen)) { | ||||
| conv_utf_16_to_8(fullname_16, fullname, maxlen); | conv_utf_16_to_8(fullname_16, fullname, maxlen); | ||||
| if (!BLI_exists(fullname)) { | if (!BLI_exists(fullname)) { | ||||
| printf("path can't be found: \"%.*s\"\n", (int)maxlen, fullname); | CLOG_ERROR(&LOG, "path can't be found: \"%.*s\"", (int)maxlen, fullname); | ||||
| MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); | MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); | ||||
| } | } | ||||
| MEM_freeN(fullname_16); | MEM_freeN(fullname_16); | ||||
| return; | return; | ||||
| } | } | ||||
| MEM_freeN(fullname_16); | MEM_freeN(fullname_16); | ||||
| } | } | ||||
| Show All 19 Lines | #endif | ||||
| else { | else { | ||||
| BLI_path_program_search(fullname, maxlen, name); | BLI_path_program_search(fullname, maxlen, name); | ||||
| } | } | ||||
| /* Remove "/./" and "/../" so string comparisons can be used on the path. */ | /* Remove "/./" and "/../" so string comparisons can be used on the path. */ | ||||
| BLI_cleanup_path(NULL, fullname); | BLI_cleanup_path(NULL, fullname); | ||||
| #if defined(DEBUG) | #if defined(DEBUG) | ||||
| if (!STREQ(name, fullname)) { | if (!STREQ(name, fullname)) { | ||||
| printf("guessing '%s' == '%s'\n", name, fullname); | CLOG_INFO(&LOG, 2, "guessing '%s' == '%s'", name, fullname); | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| void BKE_appdir_program_path_init(const char *argv0) | void BKE_appdir_program_path_init(const char *argv0) | ||||
| { | { | ||||
| where_am_i(bprogname, sizeof(bprogname), argv0); | where_am_i(bprogname, sizeof(bprogname), argv0); | ||||
| ▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| } | } | ||||
| if (BLI_is_dir(tmp_name)) { | if (BLI_is_dir(tmp_name)) { | ||||
| BLI_strncpy(basename, fullname, maxlen); | BLI_strncpy(basename, fullname, maxlen); | ||||
| BLI_strncpy(fullname, tmp_name, maxlen); | BLI_strncpy(fullname, tmp_name, maxlen); | ||||
| BLI_add_slash(fullname); | BLI_add_slash(fullname); | ||||
| } | } | ||||
| else { | else { | ||||
| printf("Warning! Could not generate a temp file name for '%s', falling back to '%s'\n", tmp_name, fullname); | CLOG_WARN(&LOG, "Could not generate a temp file name for '%s', falling back to '%s'", tmp_name, fullname); | ||||
| } | } | ||||
| MEM_freeN(tmp_name); | MEM_freeN(tmp_name); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Sets btempdir_base to userdir if specified and is a valid directory, otherwise | * Sets btempdir_base to userdir if specified and is a valid directory, otherwise | ||||
| ▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines | |||||