void setregdef(qMailOpts *popts) { CStr sBuf; // save registry/defaults if (gAppKey = GetAppRegistryKey()) { SetRegistryValue(gAppKey, "Timeout", (DWORD) (popts->timeout * 1000)); if (popts->host.Length()) SetRegistryValue(gAppKey, "Smtp", popts->host); } }
///////////////////////////////////////////////////////////////////// // // Function: // // Description: // ///////////////////////////////////////////////////////////////////// UINT CASaveSetupState::OnExecution() { tstring strInstallDirectory; tstring strDataDirectory; tstring strLaunchProgram; tstring strEnableLaunchAtLogon; tstring strEnableScreensaver; tstring strEnableProtectedApplicationExecution; tstring strEnableUseByAllUsers; tstring strSetupStateStored; strSetupStateStored = _T("TRUE"); GetProperty( _T("INSTALLDIR"), strInstallDirectory ); GetProperty( _T("DATADIR"), strDataDirectory ); GetProperty( _T("LAUNCHPROGRAM"), strLaunchProgram ); GetProperty( _T("ENABLELAUNCHATLOGON"), strEnableLaunchAtLogon ); GetProperty( _T("ENABLESCREENSAVER"), strEnableScreensaver ); GetProperty( _T("ENABLEPROTECTEDAPPLICATIONEXECUTION2"), strEnableProtectedApplicationExecution ); GetProperty( _T("ENABLEUSEBYALLUSERS"), strEnableUseByAllUsers ); SetRegistryValue( _T("INSTALLDIR"), strInstallDirectory ); SetRegistryValue( _T("DATADIR"), strDataDirectory ); SetRegistryValue( _T("LAUNCHPROGRAM"), strLaunchProgram ); SetRegistryValue( _T("ENABLELAUNCHATLOGON"), strEnableLaunchAtLogon ); SetRegistryValue( _T("ENABLESCREENSAVER"), strEnableScreensaver ); SetRegistryValue( _T("ENABLEPROTECTEDAPPLICATIONEXECUTION2"), strEnableProtectedApplicationExecution ); SetRegistryValue( _T("ENABLEUSEBYALLUSERS"), strEnableUseByAllUsers ); SetRegistryValue( _T("SETUPSTATESTORED"), strSetupStateStored ); return ERROR_SUCCESS; }
void active_flash() { GetRegistryValue("/CONFIG/BROWSER", "flash_activated", &value); if(value == 1) { oslDrawStringf(10,210, "Flash player is already activated."); } else { SetRegistryValue("/CONFIG/BROWSER", "flash_activated", 1); SetRegistryValue("/CONFIG/BROWSER", "flash_play", 1); oslDrawStringf(10,210, "Flash player activated."); } }
// // What to do on next restart // void SharedUtil::SetOnRestartCommand ( const SString& strOperation, const SString& strFile, const SString& strParameters, const SString& strDirectory, const SString& strShowCmd ) { // Encode into a string and set a registry key SString strVersion ( "%d.%d.%d-%d.%05d" ,MTASA_VERSION_MAJOR ,MTASA_VERSION_MINOR ,MTASA_VERSION_MAINTENANCE ,MTASA_VERSION_TYPE ,MTASA_VERSION_BUILD ); SString strValue ( "%s\t%s\t%s\t%s\t%s\t%s", strOperation.c_str (), strFile.c_str (), strParameters.c_str (), strDirectory.c_str (), strShowCmd.c_str (), strVersion.c_str () ); SetRegistryValue ( "", "OnRestartCommand", strValue ); }
void CMessageBox::OnButton3() { if (GetDlgItem(IDC_MESSAGEBOX_CHECKBOX)->SendMessage(BM_GETCHECK, 0, 0)==BST_CHECKED) SetRegistryValue(m_sRegistryValue, m_uButton3Ret); if ((m_uButton3Ret == IDHELP)&&(!m_sHelpPath.IsEmpty())) { typedef HWND (WINAPI* FPHH)(HWND, LPCWSTR, UINT, DWORD); FPHH pHtmlHelp=NULL; // Function pointer HINSTANCE hInstHtmlHelp = LoadLibrary(_T("HHCtrl.ocx")); HWND hHelp = NULL; if (hInstHtmlHelp != NULL) { (FARPROC&)pHtmlHelp = GetProcAddress(hInstHtmlHelp, "HtmlHelpW"); if (pHtmlHelp) hHelp = pHtmlHelp(m_hWnd, (LPCTSTR)m_sHelpPath, HH_DISPLAY_TOPIC, NULL); } if (hHelp == NULL) ::MessageBox(m_hWnd, _T("could not show help file"), _T("Help"), MB_ICONERROR); } else if (m_uButton3Ret == IDHELP) { OnHelp(); } else EndDialog(m_uButton3Ret); }
///////////////////////////////////////////////////////////////////// // // Function: // // Description: // ///////////////////////////////////////////////////////////////////// UINT CAMigrateBOINCDataCleanup::OnExecution() { tstring strMigrationVersion; UINT uiReturnValue = -1; LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("CAMigrateBOINCDataCleanup::OnExecution -- Function Begin") ); uiReturnValue = SetRegistryValue( _T("MIGRATIONVERSION"), _T("") ); if ( uiReturnValue ) return uiReturnValue; LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("CAMigrateBOINCDataCleanup::OnExecution -- Function End") ); return ERROR_SUCCESS; }
void fake_name() { oslDrawStringf(10,210, "Setting random name..."); value = chGetFakeName(20, 3465); SetRegistryValue("/CONFIG/SYSTEM", "owner_name", value); sceKernelDelayThread(2000000); oslDrawStringf(10,220, "Done"); }
///////////////////////////////////////////////////////////////////// // // Function: SetUpgradeParameters // // Description: // ///////////////////////////////////////////////////////////////////// UINT BOINCCABase::SetUpgradeParameters() { tstring strCurrentProductVersion; UINT uiReturnValue = 0; uiReturnValue = GetProperty( _T("ProductVersion"), strCurrentProductVersion ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = SetRegistryValue( _T("UpgradingTo"), strCurrentProductVersion ); if ( uiReturnValue ) return uiReturnValue; return ERROR_SUCCESS; }
void active_wma() { GetRegistryValue("/CONFIG/MUSIC", "wma_play", &value); if (value == 1) { oslDrawStringf(10,210, "WMA is already activated."); } else { SetRegistryValue("/CONFIG/MUSIC", "wma_play", 1); oslDrawStringf(10,210, "WMA activated."); } }
//Registry Func void swap_buttons() { GetRegistryValue("/CONFIG/SYSTEM/XMB", "button_assign", &value); value = !value; SetRegistryValue("/CONFIG/SYSTEM/XMB", "button_assign", value); if(value) { oslDrawStringf(10,210, "Done!, Enter button is now X"); } else { oslDrawStringf(10,210, "Done!, Enter button is now O"); } }
BOOL CInstall::UpdateRegistryValue(const char *product, const char *version, const char *name, const char *value) { char appver[MAXSTR]; BOOL flag = FALSE; HKEY hkey; // Open application/version key sprintf(appver, "SOFTWARE\\%s\\%s", product, version); if (RegOpenKey(HKEY_LOCAL_MACHINE, appver, &hkey) == ERROR_SUCCESS) { flag = SetRegistryValue(hkey, name, value); RegCloseKey(hkey); } return flag; }
BOOL AddPortW( LPWSTR pName, HWND hWnd, LPWSTR pMonitorName ) { WCHAR PortName[MAX_PATH]; DWORD Status; UNREFERENCED_PARAMETER(pName); /* Possible future enhancements: this will be the server name, so that the monitor can update remote servers. */ Status = WNetBrowsePrinterDialog( hWnd, PortName, ( sizeof PortName / sizeof *PortName ), L"Printman.hlp", 0 /* help context */, (PFUNC_VALIDATION_CALLBACK)IsPortValid ); if (Status == NO_ERROR) { EnterSplSem(); if (FindName((PINIENTRY)pIniFirstPort, PortName)) { LeaveSplSem(); Message(hWnd, MSG_ERROR, IDS_ERROR, IDS_PORT_ALREADY_EXISTS_S, PortName); return FALSE; } if( CreatePortEntry( PortName ) ) SetRegistryValue( szRegPortNames, PortName, REG_SZ, L"", 0 ); else ; /* Message box to say can't create port */ LeaveSplSem(); } return TRUE; }
static void SetLaunchOnStartup(BOOL value) { WCHAR exePath[MAX_PATH]; HKEY regkey; if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_WRITE, ®key) == ERROR_SUCCESS) { if (value) { if (GetModuleFileNameW(NULL, exePath, MAX_PATH)) SetRegistryValue(regkey, L"OpenVPN-GUI", exePath); } else RegDeleteValue(regkey, L"OpenVPN-GUI"); RegCloseKey(regkey); } }
// // Run ShellExecute with these parameters after exit // void SharedUtil::SetOnQuitCommand ( const SString& strOperation, const SString& strFile, const SString& strParameters, const SString& strDirectory, const SString& strShowCmd ) { // Encode into a string and set a registry key SString strValue ( "%s\t%s\t%s\t%s\t%s", strOperation.c_str (), strFile.c_str (), strParameters.c_str (), strDirectory.c_str (), strShowCmd.c_str () ); SetRegistryValue ( "", "OnQuitCommand", strValue ); }
// // Get/set string // void SharedUtil::SetApplicationSetting ( const SString& strPath, const SString& strName, const SString& strValue ) { SetRegistryValue ( PathJoin ( "Settings", strPath ), strName, strValue ); }
void SaveProxySettings(HWND hwndDlg) { HKEY regkey; DWORD dwDispos; TCHAR proxy_source_string[2] = _T("0"); TCHAR proxy_type_string[2] = _T("0"); /* Save Proxy Settings Source */ if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_OPENVPN) == BST_CHECKED) { o.proxy_source = config; proxy_source_string[0] = _T('0'); } else if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED) { o.proxy_source = windows; proxy_source_string[0] = _T('1'); } else if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED) { o.proxy_source = manual; proxy_source_string[0] = _T('2'); } /* Save Proxy type, address and port */ if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_HTTP) == BST_CHECKED) { o.proxy_type = http; proxy_type_string[0] = _T('0'); GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address, _countof(o.proxy_http_address)); GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, o.proxy_http_port, _countof(o.proxy_http_port)); } else { o.proxy_type = socks; proxy_type_string[0] = _T('1'); GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_socks_address, _countof(o.proxy_socks_address)); GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, o.proxy_socks_port, _countof(o.proxy_socks_port)); } /* Open Registry for writing */ if (RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, ®key, &dwDispos) != ERROR_SUCCESS) { /* error creating Registry-Key */ ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU); return; } /* Save Settings to registry */ SetRegistryValue(regkey, _T("proxy_source"), proxy_source_string); SetRegistryValue(regkey, _T("proxy_type"), proxy_type_string); SetRegistryValue(regkey, _T("proxy_http_address"), o.proxy_http_address); SetRegistryValue(regkey, _T("proxy_http_port"), o.proxy_http_port); SetRegistryValue(regkey, _T("proxy_socks_address"), o.proxy_socks_address); SetRegistryValue(regkey, _T("proxy_socks_port"), o.proxy_socks_port); RegCloseKey(regkey); }
int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD len) { LONG status; DWORD type; HKEY openvpn_key; HKEY openvpn_key_write; DWORD dwDispos; TCHAR expanded_string[MAX_PATH]; DWORD size = len * sizeof(*data); DWORD max_len = len - 1; /* If option is already set via cmd-line, return */ if (data[0] != 0) { // Expand environment variables inside the string. ExpandEnvironmentStrings(data, expanded_string, _countof(expanded_string)); _tcsncpy(data, expanded_string, max_len); return(true); } status = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\OpenVPN-GUI"), 0, KEY_READ, &openvpn_key); if (status != ERROR_SUCCESS) { if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\OpenVPN-GUI"), 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &openvpn_key, &dwDispos) != ERROR_SUCCESS) { /* error creating registry key */ ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, _T("OpenVPN-GUI")); return(false); } } /* get a registry string */ status = RegQueryValueEx(openvpn_key, name, NULL, &type, (byte *) data, &size); if (status != ERROR_SUCCESS || type != REG_SZ) { /* key did not exist - set default value */ status = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\OpenVPN-GUI"), 0, KEY_READ | KEY_WRITE, &openvpn_key_write); if (status != ERROR_SUCCESS) { /* can't open registry for writing */ ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, _T("OpenVPN-GUI"), name); return(false); } if(!SetRegistryValue(openvpn_key_write, name, default_data)) { /* cant read / set reg-key */ return(false); } _tcsncpy(data, default_data, max_len); RegCloseKey(openvpn_key_write); } else { size /= sizeof(*data); data[size - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */ } RegCloseKey(openvpn_key); // Expand environment variables inside the string. ExpandEnvironmentStrings(data, expanded_string, _countof(expanded_string)); _tcsncpy(data, expanded_string, max_len); return(true); }
void SaveProxySettings(HWND hwndDlg) { LONG status; HKEY regkey; DWORD dwDispos; char proxy_source_string[2]="0"; char proxy_type_string[2]="0"; char proxy_http_auth_string[2]="0"; /* Save Proxy Settings Source */ if (IsDlgButtonChecked(hwndDlg, RB_PROXY_USE_OPENVPN) == BST_CHECKED) { o.proxy_source = 0; proxy_source_string[0] = '0'; } if (IsDlgButtonChecked(hwndDlg, RB_PROXY_USE_IE) == BST_CHECKED) { o.proxy_source = 1; proxy_source_string[0] = '1'; } if (IsDlgButtonChecked(hwndDlg, RB_PROXY_USE_MANUAL) == BST_CHECKED) { o.proxy_source = 2; proxy_source_string[0] = '2'; } /* Save Proxy addresses and ports */ GetDlgItemText(hwndDlg, EDIT_PROXY_HTTP_ADDRESS, o.proxy_http_address, sizeof(o.proxy_http_address)); GetDlgItemText(hwndDlg, EDIT_PROXY_HTTP_PORT, o.proxy_http_port, sizeof(o.proxy_http_port)); GetDlgItemText(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS, o.proxy_socks_address, sizeof(o.proxy_http_address)); GetDlgItemText(hwndDlg, EDIT_PROXY_SOCKS_PORT, o.proxy_socks_port, sizeof(o.proxy_socks_port)); if (IsDlgButtonChecked(hwndDlg, RB_PROXY_HTTP) == BST_CHECKED) { o.proxy_type = 0; proxy_type_string[0] = '0'; } else { o.proxy_type = 1; proxy_type_string[0] = '1'; } if (IsDlgButtonChecked(hwndDlg, CHECKB_PROXY_AUTH) == BST_CHECKED) { o.proxy_http_auth = 1; proxy_http_auth_string[0] = '1'; } else { o.proxy_http_auth = 0; proxy_http_auth_string[0] = '0'; } /* Open Registry for writing */ if (RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, (LPTSTR) "", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, ®key, &dwDispos) != ERROR_SUCCESS) { /* error creating Registry-Key */ ShowLocalizedMsg(GUI_NAME, ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU); return; } /* Save Settings to registry */ SetRegistryValue(regkey, "proxy_source", proxy_source_string); SetRegistryValue(regkey, "proxy_type", proxy_type_string); SetRegistryValue(regkey, "proxy_http_auth", proxy_http_auth_string); SetRegistryValue(regkey, "proxy_http_address", o.proxy_http_address); SetRegistryValue(regkey, "proxy_http_port", o.proxy_http_port); SetRegistryValue(regkey, "proxy_socks_address", o.proxy_socks_address); SetRegistryValue(regkey, "proxy_socks_port", o.proxy_socks_port); RegCloseKey(regkey); }
void CMessageBox::OnButton1() { if (GetDlgItem(IDC_MESSAGEBOX_CHECKBOX)->SendMessage(BM_GETCHECK, 0, 0)==BST_CHECKED) SetRegistryValue(m_sRegistryValue, m_uButton1Ret); EndDialog(m_uButton1Ret); }
///////////////////////////////////////////////////////////////////// // // Function: // // Description: // ///////////////////////////////////////////////////////////////////// UINT CAMigrateBOINCData::OnExecution() { tstring strCustomActionData; tstring strCurrentInstallDirectory; tstring strFutureInstallDirectory; tstring strCurrentDataDirectory; tstring strFutureDataDirectory; tstring strMigration; tstring strMigrationVersion; tstring strMigrationDirectory; tstring strDestinationClientStateFile; tstring strRemove; tstring strProductVersion; tstring strWindowsDirectory; tstring strWindowsSystemDirectory; tstring strProgramFilesDirectory; tstring strSystemDrive; tstring strVersionWindows64; struct _stat buf; ULONGLONG ullFileSize = 0; ULONGLONG ullDirectorySize = 0; ULONGLONG ullFreeDiskSpace = 0; UINT uiReturnValue = -1; LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("CAMigrateBOINCData::OnExecution -- Function Begin") ); GetRegistryValue( _T("INSTALLDIR"), strCurrentInstallDirectory ); uiReturnValue = GetProperty( _T("INSTALLDIR"), strFutureInstallDirectory ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("DATADIR"), strFutureDataDirectory ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetRegistryValue( _T("MIGRATION"), strMigration ); uiReturnValue = GetRegistryValue( _T("MIGRATIONVERSION"), strMigrationVersion ); uiReturnValue = GetRegistryValue( _T("MIGRATIONDIR"), strMigrationDirectory ); uiReturnValue = GetProperty( _T("REMOVE"), strRemove ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("ProductVersion"), strProductVersion ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("VersionNT64"), strVersionWindows64 ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("WindowsFolder"), strWindowsDirectory ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("WindowsVolume"), strSystemDrive ); if ( uiReturnValue ) return uiReturnValue; if (strVersionWindows64.length() > 0) { uiReturnValue = GetProperty( _T("System64Folder"), strWindowsSystemDirectory ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("ProgramFiles64Folder"), strProgramFilesDirectory ); if ( uiReturnValue ) return uiReturnValue; } else { uiReturnValue = GetProperty( _T("SystemFolder"), strWindowsSystemDirectory ); if ( uiReturnValue ) return uiReturnValue; uiReturnValue = GetProperty( _T("ProgramFilesFolder"), strProgramFilesDirectory ); if ( uiReturnValue ) return uiReturnValue; } // If the REMOVE property is specified, then we are uninstalling BOINC if (strRemove.length()) { // If we successfully migrated, and the user is now uninstalling, they // are probably going back to a 6.x client, so don't migrate the // data back to the 5.x location. // strMigration = _T("FALSE"); strCustomActionData += strMigration + _T("|"); strCustomActionData += strMigrationDirectory + _T("|"); strCustomActionData += strFutureDataDirectory; } else { strDestinationClientStateFile = strFutureDataDirectory + _T("\\client_state.xml"); // Perform some basic sanity tests to see if we need to migrate // anything. BOOL bClientStateExists = (BOOL)(0 == _stat(strDestinationClientStateFile.c_str(), &buf)); BOOL bInstallDataSameDirectory = (BOOL)(strFutureInstallDirectory == strFutureDataDirectory); BOOL bDataDirExistsWithinInstallDir = (BOOL)(tstring::npos != strFutureDataDirectory.find(strFutureInstallDirectory)); BOOL bInstallDirWindowsDirSame = (BOOL)(strFutureInstallDirectory == strWindowsDirectory); BOOL bDataDirWindowsDirSame = (BOOL)(strFutureDataDirectory == strWindowsDirectory); BOOL bInstallDirSystemDriveSame = (BOOL)(strFutureInstallDirectory == strSystemDrive); BOOL bDataDirSystemDriveSame = (BOOL)(strFutureDataDirectory == strSystemDrive); BOOL bInstallDirWindowsSystemDirSame = (BOOL)(strFutureInstallDirectory == strWindowsSystemDirectory); BOOL bDataDirWindowsSystemDirSame = (BOOL)(strFutureDataDirectory == strWindowsSystemDirectory); BOOL bInstallDirProgramFilesDirSame = (BOOL)(strFutureInstallDirectory == strProgramFilesDirectory); BOOL bDataDirProgramFilesDirSame = (BOOL)(strFutureDataDirectory == strProgramFilesDirectory); if ( bClientStateExists ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data files already exists, skipping migration.") ); } else if ( bInstallDataSameDirectory ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Install directory and data directory are the same, skipping migration.") ); } else if ( bDataDirExistsWithinInstallDir ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data drectory exists within the install directory, skipping migration.") ); } else if ( bInstallDirWindowsDirSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Install directory is the same as the Windows directory, skipping migration.") ); } else if ( bDataDirWindowsDirSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data directory is the same as the Windows directory, skipping migration.") ); } else if ( bInstallDirSystemDriveSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Install directory is the same as the system drive, skipping migration.") ); } else if ( bDataDirSystemDriveSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data directory is the same as the system drive, skipping migration.") ); } else if ( bInstallDirWindowsSystemDirSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Install directory is the same as the Windows system directory, skipping migration.") ); } else if ( bDataDirWindowsSystemDirSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data directory is the same as the Windows system directory, skipping migration.") ); } else if ( bInstallDirProgramFilesDirSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Install directory is the same as the program files directory, skipping migration.") ); } else if ( bDataDirProgramFilesDirSame ) { strMigration = _T("FALSE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data directory is the same as the program files directory, skipping migration.") ); } else { strMigration = _T("TRUE"); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Data files do NOT exist, performing migration.") ); strMigrationDirectory = strCurrentInstallDirectory + _T("\\client_state.xml"); if (0 == _stat(strMigrationDirectory.c_str(), &buf)) { strMigrationDirectory = strCurrentInstallDirectory; } else { strMigrationDirectory = strFutureInstallDirectory; } if ( GetFileDirectorySizes( strMigrationDirectory, ullFileSize, ullDirectorySize ) ) { // The total amount of disk space required depends on whether or not // the files in the original location are on the same volume as the // destination. So do a quick check to see if we have enough disk // space. if (!GetFreeDiskSpace(strFutureDataDirectory, ullFreeDiskSpace)) { // If the destination directory doesn't exist, try the parent // directory tstring strBuffer = tstring(strFutureDataDirectory + _T("..\\")); if (!GetFreeDiskSpace(strBuffer, ullFreeDiskSpace)) { // If the parent directory doesn't exist, just choose // the default volume. Something is better than nothing GetFreeDiskSpace(tstring(""), ullFreeDiskSpace); } } // Are we on the same volume? if (strMigrationDirectory.substr(0, 2) == strFutureDataDirectory.substr(0, 2)) { // We only need the amount of free space as the largest file // that is going to be transfered. if (ullFileSize > ullFreeDiskSpace) { LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Not enough free disk space is available to migrate BOINC's data files to\n" "the new data directory. Please free up some disk space or migrate the files\n" "manually. (ullFileSize > ullFreeDiskSpace)") ); return ERROR_INSTALL_FAILURE; } } else { // We only need the amount of free space of the directory // that is going to be transfered. if (ullDirectorySize > ullFreeDiskSpace) { LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("Not enough free disk space is available to migrate BOINC's data files to\n" "the new data directory. Please free up some disk space or migrate the files\n" "manually. (ullDirectorySize > ullFreeDiskSpace)") ); return ERROR_INSTALL_FAILURE; } } } } // Contruct a '|' delimited string to pass along to the install script // and rollback script parts of this custom action. strCustomActionData += strMigration + _T("|"); strCustomActionData += strMigrationDirectory + _T("|"); strCustomActionData += strFutureDataDirectory; } SetRegistryValue( _T("MIGRATION"), strMigration ); SetRegistryValue( _T("MIGRATIONDIR"), strMigrationDirectory ); SetProperty( _T("CAMigrateBOINCDataInstall"), strCustomActionData ); SetProperty( _T("CAMigrateBOINCDataRollback"), strCustomActionData ); LogMessage( INSTALLMESSAGE_INFO, NULL, NULL, NULL, NULL, _T("CAMigrateBOINCData::OnExecution -- Function End") ); return ERROR_SUCCESS; }
////////////////////////////////////////////////////////// // // CInstallManager::_ProcessLayoutChecks // // Make sure new reg/dir structure is ok // ////////////////////////////////////////////////////////// SString CInstallManager::_ProcessLayoutChecks ( void ) { // // Validation // // Check data dir exists { if ( !DirectoryExists ( GetMTADataPath () ) ) ShowLayoutError ( "[Data directory not present]" ); // Can't find directory } // Check reg key exists //{ // if ( GetRegistryValue ( "", "Last Install Location" ).empty () ) // ShowLayoutError ( "[Registry key not present]" ); // Can't find reg key //} // Check data dir writable { SString strTestFilePath = PathJoin ( GetMTADataPath (), "testdir", "testfile.txt" ); FileDelete ( strTestFilePath ); RemoveDirectory ( ExtractPath ( strTestFilePath ) ); SString strContent = "test"; if ( !FileSave ( strTestFilePath, strContent ) ) ShowLayoutError ( "[Data directory not writable]" ); // Can't save file FileDelete ( strTestFilePath ); RemoveDirectory ( ExtractPath ( strTestFilePath ) ); } // Check reg key writable { RemoveRegistryKey ( "testkeypath" ); SString strValue = GetTimeString( true, true ); SetRegistryValue ( "testkeypath", "testname", strValue ); SString strValueCheck = GetRegistryValue ( "testkeypath", "testname" ); if ( strValueCheck != strValue ) ShowLayoutError ( "[Registry key not writable]" ); // Can't write reg key RemoveRegistryKey ( "testkeypath" ); } // Check install dir writable { SString strTestFilePath = CalcMTASAPath ( PathJoin ( "mta", "writetest.txt" ) ); FileDelete ( strTestFilePath ); SString strContent = "test"; if ( !FileSave ( strTestFilePath, strContent ) ) ShowLayoutError ( "[Install directory not writable]" ); // Can't save file FileDelete ( strTestFilePath ); } // // Migration // // If news/temp/upcache folder doesn't exist in new, but does in old place, move it { const char* folders[] = { "news", "temp", "upcache" }; for ( uint i = 0 ; i < NUMELMS( folders ) ; i++ ) { SString strSrc = PathJoin ( GetSystemLocalAppDataPath (), "MTA San Andreas " + GetMajorVersionString (), folders[i] ); SString strDest = PathJoin ( GetMTADataPath (), folders[i] ); if ( !DirectoryExists ( strDest ) && DirectoryExists ( strSrc ) ) MoveFile ( strSrc, strDest ); } } // If aero option reg entry doesn't exist in new, but does in old place, move it { if ( GetApplicationSetting ( "aero-enabled" ).empty () ) { SString strLegacyValue = GetVersionRegistryValueLegacy ( GetMajorVersionString (), PathJoin ( "Settings", "general" ), "aero-enabled" ); if ( !strLegacyValue.empty () ) SetApplicationSettingInt ( "aero-enabled", atoi ( strLegacyValue ) ); else SetApplicationSettingInt ( "aero-enabled", 1 ); } } return "ok"; }
void SetUserRegistryValue(const std::string& value) { SetRegistryValue(HKEY_CURRENT_USER, L"Software\\Enchant\\Test", L"Value", value); }
void SetMachineRegistryValue(const std::string& value) { SetRegistryValue(HKEY_LOCAL_MACHINE, L"Software\\Enchant\\Test", L"Value", value); }