[RAPPS_NEW]

* Turn the files into .CPP, to ease future changes. All the code remains class-free for now, with one exception.
 * Adapt the download progress dialog implementation to ATL/C++, which is a best match for COM classes.
 * Add an ATL CModule class to the process, necessary for 
CORE-9593

svn path=/trunk/; revision=67376
This commit is contained in:
David Quintana
2015-04-23 23:08:21 +00:00
parent 551a6399a2
commit 492d1e96d1
16 changed files with 184 additions and 186 deletions
@@ -1,24 +1,29 @@
project(RAPPS_NEW)
set_cpp(WITH_RUNTIME)
include_directories(${REACTOS_SOURCE_DIR}/lib/atl)
list(APPEND SOURCE
aboutdlg.c
available.c
installdlg.c
installed.c
listview.c
loaddlg.c
misc.c
richedit.c
settingsdlg.c
splitter.c
statusbar.c
toolbar.c
treeview.c
winmain.c
aboutdlg.cpp
available.cpp
installdlg.cpp
installed.cpp
listview.cpp
loaddlg.cpp
misc.cpp
richedit.cpp
settingsdlg.cpp
splitter.cpp
statusbar.cpp
toolbar.cpp
treeview.cpp
winmain.cpp
rapps.h)
add_executable(rapps_new ${SOURCE} rapps.rc)
set_module_type(rapps_new win32gui UNICODE)
target_link_libraries(rapps_new uuid)
target_link_libraries(rapps_new atlnew uuid wine)
add_importlibs(rapps_new advapi32 comctl32 gdi32 wininet user32 shell32 shlwapi ole32 msvcrt kernel32 ntdll)
add_pch(rapps_new rapps.h SOURCE)
add_dependencies(rapps_new rappsmsg_new)
@@ -223,7 +223,7 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
}
/* create a new entry */
Info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(APPLICATION_INFO));
Info = (PAPPLICATION_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(APPLICATION_INFO));
if(!Info)
break;
@@ -9,7 +9,7 @@
#include "rapps.h"
BOOL
GetApplicationString(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpString)
GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR lpString)
{
DWORD dwSize = MAX_PATH;
@@ -137,7 +137,7 @@ BOOL
ShowInstalledAppInfo(INT Index)
{
WCHAR szText[MAX_PATH], szInfo[MAX_PATH];
PINSTALLED_INFO Info = ListViewGetlParam(Index);
PINSTALLED_INFO Info = (PINSTALLED_INFO) ListViewGetlParam(Index);
if (!Info || !Info->hSubKey) return FALSE;
@@ -187,7 +187,7 @@ RemoveAppFromRegistry(INT Index)
if (!IS_INSTALLED_ENUM(SelectedEnumType))
return;
Info = ListViewGetlParam(Index);
Info = (PINSTALLED_INFO) ListViewGetlParam(Index);
if (!Info || !Info->hSubKey || (ItemIndex == -1)) return;
if (!LoadStringW(hInst, IDS_APP_REG_REMOVE, szMsgText, sizeof(szMsgText) / sizeof(WCHAR)) ||
@@ -26,193 +26,146 @@
*/
#include "rapps.h"
#include <shlobj_undoc.h>
#include <shlguid_undoc.h>
#include <atlbase.h>
#include <atlcom.h>
#include <wininet.h>
#include <shellapi.h>
#include <shellutils.h>
static PAPPLICATION_INFO AppInfo;
static HICON hIcon = NULL;
typedef struct _IBindStatusCallbackImpl
class CDownloadDialog :
public CComObjectRootEx<CComMultiThreadModelNoCS>,
public IBindStatusCallback
{
const IBindStatusCallbackVtbl *vtbl;
LONG ref;
HWND hDialog;
BOOL *pbCancelled;
} IBindStatusCallbackImpl;
HWND m_hDialog;
PBOOL m_pbCancelled;
static
HRESULT WINAPI
dlQueryInterface(IBindStatusCallback* This, REFIID riid, void** ppvObject)
{
if (!ppvObject) return E_POINTER;
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IBindStatusCallback))
public:
~CDownloadDialog()
{
IBindStatusCallback_AddRef(This);
*ppvObject = This;
DestroyWindow(m_hDialog);
}
HRESULT Initialize(HWND Dlg, BOOL *pbCancelled)
{
m_hDialog = Dlg;
m_pbCancelled = pbCancelled;
return S_OK;
}
return E_NOINTERFACE;
}
static
ULONG WINAPI
dlAddRef(IBindStatusCallback* iface)
{
IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl*) iface;
return InterlockedIncrement(&This->ref);
}
static
ULONG WINAPI
dlRelease(IBindStatusCallback* iface)
{
IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl*) iface;
DWORD ref = InterlockedDecrement(&This->ref);
if (!ref)
virtual HRESULT STDMETHODCALLTYPE OnStartBinding(
DWORD dwReserved,
IBinding *pib)
{
DestroyWindow(This->hDialog);
HeapFree(GetProcessHeap(), 0, This);
return S_OK;
}
return ref;
}
static
HRESULT WINAPI
dlOnStartBinding(IBindStatusCallback* iface, DWORD dwReserved, IBinding* pib)
{
return S_OK;
}
static
HRESULT WINAPI
dlGetPriority(IBindStatusCallback* iface, LONG* pnPriority)
{
return S_OK;
}
static
HRESULT WINAPI
dlOnLowResource( IBindStatusCallback* iface, DWORD reserved)
{
return S_OK;
}
static
HRESULT WINAPI
dlOnProgress(IBindStatusCallback* iface,
ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCWSTR szStatusText)
{
IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
HWND Item;
LONG r;
WCHAR OldText[100];
Item = GetDlgItem(This->hDialog, IDC_DOWNLOAD_PROGRESS);
if (Item && ulProgressMax)
virtual HRESULT STDMETHODCALLTYPE GetPriority(
LONG *pnPriority)
{
SendMessageW(Item, PBM_SETPOS, ((ULONGLONG)ulProgress * 100) / ulProgressMax, 0);
return S_OK;
}
Item = GetDlgItem(This->hDialog, IDC_DOWNLOAD_STATUS);
if (Item && szStatusText)
virtual HRESULT STDMETHODCALLTYPE OnLowResource(
DWORD reserved)
{
SendMessageW(Item, WM_GETTEXT, sizeof(OldText) / sizeof(OldText[0]), (LPARAM) OldText);
if (sizeof(OldText) / sizeof(OldText[0]) - 1 <= wcslen(OldText) || 0 != wcscmp(OldText, szStatusText))
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE OnProgress(
ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCWSTR szStatusText)
{
HWND Item;
LONG r;
WCHAR OldText[100];
Item = GetDlgItem(m_hDialog, IDC_DOWNLOAD_PROGRESS);
if (Item && ulProgressMax)
{
SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) szStatusText);
SendMessageW(Item, PBM_SETPOS, MulDiv(ulProgress, 100, ulProgressMax), 0);
}
Item = GetDlgItem(m_hDialog, IDC_DOWNLOAD_STATUS);
if (Item && szStatusText)
{
SendMessageW(Item, WM_GETTEXT, sizeof(OldText) / sizeof(OldText[0]), (LPARAM) OldText);
if (sizeof(OldText) / sizeof(OldText[0]) - 1 <= wcslen(OldText) || 0 != wcscmp(OldText, szStatusText))
{
SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) szStatusText);
}
}
SetLastError(0);
r = GetWindowLongPtrW(m_hDialog, GWLP_USERDATA);
if (0 != r || 0 != GetLastError())
{
*m_pbCancelled = TRUE;
return E_ABORT;
}
return S_OK;
}
SetLastError(0);
r = GetWindowLongPtrW(This->hDialog, GWLP_USERDATA);
if (0 != r || 0 != GetLastError())
virtual HRESULT STDMETHODCALLTYPE OnStopBinding(
HRESULT hresult,
LPCWSTR szError)
{
*This->pbCancelled = TRUE;
return E_ABORT;
return S_OK;
}
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE GetBindInfo(
DWORD *grfBINDF,
BINDINFO *pbindinfo)
{
return S_OK;
}
static
HRESULT WINAPI
dlOnStopBinding(IBindStatusCallback* iface, HRESULT hresult, LPCWSTR szError)
{
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(
DWORD grfBSCF,
DWORD dwSize,
FORMATETC *pformatetc,
STGMEDIUM *pstgmed)
{
return S_OK;
}
static
HRESULT WINAPI
dlGetBindInfo(IBindStatusCallback* iface, DWORD* grfBINDF, BINDINFO* pbindinfo)
{
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(
REFIID riid,
IUnknown *punk)
{
return S_OK;
}
static
HRESULT WINAPI
dlOnDataAvailable(IBindStatusCallback* iface, DWORD grfBSCF,
DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
{
return S_OK;
}
static
HRESULT WINAPI
dlOnObjectAvailable(IBindStatusCallback* iface, REFIID riid, IUnknown* punk)
{
return S_OK;
}
static const IBindStatusCallbackVtbl dlVtbl =
{
dlQueryInterface,
dlAddRef,
dlRelease,
dlOnStartBinding,
dlGetPriority,
dlOnLowResource,
dlOnProgress,
dlOnStopBinding,
dlGetBindInfo,
dlOnDataAvailable,
dlOnObjectAvailable
BEGIN_COM_MAP(CDownloadDialog)
COM_INTERFACE_ENTRY_IID(IID_IBindStatusCallback, IBindStatusCallback)
END_COM_MAP()
};
static IBindStatusCallback*
CreateDl(HWND Dlg, BOOL *pbCancelled)
extern "C"
HRESULT WINAPI CDownloadDialog_Constructor(HWND Dlg, BOOL *pbCancelled, REFIID riid, LPVOID *ppv)
{
IBindStatusCallbackImpl *This;
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IBindStatusCallbackImpl));
if (!This)
return NULL;
This->vtbl = &dlVtbl;
This->ref = 1;
This->hDialog = Dlg;
This->pbCancelled = pbCancelled;
return (IBindStatusCallback*) This;
return ShellObjectCreatorInit<CDownloadDialog>(Dlg, pbCancelled, riid, ppv);
}
static
DWORD WINAPI
ThreadFunc(LPVOID Context)
{
IBindStatusCallback *dl = NULL;
CComPtr<IBindStatusCallback> dl;
WCHAR path[MAX_PATH];
LPWSTR p;
HWND Dlg = (HWND) Context;
DWORD dwContentLen, dwBytesWritten, dwBytesRead, dwStatus;
DWORD dwCurrentBytesRead = 0;
DWORD dwStatusLen = sizeof(dwStatus);
ULONG dwContentLen, dwBytesWritten, dwBytesRead, dwStatus;
ULONG dwCurrentBytesRead = 0;
ULONG dwStatusLen = sizeof(dwStatus);
BOOL bCancelled = FALSE;
BOOL bTempfile = FALSE;
BOOL bCab = FALSE;
@@ -220,7 +173,7 @@ ThreadFunc(LPVOID Context)
HINTERNET hFile = NULL;
HANDLE hOut = INVALID_HANDLE_VALUE;
unsigned char lpBuffer[4096];
const LPWSTR lpszAgent = L"RApps/1.0";
PCWSTR lpszAgent = L"RApps/1.0";
URL_COMPONENTS urlComponents;
size_t urlLength;
@@ -256,7 +209,7 @@ ThreadFunc(LPVOID Context)
/* download it */
bTempfile = TRUE;
dl = CreateDl(Context, &bCancelled);
CDownloadDialog_Constructor(Dlg, &bCancelled, IID_PPV_ARG(IBindStatusCallback, &dl));
if (dl == NULL)
goto end;
@@ -307,7 +260,7 @@ ThreadFunc(LPVOID Context)
goto end;
urlComponents.dwSchemeLength = urlLength*sizeof(WCHAR);
urlComponents.lpszScheme = malloc(urlComponents.dwSchemeLength);
urlComponents.lpszScheme = (PWSTR)malloc(urlComponents.dwSchemeLength);
if(!InternetCrackUrlW(AppInfo->szUrlDownload, urlLength+1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
goto end;
@@ -330,7 +283,7 @@ ThreadFunc(LPVOID Context)
if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead)) goto end;
if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL)) goto end;
dwCurrentBytesRead += dwBytesRead;
IBindStatusCallback_OnProgress(dl, dwCurrentBytesRead, dwContentLen, 0, AppInfo->szUrlDownload);
dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, AppInfo->szUrlDownload);
}
while (dwBytesRead);
@@ -353,9 +306,6 @@ end:
InternetCloseHandle(hFile);
InternetCloseHandle(hOpen);
if (dl)
IBindStatusCallback_Release(dl);
if (bTempfile)
{
if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))
@@ -437,7 +387,7 @@ DownloadApplication(INT Index)
}
VOID
DownloadApplicationsDB(LPWSTR lpUrl)
DownloadApplicationsDB(LPCWSTR lpUrl)
{
APPLICATION_INFO IntInfo;
@@ -45,7 +45,8 @@ typedef struct
struct FILELIST *FilterList;
} SESSION;
HRESULT (WINAPI *pfnExtract)(SESSION *dest, LPCSTR szCabName);
typedef HRESULT(WINAPI *fnExtract)(SESSION *dest, LPCSTR szCabName);
fnExtract pfnExtract;
INT
@@ -126,7 +127,7 @@ CopyTextToClipboard(LPCWSTR lpszText)
EmptyClipboard();
cchBuffer = wcslen(lpszText) + 1;
ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
Buffer = GlobalLock(ClipBuffer);
Buffer = (PWCHAR)GlobalLock(ClipBuffer);
hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
GlobalUnlock(ClipBuffer);
@@ -268,7 +269,7 @@ ExtractFilesFromCab(LPWSTR lpCabName, LPWSTR lpOutputPath)
hCabinetDll = LoadLibraryW(L"cabinet.dll");
if (hCabinetDll)
{
pfnExtract = (void *) GetProcAddress(hCabinetDll, "Extract");
pfnExtract = (fnExtract) GetProcAddress(hCabinetDll, "Extract");
if (pfnExtract)
{
ZeroMemory(&Dest, sizeof(SESSION));
+4 -2
View File
@@ -1,6 +1,7 @@
#ifndef _RAPPS_H
#define _RAPPS_H
#include <tchar.h>
#include <stdarg.h>
#define WIN32_NO_STATUS
@@ -16,6 +17,7 @@
#include <winuser.h>
#include <wincon.h>
#include <richedit.h>
#include <shellapi.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <stdio.h>
@@ -133,7 +135,7 @@ BOOL InstallApplication(INT Index);
/* installed.c */
typedef BOOL (CALLBACK *APPENUMPROC)(INT ItemIndex, LPWSTR lpName, PINSTALLED_INFO Info);
BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc);
BOOL GetApplicationString(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpString);
BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR lpString);
BOOL ShowInstalledAppInfo(INT Index);
BOOL UninstallApplication(INT Index, BOOL bModify);
BOOL IsInstalledApplication(LPWSTR lpRegName, BOOL IsUserKey);
@@ -158,7 +160,7 @@ PVOID ListViewGetlParam(INT Index);
/* loaddlg.c */
BOOL DownloadApplication(INT Index);
VOID DownloadApplicationsDB(LPWSTR lpUrl);
VOID DownloadApplicationsDB(LPCWSTR lpUrl);
/* misc.c */
INT GetSystemColorDepth(VOID);
@@ -23,7 +23,7 @@ RichEditOnLink(HWND hwnd, ENLINK *Link)
{
if (pLink) HeapFree(GetProcessHeap(), 0, pLink);
pLink = HeapAlloc(GetProcessHeap(),
pLink = (PWSTR)HeapAlloc(GetProcessHeap(),
0,
(max(Link->chrg.cpMin, Link->chrg.cpMax) -
min(Link->chrg.cpMin, Link->chrg.cpMax) + 1) * sizeof(WCHAR));
@@ -67,9 +67,9 @@ ToolBarOnGetDispInfo(LPTOOLTIPTEXT lpttt)
VOID
AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex)
{
HANDLE hImage;
HICON hImage;
if (!(hImage = LoadImage(hInst,
if (!(hImage = (HICON) LoadImage(hInst,
MAKEINTRESOURCE(ImageIndex),
IMAGE_ICON,
TOOLBAR_HEIGHT,
@@ -9,6 +9,8 @@
#include "rapps.h"
#include <atlbase.h>
#include <atlcom.h>
#include <shellapi.h>
#define SEARCH_TIMER_ID 'SR'
@@ -22,6 +24,40 @@ SETTINGS_INFO SettingsInfo;
WCHAR szSearchPattern[MAX_STR_LEN] = L"";
BOOL SearchEnabled = TRUE;
class CRAppsModule : public CComModule
{
public:
};
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
CRAppsModule gModule;
CAtlWinModule gWinModule;
void *operator new (size_t, void *buf)
{
return buf;
}
static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
{
if (bInitialize)
{
/* HACK - the global constructors don't run, so I placement new them here */
new (&gModule) CRAppsModule;
new (&gWinModule) CAtlWinModule;
new (&_AtlBaseModule) CAtlBaseModule;
new (&_AtlComModule) CAtlComModule;
gModule.Init(ObjectMap, hInstance, NULL);
}
else
{
gModule.Term();
}
}
BOOL
SearchPatternMatch(PCWSTR szHaystack, PCWSTR szNeedle)
{
@@ -108,7 +144,7 @@ FreeInstalledAppList(VOID)
while (Count >= 0)
{
Info = ListViewGetlParam(Count);
Info = (PINSTALLED_INFO)ListViewGetlParam(Count);
if (Info)
{
RegCloseKey(Info->hSubKey);
@@ -132,7 +168,7 @@ EnumInstalledAppProc(INT ItemIndex, LPWSTR lpName, PINSTALLED_INFO Info)
return TRUE;
}
ItemInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(INSTALLED_INFO));
ItemInfo = (PINSTALLED_INFO) HeapAlloc(GetProcessHeap(), 0, sizeof(INSTALLED_INFO));
if (!ItemInfo)
{
RegCloseKey(Info->hSubKey);
@@ -203,7 +239,7 @@ UpdateApplicationsList(INT EnumType)
GetSystemColorDepth() | ILC_MASK,
0, 1);
hIcon = LoadImage(hInst,
hIcon = (HICON)LoadImage(hInst,
MAKEINTRESOURCE(IDI_MAIN),
IMAGE_ICON,
LISTVIEW_ICON_SIZE,
@@ -274,7 +310,7 @@ AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex)
INT Index;
HICON hIcon;
hIcon = LoadImage(hInst,
hIcon = (HICON)LoadImage(hInst,
MAKEINTRESOURCE(IconIndex),
IMAGE_ICON,
TREEVIEW_ICON_SIZE,
@@ -903,6 +939,8 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nSh
HACCEL KeyBrd;
MSG Msg;
InitializeAtlModule(hInstance, TRUE);
switch (GetUserDefaultUILanguage())
{
case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
@@ -989,5 +1027,7 @@ Exit:
if (hMutex)
CloseHandle(hMutex);
InitializeAtlModule(hInstance, FALSE);
return 0;
}