Skip to content

Commit a23db39

Browse files
authored
[RAPPS] Allow database to override download filename (reactos#7668)
http://example.com/setup.exe?foo=bar needs to use be able to use setup.exe as the filename.
1 parent 7e52f64 commit a23db39

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

base/applications/rapps/include/appinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ enum InstallerType
8282
#define DB_REGNAME L"RegName"
8383
#define DB_INSTALLER L"Installer"
8484
#define DB_SCOPE L"Scope" // User or Machine
85+
#define DB_SAVEAS L"SaveAs"
8586

8687
#define DB_GENINSTSECTION L"Generate"
8788
#define GENERATE_ARPSUBKEY L"RApps" // Our uninstall data is stored here

base/applications/rapps/loaddlg.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)