1 /* PROJECT: ReactOS Applications Manager
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/rapps/loaddlg.c
4 * PURPOSE: Displaying a download dialog
5 * COPYRIGHT: Copyright 2001 John R. Sheets (for CodeWeavers)
6 * Copyright 2004 Mike McCormack (for CodeWeavers)
7 * Copyright 2005 Ge van Geldorp (gvg@reactos.org)
8 * Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
11 * Based on Wine dlls/shdocvw/shdocvw_main.c
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #define WIN32_NO_STATUS
39 static PAPPLICATION_INFO AppInfo
;
40 static HICON hIcon
= NULL
;
42 typedef struct _IBindStatusCallbackImpl
44 const IBindStatusCallbackVtbl
*vtbl
;
48 } IBindStatusCallbackImpl
;
52 dlQueryInterface(IBindStatusCallback
* This
, REFIID riid
, void** ppvObject
)
54 if (!ppvObject
) return E_POINTER
;
56 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IBindStatusCallback
))
58 IBindStatusCallback_AddRef(This
);
68 dlAddRef(IBindStatusCallback
* iface
)
70 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
71 return InterlockedIncrement(&This
->ref
);
76 dlRelease(IBindStatusCallback
* iface
)
78 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
79 DWORD ref
= InterlockedDecrement(&This
->ref
);
83 DestroyWindow(This
->hDialog
);
84 HeapFree(GetProcessHeap(), 0, This
);
92 dlOnStartBinding(IBindStatusCallback
* iface
, DWORD dwReserved
, IBinding
* pib
)
99 dlGetPriority(IBindStatusCallback
* iface
, LONG
* pnPriority
)
106 dlOnLowResource( IBindStatusCallback
* iface
, DWORD reserved
)
113 dlOnProgress(IBindStatusCallback
* iface
,
117 LPCWSTR szStatusText
)
119 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
124 Item
= GetDlgItem(This
->hDialog
, IDC_DOWNLOAD_PROGRESS
);
125 if (Item
&& ulProgressMax
)
127 SendMessageW(Item
, PBM_SETPOS
, ((ULONGLONG
)ulProgress
* 100) / ulProgressMax
, 0);
130 Item
= GetDlgItem(This
->hDialog
, IDC_DOWNLOAD_STATUS
);
131 if (Item
&& szStatusText
)
133 SendMessageW(Item
, WM_GETTEXT
, sizeof(OldText
) / sizeof(OldText
[0]), (LPARAM
) OldText
);
134 if (sizeof(OldText
) / sizeof(OldText
[0]) - 1 <= wcslen(OldText
) || 0 != wcscmp(OldText
, szStatusText
))
136 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) szStatusText
);
141 r
= GetWindowLongPtrW(This
->hDialog
, GWLP_USERDATA
);
142 if (0 != r
|| 0 != GetLastError())
144 *This
->pbCancelled
= TRUE
;
153 dlOnStopBinding(IBindStatusCallback
* iface
, HRESULT hresult
, LPCWSTR szError
)
160 dlGetBindInfo(IBindStatusCallback
* iface
, DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
167 dlOnDataAvailable(IBindStatusCallback
* iface
, DWORD grfBSCF
,
168 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
175 dlOnObjectAvailable(IBindStatusCallback
* iface
, REFIID riid
, IUnknown
* punk
)
180 static const IBindStatusCallbackVtbl dlVtbl
=
195 static IBindStatusCallback
*
196 CreateDl(HWND Dlg
, BOOL
*pbCancelled
)
198 IBindStatusCallbackImpl
*This
;
200 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IBindStatusCallbackImpl
));
201 if (!This
) return NULL
;
203 This
->vtbl
= &dlVtbl
;
206 This
->pbCancelled
= pbCancelled
;
208 return (IBindStatusCallback
*) This
;
213 ThreadFunc(LPVOID Context
)
215 IBindStatusCallback
*dl
;
216 WCHAR path
[MAX_PATH
];
219 PROCESS_INFORMATION pi
;
220 HWND Dlg
= (HWND
) Context
;
222 BOOL bCancelled
= FALSE
;
223 BOOL bTempfile
= FALSE
;
226 /* built the path for the download */
227 p
= wcsrchr(AppInfo
->szUrlDownload
, L
'/');
230 len
= wcslen(AppInfo
->szUrlDownload
);
233 if (AppInfo
->szUrlDownload
[len
- 4] == '.' &&
234 AppInfo
->szUrlDownload
[len
- 3] == 'c' &&
235 AppInfo
->szUrlDownload
[len
- 2] == 'a' &&
236 AppInfo
->szUrlDownload
[len
- 1] == 'b')
239 if (!GetCurrentDirectoryW(MAX_PATH
, path
))
244 wcscpy(path
, SettingsInfo
.szDownloadDir
);
249 if (GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
251 if (!CreateDirectoryW(path
, NULL
))
260 dl
= CreateDl(Context
, &bCancelled
);
261 r
= URLDownloadToFileW(NULL
, AppInfo
->szUrlDownload
, path
, 0, dl
);
262 if (dl
) IBindStatusCallback_Release(dl
);
263 if (S_OK
!= r
) goto end
;
264 else if (bCancelled
) goto end
;
266 ShowWindow(Dlg
, SW_HIDE
);
269 memset(&si
, 0, sizeof(si
));
271 r
= CreateProcessW(path
, NULL
, NULL
, NULL
, 0, 0, NULL
, NULL
, &si
, &pi
);
272 if (0 == r
) goto end
;
274 CloseHandle(pi
.hThread
);
275 WaitForSingleObject(pi
.hProcess
, INFINITE
);
276 CloseHandle(pi
.hProcess
);
281 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
292 DownloadDlgProc(HWND Dlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
302 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_MAIN
));
305 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIcon
);
306 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIcon
);
309 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 0);
310 Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
313 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
314 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
317 Thread
= CreateThread(NULL
, 0, ThreadFunc
, Dlg
, 0, &ThreadId
);
318 if (!Thread
) return FALSE
;
323 if (wParam
== IDCANCEL
)
325 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 1);
326 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
331 if (hIcon
) DestroyIcon(hIcon
);
341 DownloadApplication(INT Index
)
343 if (!IS_AVAILABLE_ENUM(SelectedEnumType
))
346 AppInfo
= (PAPPLICATION_INFO
) ListViewGetlParam(Index
);
347 if (!AppInfo
) return FALSE
;
349 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_INSTALL
, AppInfo
->szName
);
352 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
360 DownloadApplicationsDB(LPWSTR lpUrl
)
362 APPLICATION_INFO IntInfo
;
364 ZeroMemory(&IntInfo
, sizeof(APPLICATION_INFO
));
365 wcscpy(IntInfo
.szUrlDownload
, lpUrl
);
370 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),