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
33 static PAPPLICATION_INFO AppInfo
;
34 static HICON hIcon
= NULL
;
36 typedef struct _IBindStatusCallbackImpl
38 const IBindStatusCallbackVtbl
*vtbl
;
42 } IBindStatusCallbackImpl
;
46 dlQueryInterface(IBindStatusCallback
* This
, REFIID riid
, void** ppvObject
)
48 if (!ppvObject
) return E_POINTER
;
50 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IBindStatusCallback
))
52 IBindStatusCallback_AddRef(This
);
62 dlAddRef(IBindStatusCallback
* iface
)
64 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
65 return InterlockedIncrement(&This
->ref
);
70 dlRelease(IBindStatusCallback
* iface
)
72 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
73 DWORD ref
= InterlockedDecrement(&This
->ref
);
77 DestroyWindow(This
->hDialog
);
78 HeapFree(GetProcessHeap(), 0, This
);
86 dlOnStartBinding(IBindStatusCallback
* iface
, DWORD dwReserved
, IBinding
* pib
)
93 dlGetPriority(IBindStatusCallback
* iface
, LONG
* pnPriority
)
100 dlOnLowResource( IBindStatusCallback
* iface
, DWORD reserved
)
107 dlOnProgress(IBindStatusCallback
* iface
,
111 LPCWSTR szStatusText
)
113 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
118 Item
= GetDlgItem(This
->hDialog
, IDC_DOWNLOAD_PROGRESS
);
119 if (Item
&& ulProgressMax
)
121 SendMessageW(Item
, PBM_SETPOS
, ((ULONGLONG
)ulProgress
* 100) / ulProgressMax
, 0);
124 Item
= GetDlgItem(This
->hDialog
, IDC_DOWNLOAD_STATUS
);
125 if (Item
&& szStatusText
)
127 SendMessageW(Item
, WM_GETTEXT
, sizeof(OldText
) / sizeof(OldText
[0]), (LPARAM
) OldText
);
128 if (sizeof(OldText
) / sizeof(OldText
[0]) - 1 <= wcslen(OldText
) || 0 != wcscmp(OldText
, szStatusText
))
130 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) szStatusText
);
135 r
= GetWindowLongPtrW(This
->hDialog
, GWLP_USERDATA
);
136 if (0 != r
|| 0 != GetLastError())
138 *This
->pbCancelled
= TRUE
;
147 dlOnStopBinding(IBindStatusCallback
* iface
, HRESULT hresult
, LPCWSTR szError
)
154 dlGetBindInfo(IBindStatusCallback
* iface
, DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
161 dlOnDataAvailable(IBindStatusCallback
* iface
, DWORD grfBSCF
,
162 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
169 dlOnObjectAvailable(IBindStatusCallback
* iface
, REFIID riid
, IUnknown
* punk
)
174 static const IBindStatusCallbackVtbl dlVtbl
=
189 static IBindStatusCallback
*
190 CreateDl(HWND Dlg
, BOOL
*pbCancelled
)
192 IBindStatusCallbackImpl
*This
;
194 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IBindStatusCallbackImpl
));
195 if (!This
) return NULL
;
197 This
->vtbl
= &dlVtbl
;
200 This
->pbCancelled
= pbCancelled
;
202 return (IBindStatusCallback
*) This
;
207 ThreadFunc(LPVOID Context
)
209 IBindStatusCallback
*dl
;
210 WCHAR path
[MAX_PATH
];
213 PROCESS_INFORMATION pi
;
214 HWND Dlg
= (HWND
) Context
;
216 BOOL bCancelled
= FALSE
;
217 BOOL bTempfile
= FALSE
;
220 /* built the path for the download */
221 p
= wcsrchr(AppInfo
->szUrlDownload
, L
'/');
224 len
= wcslen(AppInfo
->szUrlDownload
);
227 if (AppInfo
->szUrlDownload
[len
- 4] == '.' &&
228 AppInfo
->szUrlDownload
[len
- 3] == 'c' &&
229 AppInfo
->szUrlDownload
[len
- 2] == 'a' &&
230 AppInfo
->szUrlDownload
[len
- 1] == 'b')
233 if (!GetCurrentDirectoryW(MAX_PATH
, path
))
238 wcscpy(path
, SettingsInfo
.szDownloadDir
);
243 if (GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
245 if (!CreateDirectoryW(path
, NULL
))
254 dl
= CreateDl(Context
, &bCancelled
);
255 r
= URLDownloadToFileW(NULL
, AppInfo
->szUrlDownload
, path
, 0, dl
);
256 if (dl
) IBindStatusCallback_Release(dl
);
257 if (S_OK
!= r
) goto end
;
258 else if (bCancelled
) goto end
;
260 ShowWindow(Dlg
, SW_HIDE
);
263 ZeroMemory(&si
, sizeof(si
));
265 r
= CreateProcessW(path
, NULL
, NULL
, NULL
, 0, 0, NULL
, NULL
, &si
, &pi
);
266 if (0 == r
) goto end
;
268 CloseHandle(pi
.hThread
);
269 WaitForSingleObject(pi
.hProcess
, INFINITE
);
270 CloseHandle(pi
.hProcess
);
275 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
286 DownloadDlgProc(HWND Dlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
296 hIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_MAIN
));
299 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIcon
);
300 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIcon
);
303 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 0);
304 Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
307 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
308 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
311 Thread
= CreateThread(NULL
, 0, ThreadFunc
, Dlg
, 0, &ThreadId
);
312 if (!Thread
) return FALSE
;
317 if (wParam
== IDCANCEL
)
319 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 1);
320 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
325 if (hIcon
) DestroyIcon(hIcon
);
335 DownloadApplication(INT Index
)
337 if (!IS_AVAILABLE_ENUM(SelectedEnumType
))
340 AppInfo
= (PAPPLICATION_INFO
) ListViewGetlParam(Index
);
341 if (!AppInfo
) return FALSE
;
343 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_INSTALL
, AppInfo
->szName
);
346 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
354 DownloadApplicationsDB(LPWSTR lpUrl
)
356 APPLICATION_INFO IntInfo
;
358 ZeroMemory(&IntInfo
, sizeof(APPLICATION_INFO
));
359 wcscpy(IntInfo
.szUrlDownload
, lpUrl
);
364 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),