Esempio n. 1
0
void RegConfig::BookmarkInsertInt(int nPos, RegPath* pKey, BOOL abSaveImmediate /*= TRUE*/)
{
	if (szBookmarksValueName[0] == 0 || !pszBookmarks)
	{
		_ASSERTE(szBookmarksValueName[0] && pszBookmarks);
		return;
	}

	// Сформировать полный путь с "HKEY_xxx"
	wchar_t* pszNewKey = NULL;
	int nKeyLen = pKey->mpsz_Key ? lstrlenW(pKey->mpsz_Key) : 0;
	pszNewKey = (wchar_t*)calloc(nKeyLen+40,2);
	if (pKey->mh_Root) {
		if (!pKey->IsKeyPredefined(pKey->mh_Root)) {
			pszNewKey[0] = 0;
		} else if (!HKeyToStringKey(pKey->mh_Root, pszNewKey , 40)) {
			// Неизвестный ключ!
			InvalidOp();
			SafeFree(pszNewKey);
			return;
		}
		MCHKHEAP;
	}
	if (*pKey->mpsz_Key) {
		lstrcatW(pszNewKey, L"\\");
		lstrcpynW(pszNewKey+lstrlenW(pszNewKey), pKey->mpsz_Key, nKeyLen+1);
	}
	BookmarkInsertInt(nPos, pszNewKey, abSaveImmediate);
	SafeFree(pszNewKey);
}
Esempio n. 2
0
bool HKeyToStringKey(HKEY hkey, wchar_t* pszKey, int nMaxLen)
{
	LPCWSTR psz = HKeyToStringKey(hkey);
	if (!psz)
		return false;
	lstrcpynW(pszKey, psz, nMaxLen);
	return true;
}
Esempio n. 3
0
void RegConfig::SetLastRegPath(HKEY ahKey, LPCWSTR asSubKey)
{
	MCHKHEAP;
	int nLen = lstrlenW(asSubKey);
	if (!pszLastRegPath || (nLen + 40) >= nMaxRegPath)
	{
		SafeFree(pszLastRegPath);
		nMaxRegPath = nLen + MAX_PATH; // с запасом
		pszLastRegPath = (wchar_t*)malloc(nMaxRegPath*2);
	}
	pszLastRegPath[0] = 0;
	MCHKHEAP;
	if (ahKey)
	{
		if (!HKeyToStringKey(ahKey, pszLastRegPath, 40))
		{
			// Неизвестный ключ!
			_ASSERTE(ahKey==HKEY_CLASSES_ROOT);
		}
		else if (asSubKey && *asSubKey)
		{
			lstrcatW(pszLastRegPath, L"\\");
			lstrcatW(pszLastRegPath, asSubKey);
		}
	}
	else
	{
		_ASSERTE(asSubKey == NULL || *asSubKey == 0);
	}
	MCHKHEAP;
	
	// Записать в реестр
	_ASSERTE(sizeof(*pszLastRegPath)==2);
	DWORD nSize = (lstrlenW(pszLastRegPath)+1)*2;
	#if FAR_UNICODE>=1900
	FarSettingsCreate sc = {sizeof(FarSettingsCreate), guid_PluginGuid, INVALID_HANDLE_VALUE};
	if (psi.SettingsControl(INVALID_HANDLE_VALUE, SCTL_CREATE, 0, &sc))
	{
		FarSettingsItem fsi = {0};
		fsi.Name = L"LastRegPath";
		fsi.Type = FST_STRING;
		fsi.String = pszLastRegPath;
		psi.SettingsControl(sc.Handle, SCTL_SET, 0, &fsi);
		psi.SettingsControl(sc.Handle, SCTL_FREE, 0, 0);
	}
	#else
	HKEY hk;
	if (0 == RegCreateKeyEx(HKEY_CURRENT_USER, pszPluginKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hk, NULL))
	{
		RegSetValueExW(hk, L"LastRegPath", 0, REG_SZ, (LPBYTE)pszLastRegPath, nSize);
		RegCloseKey(hk);
	}
	#endif
	MCHKHEAP;
}