diff options
Diffstat (limited to 'source/blender/blenlib/intern/winstuff.c')
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 114 |
1 files changed, 99 insertions, 15 deletions
diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 71eac3c86c4..90754e7d2bb 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -28,16 +28,23 @@ * Windows-posix compatibility layer, windows-specific functions. */ +/** \file blender/blenlib/intern/winstuff.c + * \ingroup bli + */ + + #ifdef WIN32 #include <stdlib.h> #include <stdio.h> +#include <conio.h> #include "MEM_guardedalloc.h" #include "BLI_path_util.h" #include "BLI_string.h" #include "BKE_utildefines.h" +#include "BKE_global.h" #define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #include "BLI_winstuff.h" @@ -59,39 +66,116 @@ int BLI_getInstallationDir( char * str ) { return 1; } +int IsConsoleEmpty(void) +{ + CONSOLE_SCREEN_BUFFER_INFO csbi = {{0}}; + HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); + + return GetConsoleScreenBufferInfo(hStdOutput, &csbi) && csbi.dwCursorPosition.X == 0 && csbi.dwCursorPosition.Y == 0; +} -void RegisterBlendExtension(char * str) { +void RegisterBlendExtension_Fail(HKEY root) +{ + printf("failed\n"); + if (root) + RegCloseKey(root); + if (!G.background) + MessageBox(0,"Could not register file extension.","Blender error",MB_OK|MB_ICONERROR); + TerminateProcess(GetCurrentProcess(),1); +} + +void RegisterBlendExtension(void) { LONG lresult; HKEY hkey = 0; + HKEY root = 0; + BOOL usr_mode = FALSE; DWORD dwd = 0; - char buffer[128]; - - lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\shell\\open\\command", 0, - "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + char buffer[256]; + + char BlPath[MAX_PATH]; + char InstallDir[FILE_MAXDIR]; + char SysDir[FILE_MAXDIR]; + const char* ThumbHandlerDLL; + char RegCmd[MAX_PATH*2]; + char MBox[256]; + BOOL IsWOW64; + printf("Registering file extension..."); + GetModuleFileName(0,BlPath,MAX_PATH); + + // root is HKLM by default + lresult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Classes", 0, KEY_ALL_ACCESS, &root); + if (lresult != ERROR_SUCCESS) + { + // try HKCU on failure + usr_mode = TRUE; + lresult = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Classes", 0, KEY_ALL_ACCESS, &root); + if (lresult != ERROR_SUCCESS) + RegisterBlendExtension_Fail(0); + } + + lresult = RegCreateKeyEx(root, "blendfile", 0, + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { - sprintf(buffer, "\"%s\" \"%%1\"", str); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1); + sprintf(buffer,"%s","Blender File"); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } + if (lresult != ERROR_SUCCESS) + RegisterBlendExtension_Fail(root); - lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\DefaultIcon", 0, - "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); - + lresult = RegCreateKeyEx(root, "blendfile\\shell\\open\\command", 0, + NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); if (lresult == ERROR_SUCCESS) { - sprintf(buffer, "\"%s\",1", str); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1); + sprintf(buffer, "\"%s\" \"%%1\"", BlPath); + lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE*)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } + if (lresult != ERROR_SUCCESS) + RegisterBlendExtension_Fail(root); - lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".blend", 0, - "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); + lresult = RegCreateKeyEx(root, "blendfile\\DefaultIcon", 0, + 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); + 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); if (lresult == ERROR_SUCCESS) { sprintf(buffer, "%s", "blendfile"); - lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, 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); + + BLI_getInstallationDir(InstallDir); + GetSystemDirectory(SysDir,FILE_MAXDIR); +#ifdef WIN64 + ThumbHandlerDLL = "BlendThumb64.dll"; +#else + IsWow64Process(GetCurrentProcess(),&IsWOW64); + if (IsWOW64 == TRUE) + ThumbHandlerDLL = "BlendThumb64.dll"; + else + ThumbHandlerDLL = "BlendThumb.dll"; +#endif + 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); + } + TerminateProcess(GetCurrentProcess(),0); } DIR *opendir (const char *path) { |