2 * PROJECT: ReactOS utilities
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: apps/utils/getfirefox/getfirefox.c
5 * PURPOSE: Main program
6 * COPYRIGHT: Copyright 2001 John R. Sheets (for CodeWeavers)
7 * Copyright 2004 Mike McCormack (for CodeWeavers)
8 * Copyright 2005 Ge van Geldorp (gvg@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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define DOWNLOAD_URL L"http://links.reactos.org/getfirefox"
36 typedef struct _IBindStatusCallbackImpl
38 const IBindStatusCallbackVtbl
*vtbl
;
42 } IBindStatusCallbackImpl
;
45 dlQueryInterface(IBindStatusCallback
* This
, REFIID riid
, void** ppvObject
)
47 if (NULL
== ppvObject
)
52 if (IsEqualIID(riid
, &IID_IUnknown
) ||
53 IsEqualIID(riid
, &IID_IBindStatusCallback
))
55 IBindStatusCallback_AddRef( This
);
64 dlAddRef(IBindStatusCallback
* iface
)
66 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
68 return InterlockedIncrement(&This
->ref
);
72 dlRelease(IBindStatusCallback
* iface
)
74 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
75 DWORD ref
= InterlockedDecrement(&This
->ref
);
79 DestroyWindow( This
->hDialog
);
80 HeapFree(GetProcessHeap(), 0, This
);
87 dlOnStartBinding(IBindStatusCallback
* iface
, DWORD dwReserved
, IBinding
* pib
)
89 DPRINT1("OnStartBinding not implemented\n");
95 dlGetPriority(IBindStatusCallback
* iface
, LONG
* pnPriority
)
97 DPRINT1("GetPriority not implemented\n");
102 static HRESULT WINAPI
103 dlOnLowResource( IBindStatusCallback
* iface
, DWORD reserved
)
105 DPRINT1("OnLowResource not implemented\n");
110 static HRESULT WINAPI
111 dlOnProgress(IBindStatusCallback
* iface
, ULONG ulProgress
,
112 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
114 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
119 Item
= GetDlgItem(This
->hDialog
, IDC_PROGRESS
);
120 if (NULL
!= Item
&& 0 != ulProgressMax
)
122 SendMessageW(Item
, PBM_SETPOS
, (ulProgress
* 100) / ulProgressMax
, 0);
125 Item
= GetDlgItem(This
->hDialog
, IDC_STATUS
);
128 SendMessageW(Item
, WM_GETTEXT
, sizeof(OldText
) / sizeof(OldText
[0]),
130 if (sizeof(OldText
) / sizeof(OldText
[0]) - 1 <= wcslen(OldText
) ||
131 0 != wcscmp(OldText
, szStatusText
))
133 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) szStatusText
);
138 r
= GetWindowLongPtrW(This
->hDialog
, GWLP_USERDATA
);
139 if (0 != r
|| 0 != GetLastError())
141 *This
->pbCancelled
= TRUE
;
142 DPRINT("Cancelled\n");
149 static HRESULT WINAPI
150 dlOnStopBinding(IBindStatusCallback
* iface
, HRESULT hresult
, LPCWSTR szError
)
152 DPRINT1("OnStopBinding not implemented\n");
157 static HRESULT WINAPI
158 dlGetBindInfo(IBindStatusCallback
* iface
, DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
160 DPRINT1("GetBindInfo not implemented\n");
165 static HRESULT WINAPI
166 dlOnDataAvailable(IBindStatusCallback
* iface
, DWORD grfBSCF
,
167 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
169 DPRINT1("OnDataAvailable implemented\n");
174 static HRESULT WINAPI
175 dlOnObjectAvailable(IBindStatusCallback
* iface
, REFIID riid
, IUnknown
* punk
)
177 DPRINT1("OnObjectAvailable implemented\n");
182 static const IBindStatusCallbackVtbl dlVtbl
=
197 static IBindStatusCallback
*
198 CreateDl(HWND Dlg
, BOOL
*pbCancelled
)
200 IBindStatusCallbackImpl
*This
;
202 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(IBindStatusCallbackImpl
));
203 This
->vtbl
= &dlVtbl
;
206 This
->pbCancelled
= pbCancelled
;
208 return (IBindStatusCallback
*) This
;
212 GetShortcutName(LPWSTR ShortcutName
)
214 if (! SHGetSpecialFolderPathW(0, ShortcutName
, CSIDL_PROGRAMS
, FALSE
))
218 if (NULL
== PathAddBackslashW(ShortcutName
))
222 if (0 == LoadStringW(GetModuleHandle(NULL
), IDS_START_MENU_NAME
,
223 ShortcutName
+ wcslen(ShortcutName
),
224 MAX_PATH
- wcslen(ShortcutName
)))
228 if (MAX_PATH
- 5 < wcslen(ShortcutName
))
232 wcscat(ShortcutName
, L
".lnk");
238 ThreadFunc(LPVOID Context
)
240 static const WCHAR szUrl
[] = DOWNLOAD_URL
;
241 IBindStatusCallback
*dl
;
242 WCHAR path
[MAX_PATH
], ShortcutName
[MAX_PATH
];
245 PROCESS_INFORMATION pi
;
246 HWND Dlg
= (HWND
) Context
;
248 BOOL bCancelled
= FALSE
;
249 BOOL bTempfile
= FALSE
;
251 /* built the path for the download */
252 p
= wcsrchr(szUrl
, L
'/');
257 if (! GetTempPathW(MAX_PATH
, path
))
265 dl
= CreateDl(Context
, &bCancelled
);
266 r
= URLDownloadToFileW(NULL
, szUrl
, path
, 0, dl
);
269 IBindStatusCallback_Release(dl
);
271 if (S_OK
!= r
|| bCancelled
)
275 ShowWindow(Dlg
, SW_HIDE
);
278 memset(&si
, 0, sizeof(si
));
280 r
= CreateProcessW(path
, NULL
, NULL
, NULL
, 0, 0, NULL
, NULL
, &si
, &pi
);
285 CloseHandle(pi
.hThread
);
286 WaitForSingleObject(pi
.hProcess
, INFINITE
);
287 CloseHandle(pi
.hProcess
);
289 if (BST_CHECKED
== SendMessageW(GetDlgItem(Dlg
, IDC_REMOVE
), BM_GETCHECK
,
291 GetShortcutName(ShortcutName
))
293 DeleteFileW(ShortcutName
);
305 static INT_PTR CALLBACK
306 dlProc(HWND Dlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
312 WCHAR ShortcutName
[MAX_PATH
];
317 Icon
= LoadIconW((HINSTANCE
) GetWindowLongPtr(Dlg
, GWLP_HINSTANCE
),
318 MAKEINTRESOURCEW(IDI_ICON_MAIN
));
321 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) Icon
);
322 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) Icon
);
324 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 0);
325 Item
= GetDlgItem(Dlg
, IDC_PROGRESS
);
328 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0,100));
329 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
331 Item
= GetDlgItem(Dlg
, IDC_REMOVE
);
334 if (GetShortcutName(ShortcutName
) &&
335 INVALID_FILE_ATTRIBUTES
!= GetFileAttributesW(ShortcutName
))
337 SendMessageW(Item
, BM_SETCHECK
, BST_CHECKED
, 0);
341 SendMessageW(Item
, BM_SETCHECK
, BST_UNCHECKED
, 0);
342 ShowWindow(Item
, SW_HIDE
);
345 Thread
= CreateThread(NULL
, 0, ThreadFunc
, Dlg
, 0, &ThreadId
);
354 if (wParam
== IDCANCEL
)
356 SetWindowLongPtrW(Dlg
, GWLP_USERDATA
, 1);
357 PostMessage(Dlg
, WM_CLOSE
, 0, 0);
375 /***********************************************************************
379 main(int argc
, char *argv
[])
381 InitCommonControls();
383 DialogBoxW(GetModuleHandle(NULL
), MAKEINTRESOURCEW(IDD_GETFIREFOX
), 0,