loaddlg.cpp (12caaece) loaddlg.cpp (059ba9b0)
1/*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
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 2009 Dmitry Chapyshev (dmitry@reactos.org)

--- 508 unchanged lines hidden (view full) ---

517 }
518
519 /* paste it into our dialog and don't do it again in this instance */
520 SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) buf.GetString());
521 UrlHasBeenCopied = TRUE;
522 }
523}
524
1/*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
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 2009 Dmitry Chapyshev (dmitry@reactos.org)

--- 508 unchanged lines hidden (view full) ---

517 }
518
519 /* paste it into our dialog and don't do it again in this instance */
520 SendMessageW(Item, WM_SETTEXT, 0, (LPARAM) buf.GetString());
521 UrlHasBeenCopied = TRUE;
522 }
523}
524
525VOID ShowLastError(
525BOOL ShowLastError(
526 HWND hWndOwner,
526 HWND hWndOwner,
527 BOOL bInetError,
527 DWORD dwLastError)
528{
529 CLocalPtr<WCHAR> lpMsg;
530
531 if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
528 DWORD dwLastError)
529{
530 CLocalPtr<WCHAR> lpMsg;
531
532 if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
532 FORMAT_MESSAGE_FROM_SYSTEM |
533 FORMAT_MESSAGE_IGNORE_INSERTS,
534 NULL,
533 FORMAT_MESSAGE_IGNORE_INSERTS |
534 (bInetError ? FORMAT_MESSAGE_FROM_HMODULE : FORMAT_MESSAGE_FROM_SYSTEM),
535 (bInetError ? GetModuleHandleW(L"wininet.dll") : NULL),
535 dwLastError,
536 LANG_USER_DEFAULT,
537 (LPWSTR)&lpMsg,
538 0, NULL))
539 {
536 dwLastError,
537 LANG_USER_DEFAULT,
538 (LPWSTR)&lpMsg,
539 0, NULL))
540 {
540 return;
541 DPRINT1("FormatMessageW unexpected failure (err %d)\n", GetLastError());
542 return FALSE;
541 }
542
543 MessageBoxW(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR);
543 }
544
545 MessageBoxW(hWndOwner, lpMsg, NULL, MB_OK | MB_ICONERROR);
546 return TRUE;
544}
545
546unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
547{
548 ATL::CStringW Path;
549 PWSTR p, q;
550
551 HWND hDlg = static_cast<DownloadParam*>(param)->Dialog;

--- 39 unchanged lines hidden (view full) ---

591 ProgressBar.SendMessage(PBM_SETPOS, 0, 0);
592 }
593
594 // is this URL an update package for RAPPS? if so store it in a different place
595 if (InfoArray[iAppId].DLType != DLTYPE_APPLICATION)
596 {
597 if (!GetStorageDirectory(Path))
598 {
547}
548
549unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
550{
551 ATL::CStringW Path;
552 PWSTR p, q;
553
554 HWND hDlg = static_cast<DownloadParam*>(param)->Dialog;

--- 39 unchanged lines hidden (view full) ---

594 ProgressBar.SendMessage(PBM_SETPOS, 0, 0);
595 }
596
597 // is this URL an update package for RAPPS? if so store it in a different place
598 if (InfoArray[iAppId].DLType != DLTYPE_APPLICATION)
599 {
600 if (!GetStorageDirectory(Path))
601 {
599 ShowLastError(hMainWnd, GetLastError());
602 ShowLastError(hMainWnd, FALSE, GetLastError());
600 goto end;
601 }
602 }
603 else
604 {
605 Path = SettingsInfo.szDownloadDir;
606 }
607

--- 33 unchanged lines hidden (view full) ---

641 if (q && q > p && (q - p) > 0)
642 filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
643
644 // is the path valid? can we access it?
645 if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
646 {
647 if (!CreateDirectoryW(Path.GetString(), NULL))
648 {
603 goto end;
604 }
605 }
606 else
607 {
608 Path = SettingsInfo.szDownloadDir;
609 }
610

--- 33 unchanged lines hidden (view full) ---

644 if (q && q > p && (q - p) > 0)
645 filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
646
647 // is the path valid? can we access it?
648 if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
649 {
650 if (!CreateDirectoryW(Path.GetString(), NULL))
651 {
649 ShowLastError(hMainWnd, GetLastError());
652 ShowLastError(hMainWnd, FALSE, GetLastError());
650 goto end;
651 }
652 }
653
654 // append a \ to the provided file system path, and the filename portion from the URL after that
655
656 PathAddBackslashW(Path.GetBuffer(MAX_PATH));
657 switch (InfoArray[iAppId].DLType)

--- 37 unchanged lines hidden (view full) ---

695 break;
696 case 2: // use proxy
697 hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0);
698 break;
699 }
700
701 if (!hOpen)
702 {
653 goto end;
654 }
655 }
656
657 // append a \ to the provided file system path, and the filename portion from the URL after that
658
659 PathAddBackslashW(Path.GetBuffer(MAX_PATH));
660 switch (InfoArray[iAppId].DLType)

