minor refactoring

This commit is contained in:
Garux 2020-05-05 12:32:44 +03:00
parent 13f877b7db
commit 002f45d6d9
2 changed files with 20 additions and 21 deletions

View File

@ -232,6 +232,7 @@ DirectoryCleaned( const char* path ) : m_path( path ){
template<typename TextOutputStreamType> template<typename TextOutputStreamType>
TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const DirectoryCleaned& path ){ TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const DirectoryCleaned& path ){
const char* i = path.m_path; const char* i = path.m_path;
if( !string_empty( i ) ){
for (; *i != '\0'; ++i ) for (; *i != '\0'; ++i )
{ {
if ( *i == '\\' ) { if ( *i == '\\' ) {
@ -242,10 +243,11 @@ TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const Direct
ostream << *i; ostream << *i;
} }
} }
char c = *( i - 1 ); --i;
if ( c != '/' && c != '\\' && !string_empty( path.m_path ) ) { if ( *i != '/' && *i != '\\' ) {
ostream << '/'; ostream << '/';
} }
}
return ostream; return ostream;
} }

View File

@ -1151,22 +1151,20 @@ public:
// parse string of format *pathToLoad/depth*path2ToLoad/depth* // parse string of format *pathToLoad/depth*path2ToLoad/depth*
// */depth* for root path // */depth* for root path
ModelFolders( const char* pathsString ){ ModelFolders( const char* pathsString ){
char* str = strdup( pathsString ); StringOutputStream str( 128 );
for( char* s = str; *s; ++s ) str << PathCleaned( pathsString );
if( *s == '\\' )
*s = '/';
char* start = str; const char* start = str.c_str();
while( 1 ){ while( 1 ){
while( *start == '*' ) while( *start == '*' )
++start; ++start;
char* end = start; const char* end = start;
while( *end && *end != '*' ) while( *end && *end != '*' )
++end; ++end;
if( start == end ) if( start == end )
break; break;
char* slash = nullptr; const char* slash = nullptr;
for( char* s = start; s != end; ++s ) for( const char* s = start; s != end; ++s )
if( *s == '/' ) if( *s == '/' )
slash = s; slash = s;
if( slash != nullptr && end - slash > 1 ){ if( slash != nullptr && end - slash > 1 ){
@ -1178,7 +1176,6 @@ public:
start = end; start = end;
} }
free( str );
if( m_modelFoldersMap.empty() ) if( m_modelFoldersMap.empty() )
m_modelFoldersMap.emplace( "models/", 99 ); m_modelFoldersMap.emplace( "models/", 99 );
} }
@ -1314,7 +1311,7 @@ GtkWidget* ModelBrowser_constructWindow( GtkWindow* toplevel ){
gtk_table_attach( GTK_TABLE( table ), w, 2, 3, 0, 1, GTK_SHRINK, GTK_FILL, 0, 0 ); gtk_table_attach( GTK_TABLE( table ), w, 2, 3, 0, 1, GTK_SHRINK, GTK_FILL, 0, 0 );
gtk_widget_show( w ); gtk_widget_show( w );
GtkAdjustment *vadjustment = gtk_range_get_adjustment( GTK_RANGE( g_ModelBrowser.m_gl_scroll ) ); GtkAdjustment *vadjustment = gtk_range_get_adjustment( GTK_RANGE( w ) );
g_signal_connect( G_OBJECT( vadjustment ), "value_changed", G_CALLBACK( ModelBrowser_scrollbarScroll ), &g_ModelBrowser ); g_signal_connect( G_OBJECT( vadjustment ), "value_changed", G_CALLBACK( ModelBrowser_scrollbarScroll ), &g_ModelBrowser );
} }
{ // gl_widget { // gl_widget