2015-04-22 16:53:55 +00:00
|
|
|
/*
|
2017-09-09 20:38:06 +00:00
|
|
|
* PROJECT: ReactOS Applications Manager
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* FILE: base/applications/rapps/misc.cpp
|
|
|
|
* PURPOSE: Misc functions
|
|
|
|
* COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
|
|
|
|
* Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
|
2017-09-09 20:44:43 +00:00
|
|
|
* Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
|
2015-04-22 16:53:55 +00:00
|
|
|
*/
|
2017-09-10 23:44:22 +00:00
|
|
|
#include "rapps.h"
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-02 12:50:53 +00:00
|
|
|
#include "gui.h"
|
|
|
|
#include "misc.h"
|
2017-09-10 17:33:14 +00:00
|
|
|
#include "cabinet.h"
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
/* SESSION Operation */
|
2015-04-22 16:53:55 +00:00
|
|
|
#define EXTRACT_FILLFILELIST 0x00000001
|
|
|
|
#define EXTRACT_EXTRACTFILES 0x00000002
|
|
|
|
|
|
|
|
static HANDLE hLog = NULL;
|
2017-06-29 14:17:16 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
INT GetWindowWidth(HWND hwnd)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
RECT Rect;
|
|
|
|
|
|
|
|
GetWindowRect(hwnd, &Rect);
|
|
|
|
return (Rect.right - Rect.left);
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
INT GetWindowHeight(HWND hwnd)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
RECT Rect;
|
|
|
|
|
|
|
|
GetWindowRect(hwnd, &Rect);
|
|
|
|
return (Rect.bottom - Rect.top);
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
INT GetClientWindowWidth(HWND hwnd)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
RECT Rect;
|
|
|
|
|
|
|
|
GetClientRect(hwnd, &Rect);
|
|
|
|
return (Rect.right - Rect.left);
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
INT GetClientWindowHeight(HWND hwnd)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
RECT Rect;
|
|
|
|
|
|
|
|
GetClientRect(hwnd, &Rect);
|
|
|
|
return (Rect.bottom - Rect.top);
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID CopyTextToClipboard(LPCWSTR lpszText)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
if (!OpenClipboard(NULL))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
HRESULT hr;
|
2017-08-08 21:32:11 +00:00
|
|
|
HGLOBAL ClipBuffer;
|
|
|
|
LPWSTR Buffer;
|
|
|
|
DWORD cchBuffer;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
EmptyClipboard();
|
|
|
|
cchBuffer = wcslen(lpszText) + 1;
|
|
|
|
ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
Buffer = (PWCHAR) GlobalLock(ClipBuffer);
|
|
|
|
hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
|
|
|
|
GlobalUnlock(ClipBuffer);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
SetClipboardData(CF_UNICODETEXT, ClipBuffer);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
CloseClipboard();
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID SetWelcomeText()
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
ATL::CStringW szText;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-26 08:39:42 +00:00
|
|
|
szText.LoadStringW(IDS_WELCOME_TITLE);
|
2015-04-22 16:53:55 +00:00
|
|
|
NewRichEditText(szText, CFE_BOLD);
|
|
|
|
|
2017-08-26 08:39:42 +00:00
|
|
|
szText.LoadStringW(IDS_WELCOME_TEXT);
|
2015-04-22 16:53:55 +00:00
|
|
|
InsertRichEditText(szText, 0);
|
|
|
|
|
2017-08-26 08:39:42 +00:00
|
|
|
szText.LoadStringW(IDS_WELCOME_URL);
|
2015-04-22 16:53:55 +00:00
|
|
|
InsertRichEditText(szText, CFM_LINK);
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
HMENU hMenu = NULL;
|
|
|
|
HMENU hPopupMenu;
|
2017-08-08 21:32:11 +00:00
|
|
|
MENUITEMINFO ItemInfo;
|
2015-04-22 16:53:55 +00:00
|
|
|
POINT pt;
|
|
|
|
|
|
|
|
if (MenuID)
|
|
|
|
{
|
|
|
|
hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID));
|
|
|
|
hPopupMenu = GetSubMenu(hMenu, 0);
|
|
|
|
}
|
|
|
|
else
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
2015-04-22 16:53:55 +00:00
|
|
|
hPopupMenu = GetMenu(hwnd);
|
2017-08-08 21:32:11 +00:00
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
ZeroMemory(&ItemInfo, sizeof(ItemInfo));
|
|
|
|
ItemInfo.cbSize = sizeof(ItemInfo);
|
|
|
|
ItemInfo.fMask = MIIM_STATE;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &ItemInfo);
|
|
|
|
|
|
|
|
if (!(ItemInfo.fState & MFS_GRAYED))
|
|
|
|
{
|
2015-04-22 16:53:55 +00:00
|
|
|
SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
|
2017-08-08 21:32:11 +00:00
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
|
|
|
|
SetForegroundWindow(hwnd);
|
|
|
|
TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hMainWnd, NULL);
|
|
|
|
|
|
|
|
if (hMenu)
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
2015-04-22 16:53:55 +00:00
|
|
|
DestroyMenu(hMenu);
|
2017-08-08 21:32:11 +00:00
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL StartProcess(ATL::CStringW &Path, BOOL Wait)
|
2017-08-15 22:35:45 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
return StartProcess(const_cast<LPWSTR>(Path.GetString()), Wait);;
|
2017-07-10 21:02:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL StartProcess(LPWSTR lpPath, BOOL Wait)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOW si;
|
|
|
|
DWORD dwRet;
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_SHOW;
|
|
|
|
|
|
|
|
if (!CreateProcessW(NULL, lpPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(pi.hThread);
|
2017-08-08 21:32:11 +00:00
|
|
|
|
|
|
|
if (Wait)
|
|
|
|
{
|
|
|
|
EnableWindow(hMainWnd, FALSE);
|
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
while (Wait)
|
|
|
|
{
|
|
|
|
dwRet = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLEVENTS);
|
|
|
|
if (dwRet == WAIT_OBJECT_0 + 1)
|
|
|
|
{
|
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
2017-08-08 21:32:11 +00:00
|
|
|
DispatchMessageW(&msg);
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dwRet == WAIT_OBJECT_0 || dwRet == WAIT_FAILED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
|
|
|
if (Wait)
|
|
|
|
{
|
|
|
|
EnableWindow(hMainWnd, TRUE);
|
|
|
|
SetForegroundWindow(hMainWnd);
|
|
|
|
SetFocus(hMainWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL GetStorageDirectory(ATL::CStringW& Directory)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
if (!SHGetSpecialFolderPathW(NULL, Directory.GetBuffer(MAX_PATH), CSIDL_LOCAL_APPDATA, TRUE))
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
Directory.ReleaseBuffer();
|
2015-04-22 16:53:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
Directory.ReleaseBuffer();
|
|
|
|
Directory += L"\\rapps";
|
|
|
|
|
|
|
|
return (CreateDirectoryW(Directory.GetString(), NULL) || GetLastError() == ERROR_ALREADY_EXISTS);
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL ExtractFilesFromCab(const ATL::CStringW &CabName, const ATL::CStringW &OutputPath)
|
2017-07-10 21:02:24 +00:00
|
|
|
{
|
|
|
|
return ExtractFilesFromCab(CabName.GetString(), OutputPath.GetString());
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL ExtractFilesFromCab(LPCWSTR lpCabName, LPCWSTR lpOutputPath)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
HINSTANCE hCabinetDll;
|
|
|
|
CHAR szCabName[MAX_PATH];
|
|
|
|
SESSION Dest;
|
|
|
|
HRESULT Result;
|
2017-09-10 17:33:14 +00:00
|
|
|
fnExtract pfnExtract;
|
2018-02-03 22:42:46 +00:00
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
hCabinetDll = LoadLibraryW(L"cabinet.dll");
|
|
|
|
if (hCabinetDll)
|
|
|
|
{
|
2015-04-23 23:08:21 +00:00
|
|
|
pfnExtract = (fnExtract) GetProcAddress(hCabinetDll, "Extract");
|
2015-04-22 16:53:55 +00:00
|
|
|
if (pfnExtract)
|
|
|
|
{
|
2016-10-06 12:22:32 +00:00
|
|
|
ZeroMemory(&Dest, sizeof(Dest));
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, lpOutputPath, -1, Dest.Destination, MAX_PATH, NULL, NULL);
|
2018-02-03 22:40:58 +00:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, lpCabName, -1, szCabName, _countof(szCabName), NULL, NULL);
|
2015-04-22 16:53:55 +00:00
|
|
|
Dest.Operation = EXTRACT_FILLFILELIST;
|
|
|
|
|
|
|
|
Result = pfnExtract(&Dest, szCabName);
|
|
|
|
if (Result == S_OK)
|
|
|
|
{
|
|
|
|
Dest.Operation = EXTRACT_EXTRACTFILES;
|
2017-08-24 18:46:39 +00:00
|
|
|
CreateDirectoryW(lpOutputPath, NULL);
|
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
Result = pfnExtract(&Dest, szCabName);
|
|
|
|
if (Result == S_OK)
|
|
|
|
{
|
|
|
|
FreeLibrary(hCabinetDll);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-08-24 21:56:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RemoveDirectoryW(lpOutputPath);
|
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FreeLibrary(hCabinetDll);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID InitLogs()
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
if (!SettingsInfo.bLogEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
DWORD dwCategoryNum = 1;
|
|
|
|
DWORD dwDisp, dwData;
|
2017-08-08 21:32:11 +00:00
|
|
|
ATL::CRegKey key;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
if (key.Create(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager",
|
|
|
|
REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &dwDisp) != ERROR_SUCCESS)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-06 12:22:32 +00:00
|
|
|
if (!GetModuleFileNameW(NULL, szPath, _countof(szPath)))
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
|
2017-07-10 21:02:24 +00:00
|
|
|
EVENTLOG_INFORMATION_TYPE;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
if ((key.SetStringValue(L"EventMessageFile",
|
|
|
|
szPath,
|
|
|
|
REG_EXPAND_SZ) == ERROR_SUCCESS)
|
|
|
|
&& (key.SetStringValue(L"CategoryMessageFile",
|
|
|
|
szPath,
|
|
|
|
REG_EXPAND_SZ) == ERROR_SUCCESS)
|
|
|
|
&& (key.SetDWORDValue(L"TypesSupported",
|
|
|
|
dwData) == ERROR_SUCCESS)
|
|
|
|
&& (key.SetDWORDValue(L"CategoryCount",
|
|
|
|
dwCategoryNum) == ERROR_SUCCESS))
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
key.Close();
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID FreeLogs()
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
if (hLog)
|
|
|
|
{
|
|
|
|
DeregisterEventSource(hLog);
|
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
if (!SettingsInfo.bLogEnabled)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
if (!ReportEventW(hLog, wType, 0, dwEventID,
|
|
|
|
NULL, 1, 0, &lpMsg, NULL))
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL GetInstalledVersion_WowUser(ATL::CStringW* szVersionResult,
|
2017-09-10 21:02:06 +00:00
|
|
|
const ATL::CStringW& szRegName,
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL IsUserKey,
|
|
|
|
REGSAM keyWow)
|
2017-08-02 12:50:53 +00:00
|
|
|
{
|
|
|
|
BOOL bHasSucceded = FALSE;
|
2017-08-08 21:32:11 +00:00
|
|
|
ATL::CRegKey key;
|
2017-08-02 12:50:53 +00:00
|
|
|
ATL::CStringW szVersion;
|
2017-09-10 21:02:06 +00:00
|
|
|
ATL::CStringW szPath = ATL::CStringW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%ls") + szRegName;
|
2017-08-02 12:50:53 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
if (key.Open(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
|
|
|
szPath.GetString(),
|
|
|
|
keyWow | KEY_READ) != ERROR_SUCCESS)
|
2017-08-02 12:50:53 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (szVersionResult != NULL)
|
|
|
|
{
|
|
|
|
ULONG dwSize = MAX_PATH * sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (key.QueryStringValue(L"DisplayVersion",
|
|
|
|
szVersion.GetBuffer(MAX_PATH),
|
2017-08-02 12:50:53 +00:00
|
|
|
&dwSize) == ERROR_SUCCESS)
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
|
|
|
szVersion.ReleaseBuffer();
|
|
|
|
*szVersionResult = szVersion;
|
|
|
|
bHasSucceded = TRUE;
|
2017-08-02 12:50:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
szVersion.ReleaseBuffer();
|
|
|
|
}
|
|
|
|
}
|
2017-08-08 21:32:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
bHasSucceded = TRUE;
|
|
|
|
szVersion.ReleaseBuffer();
|
|
|
|
}
|
|
|
|
key.Close();
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-02 12:50:53 +00:00
|
|
|
return bHasSucceded;
|
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegName)
|
2017-08-02 12:50:53 +00:00
|
|
|
{
|
|
|
|
return (!szRegName.IsEmpty()
|
|
|
|
&& (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_32KEY)
|
|
|
|
|| GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_32KEY)
|
|
|
|
|| GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_64KEY)
|
|
|
|
|| GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
|
|
|
|
}
|
2017-08-15 19:36:23 +00:00
|
|
|
|
|
|
|
// CConfigParser
|
|
|
|
|
|
|
|
CConfigParser::CConfigParser(const ATL::CStringW& FileName) : szConfigPath(GetINIFullPath(FileName))
|
|
|
|
{
|
2017-09-09 19:43:39 +00:00
|
|
|
CacheINILocale();
|
2017-08-15 19:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ATL::CStringW CConfigParser::GetINIFullPath(const ATL::CStringW& FileName)
|
|
|
|
{
|
|
|
|
ATL::CStringW szDir;
|
|
|
|
ATL::CStringW szBuffer;
|
|
|
|
|
|
|
|
GetStorageDirectory(szDir);
|
2017-09-10 21:02:06 +00:00
|
|
|
szBuffer.Format(L"%ls\\rapps\\%ls", szDir.GetString(), FileName.GetString());
|
2017-08-15 19:36:23 +00:00
|
|
|
|
|
|
|
return szBuffer;
|
|
|
|
}
|
|
|
|
|
2017-09-09 19:43:39 +00:00
|
|
|
VOID CConfigParser::CacheINILocale()
|
2017-08-15 19:36:23 +00:00
|
|
|
{
|
2017-09-09 19:43:39 +00:00
|
|
|
// TODO: Set default locale if call fails
|
|
|
|
// find out what is the current system lang code (e.g. "0a") and append it to SectionLocale
|
|
|
|
GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE,
|
|
|
|
m_szLocaleID.GetBuffer(m_cchLocaleSize), m_cchLocaleSize);
|
2017-08-15 19:36:23 +00:00
|
|
|
|
2017-09-09 19:43:39 +00:00
|
|
|
m_szLocaleID.ReleaseBuffer();
|
|
|
|
m_szCachedINISectionLocale = L"Section." + m_szLocaleID;
|
2017-08-15 19:36:23 +00:00
|
|
|
|
2017-09-09 19:43:39 +00:00
|
|
|
// turn "Section.0c0a" into "Section.0a", keeping just the neutral lang part
|
|
|
|
m_szCachedINISectionLocaleNeutral = m_szCachedINISectionLocale + m_szLocaleID.Right(2);
|
2017-08-15 19:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT CConfigParser::GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString)
|
|
|
|
{
|
|
|
|
DWORD dwResult;
|
|
|
|
|
|
|
|
LPWSTR ResultStringBuffer = ResultString.GetBuffer(MAX_PATH);
|
|
|
|
// 1st - find localized strings (e.g. "Section.0c0a")
|
|
|
|
dwResult = GetPrivateProfileStringW(m_szCachedINISectionLocale.GetString(),
|
|
|
|
KeyName.GetString(),
|
|
|
|
NULL,
|
|
|
|
ResultStringBuffer,
|
|
|
|
MAX_PATH,
|
|
|
|
szConfigPath.GetString());
|
|
|
|
|
|
|
|
if (!dwResult)
|
|
|
|
{
|
|
|
|
// 2nd - if they weren't present check for neutral sub-langs/ generic translations (e.g. "Section.0a")
|
|
|
|
dwResult = GetPrivateProfileStringW(m_szCachedINISectionLocaleNeutral.GetString(),
|
|
|
|
KeyName.GetString(),
|
|
|
|
NULL,
|
|
|
|
ResultStringBuffer,
|
|
|
|
MAX_PATH,
|
|
|
|
szConfigPath.GetString());
|
|
|
|
if (!dwResult)
|
|
|
|
{
|
|
|
|
// 3rd - if they weren't present fallback to standard english strings (just "Section")
|
|
|
|
dwResult = GetPrivateProfileStringW(L"Section",
|
|
|
|
KeyName.GetString(),
|
|
|
|
NULL,
|
|
|
|
ResultStringBuffer,
|
|
|
|
MAX_PATH,
|
|
|
|
szConfigPath.GetString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultString.ReleaseBuffer();
|
|
|
|
return (dwResult != 0 ? TRUE : FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT CConfigParser::GetInt(const ATL::CStringW& KeyName)
|
|
|
|
{
|
|
|
|
ATL::CStringW Buffer;
|
|
|
|
|
|
|
|
// grab the text version of our entry
|
|
|
|
if (!GetString(KeyName, Buffer))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (Buffer.IsEmpty())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// convert it to an actual integer
|
2017-08-15 22:35:45 +00:00
|
|
|
INT result = StrToIntW(Buffer.GetString());
|
2017-08-15 19:36:23 +00:00
|
|
|
|
|
|
|
return (UINT) (result <= 0) ? 0 : result;
|
|
|
|
}
|
|
|
|
// CConfigParser
|