QString QFileSystemEntry::fileName() const { findLastSeparator(); #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':')) return m_filePath.mid(2); #endif return m_filePath.mid(m_lastSeparator + 1); }
PathName PathName::getFolder() const { if (str.isNullOrEmpty()) return *this; const char* lastSeparator = findLastSeparator(); if (lastSeparator == 0) return PathName::empty; return PathName(str.before(lastSeparator)); }
PathName PathName::getFilename() const { if (str.isNullOrEmpty()) return *this; const char* lastSeparator = findLastSeparator(); if (lastSeparator == 0) return *this; return PathName(lastSeparator+1); }
void renameOldLogFile() { //_unlink( LOG_FILENAME ); char* buffer = (char*)malloc( MAX_PATH ); int folderLength = findLastSeparator( LOG_FILENAME ); memcpy( buffer, LOG_FILENAME, folderLength + 1 ); memcpy( buffer + folderLength + 1, "rfdynhud_editor-", 16 ); unsigned int timeLength = getFileTimeString( LOG_FILENAME, buffer + folderLength + 1 + 16 ); memcpy( buffer + folderLength + 1 + 16 + timeLength, ".log", 4 + 1 ); MoveFile( LOG_FILENAME, buffer ); free( buffer ); }
QString QFileSystemEntry::path() const { findLastSeparator(); if (m_lastSeparator == -1) { #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) if (m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':')) return m_filePath.left(2); #endif return QString(QLatin1Char('.')); } if (m_lastSeparator == 0) return QString(QLatin1Char('/')); #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) if (m_lastSeparator == 2 && m_filePath.at(1) == QLatin1Char(':')) return m_filePath.left(m_lastSeparator + 1); #endif return m_filePath.left(m_lastSeparator); }
void handleArchivedLogFiles( const char* PLUGIN_PATH ) { char* filename = (char*)malloc( MAX_PATH ); const unsigned int pluginPathLength = strlen( PLUGIN_PATH ); memcpy( filename, PLUGIN_PATH, pluginPathLength ); memcpy( filename + pluginPathLength, "\\rfdynhud.ini", 14 ); char* buffer = (char*)malloc( 16 ); readIniString( filename, "GENERAL", "numArchivedLogFiles", "5", buffer, 16 ); unsigned int numArchivedLogFiles = (unsigned int)max( 0, atoi( buffer ) ); free( buffer ); buffer = NULL; const unsigned int folderLength = findLastSeparator( LOG_FILENAME ); memcpy( filename, LOG_FILENAME, folderLength + 1 ); memcpy( filename + folderLength + 1, "rfdynhud_editor-*.log", 22 ); char** files = (char**)malloc( 64 * sizeof( char* ) ); unsigned int numFiles = 0; WIN32_FIND_DATA data; HANDLE hFile = FindFirstFile( filename, &data ); if ( hFile != INVALID_HANDLE_VALUE ) { do { if ( ( ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0 ) && ( data.cFileName[0] != '.' ) ) { unsigned int len = strlen( data.cFileName ); char* filename2 = (char*)malloc( len + 1 ); memcpy( filename2, data.cFileName, len + 1 ); files[numFiles++] = filename2; } } while ( FindNextFile( hFile, &data ) && ( numFiles < 64 ) ); } unsigned int numFiles2 = numFiles; while ( numFiles2 > numArchivedLogFiles ) { unsigned int smallestIndex = -1; for ( unsigned int i = 0; i < numFiles; i++ ) { if ( files[i] != NULL ) { smallestIndex = i; break; } } for ( unsigned int i = smallestIndex + 1; i < numFiles; i++ ) { if ( ( files[i] != NULL ) && ( strcmp( files[i], files[smallestIndex] ) < 0 ) ) smallestIndex = i; } memcpy( filename + folderLength + 1, files[smallestIndex], strlen( files[smallestIndex] ) + 1 ); _unlink( filename ); free( files[smallestIndex] ); files[smallestIndex] = NULL; numFiles2--; } for ( unsigned int i = 0; i < numFiles; i++ ) { if ( files[i] != NULL ) { free( files[i] ); files[i] = NULL; } } free( files ); free( filename ); }