Author: ekohl
Date: Wed May 9 02:13:18 2007
New Revision: 26655
URL:
http://svn.reactos.org/svn/reactos?rev=26655&view=rev
Log:
Save user cursor schemes using the environment variables SystemRoot, USERPROFILE or
ProgramFiles in the cursor paths instead of absolute paths.
Modified:
trunk/reactos/dll/cpl/main/mouse.c
Modified: trunk/reactos/dll/cpl/main/mouse.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/main/mouse.c?rev=2…
==============================================================================
--- trunk/reactos/dll/cpl/main/mouse.c (original)
+++ trunk/reactos/dll/cpl/main/mouse.c Wed May 9 02:13:18 2007
@@ -424,6 +424,42 @@
}
+static VOID
+CompressPath(LPTSTR lpShortPath, LPTSTR lpPath)
+{
+ TCHAR szUserProfile[MAX_PATH];
+ TCHAR szSystemRoot[MAX_PATH];
+ TCHAR szProgramFiles[MAX_PATH];
+ DWORD dwUserProfile;
+ DWORD dwSystemRoot;
+ DWORD dwProgramFiles;
+
+ dwUserProfile = GetEnvironmentVariable(_T("USERPROFILE"), szUserProfile,
MAX_PATH);
+ dwSystemRoot = GetEnvironmentVariable(_T("SystemRoot"), szSystemRoot,
MAX_PATH);
+ dwProgramFiles = GetEnvironmentVariable(_T("ProgramFiles"), szProgramFiles,
MAX_PATH);
+
+ if (dwUserProfile > 0 && _tcsncmp(lpPath, szUserProfile, dwUserProfile) ==
0)
+ {
+ _tcscpy(lpShortPath, _T("%USERPROFILE%"));
+ _tcscat(lpShortPath, &lpPath[dwUserProfile]);
+ }
+ else if (dwSystemRoot > 0 && _tcsncmp(lpPath, szSystemRoot, dwSystemRoot)
== 0)
+ {
+ _tcscpy(lpShortPath, _T("%SystemRoot%"));
+ _tcscat(lpShortPath, &lpPath[dwSystemRoot]);
+ }
+ else if (dwProgramFiles > 0 && _tcsncmp(lpPath, szProgramFiles,
dwProgramFiles) == 0)
+ {
+ _tcscpy(lpShortPath, _T("%ProgramFiles%"));
+ _tcscat(lpShortPath, &lpPath[dwProgramFiles]);
+ }
+ else
+ {
+ _tcscpy(lpShortPath, lpPath);
+ }
+}
+
+
static BOOL
EnumerateCursorSchemes(HWND hwndDlg)
{
@@ -433,6 +469,7 @@
DWORD dwValueName;
TCHAR szSystemScheme[MAX_PATH];
TCHAR szValueData[2000];
+ TCHAR szTempData[2000];
DWORD dwValueData;
LONG lError;
HWND hDlgCtrl;
@@ -446,6 +483,50 @@
0, KEY_READ | KEY_QUERY_VALUE , &hCursorKey);
if (lError == ERROR_SUCCESS)
{
+ for (dwIndex = 0;; dwIndex++)
+ {
+ dwValueName = sizeof(szValueName) / sizeof(TCHAR);
+ dwValueData = sizeof(szValueData) / sizeof(TCHAR);
+ lError = RegEnumValue(hCursorKey, dwIndex, szValueName, &dwValueName,
+ NULL, NULL, (LPBYTE)szValueData, &dwValueData);
+ if (lError == ERROR_NO_MORE_ITEMS)
+ break;
+
+ ExpandEnvironmentStrings(szValueData, szTempData, 2000);
+
+ if (_tcslen(szTempData) > 0)
+ {
+ LPTSTR lpCopy, lpStart;
+
+ /* Remove quotation marks */
+ if (szTempData[0] == _T('"'))
+ {
+ lpStart = szValueData + 1;
+ szTempData[_tcslen(szTempData) - 1] = 0;
+ }
+ else
+ {
+ lpStart = szTempData;
+ }
+
+ lpCopy = _tcsdup(lpStart);
+
+ lResult = SendMessage(hDlgCtrl, CB_ADDSTRING, (WPARAM)0,
(LPARAM)szValueName);
+ SendMessage(hDlgCtrl, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)lpCopy);
+ }
+ }
+
+ RegCloseKey(hCursorKey);
+ }
+
+ /* Read the system cursor schemes */
+ lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control
Panel\\Cursors\\Schemes"),
+ 0, KEY_READ | KEY_QUERY_VALUE , &hCursorKey);
+ if (lError == ERROR_SUCCESS)
+ {
+ LoadString(hApplet, IDS_SYSTEM_SCHEME, szSystemScheme, MAX_PATH);
+
for (dwIndex = 0;; dwIndex++)
{
dwValueName = sizeof(szValueName) / sizeof(TCHAR);
@@ -472,48 +553,6 @@
lpCopy = _tcsdup(lpStart);
- lResult = SendMessage(hDlgCtrl, CB_ADDSTRING, (WPARAM)0,
(LPARAM)szValueName);
- SendMessage(hDlgCtrl, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)lpCopy);
- }
- }
-
- RegCloseKey(hCursorKey);
- }
-
- /* Read the system cursor schemes */
- lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control
Panel\\Cursors\\Schemes"),
- 0, KEY_READ | KEY_QUERY_VALUE , &hCursorKey);
- if (lError == ERROR_SUCCESS)
- {
- LoadString(hApplet, IDS_SYSTEM_SCHEME, szSystemScheme, MAX_PATH);
-
- for (dwIndex = 0;; dwIndex++)
- {
- dwValueName = sizeof(szValueName) / sizeof(TCHAR);
- dwValueData = sizeof(szValueData) / sizeof(TCHAR);
- lError = RegEnumValue(hCursorKey, dwIndex, szValueName, &dwValueName,
- NULL, NULL, (LPBYTE)szValueData, &dwValueData);
- if (lError == ERROR_NO_MORE_ITEMS)
- break;
-
- if (_tcslen(szValueData) > 0)
- {
- LPTSTR lpCopy, lpStart;
-
- /* Remove quotation marks */
- if (szValueData[0] == _T('"'))
- {
- lpStart = szValueData + 1;
- szValueData[_tcslen(szValueData) - 1] = 0;
- }
- else
- {
- lpStart = szValueData;
- }
-
- lpCopy = _tcsdup(lpStart);
-
_tcscat(szValueName, TEXT(" "));
_tcscat(szValueName, szSystemScheme);
@@ -661,6 +700,7 @@
TCHAR szSystemScheme[MAX_PATH];
TCHAR szSchemeName[MAX_PATH];
TCHAR szNewSchemeName[MAX_PATH];
+ TCHAR szTempPath[MAX_PATH];
TCHAR szTitle[128];
TCHAR szText[256];
INT nSel;
@@ -739,9 +779,10 @@
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
+ CompressPath(szTempPath, g_CursorData[i].szCursorPath);
if (i > 0)
_tcscat(lpSchemeData, _T(","));
- _tcscat(lpSchemeData, g_CursorData[i].szCursorPath);
+ _tcscat(lpSchemeData, szTempPath);
}
if (RegOpenCurrentUser(KEY_READ | KEY_SET_VALUE, &hCuKey) != ERROR_SUCCESS)
@@ -753,8 +794,9 @@
return FALSE;
}
- lError = RegSetValueEx(hCuCursorKey, szNewSchemeName, 0, REG_EXPAND_SZ,
- (LPBYTE)lpSchemeData, nLength * sizeof(TCHAR));
+ lError = RegSetValueEx(hCuCursorKey, szNewSchemeName, 0,
+ REG_EXPAND_SZ, (LPBYTE)lpSchemeData,
+ (_tcslen(lpSchemeData) + 1) * sizeof(TCHAR));
RegCloseKey(hCuCursorKey);
RegCloseKey(hCuKey);
@@ -1080,6 +1122,7 @@
{
TCHAR szSchemeName[MAX_PATH];
TCHAR szSystemScheme[MAX_PATH];
+ TCHAR szTempPath[MAX_PATH];
LPTSTR lpSchemeData;
DWORD dwNameLength;
DWORD dwSchemeSource;
@@ -1131,9 +1174,10 @@
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
+ CompressPath(szTempPath, g_CursorData[i].szCursorPath);
RegSetValueEx(hCursorKey, g_CursorData[i].lpValueName, 0,
- REG_EXPAND_SZ, (LPBYTE)g_CursorData[i].szCursorPath,
- (_tcslen(g_CursorData[i].szCursorPath) + 1) * sizeof(TCHAR));
+ REG_EXPAND_SZ, (LPBYTE)szTempPath,
+ (_tcslen(szTempPath) + 1) * sizeof(TCHAR));
}
RegCloseKey(hCursorKey);