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);
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);
WCHAR szLocale[4 + 1];
APPLICATION_INFO Info;
- if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+ if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
{
return FALSE;
}
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)
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
szBuf, 0, NULL,
REG_OPTION_NON_VOLATILE,
- KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
+ KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
{
return;
}
- if (!GetCurrentDirectoryW(MAX_PATH, szPath)) return;
- wcscat(szPath, L"\\rapps.exe");
+ if (!GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(szPath[0])))
+ return;
if (RegSetValueExW(hKey,
L"EventMessageFile",
(LPBYTE)szPath,
(DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
- dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
- EVENTLOG_INFORMATION_TYPE;
-
+ dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+ EVENTLOG_INFORMATION_TYPE;
+
if (RegSetValueExW(hKey,
L"TypesSupported",
0,
(LPBYTE)&dwData,
sizeof(DWORD)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
(LPBYTE)szPath,
(DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
(LPBYTE)&dwCategoryNum,
sizeof(DWORD)) != ERROR_SUCCESS)
{
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
return;
}
#include <richedit.h>
#include <shlobj.h>
#include <stdio.h>
+#include <strsafe.h>
#include <rappsmsg.h>
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);