Merge remote-tracking branch 'origin/master'

This commit is contained in:
Alibek Omarov
2026-05-07 13:50:55 +05:00
7 changed files with 68 additions and 42 deletions
+2 -2
View File
@@ -58,8 +58,8 @@ GNU General Public License for more details.
// path to saved games
#define DEFAULT_SAVE_DIRECTORY "save/"
// path to download games
#define DEFAULT_DOWNLOADED_DIRECTORY "downloaded/"
// goldsrc compatible suffix for downloads directory
#define DEFAULT_DOWNLOADED_DIRECTORY_SUFFIX "_downloads"
// path to user mod directory
#define DEFAULT_CUSTOM_DIRECTORY "custom/"
+25 -6
View File
@@ -101,6 +101,13 @@ static int HTTP_FileResolveNS( httpfile_t *file );
static int HTTP_FileSendRequest( httpfile_t *file );
static int HTTP_FileDecompress( httpfile_t *file );
static const char *HTTP_DownloadPath( char *buf, size_t buflen, const char *path, qboolean incomplete )
{
Q_snprintf( buf, buflen, "../%s" DEFAULT_DOWNLOADED_DIRECTORY_SUFFIX "/%s%s",
GI->gamefolder, path, incomplete ? ".incomplete" : "" );
return buf;
}
/*
==============
HTTP_FreeFile
@@ -110,7 +117,7 @@ Skip to next server/file
*/
static void HTTP_FreeFile( httpfile_t *file, qboolean error )
{
char incname[MAX_SYSPATH + 64]; // plus downloaded/ plus .incomplete
char incname[MAX_SYSPATH + 64]; // plus ../{gamedir}_downloads/ plus .incomplete
qboolean was_open = false;
file->blocktime = 0;
@@ -132,7 +139,7 @@ static void HTTP_FreeFile( httpfile_t *file, qboolean error )
file->socket = -1;
Q_snprintf( incname, sizeof( incname ), DEFAULT_DOWNLOADED_DIRECTORY "%s.incomplete", file->path );
HTTP_DownloadPath( incname, sizeof( incname ), file->path, true );
if( error )
{
@@ -149,7 +156,9 @@ static void HTTP_FreeFile( httpfile_t *file, qboolean error )
if( http_autoremove.value == 1 ) // remove broken file
{
Con_Printf( S_ERROR "no servers to download %s\n", file->path );
FS_AllowDirectPaths( true );
FS_Delete( incname );
FS_AllowDirectPaths( false );
}
else // autoremove disabled, keep file
{
@@ -161,14 +170,18 @@ static void HTTP_FreeFile( httpfile_t *file, qboolean error )
{
if( file->compressed )
{
FS_AllowDirectPaths( true );
FS_Delete( incname );
FS_AllowDirectPaths( false );
}
else
{
// Success, rename and process file
char name[MAX_SYSPATH];
Q_snprintf( name, sizeof( name ), DEFAULT_DOWNLOADED_DIRECTORY "%s", file->path );
HTTP_DownloadPath( name, sizeof( name ), file->path, false );
FS_AllowDirectPaths( true );
FS_Rename( incname, name );
FS_AllowDirectPaths( false );
}
}
@@ -195,9 +208,13 @@ static int HTTP_FileQueue( httpfile_t *file )
}
Con_Reportf( "HTTP: Starting download %s from %s:%d\n", file->path, file->server->host, file->server->port );
Q_snprintf( name, sizeof( name ), DEFAULT_DOWNLOADED_DIRECTORY "%s.incomplete", file->path );
HTTP_DownloadPath( name, sizeof( name ), file->path, true );
if( !( file->file = FS_Open( name, "wb+", true )))
FS_AllowDirectPaths( true );
file->file = FS_Open( name, "wb+", true );
FS_AllowDirectPaths( false );
if( !file->file )
{
Con_Printf( S_ERROR "HTTP: cannot open %s!\n", name );
HTTP_FreeFile( file, true );
@@ -458,7 +475,7 @@ static int HTTP_FileDecompress( httpfile_t *file )
data_in = Mem_Malloc( host.mempool, compressed_len + 1 );
data_out = Mem_Malloc( host.mempool, decompressed_len + 1 );
Q_snprintf( name, sizeof( name ), DEFAULT_DOWNLOADED_DIRECTORY "%s", file->path );
HTTP_DownloadPath( name, sizeof( name ), file->path, false );
memset( &decompress_stream, 0, sizeof( decompress_stream ));
decompress_stream.total_in = decompress_stream.avail_in = compressed_len;
@@ -483,7 +500,9 @@ static int HTTP_FileDecompress( httpfile_t *file )
if( zlib_result == Z_OK || zlib_result == Z_STREAM_END )
{
FS_AllowDirectPaths( true );
g_fsapi.WriteFile( name, data_out, decompressed_len );
FS_AllowDirectPaths( false );
HTTP_FreeFile( file, false );
}
else HTTP_FreeFile( file, true );
+17 -12
View File
@@ -1240,20 +1240,24 @@ qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg )
return false;
}
if( filename[0] != '!' )
{
string temp_filename;
Q_snprintf( temp_filename, sizeof( temp_filename ), DEFAULT_DOWNLOADED_DIRECTORY "%s", filename );
Q_strncpy( filename, temp_filename, sizeof( filename ));
}
Q_strncpy( chan->incomingfilename, filename, sizeof( chan->incomingfilename ));
if( filename[0] != '!' && FS_FileExists( filename, false ))
if( filename[0] != '!' )
{
Con_Printf( S_ERROR "can't download %s, already exists\n", filename );
Netchan_FlushIncoming( chan, FRAG_FILE_STREAM );
return true;
string write_path;
Q_snprintf( write_path, sizeof( write_path ), "../%s" DEFAULT_DOWNLOADED_DIRECTORY_SUFFIX "/%s", GI->gamefolder, filename );
Q_strncpy( filename, write_path, sizeof( filename ));
FS_AllowDirectPaths( true );
qboolean exists = FS_FileExists( filename, false );
FS_AllowDirectPaths( false );
if( exists )
{
Con_Printf( S_ERROR "can't download %s, already exists\n", filename );
Netchan_FlushIncoming( chan, FRAG_FILE_STREAM );
return true;
}
}
// create file from buffers
@@ -1339,8 +1343,9 @@ qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg )
}
else
{
// g-cont. it's will be stored downloaded files directly into game folder
FS_AllowDirectPaths( true );
FS_WriteFile( filename, buffer, nsize );
FS_AllowDirectPaths( false );
Mem_Free( buffer );
}