[RAPPS] Use FTP in passive mode
[reactos.git] / base / applications / rapps / loaddlg.cpp
index 30aa4a2..fe9ec04 100644 (file)
@@ -48,7 +48,7 @@
 
 #ifdef USE_CERT_PINNING
 #define CERT_ISSUER_INFO "US\r\nLet's Encrypt\r\nLet's Encrypt Authority X3"
-#define CERT_SUBJECT_INFO "svn.reactos.org"
+#define CERT_SUBJECT_INFO "rapps.reactos.org"
 #endif
 
 enum DownloadStatus
@@ -603,6 +603,8 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
     LPCWSTR szCaption = static_cast<DownloadParam*>(param)->szCaption;
     ATL::CStringW szNewCaption;
 
+    const DWORD dwUrlConnectFlags = INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION;
+
     if (InfoArray.GetSize() <= 0)
     {
         MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
@@ -709,25 +711,6 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
         if (!hOpen)
             goto end;
 
-        hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
-                                 INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION,
-                                 0);
-
-        if (!hFile)
-        {
-            MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
-            goto end;
-        }
-
-        if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
-            goto end;
-
-        if (dwStatus != HTTP_STATUS_OK)
-        {
-            MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
-            goto end;
-        }
-
         dwStatusLen = sizeof(dwStatus);
 
         memset(&urlComponents, 0, sizeof(urlComponents));
@@ -745,10 +728,44 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
         dwContentLen = 0;
 
         if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
-            HttpQueryInfoW(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatusLen, 0);
+        {
+            hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
+                                     dwUrlConnectFlags,
+                                     0);
+            if (!hFile)
+            {
+                MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
+                goto end;
+            }
+
+            // query connection
+            if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
+                goto end;
+
+            if (dwStatus != HTTP_STATUS_OK)
+            {
+                MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
+                goto end;
+            }
+
+            // query content length
+            HttpQueryInfoW(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatusLen, NULL);
+        }
 
         if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
+        {
+            // force passive mode on FTP
+            hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
+                                     dwUrlConnectFlags | INTERNET_FLAG_PASSIVE,
+                                     0);
+            if (!hFile)
+            {
+                MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
+                goto end;
+            }
+
             dwContentLen = FtpGetFileSize(hFile, &dwStatus);
+        }
 
         if (!dwContentLen)
         {