From d7f8e2933f706643ae674808fb0ddbb3fbdfee33 Mon Sep 17 00:00:00 2001 From: micio Date: Sun, 16 Jan 2011 23:16:02 +0000 Subject: [PATCH] Bazaar/Updater : fixed compilation on windows git-svn-id: svn://ultimatepp.org/upp/trunk@3026 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/Updater/Windows.cpp | 276 ++++++++++++++++++------------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/bazaar/Updater/Windows.cpp b/bazaar/Updater/Windows.cpp index 1d5947404..91e5e3166 100644 --- a/bazaar/Updater/Windows.cpp +++ b/bazaar/Updater/Windows.cpp @@ -1,138 +1,138 @@ -#include "Updater.h" - -#ifdef PLATFORM_WIN32 - - -#define Ptr Ptr_ -#define byte byte_ -#define CY win32_CY_ - - -#include -#include - -#include -#include - -#undef Ptr -#undef byte -#undef CY - - -// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ò - -String GetShellFolder(const char *name, HKEY type) -{ - return GetWinRegString(name, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", type); -} - -void DelKey(const char *dir, const char *key) -{ - HKEY hkey; - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &hkey) != ERROR_SUCCESS) - return; - RegDeleteKey(hkey, key); - RegCloseKey(hkey); -} - -bool CreateShellLink(const char *filepath, const char *linkpath, const char *desc, int icon) -{ - HRESULT hres; - IShellLink* psl; - IPersistFile* ppf; - CoInitialize(NULL); - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (PVOID *) &psl); - if(SUCCEEDED(hres)) - { - psl->SetPath(filepath); - psl->SetDescription(desc); - if(icon >= 0) - psl->SetIconLocation(filepath, icon); - hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf); - if (SUCCEEDED(hres)) - { - WCHAR szPath[_MAX_PATH] = { 0 }; - MultiByteToWideChar(CP_ACP, 0, linkpath, (int)strlen(linkpath), szPath, _MAX_PATH); - hres = ppf->Save(szPath, TRUE); - ppf->Release(); - } - } - psl->Release(); - CoUninitialize(); - return SUCCEEDED(hres); -} - -// links application to OS shell -// (i.e., add icon, menu entry, mimetype....) -bool Updater::ShellLink(void) -{ - bool success = true; - - String exePath = GetProgramsFolder() + "/" + appName + "/" + appName + ".exe"; - String linkName = appName + ".lnk"; - - // installs desktop icon - if(desktopIcon) - { - String desktopPath = GetShellFolder("Desktop", HKEY_USERS); - CreateShellLink(exePath, AppendFileName(desktopPath, linkName), comment, -1); - } - - // installs program group - // we could use "cathegory" to create a menu group... but I don't - // know how internationalize it. On ubuntu is automatic. - // maybe we could add it later - String groupName = ""; // that could be GetLNGString(cathegory) ???? - String groupFolder = GetShellFolder("Common Programs", HKEY_LOCAL_MACHINE); - if(groupName != "") - { - groupFolder = AppendFileName(groupFolder, groupName); - CreateDirectory(groupFolder, NULL); - } - CreateShellLink(exePath, AppendFileName(groupFolder, linkName), comment, -1); - - // installs uninstaller - String uninstallRegPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + appName; - SetWinRegString(appName, "DisplayName", uninstallRegPath); - SetWinRegString(appName + " --UNINSTALL", "UninstallString", uninstallRegPath); - - return success; -} - -// unlinks application -bool Updater::ShellUnlink(void) -{ - bool success = true; - - String linkName = appName + ".lnk"; - - // remove uninstaller - DelKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + appName, "DisplayName"); - DelKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + appName, "UninstallString"); - DelKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", appName); - - // remove program group - String groupName = ""; // that could be GetLNGString(cathegory) ???? - String groupFolder = GetShellFolder("Common Programs", HKEY_LOCAL_MACHINE); - if(groupName != "") - { - groupFolder = AppendFileName(groupFolder, groupName); - if(PathExists(groupFolder)) - DeleteFolderDeep(groupFolder); - } - else - { - Strink linkPath = AppendFileName(groupFolder, linkName); - if(FileExists(linkPath)) - FileDelete(linkPath); - } - - // remove desktop icon - String desktopLink = AppendFileName(GetShellFolder("Desktop", HKEY_USERS), linkName); - if(FileExists(desktopLink)) - FileDelete(desktopLine); - - return success; -} - -#endif +#include "Updater.h" + +#ifdef PLATFORM_WIN32 + + +#define Ptr Ptr_ +#define byte byte_ +#define CY win32_CY_ + + +#include +#include + +#include +#include + +#undef Ptr +#undef byte +#undef CY + + +// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ò + +String GetShellFolder(const char *name, HKEY type) +{ + return GetWinRegString(name, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", type); +} + +void DelKey(const char *dir, const char *key) +{ + HKEY hkey; + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &hkey) != ERROR_SUCCESS) + return; + RegDeleteKey(hkey, key); + RegCloseKey(hkey); +} + +bool CreateShellLink(const char *filepath, const char *linkpath, const char *desc, int icon) +{ + HRESULT hres; + IShellLink* psl; + IPersistFile* ppf; + CoInitialize(NULL); + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (PVOID *) &psl); + if(SUCCEEDED(hres)) + { + psl->SetPath(filepath); + psl->SetDescription(desc); + if(icon >= 0) + psl->SetIconLocation(filepath, icon); + hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf); + if (SUCCEEDED(hres)) + { + WCHAR szPath[_MAX_PATH] = { 0 }; + MultiByteToWideChar(CP_ACP, 0, linkpath, (int)strlen(linkpath), szPath, _MAX_PATH); + hres = ppf->Save(szPath, TRUE); + ppf->Release(); + } + } + psl->Release(); + CoUninitialize(); + return SUCCEEDED(hres); +} + +// links application to OS shell +// (i.e., add icon, menu entry, mimetype....) +bool Updater::ShellLink(void) +{ + bool success = true; + + String exePath = GetProgramsFolder() + "/" + appName + "/" + appName + ".exe"; + String linkName = appName + ".lnk"; + + // installs desktop icon + if(desktopIcon) + { + String desktopPath = GetShellFolder("Desktop", HKEY_USERS); + CreateShellLink(exePath, AppendFileName(desktopPath, linkName), comment, -1); + } + + // installs program group + // we could use "cathegory" to create a menu group... but I don't + // know how internationalize it. On ubuntu is automatic. + // maybe we could add it later + String groupName = ""; // that could be GetLNGString(cathegory) ???? + String groupFolder = GetShellFolder("Common Programs", HKEY_LOCAL_MACHINE); + if(groupName != "") + { + groupFolder = AppendFileName(groupFolder, groupName); + CreateDirectory(groupFolder, NULL); + } + CreateShellLink(exePath, AppendFileName(groupFolder, linkName), comment, -1); + + // installs uninstaller + String uninstallRegPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + appName; + SetWinRegString(appName, "DisplayName", uninstallRegPath); + SetWinRegString(appName + " --UNINSTALL", "UninstallString", uninstallRegPath); + + return success; +} + +// unlinks application +bool Updater::ShellUnlink(void) +{ + bool success = true; + + String linkName = appName + ".lnk"; + + // remove uninstaller + DelKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + appName, "DisplayName"); + DelKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + appName, "UninstallString"); + DelKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", appName); + + // remove program group + String groupName = ""; // that could be GetLNGString(cathegory) ???? + String groupFolder = GetShellFolder("Common Programs", HKEY_LOCAL_MACHINE); + if(groupName != "") + { + groupFolder = AppendFileName(groupFolder, groupName); + if(DirectoryExists(groupFolder)) + DeleteFolderDeep(groupFolder); + } + else + { + String linkPath = AppendFileName(groupFolder, linkName); + if(FileExists(linkPath)) + FileDelete(linkPath); + } + + // remove desktop icon + String desktopLink = AppendFileName(GetShellFolder("Desktop", HKEY_USERS), linkName); + if(FileExists(desktopLink)) + FileDelete(desktopLink); + + return success; +} + +#endif