コード例 #1
0
ファイル: Settings.cpp プロジェクト: vladios13/image-uploader
void CSettings::EnableAutostartup(bool enable) {
	CRegistry Reg;
	Reg.SetRootKey( HKEY_CURRENT_USER );
	bool canCreateRegistryKey = enable;

	if ( Reg.SetKey( "Software\\Zenden.ws\\Image Uploader", canCreateRegistryKey ) ) {
		if ( enable ) {
			Reg.WriteBool( "AutoStartup", enable );
		} else {
			Reg.DeleteValue("AutoStartup");
		}
	}

	if ( enable ) {
		HKEY hKey;
		CString StartupCommand = _T("\"") + CmdLine.ModuleName() + _T("\" /tray");
		LONG lRet, lRetOpen;
		lRet = RegOpenKeyEx( HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 
		                      0, KEY_WRITE, &hKey );
		if (!lRet) {
			lRetOpen = RegSetValueEx( hKey, _T("ImageUploader"), NULL, REG_SZ, (BYTE*)(LPCTSTR)StartupCommand,
			                            (StartupCommand.GetLength() + 1) * sizeof(TCHAR));
		}
		RegCloseKey( hKey );
	} else { 
		// deleting from Startup (autorun)
		HKEY hKey;
		LONG lRet;
		lRet = RegOpenKeyEx( HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_WRITE,
									&hKey );
		RegDeleteValue( hKey, _T("ImageUploader") );
	}
}
コード例 #2
0
ファイル: Settings.cpp プロジェクト: vladios13/image-uploader
void RegisterShellExtension(bool Register) {
	CString moduleName = Settings.getShellExtensionFileName();
	if ( !FileExists( moduleName ) ) {
		return;
	}

	CRegistry Reg;
	Reg.SetRootKey( HKEY_LOCAL_MACHINE );

	bool canCreateRegistryKey = Register;
	
	if ( Reg.SetKey( "Software\\Zenden.ws\\Image Uploader", canCreateRegistryKey ) ) {
		Reg.WriteBool( "ExplorerContextMenu", Register );
	}

	SHELLEXECUTEINFO TempInfo = {0};
	CString s = WinUtils::GetAppFolder();
	TempInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
	TempInfo.fMask  = SEE_MASK_NOCLOSEPROCESS;
	TempInfo.hwnd   = NULL;
	BOOL b = FALSE;
	IsElevated( &b );
	if ( IsVista() && !b ) {
		TempInfo.lpVerb = _T("runas");
	} else {
		TempInfo.lpVerb = _T("open");
	}
	TempInfo.lpFile       = _T("regsvr32");
	TempInfo.lpParameters = CString((Register ? _T("") : _T("/u "))) + _T("/s \"") + moduleName + _T("\"");
	TempInfo.lpDirectory  = s;
	TempInfo.nShow        = SW_NORMAL;
	//MessageBox(0,TempInfo.lpParameters,0,0);
	::ShellExecuteEx(&TempInfo);
	WaitForSingleObject( TempInfo.hProcess, INFINITE );
	CloseHandle( TempInfo.hProcess );
}
コード例 #3
0
ファイル: Settings.cpp プロジェクト: vladios13/image-uploader
	bool CSettings::SaveSettings()
	{
		SimpleXml xml;
		mgr_.saveToXmlNode(xml.getRoot("ImageUploader").GetChild("Settings"));
#if !defined(IU_SERVERLISTTOOL) && !defined  (IU_CLI) && !defined(IU_SHELLEXT)
		SaveConvertProfiles(xml.getRoot("ImageUploader").GetChild("Settings").GetChild("Image").GetChild("Profiles"));
		SaveServerProfiles( xml.getRoot("ImageUploader").GetChild("Settings").GetChild("Uploading").GetChild("ServerProfiles") );
#endif
		SaveAccounts(xml.getRoot("ImageUploader").GetChild("Settings").GetChild("ServersParams"));
		//std::cerr << "Saving setting to "<< IuCoreUtils::WstringToUtf8((LPCTSTR)fileName_);
		xml.SaveToFile(fileName_);

#if !defined(IU_SERVERLISTTOOL) && !defined(IU_CLI)
		CRegistry Reg;
		Reg.SetRootKey(HKEY_CURRENT_USER);
		// if(ExplorerContextMenu)
		{
			bool canCreateRegistryKey = ( ExplorerContextMenu );
			if ( Reg.SetKey("Software\\Zenden.ws\\Image Uploader", canCreateRegistryKey ) ) {
				if ( ExplorerContextMenu ) {
					Reg.WriteBool( "ExplorerCascadedMenu", ExplorerCascadedMenu );
					Reg.WriteBool("ExplorerContextMenu", ExplorerContextMenu);
					Reg.WriteBool( "ExplorerVideoContextMenu", ExplorerVideoContextMenu );
					Reg.WriteString( "Language", Language );
				} else {
					Reg.DeleteValue("ExplorerCascadedMenu");
					Reg.DeleteValue("ExplorerContextMenu");
					Reg.DeleteValue("ExplorerVideoContextMenu");
					Reg.DeleteValue("Language");
				}
			}
		}
		/*else
		{
		   //Reg.DeleteKey("Software\\Zenden.ws\\Image Uploader");
		}*/
		EnableAutostartup(AutoStartup);

		if (SendToContextMenu_changed   || ExplorerContextMenu_changed) {
			AutoStartup_changed = false;
			BOOL b;
			if ( IsVista() && IsElevated(&b) != S_OK ) {
				// Start new elevated process 
				ApplyRegistrySettings();
			} else {
				// Process has already admin rights
				ApplyRegSettingsRightNow();
			}
		}

		ExplorerContextMenu_changed = false;
		SendToContextMenu_changed = false;

		if (ShowTrayIcon_changed)
		{
			ShowTrayIcon_changed = false;
			if (ShowTrayIcon)
			{
				if (!IsRunningFloatingWnd())
				{
					CmdLine.AddParam(_T("/tray"));
					floatWnd.CreateTrayIcon();
				}
			}
			else
			{
				HWND TrayWnd = FindWindow(0, _T("ImageUploader_TrayWnd"));
				if (TrayWnd) {
					::SendMessage( TrayWnd, WM_CLOSETRAYWND, 0, 0 );
				}
			}
		}
		else if (ShowTrayIcon)
		{
			HWND TrayWnd = FindWindow(0, _T("ImageUploader_TrayWnd"));
			if (TrayWnd)
				SendMessage(TrayWnd, WM_RELOADSETTINGS,  (floatWnd.m_hWnd) ? 1 : 0, (Settings.Hotkeys_changed) ? 0 : 1);
		}

		Settings.Hotkeys_changed  = false;
#endif
		return true;
	}