Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenloaddlg.c
Go to the documentation of this file.
00001 /* PROJECT: ReactOS Applications Manager 00002 * LICENSE: GPL - See COPYING in the top level directory 00003 * FILE: base/applications/rapps/loaddlg.c 00004 * PURPOSE: Displaying a download dialog 00005 * COPYRIGHT: Copyright 2001 John R. Sheets (for CodeWeavers) 00006 * Copyright 2004 Mike McCormack (for CodeWeavers) 00007 * Copyright 2005 Ge van Geldorp (gvg@reactos.org) 00008 * Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org) 00009 */ 00010 /* 00011 * Based on Wine dlls/shdocvw/shdocvw_main.c 00012 * 00013 * This library is free software; you can redistribute it and/or 00014 * modify it under the terms of the GNU Lesser General Public 00015 * License as published by the Free Software Foundation; either 00016 * version 2.1 of the License, or (at your option) any later version. 00017 * 00018 * This library is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 * Lesser General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public 00024 * License along with this library; if not, write to the Free Software 00025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00026 */ 00027 00028 #define COBJMACROS 00029 #define WIN32_NO_STATUS 00030 00031 #include "rapps.h" 00032 00033 static PAPPLICATION_INFO AppInfo; 00034 static HICON hIcon = NULL; 00035 00036 typedef struct _IBindStatusCallbackImpl 00037 { 00038 const IBindStatusCallbackVtbl *vtbl; 00039 LONG ref; 00040 HWND hDialog; 00041 BOOL *pbCancelled; 00042 } IBindStatusCallbackImpl; 00043 00044 static 00045 HRESULT WINAPI 00046 dlQueryInterface(IBindStatusCallback* This, REFIID riid, void** ppvObject) 00047 { 00048 if (!ppvObject) return E_POINTER; 00049 00050 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IBindStatusCallback)) 00051 { 00052 IBindStatusCallback_AddRef(This); 00053 *ppvObject = This; 00054 return S_OK; 00055 } 00056 00057 return E_NOINTERFACE; 00058 } 00059 00060 static 00061 ULONG WINAPI 00062 dlAddRef(IBindStatusCallback* iface) 00063 { 00064 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl*) iface; 00065 return InterlockedIncrement(&This->ref); 00066 } 00067 00068 static 00069 ULONG WINAPI 00070 dlRelease(IBindStatusCallback* iface) 00071 { 00072 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl*) iface; 00073 DWORD ref = InterlockedDecrement(&This->ref); 00074 00075 if (!ref) 00076 { 00077 DestroyWindow(This->hDialog); 00078 HeapFree(GetProcessHeap(), 0, This); 00079 } 00080 00081 return ref; 00082 } 00083 00084 static 00085 HRESULT WINAPI 00086 dlOnStartBinding(IBindStatusCallback* iface, DWORD dwReserved, IBinding* pib) 00087 { 00088 return S_OK; 00089 } 00090 00091 static 00092 HRESULT WINAPI 00093 dlGetPriority(IBindStatusCallback* iface, LONG* pnPriority) 00094 { 00095 return S_OK; 00096 } 00097 00098 static 00099 HRESULT WINAPI 00100 dlOnLowResource( IBindStatusCallback* iface, DWORD reserved) 00101 { 00102 return S_OK; 00103 } 00104 00105 static 00106 HRESULT WINAPI 00107 dlOnProgress(IBindStatusCallback* iface, 00108 ULONG ulProgress, 00109 ULONG ulProgressMax, 00110 ULONG ulStatusCode, 00111 LPCWSTR szStatusText) 00112 { 00113 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface; 00114 HWND Item; 00115 LONG r; 00116 WCHAR OldText[100]; 00117 00118 Item = GetDlgItem(This->hDialog, IDC_DOWNLOAD_PROGRESS); 00119 if (Item && ulProgressMax) 00120 { 00121 SendMessageW(Item, PBM_SETPOS, ((ULONGLONG)ulProgress * 100) / ulProgressMax, 0); 00122 } 00123 00124 Item = GetDlgItem(This->hDialog, IDC_DOWNLOAD_STATUS); 00125 if (Item && szStatusText) 00126 { 00127 SendMessageW(Item, WM_GETTEXT, sizeof(OldText) / sizeof(OldText[0]), (LPARAM) OldText); 00128 if (sizeof(OldText) / sizeof(OldText[0]) - 1 <= wcslen(OldText) || 0 != wcscmp(OldText, szStatusText)) 00129 { 00130 SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) szStatusText); 00131 } 00132 } 00133 00134 SetLastError(0); 00135 r = GetWindowLongPtrW(This->hDialog, GWLP_USERDATA); 00136 if (0 != r || 0 != GetLastError()) 00137 { 00138 *This->pbCancelled = TRUE; 00139 return E_ABORT; 00140 } 00141 00142 return S_OK; 00143 } 00144 00145 static 00146 HRESULT WINAPI 00147 dlOnStopBinding(IBindStatusCallback* iface, HRESULT hresult, LPCWSTR szError) 00148 { 00149 return S_OK; 00150 } 00151 00152 static 00153 HRESULT WINAPI 00154 dlGetBindInfo(IBindStatusCallback* iface, DWORD* grfBINDF, BINDINFO* pbindinfo) 00155 { 00156 return S_OK; 00157 } 00158 00159 static 00160 HRESULT WINAPI 00161 dlOnDataAvailable(IBindStatusCallback* iface, DWORD grfBSCF, 00162 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed) 00163 { 00164 return S_OK; 00165 } 00166 00167 static 00168 HRESULT WINAPI 00169 dlOnObjectAvailable(IBindStatusCallback* iface, REFIID riid, IUnknown* punk) 00170 { 00171 return S_OK; 00172 } 00173 00174 static const IBindStatusCallbackVtbl dlVtbl = 00175 { 00176 dlQueryInterface, 00177 dlAddRef, 00178 dlRelease, 00179 dlOnStartBinding, 00180 dlGetPriority, 00181 dlOnLowResource, 00182 dlOnProgress, 00183 dlOnStopBinding, 00184 dlGetBindInfo, 00185 dlOnDataAvailable, 00186 dlOnObjectAvailable 00187 }; 00188 00189 static IBindStatusCallback* 00190 CreateDl(HWND Dlg, BOOL *pbCancelled) 00191 { 00192 IBindStatusCallbackImpl *This; 00193 00194 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IBindStatusCallbackImpl)); 00195 if (!This) return NULL; 00196 00197 This->vtbl = &dlVtbl; 00198 This->ref = 1; 00199 This->hDialog = Dlg; 00200 This->pbCancelled = pbCancelled; 00201 00202 return (IBindStatusCallback*) This; 00203 } 00204 00205 static 00206 DWORD WINAPI 00207 ThreadFunc(LPVOID Context) 00208 { 00209 IBindStatusCallback *dl; 00210 WCHAR path[MAX_PATH]; 00211 LPWSTR p; 00212 STARTUPINFOW si; 00213 PROCESS_INFORMATION pi; 00214 HWND Dlg = (HWND) Context; 00215 DWORD r, len; 00216 BOOL bCancelled = FALSE; 00217 BOOL bTempfile = FALSE; 00218 BOOL bCab = FALSE; 00219 00220 /* built the path for the download */ 00221 p = wcsrchr(AppInfo->szUrlDownload, L'/'); 00222 if (!p) goto end; 00223 00224 len = wcslen(AppInfo->szUrlDownload); 00225 if (len > 4) 00226 { 00227 if (AppInfo->szUrlDownload[len - 4] == '.' && 00228 AppInfo->szUrlDownload[len - 3] == 'c' && 00229 AppInfo->szUrlDownload[len - 2] == 'a' && 00230 AppInfo->szUrlDownload[len - 1] == 'b') 00231 { 00232 bCab = TRUE; 00233 if (!GetCurrentDirectoryW(MAX_PATH, path)) 00234 goto end; 00235 } 00236 else 00237 { 00238 wcscpy(path, SettingsInfo.szDownloadDir); 00239 } 00240 } 00241 else goto end; 00242 00243 if (GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES) 00244 { 00245 if (!CreateDirectoryW(path, NULL)) 00246 goto end; 00247 } 00248 00249 wcscat(path, L"\\"); 00250 wcscat(path, p + 1); 00251 00252 /* download it */ 00253 bTempfile = TRUE; 00254 dl = CreateDl(Context, &bCancelled); 00255 r = URLDownloadToFileW(NULL, AppInfo->szUrlDownload, path, 0, dl); 00256 if (dl) IBindStatusCallback_Release(dl); 00257 if (S_OK != r) goto end; 00258 else if (bCancelled) goto end; 00259 00260 ShowWindow(Dlg, SW_HIDE); 00261 00262 /* run it */ 00263 memset(&si, 0, sizeof(si)); 00264 si.cb = sizeof(si); 00265 r = CreateProcessW(path, NULL, NULL, NULL, 0, 0, NULL, NULL, &si, &pi); 00266 if (0 == r) goto end; 00267 00268 CloseHandle(pi.hThread); 00269 WaitForSingleObject(pi.hProcess, INFINITE); 00270 CloseHandle(pi.hProcess); 00271 00272 end: 00273 if (bTempfile) 00274 { 00275 if (bCancelled || (SettingsInfo.bDelInstaller && !bCab)) 00276 DeleteFileW(path); 00277 } 00278 00279 EndDialog(Dlg, 0); 00280 00281 return 0; 00282 } 00283 00284 static 00285 INT_PTR CALLBACK 00286 DownloadDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam) 00287 { 00288 HANDLE Thread; 00289 DWORD ThreadId; 00290 HWND Item; 00291 00292 switch (Msg) 00293 { 00294 case WM_INITDIALOG: 00295 00296 hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN)); 00297 if (hIcon) 00298 { 00299 SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon); 00300 SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon); 00301 } 00302 00303 SetWindowLongPtrW(Dlg, GWLP_USERDATA, 0); 00304 Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS); 00305 if (Item) 00306 { 00307 SendMessageW(Item, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); 00308 SendMessageW(Item, PBM_SETPOS, 0, 0); 00309 } 00310 00311 Thread = CreateThread(NULL, 0, ThreadFunc, Dlg, 0, &ThreadId); 00312 if (!Thread) return FALSE; 00313 CloseHandle(Thread); 00314 return TRUE; 00315 00316 case WM_COMMAND: 00317 if (wParam == IDCANCEL) 00318 { 00319 SetWindowLongPtrW(Dlg, GWLP_USERDATA, 1); 00320 PostMessageW(Dlg, WM_CLOSE, 0, 0); 00321 } 00322 return FALSE; 00323 00324 case WM_CLOSE: 00325 if (hIcon) DestroyIcon(hIcon); 00326 EndDialog(Dlg, 0); 00327 return TRUE; 00328 00329 default: 00330 return FALSE; 00331 } 00332 } 00333 00334 BOOL 00335 DownloadApplication(INT Index) 00336 { 00337 if (!IS_AVAILABLE_ENUM(SelectedEnumType)) 00338 return FALSE; 00339 00340 AppInfo = (PAPPLICATION_INFO) ListViewGetlParam(Index); 00341 if (!AppInfo) return FALSE; 00342 00343 WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_INSTALL, AppInfo->szName); 00344 00345 DialogBoxW(hInst, 00346 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), 00347 hMainWnd, 00348 DownloadDlgProc); 00349 00350 return TRUE; 00351 } 00352 00353 VOID 00354 DownloadApplicationsDB(LPWSTR lpUrl) 00355 { 00356 APPLICATION_INFO IntInfo; 00357 00358 ZeroMemory(&IntInfo, sizeof(APPLICATION_INFO)); 00359 wcscpy(IntInfo.szUrlDownload, lpUrl); 00360 00361 AppInfo = &IntInfo; 00362 00363 DialogBoxW(hInst, 00364 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), 00365 hMainWnd, 00366 DownloadDlgProc); 00367 } 00368 Generated on Fri May 25 2012 04:15:40 for ReactOS by
1.7.6.1
|