📄 theme_loader.cpp
字号:
{ newPath = newPath.replace( p, 1, sep ); p = newPath.find( "/", p + 1 ); } return newPath;}bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, string &themeFilePath ){ // Path separator const string &sep = OSFactory::instance( getIntf() )->getDirSeparator(); DIR *pCurrDir; struct dirent *pDirContent; // Open the dir pCurrDir = opendir( rootDir.c_str() ); if( pCurrDir == NULL ) { // An error occurred msg_Dbg( getIntf(), "cannot open directory %s", rootDir.c_str() ); return false; } // Get the first directory entry pDirContent = (dirent*)readdir( pCurrDir ); // While we still have entries in the directory while( pDirContent != NULL ) { string newURI = rootDir + sep + pDirContent->d_name; // Skip . and .. if( string( pDirContent->d_name ) != "." && string( pDirContent->d_name ) != ".." ) {#if defined( S_ISDIR ) struct stat stat_data; stat( newURI.c_str(), &stat_data ); if( S_ISDIR(stat_data.st_mode) )#elif defined( DT_DIR ) if( pDirContent->d_type & DT_DIR )#else if( 0 )#endif { // Can we find the file in this subdirectory? if( findFile( newURI, rFileName, themeFilePath ) ) { closedir( pCurrDir ); return true; } } else { // Found the theme file? if( rFileName == string( pDirContent->d_name ) ) { themeFilePath = sFromLocale( newURI ); closedir( pCurrDir ); return true; } } } pDirContent = (dirent*)readdir( pCurrDir ); } closedir( pCurrDir ); return false;}#if !defined( HAVE_LIBTAR_H ) && defined( HAVE_ZLIB_H )/* Values used in typeflag field */#define REGTYPE '0' /* regular file */#define AREGTYPE '\0' /* regular file */#define DIRTYPE '5' /* directory */#define BLOCKSIZE 512struct tar_header{ /* byte offset */ char name[100]; /* 0 */ char mode[8]; /* 100 */ char uid[8]; /* 108 */ char gid[8]; /* 116 */ char size[12]; /* 124 */ char mtime[12]; /* 136 */ char chksum[8]; /* 148 */ char typeflag; /* 156 */ char linkname[100]; /* 157 */ char magic[6]; /* 257 */ char version[2]; /* 263 */ char uname[32]; /* 265 */ char gname[32]; /* 297 */ char devmajor[8]; /* 329 */ char devminor[8]; /* 337 */ char prefix[155]; /* 345 */ /* 500 */};union tar_buffer { char buffer[BLOCKSIZE]; struct tar_header header;};int tar_open( TAR **t, char *pathname, int oflags ){ gzFile f = gzopen( pathname, "rb" ); if( f == NULL ) { fprintf( stderr, "Couldn't gzopen %s\n", pathname ); return -1; } *t = (gzFile *)malloc( sizeof(gzFile) ); **t = f; return 0;}int tar_extract_all( TAR *t, char *prefix ){ union tar_buffer buffer; int len, err, getheader = 1, remaining = 0; FILE *outfile = NULL; char fname[BLOCKSIZE + PATH_MAX]; while( 1 ) { len = gzread( *t, &buffer, BLOCKSIZE ); if( len < 0 ) { fprintf( stderr, "%s\n", gzerror(*t, &err) ); } /* * Always expect complete blocks to process * the tar information. */ if( len != 0 && len != BLOCKSIZE ) { fprintf( stderr, "gzread: incomplete block read\n" ); return -1; } /* * If we have to get a tar header */ if( getheader == 1 ) { /* * If we met the end of the tar * or the end-of-tar block, we are done */ if( (len == 0) || (buffer.header.name[0] == 0) ) { break; } sprintf( fname, "%s/%s", prefix, buffer.header.name ); /* Check magic value in header */ if( strncmp( buffer.header.magic, "GNUtar", 6 ) && strncmp( buffer.header.magic, "ustar", 5 ) ) { //fprintf(stderr, "not a tar file\n"); return -1; } switch( buffer.header.typeflag ) { case DIRTYPE: makedir( fname ); break; case REGTYPE: case AREGTYPE: remaining = getoct( buffer.header.size, 12 ); if( remaining ) { outfile = fopen( fname, "wb" ); if( outfile == NULL ) { /* try creating directory */ char *p = strrchr( fname, '/' ); if( p != NULL ) { *p = '\0'; makedir( fname ); *p = '/'; outfile = fopen( fname, "wb" ); if( !outfile ) { fprintf( stderr, "tar couldn't create %s\n", fname ); } } } } else outfile = NULL; /* * could have no contents */ getheader = (remaining) ? 0 : 1; break; default: break; } } else { unsigned int bytes = (remaining > BLOCKSIZE)?BLOCKSIZE:remaining; if( outfile != NULL ) { if( fwrite( &buffer, sizeof(char), bytes, outfile ) != bytes ) { fprintf( stderr, "error writing %s skipping...\n", fname ); fclose( outfile ); unlink( fname ); } } remaining -= bytes; if( remaining == 0 ) { getheader = 1; if( outfile != NULL ) { fclose(outfile); outfile = NULL; } } } } return 0;}int tar_close( TAR *t ){ if( gzclose( *t ) != Z_OK ) fprintf( stderr, "failed gzclose\n" ); free( t ); return 0;}/* helper functions */int getoct( char *p, int width ){ int result = 0; char c; while( width-- ) { c = *p++; if( c == ' ' ) continue; if( c == 0 ) break; result = result * 8 + (c - '0'); } return result;}#endif#ifdef WIN32# define mkdir(dirname,mode) _mkdir(dirname)#endif/* Recursive make directory * Abort if you get an ENOENT errno somewhere in the middle * e.g. ignore error "mkdir on existing directory" * * return 1 if OK, 0 on error */int makedir( const char *newdir ){ char *p, *buffer = strdup( newdir ); int len = strlen( buffer ); if( len <= 0 ) { free( buffer ); return 0; } if( buffer[len-1] == '/' ) { buffer[len-1] = '\0'; } if( mkdir( buffer, 0775 ) == 0 ) { free( buffer ); return 1; } p = buffer + 1; while( 1 ) { char hold; while( *p && *p != '\\' && *p != '/' ) p++; hold = *p; *p = 0; if( ( mkdir( buffer, 0775 ) == -1 ) && ( errno == ENOENT ) ) { fprintf( stderr, "couldn't create directory %s\n", buffer ); free( buffer ); return 0; } if( hold == 0 ) break; *p++ = hold; } free( buffer ); return 1;}#ifdef HAVE_ZLIB_Hstatic int currentGzFd = -1;static void * currentGzVp = NULL;int gzopen_frontend( char *pathname, int oflags, int mode ){ char *gzflags; gzFile gzf; switch( oflags ) { case O_WRONLY: gzflags = "wb"; break; case O_RDONLY: gzflags = "rb"; break; case O_RDWR: default: errno = EINVAL; return -1; } gzf = gzopen( pathname, gzflags ); if( !gzf ) { errno = ENOMEM; return -1; } /** Hum ... */ currentGzFd = 42; currentGzVp = gzf; return currentGzFd;}int gzclose_frontend( int fd ){ if( currentGzVp != NULL && fd != -1 ) { void *toClose = currentGzVp; currentGzVp = NULL; currentGzFd = -1; return gzclose( toClose ); } return -1;}int gzread_frontend( int fd, void *p_buffer, size_t i_length ){ if( currentGzVp != NULL && fd != -1 ) { return gzread( currentGzVp, p_buffer, i_length ); } return -1;}int gzwrite_frontend( int fd, const void * p_buffer, size_t i_length ){ if( currentGzVp != NULL && fd != -1 ) { return gzwrite( currentGzVp, const_cast<void*>(p_buffer), i_length ); } return -1;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -