From e4e78d475457ad86f5f29a0ccbd0090c2ba6b1d6 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Tue, 29 Mar 2011 13:00:03 +0000 Subject: Apply [#26044] Windows thumbnails and improved filetype registration submitted by Tom Edwards Fix [#25473] 64bit Windows installer for version 2.56 is not working patch submitted by Caleb (Dobz) The thumbnail patch adds a thumb handler DLL that adds .blend thumbnail support in Windows Explorer. A -r option is added to do registration in background. The patch also improves icon building and metadata for blender.exe. Caleb fixes and cleans up our installer to an acceptable state. The patch uses the new -r option to do the .blend extension and thumbnailer registration. Thanks to both Caleb and Tom for their efforts! --- source/blender/blenlib/BLI_winstuff.h | 2 +- source/blender/blenlib/intern/winstuff.c | 100 ++++++++++++++++++++++++++----- 2 files changed, 86 insertions(+), 16 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index 957e5fd0b78..d0eb3c7d67d 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -127,7 +127,7 @@ typedef struct _DIR { struct dirent direntry; } DIR; -void RegisterBlendExtension(char * str); +void RegisterBlendExtension(void); DIR *opendir (const char *path); struct dirent *readdir(DIR *dp); int closedir (DIR *dp); diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index a6dae7958cc..2f750545223 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -43,6 +43,7 @@ #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" @@ -64,39 +65,108 @@ int BLI_getInstallationDir( char * str ) { return 1; } +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(char * str) { +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]; + 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) { -- cgit v1.2.3