@@ -144,6 +144,10 @@ struct DownloadInfo
144144 IType = AppInfo.GetInstallerType ();
145145 if (IType == INSTALLER_GENERATE)
146146 szPackageName = AppInfo.szIdentifier ;
147+
148+ CConfigParser *cfg = static_cast <const CAvailableApplicationInfo&>(AppInfo).GetConfigParser ();
149+ if (cfg)
150+ cfg->GetString (DB_SAVEAS, szFileName);
147151 }
148152
149153 bool Equal (const DownloadInfo &other) const
@@ -157,6 +161,7 @@ struct DownloadInfo
157161 CStringW szName;
158162 CStringW szSHA1;
159163 CStringW szPackageName;
164+ CStringW szFileName;
160165 ULONG SizeInBytes;
161166};
162167
@@ -719,7 +724,7 @@ CDownloadManager::PerformDownloadAndInstall(const DownloadInfo &Info)
719724
720725 CStringW str;
721726 CPathW Path;
722- PCWSTR p, q ;
727+ PCWSTR p;
723728
724729 ULONG dwContentLen, dwBytesWritten, dwBytesRead, dwStatus, dwStatusLen;
725730 ULONG dwCurrentBytesRead = 0 ;
@@ -734,7 +739,7 @@ CDownloadManager::PerformDownloadAndInstall(const DownloadInfo &Info)
734739 const DWORD dwUrlConnectFlags =
735740 INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION;
736741 URL_COMPONENTSW urlComponents;
737- size_t urlLength, filenameLength ;
742+ size_t urlLength;
738743 unsigned char lpBuffer[4096 ];
739744
740745 // Change caption to show the currently downloaded app
@@ -768,7 +773,6 @@ CDownloadManager::PerformDownloadAndInstall(const DownloadInfo &Info)
768773
769774 // build the path for the download
770775 p = wcsrchr (Info.szUrl .GetString (), L' /' );
771- q = wcsrchr (Info.szUrl .GetString (), L' ?' );
772776
773777 // do we have a final slash separator?
774778 if (!p)
@@ -777,14 +781,6 @@ CDownloadManager::PerformDownloadAndInstall(const DownloadInfo &Info)
777781 goto end;
778782 }
779783
780- // prepare the tentative length of the filename, maybe we've to remove part of it later on
781- filenameLength = wcslen (p) * sizeof (WCHAR);
782-
783- /* do we have query arguments in the target URL after the filename? account for them
784- (e.g. https://example.org/myfile.exe?no_adware_plz) */
785- if (q && q > p && (q - p) > 0 )
786- filenameLength -= wcslen (q - 1 ) * sizeof (WCHAR);
787-
788784 // is the path valid? can we access it?
789785 if (GetFileAttributesW (Path) == INVALID_FILE_ATTRIBUTES)
790786 {
@@ -803,9 +799,11 @@ CDownloadManager::PerformDownloadAndInstall(const DownloadInfo &Info)
803799 break ;
804800 case DLTYPE_APPLICATION:
805801 {
806- CStringW str = p + 1 ; // use the filename retrieved from URL
807- UrlUnescapeAndMakeFileNameValid (str);
808- Path += str;
802+ CStringW name = Info.szFileName ;
803+ if (name.IsEmpty ())
804+ name = p + 1 ; // use the filename retrieved from URL
805+ UrlUnescapeAndMakeFileNameValid (name);
806+ Path += name;
809807 break ;
810808 }
811809 }
0 commit comments