add and use class PathExtensionless
This commit is contained in:
parent
7fc079c658
commit
8b204ac054
|
|
@ -207,6 +207,21 @@ inline MatchFileExtension<Functor> matchFileExtension( const char* extension, co
|
||||||
return MatchFileExtension<Functor>( extension, functor );
|
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
|
class PathCleaned
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -2351,7 +2351,7 @@ void map_autocaulk_selected(){
|
||||||
ScopeDisableScreenUpdates disableScreenUpdates( "processing", "autocaulk" );
|
ScopeDisableScreenUpdates disableScreenUpdates( "processing", "autocaulk" );
|
||||||
|
|
||||||
StringOutputStream filename( 256 );
|
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
|
{// write .map
|
||||||
const Vector3 spawn( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ) );
|
const Vector3 spawn( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ) );
|
||||||
|
|
@ -2463,7 +2463,7 @@ void map_autocaulk_selected(){
|
||||||
CaulkMap map;
|
CaulkMap map;
|
||||||
{ // load
|
{ // load
|
||||||
filename.clear();
|
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() );
|
TextFileInputStream file( filename.c_str() );
|
||||||
if( file.failed() ){
|
if( file.failed() ){
|
||||||
|
|
|
||||||
|
|
@ -174,9 +174,7 @@ void CPointfile::GenerateDisplayList(){
|
||||||
|
|
||||||
void Pointfile_Delete( void ){
|
void Pointfile_Delete( void ){
|
||||||
const char* mapname = Map_Name( g_map );
|
const char* mapname = Map_Name( g_map );
|
||||||
StringOutputStream name( 256 );
|
file_remove( StringOutputStream( 256 )( PathExtensionless( mapname ), ".lin" ).c_str() );
|
||||||
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".lin";
|
|
||||||
file_remove( name.c_str() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -258,14 +256,14 @@ void Pointfile_Parse( CPointfile& pointfile ){
|
||||||
|
|
||||||
const char* mapname = Map_Name( g_map );
|
const char* mapname = Map_Name( g_map );
|
||||||
StringOutputStream name( 256 );
|
StringOutputStream name( 256 );
|
||||||
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".lin";
|
name << PathExtensionless( mapname ) << ".lin";
|
||||||
|
|
||||||
size = LoadFile( name.c_str(), (void**)&data );
|
size = LoadFile( name.c_str(), (void**)&data );
|
||||||
if ( size == -1 ) {
|
if ( size == -1 ) {
|
||||||
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
|
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
|
||||||
/* try .pts (q1) */
|
/* try .pts (q1) */
|
||||||
name.clear();
|
name.clear();
|
||||||
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".pts";
|
name << PathExtensionless( mapname ) << ".pts";
|
||||||
size = LoadFile( name.c_str(), (void**)&data );
|
size = LoadFile( name.c_str(), (void**)&data );
|
||||||
if ( size == -1 ) {
|
if ( size == -1 ) {
|
||||||
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
|
globalErrorStream() << "Pointfile " << name.c_str() << " not found\n";
|
||||||
|
|
|
||||||
|
|
@ -173,15 +173,11 @@ void bsp_init(){
|
||||||
|
|
||||||
const char* mapname = Map_Name( g_map );
|
const char* mapname = Map_Name( g_map );
|
||||||
{
|
{
|
||||||
StringOutputStream name( 256 );
|
build_set_variable( "BspFile", StringOutputStream( 256 )( PathExtensionless( mapname ), ".bsp" ).c_str() );
|
||||||
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp";
|
|
||||||
build_set_variable( "BspFile", name.c_str() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( g_region_active ){
|
if( g_region_active ){
|
||||||
StringOutputStream name( 256 );
|
build_set_variable( "MapFile", StringOutputStream( 256 )( PathExtensionless( mapname ), ".reg" ).c_str() );
|
||||||
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".reg";
|
|
||||||
build_set_variable( "MapFile", name.c_str() );
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
build_set_variable( "MapFile", mapname );
|
build_set_variable( "MapFile", mapname );
|
||||||
|
|
@ -272,9 +268,7 @@ void RunBSP( const char* name ){
|
||||||
|
|
||||||
if ( g_region_active ) {
|
if ( g_region_active ) {
|
||||||
const char* mapname = Map_Name( g_map );
|
const char* mapname = Map_Name( g_map );
|
||||||
StringOutputStream name( 256 );
|
Map_SaveRegion( StringOutputStream( 256 )( PathExtensionless( mapname ), ".reg" ).c_str() );
|
||||||
name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".reg";
|
|
||||||
Map_SaveRegion( name.c_str() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pointfile_Delete();
|
Pointfile_Delete();
|
||||||
|
|
|
||||||
|
|
@ -740,8 +740,7 @@ void operator()( const char* name ) const {
|
||||||
};
|
};
|
||||||
|
|
||||||
void TextureDirectory_loadTexture( const char* directory, const char* texture ){
|
void TextureDirectory_loadTexture( const char* directory, const char* texture ){
|
||||||
StringOutputStream name( 256 );
|
const auto name = StringOutputStream( 256 )( directory, PathExtensionless( texture ) );
|
||||||
name << directory << StringRange( texture, path_get_filename_base_end( texture ) );
|
|
||||||
|
|
||||||
if ( texture_name_ignore( name.c_str() ) ) {
|
if ( texture_name_ignore( name.c_str() ) ) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1384,7 +1384,7 @@ void BackgroundImage::set( const VIEWTYPE viewtype ){
|
||||||
free_tex();
|
free_tex();
|
||||||
const char *filename = background_image_dialog();
|
const char *filename = background_image_dialog();
|
||||||
if( filename ){
|
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() );
|
Image *image = QERApp_LoadImage( 0, filename_noext.c_str() );
|
||||||
if ( !image ) {
|
if ( !image ) {
|
||||||
globalErrorStream() << "Could not load texture " << filename_noext.c_str() << "\n";
|
globalErrorStream() << "Could not load texture " << filename_noext.c_str() << "\n";
|
||||||
|
|
|
||||||
|
|
@ -244,11 +244,11 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, const
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load skin file */
|
/* 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 );
|
skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 );
|
||||||
if ( skinfilesize < 0 && skin != 0 ) {
|
if ( skinfilesize < 0 && skin != 0 ) {
|
||||||
/* fallback to skin 0 if invalid */
|
/* 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 );
|
skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 );
|
||||||
if ( skinfilesize >= 0 ) {
|
if ( skinfilesize >= 0 ) {
|
||||||
Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
|
Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user