HKEY CXTPRegistryManager::GetSectionKey(LPCTSTR lpszSection, REGSAM samDesired)
{
	if (GetFullPathKey(lpszSection))
	{
		return RecurseOpenKey(lpszSection, samDesired);
	}

	if (!GetProfileInfo())
		return 0;

	ASSERT(lpszSection != NULL);
	if (!lpszSection)
		return 0;

	HKEY hSectionKey = NULL;
	CHKey hAppKey(GetAppRegistryKey(samDesired));

	if (hAppKey == NULL)
		return NULL;

	DWORD dw = 0;
	m_lResult = ::RegCreateKeyEx(hAppKey, lpszSection, 0, REG_NONE,
		REG_OPTION_NON_VOLATILE, samDesired, NULL, &hSectionKey, &dw);

	if (m_lResult != ERROR_SUCCESS)
		return NULL;

	return hSectionKey;
}
Exemplo n.º 2
0
	void LoadSettingsFromRegistory(void)
	{
		struct Reg {
			static StdString ReadString(HKEY hKey, const TCHAR *name, const TCHAR *defaultValue = _T(""))
			{
				const UINT MAX_STRING_LENGTH = 1024;
				TCHAR value[MAX_STRING_LENGTH + 1];
				ZeroMemory(value, sizeof(value));
				DWORD type = 0;
				DWORD bytes = MAX_STRING_LENGTH * sizeof(TCHAR);
				LONG result = RegQueryValueEx(hKey, name, NULL, &type, (BYTE *)value, &bytes);
				if(result == ERROR_SUCCESS && type == REG_SZ){
					return StdString(value);
				}
				return defaultValue;
			}
		};
		HKEY hKey;
		if(::RegOpenKeyEx(HKEY_CURRENT_USER, GetAppRegistryKey(), NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS){
			return; //error
		}
		outputFilename_ = Reg::ReadString(hKey, "OutputFilename");
		outputHTTPURL_ = Reg::ReadString(hKey, "OutputHTTPURL");
		RegCloseKey(hKey);
	}
Exemplo n.º 3
0
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);
	}
}
Exemplo n.º 4
0
BOOL CPCSpimApp::InitInstance()
{
    // SPIM is bad about cleaning up after itself...
    AfxEnableMemoryTracking(FALSE);

    // Standard initialization

    // Turn on registry (vs. INI) support, and set the "company" tag.
    SetRegistryKey("LarusStone");

    // If registry settings for this user do not exist, copy them from
    // the "Default Settings" tree in HKLM.
    HKEY hKeySrc, hKeySettings;
    HKEY hKeyDest = GetAppRegistryKey();
    if (S_OK != RegMan_OpenKey(hKeyDest, "Settings", &hKeySettings))
    {
        if (S_OK == RegMan_OpenKey(HKEY_LOCAL_MACHINE,
            SPIM_REG_DEFAULTSETTINGS,
            &hKeySrc))
        {
            RegMan_CopyTree(hKeySrc, hKeyDest);
            RegMan_CloseKey(hKeySrc);
        }
    }
    else
    {
        RegMan_CloseKey(hKeySettings);
    }
    RegMan_CloseKey(hKeyDest);


    LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)

    // Register the application's document templates.  Document templates
    // serve as the connection between documents, frame windows and views.
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,
        RUNTIME_CLASS(CPCSpimDoc),
        // main SDI frame window
        RUNTIME_CLASS(CMainFrame),
        RUNTIME_CLASS(CPCSpimView));
    AddDocTemplate(pDocTemplate);


    // We do our own cmdline processing later.  Even though we aren't using
    // MFC's standard cmdline processing (we aren't calling ParseCommandLine),
    // we _must_ call ProcessShellCommand...
    CCommandLineInfo cmdInfo;
    if (!ProcessShellCommand(cmdInfo))
    {
        return FALSE;
    }
    return TRUE;
}
BOOL CXTPRegistryManager::WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue)
{
	ASSERT(lpszSection != NULL);
	if (!lpszSection)
		return 0;

	if (m_strINIFileName.IsEmpty())
	{
		if (lpszEntry == NULL) //delete whole section
		{
			CHKey hAppKey(GetAppRegistryKey(FALSE));
			if (hAppKey == NULL)
				return FALSE;

			m_lResult = ::RegDeleteKey(hAppKey, lpszSection);

			if (m_lResult != ERROR_SUCCESS)
				return FALSE;
		}
		else if (lpszValue == NULL)
		{
			CHKey hSecKey(GetSectionKey(lpszSection));
			if (hSecKey == NULL)
				return FALSE;

			// necessary to cast away const below
			m_lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);

			if (m_lResult != ERROR_SUCCESS)
				return FALSE;
		}
		else
		{
			CHKey hSecKey(GetSectionKey(lpszSection));
			if (hSecKey == NULL)
				return FALSE;

			m_lResult = ::RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
				(LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));

			if (m_lResult != ERROR_SUCCESS)
				return FALSE;
		}

		return TRUE;
	}
	else
	{
		ASSERT(m_strINIFileName.IsEmpty() == FALSE);
		ASSERT(m_strINIFileName.GetLength() < 4095); // can't read in bigger
		return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,
			m_strINIFileName);
	}
}
Exemplo n.º 6
0
// returns key for:
//      HKEY_CURRENT_USER\"Software"\RegistryKey\AppName\lpszSection
// creating it if it doesn't exist.
// responsibility of the caller to call RegCloseKey() on the returned HKEY
HKEY GetSectionKey(STR lpszSection)
{
	HKEY hSectionKey = NULL;
	HKEY hAppKey = GetAppRegistryKey();
	DWORD dw;

	assert(lpszSection != NULL);

	if (hAppKey == NULL)
		return NULL;

	RegCreateKeyEx(hAppKey, lpszSection, 0, REG_NONE,
		REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
		&hSectionKey, &dw);
	RegCloseKey(hAppKey);
	return hSectionKey;
}
Exemplo n.º 7
0
BOOL WriteProfileChar(STR lpszSection, STR lpszEntry, STR lpszValue)
{
	assert(lpszSection != NULL);

	if (gszRegistryKey[0] != '\0')
	{
		LONG lResult;
		if (lpszEntry == NULL) //delete whole section
		{
			HKEY hAppKey = GetAppRegistryKey();
			if (hAppKey == NULL)
				return FALSE;
			lResult = RegDeleteKey(hAppKey, lpszSection);
			RegCloseKey(hAppKey);
		}
		else if (lpszValue == NULL)
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			// necessary to cast away const below
			lResult = RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
			RegCloseKey(hSecKey);
		}
		else
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			lResult = RegSetValueEx(hSecKey, lpszEntry, 0, REG_SZ,
				(LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
			RegCloseKey(hSecKey);
		}
		return lResult == ERROR_SUCCESS;
	}
//	else
//	{
//		assert(gpszProfileName != NULL);
//		assert(lstrlen(gpszProfileName) < 4095); // can't read in bigger
//		return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,
//			gpszProfileName);
//	}
	return TRUE;
}
Exemplo n.º 8
0
	void StoreSettingsToRegistory(void)
	{
		struct Reg {
			static void WriteString(HKEY hKey, const TCHAR *name, const StdString &value)
			{
				const DWORD bytes = (DWORD)((value.size() + 1) * sizeof(TCHAR));
				LONG result = RegSetValueEx(hKey, name, NULL, REG_SZ, (BYTE *)value.c_str(), bytes);
				//if(result == ERROR_SUCCESS){
			}
		};
		HKEY hKey;
		DWORD disposition;
		if(::RegCreateKeyEx(HKEY_CURRENT_USER, GetAppRegistryKey(), NULL, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disposition) != ERROR_SUCCESS){
			return; // error
		}
		Reg::WriteString(hKey, "OutputFilename", outputFilename_);
		Reg::WriteString(hKey, "OutputHTTPURL", outputHTTPURL_);
		RegCloseKey(hKey);
	}
