DaoxImage* DaoxResource_LoadImage( DaoxResource *self, DString *fname, DString *path ) { DaoxImage *image = NULL; DString *file = DString_Copy( fname ); DString *source = DString_New(); DString_Change( file, "\\\\", "/", 0 ); DString_Change( file, "\\", "/", 0 ); if( DaoxResource_SearchFile( self, file, path ) ){ DNode *it = DMap_Find( self->images, file ); if( it != NULL ){ image = (DaoxImage*) it->value.pValue; }else if( DaoxResource_ReadFile( self, file, source ) ){ image = DaoxImage_New(); DaoxImage_Decode( image, source ); DMap_Insert( self->images, file, image ); } } DString_Delete( source ); DString_Delete( file ); return image; }
void DString_MakePath( DString *base, DString *path ) { if( base->size == 0 ) return; if( path->size >= 2 && path->chars[0] == '$' && path->chars[1] == '(' ) return; if( path->size >= 2 && isalpha( path->chars[0] ) && path->chars[1] == ':' ) return; if( path->chars[0] == '/' ) return; base = DString_Copy( base ); Dao_NormalizePathSep( base ); Dao_NormalizePathSep( path ); while( DString_Match( path, " ^ %.%. / ", NULL, NULL ) ){ if( DString_Match( base, " [^/] + ( / | ) $ ", NULL, NULL ) ){ DString_Change( path, " ^ %.%. / ", "", 1 ); DString_Change( base, " [^/] + ( / |) $ ", "", 0 ); }else{ DString_Delete( base ); return; } } if( DString_Match( path, " ^ %.%. $ ", NULL, NULL ) ){ if( DString_Match( base, " [^/] + ( / | ) $ ", NULL, NULL ) ){ DString_Clear( path ); DString_Change( base, " [^/] + ( / |) $ ", "", 0 ); } } if( base->size && path->size ){ if( base->chars[ base->size-1 ] != '/' && path->chars[0] != '/' ) DString_InsertChar( path, '/', 0 ); DString_Insert( path, base, 0, 0, 0 ); }else if( base->size && path->size == 0 ){ DString_Assign( path, base ); } while( DString_Change( path, "/ %. (/|$)", "/", 0 ) ); DString_Delete( base ); }
void Dao_NormalizePathSep( DString *path ) { #ifdef _WIN32 DString_Change( path, "\\", "/", 0 ); #endif }