MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / RibbitDownloadFile

Function RibbitDownloadFile

src/External/CascLib/src/CascFiles.cpp:1134–1197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1132}
1133
1134static DWORD RibbitDownloadFile(LPCTSTR szCdnHostUrl, LPCTSTR szProduct, LPCTSTR szFileName, CASC_PATH<TCHAR> & LocalPath, CASC_BLOB & FileData)
1135{
1136 CASC_PATH<TCHAR> LocalFile;
1137 TFileStream * pStream;
1138 ULONGLONG FileSize = 0;
1139 TCHAR szRemoteUrl[256];
1140 DWORD dwErrCode = ERROR_CAN_NOT_COMPLETE;
1141
1142 // If required, try to load the local name first
1143 if(LocalPath.Length() && LocalPath.LocalCaching())
1144 {
1145 // Load the local file into memory
1146 if((dwErrCode = LoadFileToMemory(LocalPath, FileData)) == ERROR_SUCCESS)
1147 {
1148 // Pass the file data to the caller
1149 return ERROR_SUCCESS;
1150 }
1151 }
1152
1153 // Supply the default CDN URL, if not present
1154 if(szCdnHostUrl == NULL || szCdnHostUrl[0] == 0)
1155 szCdnHostUrl = szDefaultCDN;
1156
1157 // Construct the full URL (https://wowdev.wiki/Ribbit)
1158 // Old (HTTP) download: wget http://us.patch.battle.net:1119/wow_classic/cdns
1159 CascStrPrintf(szRemoteUrl, _countof(szRemoteUrl), _T("%s/%s/%s"), szCdnHostUrl, szProduct, szFileName);
1160
1161 // Open the file stream
1162 if((pStream = FileStream_OpenFile(szRemoteUrl, 0)) != NULL)
1163 {
1164 if(FileStream_GetSize(pStream, &FileSize) && FileSize <= 0x04000000)
1165 {
1166 // Fill-in the file pointer and size
1167 if((dwErrCode = FileData.SetSize((size_t)FileSize)) == ERROR_SUCCESS)
1168 {
1169 if(FileStream_Read(pStream, NULL, FileData.pbData, (DWORD)FileSize))
1170 {
1171 dwErrCode = ERROR_SUCCESS;
1172 }
1173 else
1174 {
1175 dwErrCode = GetCascError();
1176 FileData.Free();
1177 }
1178 }
1179 }
1180 else
1181 {
1182 dwErrCode = GetCascError();
1183 }
1184
1185 // Close the remote stream
1186 FileStream_Close(pStream);
1187 }
1188 else
1189 {
1190 dwErrCode = GetCascError();
1191 }

Callers 2

LoadCsvFileFunction · 0.85
CascCdnDownloadFunction · 0.85

Calls 12

LoadFileToMemoryFunction · 0.85
CascStrPrintfFunction · 0.85
FileStream_OpenFileFunction · 0.85
FileStream_GetSizeFunction · 0.85
FileStream_ReadFunction · 0.85
GetCascErrorFunction · 0.85
FileStream_CloseFunction · 0.85
SaveLocalFileFunction · 0.85
LocalCachingMethod · 0.80
SetSizeMethod · 0.80
LengthMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected