static int get_thumb_dir(char *dir, ThumbSize size) { #ifdef WIN32 wchar_t dir_16[MAX_PATH]; /* yes, applications shouldn't store data there, but so does GIMP :)*/ SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0); conv_utf_16_to_8(dir_16, dir, FILE_MAX); #else const char *home = getenv("HOME"); if (!home) return 0; BLI_strncpy(dir, home, FILE_MAX); #endif switch (size) { case THB_NORMAL: strcat(dir, "/.thumbnails/normal/"); break; case THB_LARGE: strcat(dir, "/.thumbnails/large/"); break; case THB_FAIL: strcat(dir, "/.thumbnails/fail/blender/"); break; default: return 0; /* unknown size */ } return 1; }
static char *BLI_alloc_utf_8_from_16(wchar_t *in16, size_t add) { size_t bsize = count_utf_8_from_16(in16); char *out8 = NULL; if (!bsize) return NULL; out8 = (char *)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String"); conv_utf_16_to_8(in16, out8, bsize); return out8; }
static size_t updateUtf8Buf(ImeComposition &info) { size_t len = count_utf_8_from_16(info.ime_string.c_str()); info.utf8_buf.resize(len); conv_utf_16_to_8(info.ime_string.c_str(), &info.utf8_buf[0], len); convert_utf16_to_utf8_len(info.ime_string, info.cursor_position); convert_utf16_to_utf8_len(info.ime_string, info.target_start); convert_utf16_to_utf8_len(info.ime_string, info.target_end); return len - 1; }
const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const { static char fullname[MAX_PATH*3] = {0}; wchar_t fullname_16[MAX_PATH*3]; if(GetModuleFileNameW(0, fullname_16, MAX_PATH)) { conv_utf_16_to_8(fullname_16,fullname,MAX_PATH*3); return (GHOST_TUns8*)fullname; } return NULL; }
GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw) { int keyDown = 0; char vk; GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem(); GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk); GHOST_EventKey *event; if (key != GHOST_kKeyUnknown) { char utf8_char[6] = {0}; char ascii = 0; wchar_t utf16[3] = {0}; BYTE state[256] = {0}; int r; GetKeyboardState((PBYTE)state); // don't call ToUnicodeEx on dead keys as it clears the buffer and so won't allow diacritical composition. if (MapVirtualKeyW(vk,2) != 0) { // todo: ToUnicodeEx can respond with up to 4 utf16 chars (only 2 here). Could be up to 24 utf8 bytes. if ((r = ToUnicodeEx(vk, raw.data.keyboard.MakeCode, state, utf16, 2, 0, system->m_keylayout))) { if ((r > 0 && r < 3)) { utf16[r] = 0; conv_utf_16_to_8(utf16, utf8_char, 6); } else if (r == -1) { utf8_char[0] = '\0'; } } } if (!keyDown) { utf8_char[0] = '\0'; ascii = '\0'; } else { ascii = utf8_char[0] & 0x80 ? '?' : utf8_char[0]; } event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, key, ascii, utf8_char); #ifdef GHOST_DEBUG std::cout << ascii << std::endl; #endif } else { event = 0; } return event; }
const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const { static char knownpath[MAX_PATH*3] = {0}; wchar_t knownpath_16[MAX_PATH]; HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16); if (hResult == S_OK) { conv_utf_16_to_8(knownpath_16,knownpath,MAX_PATH*3); return (GHOST_TUns8*)knownpath; } return NULL; }
const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const { static char knownpath[MAX_PATH*3] = {0}; /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/ wchar_t knownpath_16[MAX_PATH]; HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16); if (hResult == S_OK) { conv_utf_16_to_8(knownpath_16,knownpath,MAX_PATH*3); return (GHOST_TUns8*)knownpath; } return NULL; }
static bool get_thumb_dir(char *dir, ThumbSize size) { char *s = dir; const char *subdir; #ifdef WIN32 wchar_t dir_16[MAX_PATH]; /* yes, applications shouldn't store data there, but so does GIMP :)*/ SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0); conv_utf_16_to_8(dir_16, dir, FILE_MAX); s += strlen(dir); #else #if defined(USE_FREEDESKTOP) const char *home_cache = getenv("XDG_CACHE_HOME"); const char *home = home_cache ? home_cache : getenv("HOME"); #else const char *home = getenv("HOME"); #endif if (!home) return 0; s += BLI_strncpy_rlen(s, home, FILE_MAX); #ifdef USE_FREEDESKTOP if (!home_cache) { s += BLI_strncpy_rlen(s, "/.cache", FILE_MAX - (s - dir)); } #endif #endif switch (size) { case THB_NORMAL: subdir = "/" THUMBNAILS "/normal/"; break; case THB_LARGE: subdir = "/" THUMBNAILS "/large/"; break; case THB_FAIL: subdir = "/" THUMBNAILS "/fail/blender/"; break; default: return 0; /* unknown size */ } s += BLI_strncpy_rlen(s, subdir, FILE_MAX - (s - dir)); (void)s; return 1; }
int uput_getenv(const char *varname, char * value, size_t buffsize) { int r = 0; wchar_t * str; if(!buffsize) return r; UTF16_ENCODE(varname); if(varname_16) { str = _wgetenv(varname_16); conv_utf_16_to_8(str, value, buffsize); r = 1; } UTF16_UN_ENCODE(varname); if (!r) value[0] = 0; return r; }
/** * Checks if name is a fully qualified filename to an executable. * If not it searches $PATH for the file. On Windows it also * adds the correct extension (.com .exe etc) from * $PATHEXT if necessary. Also on Windows it translates * the name to its 8.3 version to prevent problems with * spaces and stuff. Final result is returned in fullname. * * \param fullname The full path and full name of the executable * (must be FILE_MAX minimum) * \param name The name of the executable (usually argv[0]) to be checked */ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name) { char filename[FILE_MAX]; const char *path = NULL, *temp; #ifdef _WIN32 const char *separator = ";"; #else const char *separator = ":"; #endif #ifdef WITH_BINRELOC /* linux uses binreloc since argv[0] is not reliable, call br_init( NULL ) first */ path = br_find_exe(NULL); if (path) { BLI_strncpy(fullname, path, maxlen); free((void *)path); return; } #endif #ifdef _WIN32 wchar_t *fullname_16 = MEM_mallocN(maxlen * sizeof(wchar_t), "ProgramPath"); if (GetModuleFileNameW(0, fullname_16, maxlen)) { conv_utf_16_to_8(fullname_16, fullname, maxlen); if (!BLI_exists(fullname)) { printf("path can't be found: \"%.*s\"\n", maxlen, fullname); MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); } MEM_freeN(fullname_16); return; } MEM_freeN(fullname_16); #endif /* unix and non linux */ if (name && name[0]) { BLI_strncpy(fullname, name, maxlen); if (name[0] == '.') { char wdir[FILE_MAX] = ""; BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ // not needed but avoids annoying /./ in name if (name[1] == SEP) BLI_join_dirfile(fullname, maxlen, wdir, name + 2); else BLI_join_dirfile(fullname, maxlen, wdir, name); add_win32_extension(fullname); /* XXX, doesnt respect length */ } else if (BLI_last_slash(name)) { // full path BLI_strncpy(fullname, name, maxlen); add_win32_extension(fullname); } else { // search for binary in $PATH path = getenv("PATH"); if (path) { do { temp = strstr(path, separator); if (temp) { strncpy(filename, path, temp - path); filename[temp - path] = 0; path = temp + 1; } else { strncpy(filename, path, sizeof(filename)); } BLI_join_dirfile(fullname, maxlen, fullname, name); if (add_win32_extension(filename)) { BLI_strncpy(fullname, filename, maxlen); break; } } while (temp); } } #if defined(DEBUG) if (strcmp(name, fullname)) { printf("guessing '%s' == '%s'\n", name, fullname); } #endif } }