Author: dreimer
Date: Sun Jan 26 15:46:34 2014
New Revision: 61832
URL:
http://svn.reactos.org/svn/reactos?rev=61832&view=rev
Log:
[RAPPS]
- Replace URLDownloadToFileW download routine by InternetOpenW, InternetOpenUrlW,
InternetReadFile download routine. This makes it possible to set the user agent which
allows us to use
http://download.sourceforge.net URLs and not needing any hard coded
mirrors anymore. (Thx goes to Usurp for that idea.)
- Replace CreateProcessW by ShellExecute. This reenables the question for elevated rights
in Windows and allows RApps to open any file format the shell knows about.
Big thx goes out to AmineKhaldi, Christoph_vW, gigaherz and ThFabba for helping a rusted
Java coder to get things in a resonable shape. ^^
Modified:
trunk/reactos/base/applications/rapps/CMakeLists.txt
trunk/reactos/base/applications/rapps/loaddlg.c
Modified: trunk/reactos/base/applications/rapps/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/CM…
==============================================================================
--- trunk/reactos/base/applications/rapps/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/CMakeLists.txt [iso-8859-1] Sun Jan 26 15:46:34
2014
@@ -25,7 +25,7 @@
add_pch(rapps rapps.h)
set_module_type(rapps win32gui UNICODE)
target_link_libraries(rapps uuid)
-add_importlibs(rapps advapi32 comctl32 gdi32 urlmon user32 shell32 shlwapi ole32 msvcrt
kernel32 ntdll)
+add_importlibs(rapps advapi32 comctl32 gdi32 urlmon wininet user32 shell32 shlwapi ole32
msvcrt kernel32 ntdll)
add_dependencies(rapps rappsmsg)
add_message_headers(ANSI rappsmsg.mc)
add_cd_file(TARGET rapps DESTINATION reactos/system32 FOR all)
Modified: trunk/reactos/base/applications/rapps/loaddlg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/lo…
==============================================================================
--- trunk/reactos/base/applications/rapps/loaddlg.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/loaddlg.c [iso-8859-1] Sun Jan 26 15:46:34 2014
@@ -26,6 +26,8 @@
*/
#include "rapps.h"
+#include <wininet.h>
+#include <shellapi.h>
static PAPPLICATION_INFO AppInfo;
static HICON hIcon = NULL;
@@ -206,13 +208,17 @@
IBindStatusCallback *dl;
WCHAR path[MAX_PATH];
LPWSTR p;
- STARTUPINFOW si;
- PROCESS_INFORMATION pi;
HWND Dlg = (HWND) Context;
- DWORD r, len;
+ DWORD len, dwContentLen, dwBytesWritten, dwBytesRead, dwCurrentBytesRead;
+ DWORD dwBufLen = sizeof(dwContentLen);
BOOL bCancelled = FALSE;
BOOL bTempfile = FALSE;
BOOL bCab = FALSE;
+ HINTERNET hOpen = NULL;
+ HINTERNET hFile = NULL;
+ HANDLE hOut = NULL;
+ unsigned char lpBuffer[4096];
+ const LPWSTR lpszAgent = L"RApps/1.0";
/* built the path for the download */
p = wcsrchr(AppInfo->szUrlDownload, L'/');
@@ -255,24 +261,43 @@
/* download it */
bTempfile = TRUE;
dl = CreateDl(Context, &bCancelled);
- r = URLDownloadToFileW(NULL, AppInfo->szUrlDownload, path, 0, dl);
+
+ hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+ if (!hOpen) goto end;
+
+ hFile = InternetOpenUrlW(hOpen, AppInfo->szUrlDownload, NULL, 0,
INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_KEEP_CONNECTION, 0);
+ if(!hFile) goto end;
+
+ hOut = CreateFileW(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, 0, NULL);
+ if (hOut == INVALID_HANDLE_VALUE) goto end;
+
+ HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
&dwContentLen, &dwBufLen, 0);
+
+ do
+ {
+ if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
goto end;
+ if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
goto end;
+ dwCurrentBytesRead += dwBytesRead;
+ IBindStatusCallback_OnProgress(dl, dwCurrentBytesRead, dwContentLen, 0,
AppInfo->szUrlDownload);
+ }
+ while (dwBytesRead);
+
+ CloseHandle(hOut);
if (dl) IBindStatusCallback_Release(dl);
- if (S_OK != r) goto end;
- else if (bCancelled) goto end;
+ if (bCancelled) goto end;
ShowWindow(Dlg, SW_HIDE);
/* run it */
- ZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- r = CreateProcessW(path, NULL, NULL, NULL, 0, 0, NULL, NULL, &si, &pi);
- if (0 == r) goto end;
-
- CloseHandle(pi.hThread);
- WaitForSingleObject(pi.hProcess, INFINITE);
- CloseHandle(pi.hProcess);
-
+ if (!bCab)
+ {
+ ShellExecute( NULL, L"open", path, NULL, NULL, SW_SHOWNORMAL );
+ }
end:
+ CloseHandle(hOut);
+ InternetCloseHandle(hFile);
+ InternetCloseHandle(hOpen);
+
if (bTempfile)
{
if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))