diff options
Diffstat (limited to 'plugins/SessionLoader/Windows/sessionLoader.cpp')
-rw-r--r--[-rwxr-xr-x] | plugins/SessionLoader/Windows/sessionLoader.cpp | 99 |
1 files changed, 55 insertions, 44 deletions
diff --git a/plugins/SessionLoader/Windows/sessionLoader.cpp b/plugins/SessionLoader/Windows/sessionLoader.cpp index 8e1595c..5080bdc 100755..100644 --- a/plugins/SessionLoader/Windows/sessionLoader.cpp +++ b/plugins/SessionLoader/Windows/sessionLoader.cpp @@ -1,69 +1,80 @@ /** \file session-loader.cpp \brief Define the session plugin loader test -\author alpha_one_x86 -\version 0.3 -\date 2010 */ +\author alpha_one_x86 */ -#include <QtCore> +#include "sessionLoader.h" + +#include <QCoreApplication> -#if defined (Q_OS_WIN32) -#include <windows.h> +#ifdef Q_OS_WIN32 + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include <windows.h> #else -#error "Not under windows, plugin will not work" + #error "This plugin will only work under Windows" #endif -#include "sessionLoader.h" - -void SessionLoader::setEnabled(bool newValue) +void WindowsSessionLoader::setEnabled(const bool &newValue) { - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, newValue: "+QString::number(newValue)); - //set value into the variable - HKEY ultracopier_regkey; - //for autostart - QString runStringApp = "\"" + QApplication::applicationFilePath() + "\""; - runStringApp.replace( "/", "\\" ); - wchar_t windowsString[255]; - runStringApp.toWCharArray(windowsString); - RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, 0, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, 0, &ultracopier_regkey, 0); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, newValue: "+QString::number(newValue)); + //set value into the variable + HKEY ultracopier_regkey; + //for autostart + QString runStringApp = "\"" + QCoreApplication::applicationFilePath() + "\""; + runStringApp.replace( "/", "\\" ); + wchar_t windowsString[255]; + runStringApp.toWCharArray(windowsString); + if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, 0, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, 0, &ultracopier_regkey, 0)==ERROR_SUCCESS) + { if(newValue) - RegSetValueEx(ultracopier_regkey, TEXT("ultracopier"), 0, REG_SZ, (BYTE*)windowsString, runStringApp.length()*2); - else - RegDeleteValue(ultracopier_regkey, TEXT("ultracopier")); + { + if(RegSetValueEx(ultracopier_regkey, TEXT("ultracopier"), 0, REG_SZ, (BYTE*)windowsString, runStringApp.length()*2)!=ERROR_SUCCESS) + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"newValue: "+QString::number(newValue)+" failed"); + } + else + { + if(RegDeleteValue(ultracopier_regkey, TEXT("ultracopier"))!=ERROR_SUCCESS) + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"newValue: "+QString::number(newValue)+" failed"); + } RegCloseKey(ultracopier_regkey); + } + else + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"RegCreateKeyEx: Software\\Microsoft\\Windows\\CurrentVersion\\Run failed"); } -bool SessionLoader::getEnabled() +bool WindowsSessionLoader::getEnabled() const { - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); - //return the value into the variable - HKEY ultracopier_regkey; - bool temp=false; - RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, 0, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, 0, &ultracopier_regkey, 0); - DWORD kSize=254; - if(RegQueryValueEx(ultracopier_regkey,TEXT("ultracopier"),NULL,NULL,(LPBYTE)0,&kSize) == ERROR_SUCCESS) - temp=true; - RegCloseKey(ultracopier_regkey); - ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"return this value: "+QString::number(temp)); - return temp; + //return the value into the variable + HKEY ultracopier_regkey; + bool temp=false; + if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, 0, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, 0, &ultracopier_regkey, 0)==ERROR_SUCCESS) + { + DWORD kSize=254; + if(RegQueryValueEx(ultracopier_regkey,TEXT("ultracopier"),NULL,NULL,(LPBYTE)0,&kSize) == ERROR_SUCCESS) + temp=true; + RegCloseKey(ultracopier_regkey); + } + else + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"RegCreateKeyEx: Software\\Microsoft\\Windows\\CurrentVersion\\Run failed"); + return temp; } -void SessionLoader::setResources(OptionInterface * options,QString writePath,QString pluginPath,bool portableVersion) +void WindowsSessionLoader::setResources(OptionInterface * options,const QString &writePath,const QString &pluginPath,const bool &portableVersion) { - Q_UNUSED(options); - Q_UNUSED(writePath); - Q_UNUSED(pluginPath); - Q_UNUSED(portableVersion); + Q_UNUSED(options); + Q_UNUSED(writePath); + Q_UNUSED(pluginPath); + Q_UNUSED(portableVersion); } /// \brief to get the options widget, NULL if not have -QWidget * SessionLoader::options() +QWidget * WindowsSessionLoader::options() { - return NULL; + return NULL; } /// \brief to reload the translation, because the new language have been loaded -void SessionLoader::newLanguageLoaded() +void WindowsSessionLoader::newLanguageLoaded() { } - -Q_EXPORT_PLUGIN2(sessionLoader, SessionLoader); |