* PURPOSE: Misc functions
* PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
* Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
+ * Alexander Shaposhnikov (chaez.san@gmail.com)
*/
#include "rapps.h"
-/* SESSION Operation */
+ /* SESSION Operation */
#define EXTRACT_FILLFILELIST 0x00000001
#define EXTRACT_EXTRACTFILES 0x00000002
static HANDLE hLog = NULL;
-WCHAR szCachedINISectionLocale[MAX_PATH] = L"Section.";
-WCHAR szCachedINISectionLocaleNeutral[MAX_PATH] = {0};
-BYTE bCachedSectionStatus = FALSE;
typedef struct
{
typedef HRESULT(WINAPI *fnExtract)(SESSION *dest, LPCSTR szCabName);
fnExtract pfnExtract;
-
INT
GetSystemColorDepth(VOID)
{
pDevMode.dmSize = sizeof(pDevMode);
pDevMode.dmDriverExtra = 0;
- if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &pDevMode))
+ if (!EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &pDevMode))
{
/* TODO: Error message */
return ILC_COLOR;
switch (pDevMode.dmBitsPerPel)
{
- case 32: ColorDepth = ILC_COLOR32; break;
- case 24: ColorDepth = ILC_COLOR24; break;
- case 16: ColorDepth = ILC_COLOR16; break;
- case 8: ColorDepth = ILC_COLOR8; break;
- case 4: ColorDepth = ILC_COLOR4; break;
- default: ColorDepth = ILC_COLOR; break;
+ case 32: ColorDepth = ILC_COLOR32; break;
+ case 24: ColorDepth = ILC_COLOR24; break;
+ case 16: ColorDepth = ILC_COLOR16; break;
+ case 8: ColorDepth = ILC_COLOR8; break;
+ case 4: ColorDepth = ILC_COLOR4; break;
+ default: ColorDepth = ILC_COLOR; break;
}
return ColorDepth;
EmptyClipboard();
cchBuffer = wcslen(lpszText) + 1;
ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
- Buffer = (PWCHAR)GlobalLock(ClipBuffer);
+ Buffer = (PWCHAR) GlobalLock(ClipBuffer);
hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
GlobalUnlock(ClipBuffer);
VOID
SetWelcomeText(VOID)
{
- WCHAR szText[MAX_STR_LEN*3];
+ ATL::CStringW szText;
- LoadStringW(hInst, IDS_WELCOME_TITLE, szText, _countof(szText));
+ szText.LoadStringW(hInst, IDS_WELCOME_TITLE);
NewRichEditText(szText, CFE_BOLD);
- LoadStringW(hInst, IDS_WELCOME_TEXT, szText, _countof(szText));
+ szText.LoadStringW(hInst, IDS_WELCOME_TEXT);
InsertRichEditText(szText, 0);
- LoadStringW(hInst, IDS_WELCOME_URL, szText, _countof(szText));
+ szText.LoadStringW(hInst, IDS_WELCOME_URL);
InsertRichEditText(szText, CFM_LINK);
}
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STATE;
- GetMenuItemInfo(hPopupMenu, DefaultItem, FALSE, &mii);
+ GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &mii);
if (!(mii.fState & MFS_GRAYED))
SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
DestroyMenu(hMenu);
}
+BOOL
+StartProcess(ATL::CStringW &Path, BOOL Wait)
+{
+ BOOL result = StartProcess(const_cast<LPWSTR>(Path.GetString()), Wait);
+ return result;
+}
+
BOOL
StartProcess(LPWSTR lpPath, BOOL Wait)
{
}
BOOL
-GetStorageDirectory(PWCHAR lpDirectory, DWORD cch)
+GetStorageDirectory(ATL::CStringW& Directory)
{
- 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)
+ if (!SHGetSpecialFolderPathW(NULL, Directory.GetBuffer(MAX_PATH), CSIDL_LOCAL_APPDATA, TRUE))
{
+ Directory.ReleaseBuffer();
return FALSE;
}
- return TRUE;
+ Directory.ReleaseBuffer();
+ Directory += L"\\rapps";
+
+ return (CreateDirectoryW(Directory.GetString(), NULL) || GetLastError() == ERROR_ALREADY_EXISTS);
}
BOOL
-ExtractFilesFromCab(LPWSTR lpCabName, LPWSTR lpOutputPath)
+ExtractFilesFromCab(const ATL::CStringW &CabName, const ATL::CStringW &OutputPath)
+{
+ return ExtractFilesFromCab(CabName.GetString(), OutputPath.GetString());
+}
+
+BOOL
+ExtractFilesFromCab(LPCWSTR lpCabName, LPCWSTR lpOutputPath)
{
HINSTANCE hCabinetDll;
CHAR szCabName[MAX_PATH];
L"EventMessageFile",
0,
REG_EXPAND_SZ,
- (LPBYTE)szPath,
- (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
+ (LPBYTE) szPath,
+ (DWORD) (wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return;
}
dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
- EVENTLOG_INFORMATION_TYPE;
+ EVENTLOG_INFORMATION_TYPE;
if (RegSetValueExW(hKey,
L"TypesSupported",
0,
REG_DWORD,
- (LPBYTE)&dwData,
+ (LPBYTE) &dwData,
sizeof(DWORD)) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
L"CategoryMessageFile",
0,
REG_EXPAND_SZ,
- (LPBYTE)szPath,
- (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
+ (LPBYTE) szPath,
+ (DWORD) (wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return;
L"CategoryCount",
0,
REG_DWORD,
- (LPBYTE)&dwCategoryNum,
+ (LPBYTE) &dwCategoryNum,
sizeof(DWORD)) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
BOOL
-WriteLogMessage(WORD wType, DWORD dwEventID, LPWSTR lpMsg)
+WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
{
if (!SettingsInfo.bLogEnabled) return TRUE;
- if (!ReportEventW(hLog,
- wType,
- 0,
- dwEventID,
- NULL,
- 1,
- 0,
- (LPCWSTR*)&lpMsg,
- NULL))
+ if (!ReportEventW(hLog, wType, 0, dwEventID,
+ NULL, 1, 0, &lpMsg, NULL))
{
return FALSE;
}
}
-LPWSTR GetINIFullPath(LPCWSTR lpFileName)
-{
- WCHAR szDir[MAX_PATH];
- static WCHAR szBuffer[MAX_PATH];
-
- GetStorageDirectory(szDir, _countof(szDir));
- StringCbPrintfW(szBuffer, sizeof(szBuffer), L"%ls\\rapps\\%ls", szDir, lpFileName);
-
- return szBuffer;
-}
-
-
-UINT ParserGetString(LPCWSTR lpKeyName, LPWSTR lpReturnedString, UINT nSize, LPCWSTR lpFileName)
-{
- PWSTR lpFullFileName = GetINIFullPath(lpFileName);
- DWORD dwResult;
-
- /* we don't have cached section strings for the current system language, create them */
- if(bCachedSectionStatus == FALSE)
- {
- WCHAR szLocale[4 + 1];
- DWORD len;
-
- /* find out what is the current system lang code (e.g. "0a") and append it to SectionLocale */
- GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE,
- szLocale, _countof(szLocale));
-
- StringCbCatW(szCachedINISectionLocale, sizeof(szCachedINISectionLocale), szLocale);
-
- /* copy the locale-dependent string into the buffer of the future neutral one */
- StringCbCopyW(szCachedINISectionLocaleNeutral,
- sizeof(szCachedINISectionLocaleNeutral),
- szCachedINISectionLocale);
-
- /* turn "Section.0c0a" into "Section.0a", keeping just the neutral lang part */
- len = wcslen(szCachedINISectionLocale);
-
- memmove((szCachedINISectionLocaleNeutral + len) - 4,
- (szCachedINISectionLocaleNeutral + len) - 2,
- (2 * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
-
- /* finally, mark us as cache-friendly for the next time */
- bCachedSectionStatus = TRUE;
- }
-
- /* 1st - find localized strings (e.g. "Section.0c0a") */
- dwResult = GetPrivateProfileStringW(szCachedINISectionLocale,
- lpKeyName,
- NULL,
- lpReturnedString,
- nSize,
- lpFullFileName);
-
- if (dwResult != 0)
- return TRUE;
-
- /* 2nd - if they weren't present check for neutral sub-langs/ generic translations (e.g. "Section.0a") */
- dwResult = GetPrivateProfileStringW(szCachedINISectionLocaleNeutral,
- lpKeyName,
- NULL,
- lpReturnedString,
- nSize,
- lpFullFileName);
-
- if (dwResult != 0)
- return TRUE;
-
- /* 3rd - if they weren't present fallback to standard english strings (just "Section") */
- dwResult = GetPrivateProfileStringW(L"Section",
- lpKeyName,
- NULL,
- lpReturnedString,
- nSize,
- lpFullFileName);
-
- return (dwResult != 0 ? TRUE : FALSE);
-}
-
-UINT ParserGetInt(LPCWSTR lpKeyName, LPCWSTR lpFileName)
-{
- WCHAR Buffer[30];
- UNICODE_STRING BufferW;
- ULONG Result;
-
- /* grab the text version of our entry */
- if (!ParserGetString(lpKeyName, Buffer, _countof(Buffer), lpFileName))
- return FALSE;
-
- if (!Buffer[0])
- return FALSE;
-
- /* convert it to an actual integer */
- RtlInitUnicodeString(&BufferW, Buffer);
- RtlUnicodeStringToInteger(&BufferW, 0, &Result);
-
- return Result;
-}
-
-
-BOOL
-ParseVersion(LPWSTR szVersion, INT* version)
-{
- return TRUE;
-}
-
-
-//Finds subkey in key by name or path and returns it
-BOOL
-FindRegistryKeyByName(_In_ HKEY hKeyBase, _In_ REGSAM keyWow, _In_ LPCWSTR lpcKey, _Out_opt_ PHKEY hKeyResult)
-{
- HKEY hSubKey;
- if (RegOpenKeyExW(hKeyBase, lpcKey, 0, keyWow | KEY_READ, &hSubKey) == ERROR_SUCCESS)
- {
- hKeyResult = &hSubKey;
- return TRUE;
- }
- hKeyResult = NULL;
- RegCloseKey(hSubKey);
- return FALSE;
-}