--- 37 unchanged lines hidden (view full) ---

698 break;
699 case 2: // use proxy
700 hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0);
701 break;
702 }
703
704 if (!hOpen)
705 {
703 ShowLastError(hMainWnd, GetLastError());
706 ShowLastError(hMainWnd, TRUE, GetLastError());
704 goto end;
705 }
706
707 dwStatusLen = sizeof(dwStatus);
708
709 memset(&urlComponents, 0, sizeof(urlComponents));
710 urlComponents.dwStructSize = sizeof(urlComponents);
711
712 urlLength = InfoArray[iAppId].szUrl.GetLength();
713 urlComponents.dwSchemeLength = urlLength + 1;
714 urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
715
716 if (!InternetCrackUrlW(InfoArray[iAppId].szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
717 {
707 goto end;
708 }
709
710 dwStatusLen = sizeof(dwStatus);
711
712 memset(&urlComponents, 0, sizeof(urlComponents));
713 urlComponents.dwStructSize = sizeof(urlComponents);
714
715 urlLength = InfoArray[iAppId].szUrl.GetLength();
716 urlComponents.dwSchemeLength = urlLength + 1;
717 urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
718
719 if (!InternetCrackUrlW(InfoArray[iAppId].szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
720 {
718 ShowLastError(hMainWnd, GetLastError());
721 ShowLastError(hMainWnd, TRUE, GetLastError());
719 goto end;
720 }
721
722 dwContentLen = 0;
723
724 if (urlComponents.nScheme == INTERNET_SCHEME_HTTP ||
725 urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
726 {
727 hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
728 dwUrlConnectFlags,
729 0);
730 if (!hFile)
731 {
722 goto end;
723 }
724
725 dwContentLen = 0;
726
727 if (urlComponents.nScheme == INTERNET_SCHEME_HTTP ||
728 urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
729 {
730 hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
731 dwUrlConnectFlags,
732 0);
733 if (!hFile)
734 {
732 ShowLastError(hMainWnd, GetLastError());
735 if (!ShowLastError(hMainWnd, TRUE, GetLastError()))
736 {
737 /* Workaround for CORE-17377 */
738 MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
739 }
733 goto end;
734 }
735
736 // query connection
737 if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
738 {
740 goto end;
741 }
742
743 // query connection
744 if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
745 {
739 ShowLastError(hMainWnd, GetLastError());
746 ShowLastError(hMainWnd, TRUE, GetLastError());
740 goto end;
741 }
742
743 if (dwStatus != HTTP_STATUS_OK)
744 {
745 MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
746 goto end;
747 }

--- 4 unchanged lines hidden (view full) ---

752 else if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
753 {
754 // force passive mode on FTP
755 hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl, NULL, 0,
756 dwUrlConnectFlags | INTERNET_FLAG_PASSIVE,
757 0);
758 if (!hFile)
759 {
747 goto end;
748 }
749
750 if (dwStatus != HTTP_STATUS_OK)
751 {
752 MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
753 goto end;
754 }

--- 4 unchanged lines hidden (view full) ---

759 else if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
760 {
761 // force passive mode on FTP
762 hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl, NULL, 0,
763 dwUrlConnectFlags | INTERNET_FLAG_PASSIVE,
764 0);
765 if (!hFile)
766 {
760 ShowLastError(hMainWnd, GetLastError());
767 if (!ShowLastError(hMainWnd, TRUE, GetLastError()))
768 {
769 /* Workaround for CORE-17377 */
770 MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
771 }
761 goto end;
762 }
763
764 dwContentLen = FtpGetFileSize(hFile, &dwStatus);
765 }
766 else if (urlComponents.nScheme == INTERNET_SCHEME_FILE)
767 {
768 // Add support for the file scheme so testing locally is simpler

--- 4 unchanged lines hidden (view full) ---

773 if (SUCCEEDED(hr))
774 {
775 if (CopyFileW(LocalFilePath, Path, FALSE))
776 {
777 goto run;
778 }
779 else
780 {
772 goto end;
773 }
774
775 dwContentLen = FtpGetFileSize(hFile, &dwStatus);
776 }
777 else if (urlComponents.nScheme == INTERNET_SCHEME_FILE)
778 {
779 // Add support for the file scheme so testing locally is simpler

--- 4 unchanged lines hidden (view full) ---

784 if (SUCCEEDED(hr))
785 {
786 if (CopyFileW(LocalFilePath, Path, FALSE))
787 {
788 goto run;
789 }
790 else
791 {
781 ShowLastError(hMainWnd, GetLastError());
792 ShowLastError(hMainWnd, FALSE, GetLastError());
782 goto end;
783 }
784 }
785 else
786 {
793 goto end;
794 }
795 }
796 else
797 {
787 ShowLastError(hMainWnd, hr);
798 ShowLastError(hMainWnd, FALSE, hr);
788 goto end;
789 }
790 }
791
792 if (!dwContentLen)
793 {
794 // Someone was nice enough to add this, let's use it
795 if (InfoArray[iAppId].SizeInBytes)

--- 41 unchanged lines hidden (view full) ---

837 }
838 }
839#endif
840
841 hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
842
843 if (hOut == INVALID_HANDLE_VALUE)
844 {
799 goto end;
800 }
801 }
802
803 if (!dwContentLen)
804 {
805 // Someone was nice enough to add this, let's use it
806 if (InfoArray[iAppId].SizeInBytes)

--- 41 unchanged lines hidden (view full) ---

848 }
849 }
850#endif
851
852 hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
853
854 if (hOut == INVALID_HANDLE_VALUE)
855 {
845 ShowLastError(hMainWnd, GetLastError());
856 ShowLastError(hMainWnd, FALSE, GetLastError());
846 goto end;
847 }
848
849 dwCurrentBytesRead = 0;
850 do
851 {
852 if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
853 {
857 goto end;
858 }
859
860 dwCurrentBytesRead = 0;
861 do
862 {
863 if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
864 {
854 ShowLastError(hMainWnd, GetLastError());
865 ShowLastError(hMainWnd, TRUE, GetLastError());
855 goto end;
856 }
857
858 if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
859 {
866 goto end;
867 }
868
869 if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
870 {
860 ShowLastError(hMainWnd, GetLastError());
871 ShowLastError(hMainWnd, FALSE, GetLastError());
861 goto end;
862 }
863
864 dwCurrentBytesRead += dwBytesRead;
865 if (!IsWindow(hDlg)) goto end;
866 UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
867 } while (dwBytesRead && !bCancelled);
868

--- 73 unchanged lines hidden (view full) ---

942 DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_INSTALLING);
943
944 //TODO: issue an install operation separately so that the apps could be downloaded in the background
945 WaitForSingleObject(shExInfo.hProcess, INFINITE);
946 CloseHandle(shExInfo.hProcess);
947 }
948 else
949 {
872 goto end;
873 }
874
875 dwCurrentBytesRead += dwBytesRead;
876 if (!IsWindow(hDlg)) goto end;
877 UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
878 } while (dwBytesRead && !bCancelled);
879

--- 73 unchanged lines hidden (view full) ---

953 DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_INSTALLING);
954
955 //TODO: issue an install operation separately so that the apps could be downloaded in the background
956 WaitForSingleObject(shExInfo.hProcess, INFINITE);
957 CloseHandle(shExInfo.hProcess);
958 }
959 else
960 {
950 ShowLastError(hMainWnd, GetLastError());
961 ShowLastError(hMainWnd, FALSE, GetLastError());
951 }
952 }
953
954end:
955 if (hOut != INVALID_HANDLE_VALUE)
956 CloseHandle(hOut);
957
958 if (hFile)

--- 76 unchanged lines hidden ---
962 }
963 }
964
965end:
966 if (hOut != INVALID_HANDLE_VALUE)
967 CloseHandle(hOut);
968
969 if (hFile)

--- 76 unchanged lines hidden ---