From: Ketmar Dark Date: Sat, 12 Oct 2019 22:04:56 +0000 (+0300) Subject: net: append part of md5 file hash to downloaded wads, so wads with the same names... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=782be84c041a01f0255ce718e2b5757d31e5c0d9;p=d2df-sdl.git net: append part of md5 file hash to downloaded wads, so wads with the same names won't conflict --- diff --git a/src/game/g_res_downloader.pas b/src/game/g_res_downloader.pas index 961a84c..098e0dd 100644 --- a/src/game/g_res_downloader.pas +++ b/src/game/g_res_downloader.pas @@ -366,6 +366,34 @@ begin 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 @@ -422,7 +450,8 @@ begin 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 @@ -430,7 +459,6 @@ begin result := ''; exit; end; - tf.diskName := fname; try res := g_Net_ReceiveResourceFile(-1{map}, tf, strm); except @@ -508,7 +536,7 @@ begin 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);