Author: tfaber
Date: Sat Jan 18 11:21:48 2014
New Revision: 61669
URL:
http://svn.reactos.org/svn/reactos?rev=61669&view=rev
Log:
[RAPPS]
- Do not write to the application directory. Welcome to Windows NT...
Modified:
trunk/reactos/base/applications/rapps/available.c
trunk/reactos/base/applications/rapps/loaddlg.c
trunk/reactos/base/applications/rapps/misc.c
trunk/reactos/base/applications/rapps/parser.c
trunk/reactos/base/applications/rapps/rapps.h
Modified: trunk/reactos/base/applications/rapps/available.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/av…
==============================================================================
--- trunk/reactos/base/applications/rapps/available.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/available.c [iso-8859-1] Sat Jan 18 11:21:48
2014
@@ -47,7 +47,7 @@
WCHAR szPath[MAX_PATH];
WCHAR szTmp[MAX_PATH];
- if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+ if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
return FALSE;
swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
@@ -94,7 +94,7 @@
DownloadApplicationsDB(APPLICATION_DATEBASE_URL);
- if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+ if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
return FALSE;
swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
@@ -120,7 +120,7 @@
WCHAR szLocale[4 + 1];
APPLICATION_INFO Info;
- if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+ if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
{
return FALSE;
}
Modified: trunk/reactos/base/applications/rapps/loaddlg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/lo…
==============================================================================
--- trunk/reactos/base/applications/rapps/loaddlg.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/loaddlg.c [iso-8859-1] Sat Jan 18 11:21:48 2014
@@ -227,7 +227,7 @@
AppInfo->szUrlDownload[len - 1] == 'b')
{
bCab = TRUE;
- if (!GetCurrentDirectoryW(MAX_PATH, path))
+ if (!GetStorageDirectory(path, sizeof(path) / sizeof(path[0])))
goto end;
}
else
Modified: trunk/reactos/base/applications/rapps/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/mi…
==============================================================================
--- trunk/reactos/base/applications/rapps/misc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/misc.c [iso-8859-1] Sat Jan 18 11:21:48 2014
@@ -208,6 +208,26 @@
return TRUE;
}
+BOOL
+GetStorageDirectory(PWCHAR lpDirectory, DWORD cch)
+{
+ if (cch < MAX_PATH)
+ return FALSE;
+
+ if (!SHGetSpecialFolderPathW(NULL, lpDirectory, CSIDL_LOCAL_APPDATA, TRUE))
+ return FALSE;
+
+ if (FAILED(StringCchCatW(lpDirectory, cch, L"\\rapps")))
+ return FALSE;
+
+ if (!CreateDirectoryW(lpDirectory, NULL) &&
+ GetLastError() != ERROR_ALREADY_EXISTS)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
BOOL
ExtractFilesFromCab(LPWSTR lpCabName, LPWSTR lpOutputPath)
@@ -261,13 +281,13 @@
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
szBuf, 0, NULL,
REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
- {
- return;
- }
-
- if (!GetCurrentDirectoryW(MAX_PATH, szPath)) return;
- wcscat(szPath, L"\\rapps.exe");
+ KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
+ {
+ return;
+ }
+
+ if (!GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(szPath[0])))
+ return;
if (RegSetValueExW(hKey,
L"EventMessageFile",
@@ -276,13 +296,13 @@
(LPBYTE)szPath,
(DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
- return;
- }
-
- dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
- EVENTLOG_INFORMATION_TYPE;
-
+ RegCloseKey(hKey);
+ return;
+ }
+
+ dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+ EVENTLOG_INFORMATION_TYPE;
+
if (RegSetValueExW(hKey,
L"TypesSupported",
0,
@@ -290,7 +310,7 @@
(LPBYTE)&dwData,
sizeof(DWORD)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
@@ -301,7 +321,7 @@
(LPBYTE)szPath,
(DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
@@ -312,7 +332,7 @@
(LPBYTE)&dwCategoryNum,
sizeof(DWORD)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
Modified: trunk/reactos/base/applications/rapps/parser.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/pa…
==============================================================================
--- trunk/reactos/base/applications/rapps/parser.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/parser.c [iso-8859-1] Sat Jan 18 11:21:48 2014
@@ -557,7 +557,7 @@
ItemsArray[i]->encoding = ENCODING_UTF8;
}
- GetCurrentDirectoryW(MAX_PATH, szDir);
+ GetStorageDirectory(szDir, sizeof(szDir) / sizeof(szDir[0]));
wcscpy(buffer, szDir);
wcscat(buffer, wszSeparator);
Modified: trunk/reactos/base/applications/rapps/rapps.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/ra…
==============================================================================
--- trunk/reactos/base/applications/rapps/rapps.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/rapps.h [iso-8859-1] Sat Jan 18 11:21:48 2014
@@ -15,6 +15,7 @@
#include <richedit.h>
#include <shlobj.h>
#include <stdio.h>
+#include <strsafe.h>
#include <rappsmsg.h>
@@ -150,6 +151,7 @@
VOID SetWelcomeText(VOID);
VOID ShowPopupMenu(HWND hwnd, UINT MenuID);
BOOL StartProcess(LPWSTR lpPath, BOOL Wait);
+BOOL GetStorageDirectory(PWCHAR lpDirectory, DWORD cch);
BOOL ExtractFilesFromCab(LPWSTR lpCabName, LPWSTR lpOutputPath);
VOID InitLogs(VOID);
VOID FreeLogs(VOID);