diff options
Diffstat (limited to 'source/blender/blenlib/intern/winstuff.c')
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index d853e398adc..3eb62228aad 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -44,16 +44,16 @@ #include "BKE_utildefines.h" #include "BKE_global.h" -#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY +#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #include "BLI_winstuff.h" #include "BLI_utildefines.h" #include "utf_winfunc.h" #include "utfconv.h" - /* FILE_MAXDIR + FILE_MAXFILE */ +/* FILE_MAXDIR + FILE_MAXFILE */ -int BLI_getInstallationDir(char * str) +int BLI_getInstallationDir(char *str) { char dir[FILE_MAXDIR]; int a; @@ -61,7 +61,7 @@ int BLI_getInstallationDir(char * str) GetModuleFileName(NULL, str, FILE_MAX); BLI_split_dir_part(str, dir, sizeof(dir)); /* shouldn't be relative */ a = strlen(dir); - if (dir[a-1] == '\\') dir[a-1]=0; + if (dir[a - 1] == '\\') dir[a - 1] = 0; strcpy(str, dir); @@ -74,7 +74,7 @@ void RegisterBlendExtension_Fail(HKEY root) if (root) RegCloseKey(root); if (!G.background) - MessageBox(0, "Could not register file extension.", "Blender error", MB_OK|MB_ICONERROR); + MessageBox(0, "Could not register file extension.", "Blender error", MB_OK | MB_ICONERROR); TerminateProcess(GetCurrentProcess(), 1); } @@ -91,7 +91,7 @@ void RegisterBlendExtension(void) char InstallDir[FILE_MAXDIR]; char SysDir[FILE_MAXDIR]; const char *ThumbHandlerDLL; - char RegCmd[MAX_PATH*2]; + char RegCmd[MAX_PATH * 2]; char MBox[256]; BOOL IsWOW64; @@ -109,40 +109,40 @@ void RegisterBlendExtension(void) } lresult = RegCreateKeyEx(root, "blendfile", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { strcpy(buffer, "Blender File"); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) RegisterBlendExtension_Fail(root); lresult = RegCreateKeyEx(root, "blendfile\\shell\\open\\command", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "\"%s\" \"%%1\"", BlPath); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) RegisterBlendExtension_Fail(root); lresult = RegCreateKeyEx(root, "blendfile\\DefaultIcon", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "\"%s\", 1", BlPath); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) RegisterBlendExtension_Fail(root); lresult = RegCreateKeyEx(root, ".blend", 0, - NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "%s", "blendfile"); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } if (lresult != ERROR_SUCCESS) @@ -159,32 +159,32 @@ void RegisterBlendExtension(void) else ThumbHandlerDLL = "BlendThumb.dll"; #endif - snprintf(RegCmd, MAX_PATH*2, "%s\\regsvr32 /s \"%s\\%s\"", SysDir, InstallDir, ThumbHandlerDLL); + snprintf(RegCmd, MAX_PATH * 2, "%s\\regsvr32 /s \"%s\\%s\"", SysDir, InstallDir, ThumbHandlerDLL); system(RegCmd); RegCloseKey(root); printf("success (%s)\n", usr_mode ? "user" : "system"); if (!G.background) { sprintf(MBox, "File extension registered for %s.", usr_mode ? "the current user. To register for all users, run as an administrator" : "all users"); - MessageBox(0, MBox, "Blender", MB_OK|MB_ICONINFORMATION); + MessageBox(0, MBox, "Blender", MB_OK | MB_ICONINFORMATION); } TerminateProcess(GetCurrentProcess(), 0); } -DIR *opendir (const char *path) +DIR *opendir(const char *path) { wchar_t *path_16 = alloc_utf16_from_8(path, 0); if (GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) { - DIR *newd= MEM_mallocN(sizeof(DIR), "opendir"); + DIR *newd = MEM_mallocN(sizeof(DIR), "opendir"); newd->handle = INVALID_HANDLE_VALUE; sprintf(newd->path, "%s\\*", path); - newd->direntry.d_ino= 0; - newd->direntry.d_off= 0; - newd->direntry.d_reclen= 0; - newd->direntry.d_name= NULL; + newd->direntry.d_ino = 0; + newd->direntry.d_off = 0; + newd->direntry.d_reclen = 0; + newd->direntry.d_name = NULL; free(path_16); return newd; @@ -200,43 +200,42 @@ 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"); + out8 = (char *)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String"); conv_utf_16_to_8(in16, out8, bsize); return out8; } -static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8)(char *in8, size_t add) +static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8) (char *in8, size_t add) { size_t bsize = count_utf_16_from_8(in8); wchar_t *out16 = NULL; if (!bsize) return NULL; - out16 =(wchar_t*) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String"); + out16 = (wchar_t *) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String"); conv_utf_8_to_16(in8, out16, bsize); return out16; } -struct dirent *readdir(DIR *dp) -{ +struct dirent *readdir(DIR *dp){ if (dp->direntry.d_name) { MEM_freeN(dp->direntry.d_name); - dp->direntry.d_name= NULL; + dp->direntry.d_name = NULL; } - if (dp->handle==INVALID_HANDLE_VALUE) { - wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0); - dp->handle= FindFirstFileW(path_16, &(dp->data)); + if (dp->handle == INVALID_HANDLE_VALUE) { + wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0); + dp->handle = FindFirstFileW(path_16, &(dp->data)); free(path_16); - if (dp->handle==INVALID_HANDLE_VALUE) + if (dp->handle == INVALID_HANDLE_VALUE) return NULL; - dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); + dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); return &dp->direntry; } - else if (FindNextFileW (dp->handle, &(dp->data))) { - dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); + else if (FindNextFileW(dp->handle, &(dp->data))) { + dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); return &dp->direntry; } @@ -248,7 +247,7 @@ struct dirent *readdir(DIR *dp) int closedir(DIR *dp) { if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name); - if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle); + if (dp->handle != INVALID_HANDLE_VALUE) FindClose(dp->handle); MEM_freeN(dp); @@ -257,12 +256,12 @@ int closedir(DIR *dp) void get_default_root(char *root) { - char str[MAX_PATH+1]; + char str[MAX_PATH + 1]; /* the default drive to resolve a directory without a specified drive * should be the Windows installation drive, since this was what the OS * assumes. */ - if (GetWindowsDirectory(str, MAX_PATH+1)) { + if (GetWindowsDirectory(str, MAX_PATH + 1)) { root[0] = str[0]; root[1] = ':'; root[2] = '\\'; @@ -271,7 +270,7 @@ void get_default_root(char *root) else { /* if GetWindowsDirectory fails, something has probably gone wrong, * we are trying the blender install dir though */ - if (GetModuleFileName(NULL, str, MAX_PATH+1)) { + if (GetModuleFileName(NULL, str, MAX_PATH + 1)) { printf("Error! Could not get the Windows Directory - Defaulting to Blender installation Dir!"); root[0] = str[0]; root[1] = ':'; @@ -284,10 +283,10 @@ void get_default_root(char *root) int rc = 0; /* now something has gone really wrong - still trying our best guess */ printf("Error! Could not get the Windows Directory - Defaulting to first valid drive! Path might be invalid!"); - tmp= GetLogicalDrives(); - for (i=2; i < 26; i++) { - if ((tmp>>i) & 1) { - root[0] = 'a'+i; + tmp = GetLogicalDrives(); + for (i = 2; i < 26; i++) { + if ((tmp >> i) & 1) { + root[0] = 'a' + i; root[1] = ':'; root[2] = '\\'; root[3] = '\0'; @@ -338,20 +337,20 @@ int check_file_chars(char *filename) const char *dirname(char *path) { char *p; - if ( path == NULL || *path == '\0' ) + if (path == NULL || *path == '\0') return "."; p = path + strlen(path) - 1; - while ( *p == '/' ) { - if ( p == path ) + while (*p == '/') { + if (p == path) return path; *p-- = '\0'; } - while ( p >= path && *p != '/' ) + while (p >= path && *p != '/') p--; return - p < path ? "." : - p == path ? "/" : - (*p = '\0', path); + p < path ? "." : + p == path ? "/" : + (*p = '\0', path); } /* End of copied part */ |