Exemplo n.º 9
0
BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
			LPCTSTR lpszValue)
{
	ASSERT(lpszSection != NULL);
	if (m_pszRegistryKey != NULL)
	{
		LONG lResult;
		if (lpszEntry == NULL) //delete whole section
		{
			HKEY hAppKey = GetAppRegistryKey();
			if (hAppKey == NULL)
				return FALSE;
			lResult = ::RegDeleteKey(hAppKey, lpszSection);
			RegCloseKey(hAppKey);
		}
		else if (lpszValue == NULL)
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			// necessary to cast away const below
			lResult = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry);
			RegCloseKey(hSecKey);
		}
		else
		{
			HKEY hSecKey = GetSectionKey(lpszSection);
			if (hSecKey == NULL)
				return FALSE;
			lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_SZ,
				(LPBYTE)lpszValue, (ATL::lstrlen(lpszValue)+1)*sizeof(TCHAR));
			RegCloseKey(hSecKey);
		}
		return lResult == ERROR_SUCCESS;
	}
	return FALSE;
}
Exemplo n.º 10
0
void getregdef(qMailOpts *popts)
{
// read qmail registry - defaults
	if (gAppKey = GetAppRegistryKey())
	{
		CStr sBuf;
		DWORD dwBuf;
		if ( GetRegistryValue(gAppKey, "Timeout", dwBuf))
			popts->timeout = (float) (dwBuf / 1000.0f);
		else if (popts->timeout == 0.0f)
			popts->timeout = Q_MINTIMEOUT;

		if (GetRegistryValue(gAppKey, "Smtp", sBuf))
			popts->host = sBuf;

		if (GetRegistryValue(gAppKey, "From", sBuf))
			popts->from = sBuf;
	}

// read microsoft preferences
	if (!popts->host.Length() || !popts->from) {
		HKEY hk1; CStr str; DWORD dw;
		CStr host;
		if (RegOpenKeyEx(HKEY_CURRENT_USER, 
			"software\\microsoft\\office\\8.0\\outlook\\internet account manager", 0, KEY_READ, &hk1) == ERROR_SUCCESS) 
		{
			if (GetRegistryValue(hk1, "default mail account", str)) {
				HKEY hk2;
				str = "accounts\\" << str;
				if (RegOpenKeyEx(hk1, (const char *) str, 0, KEY_QUERY_VALUE, &hk2) == ERROR_SUCCESS) {
					if (!popts->host.Length()) {
				 		if (GetRegistryValue(hk2, "POP3 User Name", str)) {
							host = str;
							host += '@';
						}
						if (GetRegistryValue(hk2, "SMTP Server", str)) {
							host += str;
						}
						if (GetRegistryValue(hk2, "SMTP Port", dw)) {
							host += ':';
							host += (int) dw;
						}
						popts->host = host;
					}
					
					if (popts->timeout == 0) {
						if (GetRegistryValue(hk2, "SMTP Timeout", dw))
							popts->timeout = (float) dw;
					}

					if (!popts->from.Length()) {
						if (GetRegistryValue(hk2, "SMTP Display Name", str))
							popts->from = str;
						if (GetRegistryValue(hk2, "SMTP Email Address", str)) {
							if (popts->from) {
								popts->from += '<';
								popts->from += str;
								popts->from += '>';
							} else 
								popts->from = str;
						}
					}
					RegCloseKey(hk2);
				}
			}
			RegCloseKey(hk1);
		}
	}
}