From 6ad9377d2d8cbc3fd7e1fb3891c7041da9163f65 Mon Sep 17 00:00:00 2001 From: Daniel Reimer Date: Sun, 26 Jan 2014 15:46:34 +0000 Subject: [PATCH] [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. ^^ svn path=/trunk/; revision=61832 --- .../base/applications/rapps/CMakeLists.txt | 2 +- reactos/base/applications/rapps/loaddlg.c | 55 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/reactos/base/applications/rapps/CMakeLists.txt b/reactos/base/applications/rapps/CMakeLists.txt index ee33a605284..0484d12732e 100644 --- a/reactos/base/applications/rapps/CMakeLists.txt +++ b/reactos/base/applications/rapps/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable(rapps ${SOURCE}) 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) diff --git a/reactos/base/applications/rapps/loaddlg.c b/reactos/base/applications/rapps/loaddlg.c index c4c17ffcab2..2687448f0db 100644 --- a/reactos/base/applications/rapps/loaddlg.c +++ b/reactos/base/applications/rapps/loaddlg.c @@ -26,6 +26,8 @@ */ #include "rapps.h" +#include +#include static PAPPLICATION_INFO AppInfo; static HICON hIcon = NULL; @@ -206,13 +208,17 @@ ThreadFunc(LPVOID Context) 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 @@ ThreadFunc(LPVOID Context) /* 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))