1 /* PROJECT: ReactOS Downloader (was GetFirefox)
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/downloader/download.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 2007 Dmitry Chapyshev (lentind@yandex.ru)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define WIN32_NO_STATUS
36 #include "resources.h"
37 #include "structures.h"
42 extern struct Application
* SelectedApplication
;
43 extern WCHAR Strings
[STRING_COUNT
][MAX_STRING_LENGHT
];
45 typedef struct _IBindStatusCallbackImpl
47 const IBindStatusCallbackVtbl
*vtbl
;
51 } IBindStatusCallbackImpl
;
54 dlQueryInterface(IBindStatusCallback
* This
, REFIID riid
, void** ppvObject
)
56 if (NULL
== ppvObject
)
61 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IBindStatusCallback
))
63 IBindStatusCallback_AddRef( This
);
72 dlAddRef(IBindStatusCallback
* iface
)
74 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
76 return InterlockedIncrement(&This
->ref
);
80 dlRelease(IBindStatusCallback
* iface
)
82 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
83 DWORD ref
= InterlockedDecrement(&This
->ref
);
87 DestroyWindow( This
->hDialog
);
88 HeapFree(GetProcessHeap(), 0, This
);
95 dlOnStartBinding(IBindStatusCallback
* iface
, DWORD dwReserved
, IBinding
* pib
)
97 DPRINT1("OnStartBinding not implemented\n");
102 static HRESULT WINAPI
103 dlGetPriority(IBindStatusCallback
* iface
, LONG
* pnPriority
)
105 DPRINT1("GetPriority not implemented\n");
110 static HRESULT WINAPI
111 dlOnLowResource( IBindStatusCallback
* iface
, DWORD reserved
)
113 DPRINT1("OnLowResource not implemented\n");
118 static HRESULT WINAPI
119 dlOnProgress(IBindStatusCallback
* iface
, ULONG ulProgress
,
120 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
122 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
127 Item
= GetDlgItem(This
->hDialog
, IDC_PROGRESS
);
128 if (NULL
!= Item
&& 0 != ulProgressMax
)
130 SendMessageW(Item
, PBM_SETPOS
, ((ULONGLONG
)ulProgress
* 100) / ulProgressMax
, 0);
133 Item
= GetDlgItem(This
->hDialog
, IDC_STATUS
);
134 if (NULL
!= Item
&& NULL
!= szStatusText
)
136 SendMessageW(Item
, WM_GETTEXT
, sizeof(OldText
) / sizeof(OldText
[0]),
138 if (sizeof(OldText
) / sizeof(OldText
[0]) - 1 <= wcslen(OldText
) || 0 != wcscmp(OldText
, szStatusText
))
140 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) szStatusText
);
145 r
= GetWindowLongPtrW(This
->hDialog
, GWLP_USERDATA
);
146 if (0 != r
|| 0 != GetLastError())
148 *This
->pbCancelled
= TRUE
;
149 DPRINT("Cancelled\n");
156 static HRESULT WINAPI
157 dlOnStopBinding(IBindStatusCallback
* iface
, HRESULT hresult
, LPCWSTR szError
)
159 DPRINT1("OnStopBinding not implemented\n");
164 static HRESULT WINAPI
165 dlGetBindInfo(IBindStatusCallback
* iface
, DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
167 DPRINT1("GetBindInfo not implemented\n");
172 static HRESULT WINAPI
173 dlOnDataAvailable(IBindStatusCallback
* iface
, DWORD grfBSCF
,
174 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
176 DPRINT1("OnDataAvailable implemented\n");
181 static HRESULT WINAPI
182 dlOnObjectAvailable(IBindStatusCallback
* iface
, REFIID riid
, IUnknown
* punk
)
184 DPRINT1("OnObjectAvailable implemented\n");
189 static const IBindStatusCallbackVtbl dlVtbl
=
204 static IBindStatusCallback
*
205 CreateDl(HWND Dlg
, BOOL
*pbCancelled
)
207 IBindStatusCallbackImpl
*This
;
209 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IBindStatusCallbackImpl
));
213 This
->vtbl
= &dlVtbl
;
216 This
->pbCancelled
= pbCancelled
;
218 return (IBindStatusCallback
*) This
;
222 ThreadFunc(LPVOID Context
)
224 //static const WCHAR szUrl[] = DownloadUrl;
225 IBindStatusCallback
*dl
;
226 WCHAR path
[MAX_PATH
];
229 PROCESS_INFORMATION pi
;
230 HWND Dlg
= (HWND
) Context
;
232 BOOL bCancelled
= FALSE
;
233 BOOL bTempfile
= FALSE
;
235 DWORD dwSize
= MAX_PATH
;
237 /* built the path for the download */
238 p
= wcsrchr(SelectedApplication
->Location
, L
'/');
244 /* Create default download path */
245 if (GetWindowsDirectory(path
, sizeof(path
) / sizeof(WCHAR
)))
249 for (i
= 0; i
< 4; i
++)
258 LoadString(GetModuleHandle(NULL
), IDS_DOWNLOAD_FOLDER
, path
, sizeof(path
) / sizeof(WCHAR
));
259 wcscat((LPWSTR
)DPath
, path
);
263 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
264 TEXT("Software\\ReactOS\\Downloader"),
265 &hKey
) == ERROR_SUCCESS
)
267 if ((RegQueryValueEx(hKey
,
272 &dwSize
) != ERROR_SUCCESS
) && (path
[0] == 0))
278 if (GetFileAttributes(path
) == 0xFFFFFFFF)
279 if (!CreateDirectory((LPCTSTR
)path
,NULL
))
288 dl
= CreateDl(Context
, &bCancelled
);
289 r
= URLDownloadToFileW(NULL
, SelectedApplication
->Location
, path
, 0, dl
);
292 IBindStatusCallback_Release(dl
);
296 MessageBoxW(0,Strings
[IDS_DOWNLOAD_ERROR
],0,0);
303 ShowWindow(Dlg
, SW_HIDE
);
306 memset(&si
, 0, sizeof(si
));
308 r
= CreateProcessW(path
, NULL
, NULL
, NULL
, 0, 0, NULL
, NULL
, &si
, &pi
);
313 CloseHandle(pi
.hThread
);
314 WaitForSingleObject(pi
.hProcess
, INFINITE
);
315 CloseHandle(pi
.hProcess
);
324 DWORD dwSize
= sizeof(DWORD
);
325 DWORD dwValue
, dwType
= REG_DWORD
;
326 if (RegQueryValueEx(hKey
,
331 &dwSize
) == ERROR_SUCCESS
)
342 DownloadProc(HWND Dlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
350 case WM_INITDIALOG
:/*
351 Icon = LoadIconW((HINSTANCE) GetWindowLongPtr(Dlg, GWLP_HINSTANCE),
352 MAKEINTRESOURCEW(IDI_ICON_MAIN));
355 SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM) Icon);
356 SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM) Icon);
358 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 0);
359 Item
= GetDlgItem(Dlg
, IDC_PROGRESS
);
362 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
363 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
365 Item = GetDlgItem(Dlg, IDC_REMOVE);
368 if (GetShortcutName(ShortcutName) &&
369 INVALID_FILE_ATTRIBUTES != GetFileAttributesW(ShortcutName))
371 SendMessageW(Item, BM_SETCHECK, BST_CHECKED, 0);
375 SendMessageW(Item, BM_SETCHECK, BST_UNCHECKED, 0);
376 ShowWindow(Item, SW_HIDE);
379 Thread
= CreateThread(NULL
, 0, ThreadFunc
, Dlg
, 0, &ThreadId
);
388 if (wParam
== IDCANCEL
)
390 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 1);
391 PostMessage(Dlg
, WM_CLOSE
, 0, 0);