add and use class PathExtensionless

This commit is contained in:
Garux 2021-01-21 15:15:07 +03:00
parent 7fc079c658
commit 8b204ac054
7 changed files with 27 additions and 21 deletions

View File

@ -207,6 +207,21 @@ inline MatchFileExtension<Functor> matchFileExtension( const char* extension, co
return MatchFileExtension<Functor>( extension, functor );
}
class PathExtensionless
{
public:
const char* m_path;
PathExtensionless( const char* path ) : m_path( path ){
}
};
/// \brief Writes \p path to \p ostream without .ext part.
template<typename TextOutputStreamType>
TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const PathExtensionless& path ){
ostream << StringRange( path.m_path, path_get_filename_base_end( path.m_path ) );
return ostream;
}
class PathCleaned
{
public:

View File

@ -2351,7 +2351,7 @@ void map_autocaulk_selected(){
ScopeDisableScreenUpdates disableScreenUpdates( "processing", "autocaulk" );
StringOutputStream filename( 256 );
filename << StringRange( g_map.m_name.c_str(), path_get_filename_base_end( g_map.m_name.c_str() ) ) << "_ac.map";
filename << PathExtensionless( g_map.m_name.c_str() ) << "_ac.map";
{// write .map
const Vector3 spawn( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ) );
@ -2463,7 +2463,7 @@ void map_autocaulk_selected(){
CaulkMap map;
{ // load
filename.clear();
filename << StringRange( g_map.m_name.c_str(), path_get_filename_base_end( g_map.m_name.c_str() ) ) << "_ac.caulk";
filename << PathExtensionless( g_map.m_name.c_str() ) << "_ac.caulk";
TextFileInputStream file( filename.c_str() );
if( file.failed() ){

View File

@ -174,9 +174,7 @@ void CPointfile::GenerateDisplayList(){
void Pointfile_Delete( void ){
const char* mapname = Map_Name( g_map );
StringOutputStream name( 256 );
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".lin";
file_remove( name.c_str() );
file_remove( StringOutputStream( 256 )( PathExtensionless( mapname ), ".lin" ).c_str() );
}
@ -258,14 +256,14 @@ void Pointfile_Parse( CPointfile& pointfile ){
const char* mapname = Map_Name( g_map );
StringOutputStream name( 256 );
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".lin";
name << PathExtensionless( mapname ) << ".lin";
size = LoadFile( name.c_str(), (void**)&data );
if ( size == -1 ) {
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
/* try .pts (q1) */
name.clear();
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".pts";
name << PathExtensionless( mapname ) << ".pts";
size = LoadFile( name.c_str(), (void**)&data );
if ( size == -1 ) {
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";

View File

@ -173,15 +173,11 @@ void bsp_init(){
const char* mapname = Map_Name( g_map );
{
StringOutputStream name( 256 );
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp";
build_set_variable( "BspFile", name.c_str() );
build_set_variable( "BspFile", StringOutputStream( 256 )( PathExtensionless( mapname ), ".bsp" ).c_str() );
}
if( g_region_active ){
StringOutputStream name( 256 );
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".reg";
build_set_variable( "MapFile", name.c_str() );
build_set_variable( "MapFile", StringOutputStream( 256 )( PathExtensionless( mapname ), ".reg" ).c_str() );
}
else{
build_set_variable( "MapFile", mapname );
@ -272,9 +268,7 @@ void RunBSP( const char* name ){
if ( g_region_active ) {
const char* mapname = Map_Name( g_map );
StringOutputStream name( 256 );
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".reg";
Map_SaveRegion( name.c_str() );
Map_SaveRegion( StringOutputStream( 256 )( PathExtensionless( mapname ), ".reg" ).c_str() );
}
Pointfile_Delete();

View File

@ -740,8 +740,7 @@ void operator()( const char* name ) const {
};
void TextureDirectory_loadTexture( const char* directory, const char* texture ){
StringOutputStream name( 256 );
name << directory << StringRange( texture, path_get_filename_base_end( texture ) );
const auto name = StringOutputStream( 256 )( directory, PathExtensionless( texture ) );
if ( texture_name_ignore( name.c_str() ) ) {
return;

View File

@ -1384,7 +1384,7 @@ void BackgroundImage::set( const VIEWTYPE viewtype ){
free_tex();
const char *filename = background_image_dialog();
if( filename ){
const auto filename_noext = StringOutputStream( 256 )( StringRange( filename, path_get_filename_base_end( filename ) ) );
const auto filename_noext = StringOutputStream( 256 )( PathExtensionless( filename ) );
Image *image = QERApp_LoadImage( 0, filename_noext.c_str() );
if ( !image ) {
globalErrorStream() << "Could not load texture " << filename_noext.c_str() << "\n";

View File

@ -244,11 +244,11 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, const
}
/* load skin file */
auto skinfilename = StringOutputStream(99)( StringRange( name, path_get_filename_base_end( name ) ), '_', skin, ".skin" );
auto skinfilename = StringOutputStream(99)( PathExtensionless( name ), '_', skin, ".skin" );
skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 );
if ( skinfilesize < 0 && skin != 0 ) {
/* fallback to skin 0 if invalid */
skinfilename( StringRange( name, path_get_filename_base_end( name ) ), "_0.skin" );
skinfilename( PathExtensionless( name ), "_0.skin" );
skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 );
if ( skinfilesize >= 0 ) {
Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );