summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a07765f)
raw | patch | inline | side by side (parent: a07765f)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 12 Oct 2019 22:04:56 +0000 (01:04 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 12 Oct 2019 22:15:53 +0000 (01:15 +0300) |
src/game/g_res_downloader.pas | patch | blob | history |
index 961a84c99260bfac880e028fde712135fc07435d..098e0dd706313aa02bc4a6037541bd241f66f21b 100644 (file)
end;
+//==========================================================================
+//
+// generateFileName
+//
+// generate new file name based on the given one and the hash
+// you can pass files with pathes here too
+//
+//==========================================================================
+function generateFileName (fname: AnsiString; const hash: TMD5Digest): AnsiString;
+var
+ mds: AnsiString;
+ path: AnsiString;
+ base: AnsiString;
+ ext: AnsiString;
+begin
+ mds := MD5Print(hash);
+ if (length(mds) > 16) then mds := Copy(mds, 1, 16);
+ mds := '_'+mds;
+ if (length(fname) = 0) then begin result := mds; exit; end;
+ path := ExtractFilePath(fname);
+ base := ExtractFileName(fname);
+ ext := getFilenameExt(base);
+ base := forceFilenameExt(base, '');
+ if (length(path) > 0) then result := IncludeTrailingPathDelimiter(path) else result := '';
+ result := result+base+mds+ext;
+end;
+
+
//==========================================================================
//
// g_Res_DownloadMapWAD
CreateDir(GameDir+'/maps/downloads');
except
end;
- fname := GameDir+'/maps/downloads/'+FileName;
+ fname := GameDir+'/maps/downloads/'+generateFileName(FileName, mapHash);
+ tf.diskName := fname;
try
strm := openDiskFileRW(fname);
except
result := '';
exit;
end;
- tf.diskName := fname;
try
res := g_Net_ReceiveResourceFile(-1{map}, tf, strm);
except
CreateDir(GameDir+'/wads/downloads');
except
end;
- fname := GameDir+'/wads/downloads/'+tf.diskName;
+ fname := GameDir+'/wads/downloads/'+generateFileName(tf.diskName, tf.hash);
e_LogWritefln('downloading resource `%s` to `%s`...', [tf.diskName, fname]);
try
strm := openDiskFileRW(fname);