- Store settings in HKEY_CURRENT_USER
- Correctly show the main window if UpdateAtStart is enabled
- Improve error handling

svn path=/trunk/; revision=61672
This commit is contained in:
Thomas Faber 2014-01-18 13:07:59 +00:00
parent 6c3df451fb
commit cf6bf15e65
5 changed files with 42 additions and 41 deletions

View file

@ -47,6 +47,7 @@ DeleteCurrentAppsDB(VOID)
WCHAR szPath[MAX_PATH];
WCHAR szTmp[MAX_PATH];
HRESULT hr;
BOOL result = TRUE;
if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
return FALSE;
@ -57,11 +58,7 @@ DeleteCurrentAppsDB(VOID)
if (FAILED(hr))
return FALSE;
if (GetFileAttributesW(szCabPath) != INVALID_FILE_ATTRIBUTES)
{
if (!DeleteFileW(szCabPath))
return FALSE;
}
result = result && DeleteFileW(szCabPath);
hr = StringCbCatW(szPath, sizeof(szPath), L"\\rapps\\");
if (FAILED(hr))
@ -75,24 +72,21 @@ DeleteCurrentAppsDB(VOID)
hFind = FindFirstFileW(szSearchPath, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
return TRUE;
return result;
do
{
hr = StringCbPrintfW(szTmp, sizeof(szTmp),
L"%ls%ls",
szPath, FindFileData.cFileName);
if (FAILED(hr) || !DeleteFileW(szTmp))
{
FindClose(hFind);
return FALSE;
}
}
while (FindNextFileW(hFind, &FindFileData) != 0);
if (FAILED(hr))
continue;
result = result && DeleteFileW(szTmp);
} while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind);
return TRUE;
return result;
}
@ -145,9 +139,7 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
HRESULT hr;
if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
{
return FALSE;
}
hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
L"%ls\\rappmgr.cab",
@ -168,11 +160,6 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
return FALSE;
}
GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE, szLocale, sizeof(szLocale) / sizeof(WCHAR));
hr = StringCbCatW(szSectionLocale, sizeof(szSectionLocale), szLocale);
if (FAILED(hr))
return FALSE;
hr = StringCbCatW(szPath, sizeof(szPath), L"*.txt");
if (FAILED(hr))
return FALSE;
@ -189,6 +176,16 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
return FALSE;
}
if (!GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE,
szLocale, sizeof(szLocale) / sizeof(WCHAR)))
{
return FALSE;
}
hr = StringCbCatW(szSectionLocale, sizeof(szSectionLocale), szLocale);
if (FAILED(hr))
return FALSE;
#define GET_STRING1(a, b) \
if (!ParserGetString(szSectionLocale, a, b, MAX_PATH, FindFileData.cFileName)) \
if (!ParserGetString(L"Section", a, b, MAX_PATH, FindFileData.cFileName)) \
@ -223,8 +220,7 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
GET_STRING2(L"CDPath", Info.szCDPath);
if (!lpEnumProc(Info)) break;
}
while (FindNextFileW(hFind, &FindFileData) != 0);
} while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind);

View file

@ -113,7 +113,7 @@ CopyTextToClipboard(LPCWSTR lpszText)
{
HRESULT hr;
if(OpenClipboard(NULL))
if (OpenClipboard(NULL))
{
HGLOBAL ClipBuffer;
WCHAR *Buffer;
@ -122,7 +122,7 @@ CopyTextToClipboard(LPCWSTR lpszText)
EmptyClipboard();
cchBuffer = wcslen(lpszText) + 1;
ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
Buffer = (WCHAR*)GlobalLock(ClipBuffer);
Buffer = GlobalLock(ClipBuffer);
hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
GlobalUnlock(ClipBuffer);

View file

@ -489,7 +489,7 @@ SECTIONKEY
if (!create) return NULL;
cch = wcslen(section_name) + 1;
*section = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(SECTION, name) + cch * sizeof(WCHAR));
if(*section == NULL) return NULL;
if (*section == NULL) return NULL;
StringCchCopyW((*section)->name, cch, section_name);
(*section)->next = NULL;
cch = wcslen(key_name) + 1;
@ -562,11 +562,15 @@ ParserOpen(LPCWSTR filename, BOOL write_access)
ItemsArray[i]->encoding = ENCODING_UTF8;
}
GetStorageDirectory(szDir, sizeof(szDir) / sizeof(szDir[0]));
if (!GetStorageDirectory(szDir, sizeof(szDir) / sizeof(szDir[0])))
return FALSE;
StringCbPrintfW(buffer, sizeof(buffer),
L"%ls\\rapps\\%ls",
szDir, filename);
if (FAILED(StringCbPrintfW(buffer, sizeof(buffer),
L"%ls\\rapps\\%ls",
szDir, filename)))
{
return FALSE;
}
hFile = CreateFileW(buffer, GENERIC_READ | (write_access ? GENERIC_WRITE : 0),
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,

View file

@ -23,10 +23,10 @@ RichEditOnLink(HWND hwnd, ENLINK *Link)
{
if (pLink) HeapFree(GetProcessHeap(), 0, pLink);
pLink = (PWSTR) HeapAlloc(GetProcessHeap(),
0,
(max(Link->chrg.cpMin, Link->chrg.cpMax) -
min(Link->chrg.cpMin, Link->chrg.cpMax) + 1) * sizeof(WCHAR));
pLink = HeapAlloc(GetProcessHeap(),
0,
(max(Link->chrg.cpMin, Link->chrg.cpMax) -
min(Link->chrg.cpMin, Link->chrg.cpMax) + 1) * sizeof(WCHAR));
if (!pLink)
{
/* TODO: Error message */

View file

@ -40,7 +40,7 @@ LoadSettings(VOID)
HKEY hKey;
DWORD dwSize;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\ReactOS\\rapps", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
dwSize = sizeof(SETTINGS_INFO);
if (RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&SettingsInfo, &dwSize) == ERROR_SUCCESS)
@ -73,7 +73,7 @@ SaveSettings(HWND hwnd)
SettingsInfo.Maximized = (IsZoomed(hwnd) || (wp.flags & WPF_RESTORETOMAXIMIZED));
}
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"Software\\ReactOS\\rapps", 0, NULL,
if (RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{
RegSetValueExW(hKey, L"Settings", 0, REG_BINARY, (LPBYTE)&SettingsInfo, sizeof(SETTINGS_INFO));
@ -115,10 +115,10 @@ EnumInstalledAppProc(INT ItemIndex, LPWSTR lpName, INSTALLED_INFO Info)
Index = ListViewAddItem(ItemIndex, 0, lpName, (LPARAM)ItemInfo);
/* Get version info */
GetApplicationString((HKEY)ItemInfo->hSubKey, L"DisplayVersion", szText);
GetApplicationString(ItemInfo->hSubKey, L"DisplayVersion", szText);
ListView_SetItemText(hListView, Index, 1, szText);
/* Get comments */
GetApplicationString((HKEY)ItemInfo->hSubKey, L"Comments", szText);
GetApplicationString(ItemInfo->hSubKey, L"Comments", szText);
ListView_SetItemText(hListView, Index, 2, szText);
return TRUE;
@ -538,8 +538,6 @@ MainWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
if (!InitControls(hwnd))
PostMessage(hwnd, WM_CLOSE, 0, 0);
if (SettingsInfo.bUpdateAtStart)
UpdateAppsDB();
break;
case WM_COMMAND:
@ -843,9 +841,12 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nSh
if (!hMainWnd) goto Exit;
/* Show it */
ShowWindow(hMainWnd, SW_SHOW);
ShowWindow(hMainWnd, nShowCmd);
UpdateWindow(hMainWnd);
if (SettingsInfo.bUpdateAtStart)
UpdateAppsDB();
/* Message Loop */
while (GetMessage(&Msg, NULL, 0, 0))
{