diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2011-03-29 17:00:03 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2011-03-29 17:00:03 +0400 |
commit | e4e78d475457ad86f5f29a0ccbd0090c2ba6b1d6 (patch) | |
tree | f83fbddff846b39862f2d6bc2af4020bd6821009 /source/blender/blenlib/intern/winstuff.c | |
parent | 74e044065b35e5444871f8f5836b221144588082 (diff) |
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!
Diffstat (limited to 'source/blender/blenlib/intern/winstuff.c')
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 100 |
1 files changed, 85 insertions, 15 deletions
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) { |