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
30 static PAPPLICATION_INFO AppInfo
;
31 static HICON hIcon
= NULL
;
33 typedef struct _IBindStatusCallbackImpl
35 const IBindStatusCallbackVtbl
*vtbl
;
39 } IBindStatusCallbackImpl
;
43 dlQueryInterface(IBindStatusCallback
* This
, REFIID riid
, void** ppvObject
)
45 if (!ppvObject
) return E_POINTER
;
47 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IBindStatusCallback
))
49 IBindStatusCallback_AddRef(This
);
59 dlAddRef(IBindStatusCallback
* iface
)
61 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
62 return InterlockedIncrement(&This
->ref
);
67 dlRelease(IBindStatusCallback
* iface
)
69 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
70 DWORD ref
= InterlockedDecrement(&This
->ref
);
74 DestroyWindow(This
->hDialog
);
75 HeapFree(GetProcessHeap(), 0, This
);
83 dlOnStartBinding(IBindStatusCallback
* iface
, DWORD dwReserved
, IBinding
* pib
)
90 dlGetPriority(IBindStatusCallback
* iface
, LONG
* pnPriority
)
97 dlOnLowResource( IBindStatusCallback
* iface
, DWORD reserved
)
104 dlOnProgress(IBindStatusCallback
* iface
,
108 LPCWSTR szStatusText
)
110 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
115 Item
= GetDlgItem(This
->hDialog
, IDC_DOWNLOAD_PROGRESS
);
116 if (Item
&& ulProgressMax
)
118 SendMessageW(Item
, PBM_SETPOS
, ((ULONGLONG
)ulProgress
* 100) / ulProgressMax
, 0);
121 Item
= GetDlgItem(This
->hDialog
, IDC_DOWNLOAD_STATUS
);
122 if (Item
&& szStatusText
)
124 SendMessageW(Item
, WM_GETTEXT
, sizeof(OldText
) / sizeof(OldText
[0]), (LPARAM
) OldText
);
125 if (sizeof(OldText
) / sizeof(OldText
[0]) - 1 <= wcslen(OldText
) || 0 != wcscmp(OldText
, szStatusText
))
127 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) szStatusText
);
132 r
= GetWindowLongPtrW(This
->hDialog
, GWLP_USERDATA
);
133 if (0 != r
|| 0 != GetLastError())
135 *This
->pbCancelled
= TRUE
;
144 dlOnStopBinding(IBindStatusCallback
* iface
, HRESULT hresult
, LPCWSTR szError
)
151 dlGetBindInfo(IBindStatusCallback
* iface
, DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
158 dlOnDataAvailable(IBindStatusCallback
* iface
, DWORD grfBSCF
,
159 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
166 dlOnObjectAvailable(IBindStatusCallback
* iface
, REFIID riid
, IUnknown
* punk
)
171 static const IBindStatusCallbackVtbl dlVtbl
=
186 static IBindStatusCallback
*
187 CreateDl(HWND Dlg
, BOOL
*pbCancelled
)
189 IBindStatusCallbackImpl
*This
;
191 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IBindStatusCallbackImpl
));
192 if (!This
) return NULL
;
194 This
->vtbl
= &dlVtbl
;
197 This
->pbCancelled
= pbCancelled
;
199 return (IBindStatusCallback
*) This
;
204 ThreadFunc(LPVOID Context
)
206 IBindStatusCallback
*dl
;
207 WCHAR path
[MAX_PATH
];
210 PROCESS_INFORMATION pi
;
211 HWND Dlg
= (HWND
) Context
;
213 BOOL bCancelled
= FALSE
;
214 BOOL bTempfile
= FALSE
;
217 /* built the path for the download */
218 p
= wcsrchr(AppInfo
->szUrlDownload
, L
'/');
221 len
= wcslen(AppInfo
->szUrlDownload
);
224 if (AppInfo
->szUrlDownload
[len
- 4] == '.' &&
225 AppInfo
->szUrlDownload
[len
- 3] == 'c' &&
226 AppInfo
->szUrlDownload
[len
- 2] == 'a' &&
227 AppInfo
->szUrlDownload
[len
- 1] == 'b')
230 if (!GetCurrentDirectoryW(MAX_PATH
, path
))
235 wcscpy(path
, SettingsInfo
.szDownloadDir
);
240 if (GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
242 if (!CreateDirectoryW(path
, NULL
))
251 dl
= CreateDl(Context
, &bCancelled
);
252 r
= URLDownloadToFileW(NULL
, AppInfo
->szUrlDownload
, path
, 0, dl
);
253 if (dl
) IBindStatusCallback_Release(dl
);
254 if (S_OK
!= r
) goto end
;
255 else if (bCancelled
) goto end
;
257 ShowWindow(Dlg
, SW_HIDE
);
260 ZeroMemory(&si
, sizeof(si
));
262 r
= CreateProcessW(path
, NULL
, NULL
, NULL
, 0, 0, NULL
, NULL
, &si
, &pi
);
263 if (0 == r
) goto end
;
265 CloseHandle(pi
.hThread
);
266 WaitForSingleObject(pi
.hProcess
, INFINITE
);
267 CloseHandle(pi
.hProcess
);
272 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
283 DownloadDlgProc(HWND Dlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
293 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_MAIN
));
296 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIcon
);
297 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIcon
);
300 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 0);
301 Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
304 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
305 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
308 Thread
= CreateThread(NULL
, 0, ThreadFunc
, Dlg
, 0, &ThreadId
);
309 if (!Thread
) return FALSE
;
314 if (wParam
== IDCANCEL
)
316 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 1);
317 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
322 if (hIcon
) DestroyIcon(hIcon
);
332 DownloadApplication(INT Index
)
334 if (!IS_AVAILABLE_ENUM(SelectedEnumType
))
337 AppInfo
= (PAPPLICATION_INFO
) ListViewGetlParam(Index
);
338 if (!AppInfo
) return FALSE
;
340 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_INSTALL
, AppInfo
->szName
);
343 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
351 DownloadApplicationsDB(LPWSTR lpUrl
)
353 APPLICATION_INFO IntInfo
;
355 ZeroMemory(&IntInfo
, sizeof(APPLICATION_INFO
));
356 wcscpy(IntInfo
.szUrlDownload
, lpUrl
);
361 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),