mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
[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
This commit is contained in:
parent
1e1bd36010
commit
6ad9377d2d
2 changed files with 41 additions and 16 deletions
|
@ -25,7 +25,7 @@ add_executable(rapps ${SOURCE})
|
||||||
add_pch(rapps rapps.h)
|
add_pch(rapps rapps.h)
|
||||||
set_module_type(rapps win32gui UNICODE)
|
set_module_type(rapps win32gui UNICODE)
|
||||||
target_link_libraries(rapps uuid)
|
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_dependencies(rapps rappsmsg)
|
||||||
add_message_headers(ANSI rappsmsg.mc)
|
add_message_headers(ANSI rappsmsg.mc)
|
||||||
add_cd_file(TARGET rapps DESTINATION reactos/system32 FOR all)
|
add_cd_file(TARGET rapps DESTINATION reactos/system32 FOR all)
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rapps.h"
|
#include "rapps.h"
|
||||||
|
#include <wininet.h>
|
||||||
|
#include <shellapi.h>
|
||||||
|
|
||||||
static PAPPLICATION_INFO AppInfo;
|
static PAPPLICATION_INFO AppInfo;
|
||||||
static HICON hIcon = NULL;
|
static HICON hIcon = NULL;
|
||||||
|
@ -206,13 +208,17 @@ ThreadFunc(LPVOID Context)
|
||||||
IBindStatusCallback *dl;
|
IBindStatusCallback *dl;
|
||||||
WCHAR path[MAX_PATH];
|
WCHAR path[MAX_PATH];
|
||||||
LPWSTR p;
|
LPWSTR p;
|
||||||
STARTUPINFOW si;
|
|
||||||
PROCESS_INFORMATION pi;
|
|
||||||
HWND Dlg = (HWND) Context;
|
HWND Dlg = (HWND) Context;
|
||||||
DWORD r, len;
|
DWORD len, dwContentLen, dwBytesWritten, dwBytesRead, dwCurrentBytesRead;
|
||||||
|
DWORD dwBufLen = sizeof(dwContentLen);
|
||||||
BOOL bCancelled = FALSE;
|
BOOL bCancelled = FALSE;
|
||||||
BOOL bTempfile = FALSE;
|
BOOL bTempfile = FALSE;
|
||||||
BOOL bCab = 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 */
|
/* built the path for the download */
|
||||||
p = wcsrchr(AppInfo->szUrlDownload, L'/');
|
p = wcsrchr(AppInfo->szUrlDownload, L'/');
|
||||||
|
@ -255,24 +261,43 @@ ThreadFunc(LPVOID Context)
|
||||||
/* download it */
|
/* download it */
|
||||||
bTempfile = TRUE;
|
bTempfile = TRUE;
|
||||||
dl = CreateDl(Context, &bCancelled);
|
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 (dl) IBindStatusCallback_Release(dl);
|
||||||
if (S_OK != r) goto end;
|
if (bCancelled) goto end;
|
||||||
else if (bCancelled) goto end;
|
|
||||||
|
|
||||||
ShowWindow(Dlg, SW_HIDE);
|
ShowWindow(Dlg, SW_HIDE);
|
||||||
|
|
||||||
/* run it */
|
/* run it */
|
||||||
ZeroMemory(&si, sizeof(si));
|
if (!bCab)
|
||||||
si.cb = sizeof(si);
|
{
|
||||||
r = CreateProcessW(path, NULL, NULL, NULL, 0, 0, NULL, NULL, &si, &pi);
|
ShellExecute( NULL, L"open", path, NULL, NULL, SW_SHOWNORMAL );
|
||||||
if (0 == r) goto end;
|
}
|
||||||
|
|
||||||
CloseHandle(pi.hThread);
|
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
||||||
CloseHandle(pi.hProcess);
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
CloseHandle(hOut);
|
||||||
|
InternetCloseHandle(hFile);
|
||||||
|
InternetCloseHandle(hOpen);
|
||||||
|
|
||||||
if (bTempfile)
|
if (bTempfile)
|
||||||
{
|
{
|
||||||
if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))
|
if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))
|
||||||
|
|
Loading…
Reference in a new issue