From c7b923b11973c7a36b53992d21d052b96978f4d7 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 13 Aug 2013 04:29:47 +0000 Subject: [PATCH] Update registry file associations at startup. --- qt/qtmain.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ tools/setup/leocad.nsi | 23 ++++++++------------ 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 44006800..5ee32f7c 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -5,6 +5,53 @@ #include "mainwnd.h" #include +#ifdef Q_OS_WIN + +static void lcRegisterShellFileTypes() +{ + TCHAR modulePath[_MAX_PATH], longModulePath[_MAX_PATH]; + TCHAR temp[2*_MAX_PATH]; + + GetModuleFileName(NULL, longModulePath, _MAX_PATH); + if (GetShortPathName(longModulePath, modulePath, _MAX_PATH) == 0) + lstrcpy(modulePath, longModulePath); + + if (RegSetValue(HKEY_CLASSES_ROOT, TEXT("LeoCAD.Project"), REG_SZ, TEXT("LeoCAD Project"), lstrlen(TEXT("LeoCAD Project")) * sizeof(TCHAR)) != ERROR_SUCCESS) + return; + + lstrcpy(temp, modulePath); + lstrcat(temp, TEXT(",0")); + if (RegSetValue(HKEY_CLASSES_ROOT, TEXT("LeoCAD.Project\\DefaultIcon"), REG_SZ, temp, lstrlen(temp) * sizeof(TCHAR)) != ERROR_SUCCESS) + return; + + lstrcpy(temp, modulePath); + lstrcat(temp, TEXT(" \"%1\"")); + if (RegSetValue(HKEY_CLASSES_ROOT, TEXT("LeoCAD.Project\\shell\\open\\command"), REG_SZ, temp, lstrlen(temp) * sizeof(TCHAR)) != ERROR_SUCCESS) + return; + + LONG size = 2 * _MAX_PATH; + LONG result = RegQueryValue(HKEY_CLASSES_ROOT, TEXT(".lcd"), temp, &size); + + if (result != ERROR_SUCCESS || !lstrlen(temp) || lstrcmp(temp, TEXT("LeoCAD.Project"))) + { + if (RegSetValue(HKEY_CLASSES_ROOT, TEXT(".lcd"), REG_SZ, TEXT("LeoCAD.Project"), lstrlen(TEXT("LeoCAD.Project")) * sizeof(TCHAR)) != ERROR_SUCCESS) + return; + + HKEY key; + DWORD disposition = 0; + + if (RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT(".lcd\\ShellNew"), 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key, &disposition) != ERROR_SUCCESS) + return; + + LONG result = RegSetValueEx(key, TEXT("NullFile"), 0, REG_SZ, (CONST BYTE*)TEXT(""), (lstrlen(TEXT("")) + 1) * sizeof(TCHAR)); + + if (RegCloseKey(key) != ERROR_SUCCESS || result != ERROR_SUCCESS) + return; + } +} + +#endif + int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -23,6 +70,8 @@ int main(int argc, char *argv[]) ptr = strrchr(libPath,'\\'); if (ptr) *(++ptr) = 0; + + lcRegisterShellFileTypes(); #endif #ifdef Q_OS_LINUX diff --git a/tools/setup/leocad.nsi b/tools/setup/leocad.nsi index 1832d055..5673a928 100644 --- a/tools/setup/leocad.nsi +++ b/tools/setup/leocad.nsi @@ -56,16 +56,11 @@ Section "LeoCAD" SecLeoCAD SetOutPath "$INSTDIR" - File "..\..\win\release\LeoCAD.exe" - File "..\..\win\release\LeoCAD.hlp" - File "..\..\win\release\LeoCAD.cnt" - File "..\..\readme.txt" - File "..\..\win\release\library.bin" - ;File "..\..\win\release\pieces.bin" - ;File "..\..\win\release\pieces.idx" - ;File "..\..\win\release\textures.bin" - ;File "..\..\win\release\textures.idx" - ;File "..\..\win\release\sysfont.txf" + File "LeoCAD.exe" + File "LeoCAD.hlp" + File "LeoCAD.cnt" + File "ReadMe.txt" + File "library.bin" ;Register file extension WriteRegStr HKCR ".lcd" "" "LeoCAD.Project" @@ -74,10 +69,10 @@ Section "LeoCAD" SecLeoCAD WriteRegStr HKCR "LeoCAD.Project\DefaultIcon" "" "$INSTDIR\LeoCAD.exe,0" WriteRegStr HKCR "LeoCAD.Project\shell" "" "open" WriteRegStr HKCR "LeoCAD.Project\shell\open\command" "" '"$INSTDIR\LeoCAD.exe" "%1"' - WriteRegStr HKCR "LeoCAD.Project\shell" "" "print" - WriteRegStr HKCR "LeoCAD.Project\shell\print\command" "" '"$INSTDIR\LeoCAD.exe" /p "%1"' - WriteRegStr HKCR "LeoCAD.Project\shell" "" "printto" - WriteRegStr HKCR "LeoCAD.Project\shell\printto\command" "" '"$INSTDIR\LeoCAD.exe" /pt "%1" "%2" "%3" "%4"' + ;WriteRegStr HKCR "LeoCAD.Project\shell" "" "print" + ;WriteRegStr HKCR "LeoCAD.Project\shell\print\command" "" '"$INSTDIR\LeoCAD.exe" /p "%1"' + ;WriteRegStr HKCR "LeoCAD.Project\shell" "" "printto" + ;WriteRegStr HKCR "LeoCAD.Project\shell\printto\command" "" '"$INSTDIR\LeoCAD.exe" /pt "%1" "%2" "%3" "%4"' System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)' ;Store installation folder