Класс для работы с файлами. Подробнее...
#include <utilities/file_utilities.h>
Базовые классы:nitro::FileAbstraction.
Открытые члены | |
| File (void) | |
| File (const char *FilePath, const std::size_t Mode) | |
| File (const std::string &FilePath, const std::size_t Mode) | |
| ALIAS_FUNCTION_2 (Open, tstOpen, const char *, std::size_t) | |
| ALIAS_FUNCTION_0 (Close, tstClose) | |
| void | Write (const char *Data) |
| void | Write (const std::string &Data) |
| std::size_t | FileSize (void) |
Открытые статические члены | |
| static void | SaveBinDataToFile (const BinaryData &BinData, const char *Path) |
| static void | SaveBinDataToFile (const BinaryData &BinData, const std::string &Path) |
| static void | LoadBinDataFromFile (nitro::BinaryData &BinData, const char *Path) |
| static void | LoadBinDataFromFile (nitro::BinaryData &BinData, const std::string &Path) |
| static tm | GetLastModified (const char *Path) |
| static tm | GetLastModified (const std::string &Path) |
| static bool | FileExists (const char *FilePath) |
| static bool | FileExists (const std::string &FilePath) |
| static void | ForceCreateFile (const char *FilePath) |
| static void | ForceCreateFile (const std::string &FilePath) |
Закрытые члены | |
| File (const File &File) | |
| File | operator= (const File &File) |
Класс для работы с файлами.
Класс таймера.
См. определение в файле file_utilities.h строка 58
| nitro::File::File | ( | void | ) |
Конструктор по-умолчанию.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 10
{
}
| nitro::File::File | ( | const char * | FilePath, | |
| const std::size_t | Mode | |||
| ) |
Открытие файла по пути FilePath в режиме Mode.
| FilePath | - Путь к открываемому файлу. | |
| Mode | - Режим открываемого файла. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 14
Перекрестные ссылки nitro::exception::code(), nitro::FileAbstraction::Open() и nitro::exception::what().
{
try
{
nitro::FileAbstraction::Open( FilePath , Mode );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::File( const char * FilePath , const std::size_t Mode )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::File( const char * FilePath , const std::size_t Mode )::An error occured" ) , 0 ) );
}
}

| nitro::File::File | ( | const std::string & | FilePath, | |
| const std::size_t | Mode | |||
| ) |
Открытие файла по пути FilePath в режиме Mode.
| FilePath | - Путь к открываемому файлу. | |
| Mode | - Режим открываемого файла. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 195
Перекрестные ссылки nitro::exception::code(), nitro::FileAbstraction::Open() и nitro::exception::what().
{
try
{
FileAbstraction::Open( FilePath.c_str() , Mode );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::File( const std::string & FilePath , const std::size_t Mode )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::File( const std::string & FilePath , const std::size_t Mode )::An error occured" ) , 0 ) );
}
}

| nitro::File::File | ( | const File & | File | ) | [inline, private] |
Закрытый конструктор копирования.
| File | - Присваиваемый файл. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.h строка 456
{}
| nitro::File::ALIAS_FUNCTION_0 | ( | Close | , | |
| tstClose | ||||
| ) |
| nitro::File::ALIAS_FUNCTION_2 | ( | Open | , | |
| tstOpen | , | |||
| const char * | , | |||
| std::size_t | ||||
| ) |
| bool nitro::File::FileExists | ( | const char * | FilePath | ) | [static] |
Функция проверки существует ли файл.
| FilePath | - Путь к файлу, который будем проверять. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 113
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
Используется в nitro::MVC::Create(), FileExists(), nitro::MVC::LoadModule(), nitro::UnZIPAbstraction::Open() и nitro::ZIPAbstraction::Open().
{
try
{
if( strlen( FilePath ) == 0 )return( false );
std::ifstream file( FilePath );
return( file.good() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "bool File::FileExists( const char * FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "bool File::FileExists( const char * FilePath )::An error occured" ) , 0 ) );
}
}

| bool nitro::File::FileExists | ( | const std::string & | FilePath | ) | [static] |
Функция проверки существует ли файл.
| FilePath | - Путь к файлу, который будем проверять. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 264
Перекрестные ссылки nitro::exception::code(), FileExists() и nitro::exception::what().
{
try
{
return( FileExists( FilePath.c_str() ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::FileExists( const std::string & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::FileExists( const std::string & FilePath )::An error occured" ) , 0 ) );
}
}

| std::size_t nitro::File::FileSize | ( | void | ) |
Функция получения размера файла.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 171
Перекрестные ссылки nitro::exception::code(), nitro::FA_FILE_BEGIN, nitro::FA_FILE_END, nitro::FileAbstraction::Seek(), nitro::FileAbstraction::Tell() и nitro::exception::what().
{
try
{
std::size_t CurrentPosition( nitro::FileAbstraction::Tell() );
nitro::FileAbstraction::Seek( 0 , nitro::FA_FILE_END );
std::size_t EndPosition( nitro::FileAbstraction::Tell() );
FileAbstraction::Seek( CurrentPosition , nitro::FA_FILE_BEGIN );
return( EndPosition );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "std::size_t File::FileSize( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "std::size_t File::FileSize( void )::An error occured" ) , 0 ) );
}
}

| void nitro::File::ForceCreateFile | ( | const std::string & | FilePath | ) | [static] |
Функция принудительного создания файла.
| FilePath | - Путь к создаваемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 296
Перекрестные ссылки nitro::exception::code(), ForceCreateFile() и nitro::exception::what().
{
try
{
ForceCreateFile( FilePath.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::ForceCreateFile( const std::string & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::ForceCreateFile( const std::string & FilePath )::An error occured" ) , 0 ) );
}
}

| void nitro::File::ForceCreateFile | ( | const char * | FilePath | ) | [static] |
Функция принудительного создания файла.
| FilePath | - Путь к создаваемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 149
Перекрестные ссылки nitro::exception::code(), nitro::FSPath::ExtractFilePath(), nitro::FA_FILE_BINARY, nitro::FA_FILE_WRITE, nitro::Directory::ForceCreateDirectory() и nitro::exception::what().
Используется в ForceCreateFile(), SaveBinDataToFile() и nitro::UnZIPAbstraction::UnZIPFile().
{
try
{
std::string ClearPath( nitro::FSPath::ExtractFilePath( std::string( FilePath ) ) );
// убеждаемся что для нового файла будет создана директория
Directory::ForceCreateDirectory( ClearPath.c_str() );
// создаем файл в только что созданной директории
File TmpFile( FilePath , nitro::FA_FILE_BINARY | nitro::FA_FILE_WRITE );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "void File::ForceCreateFile( const char * FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "void File::ForceCreateFile( const char * FilePath )::An error occured" ) , 0 ) );
}
}

| tm nitro::File::GetLastModified | ( | const std::string & | Path | ) | [static] |
Функция получения времени и даты последней модификации файла.
| Path | - Путь к файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 248
Перекрестные ссылки nitro::exception::code(), GetLastModified() и nitro::exception::what().
{
try
{
return( GetLastModified( Path.c_str() ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::GetLastModified( const std::string & Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::GetLastModified( const std::string & Path )::An error occured" ) , 0 ) );
}
}

| tm nitro::File::GetLastModified | ( | const char * | Path | ) | [static] |
Функция получения времени и даты последней модификации файла.
| Path | - Путь к файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 86
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
Используется в nitro::ZIPAbstraction::AddFile() и GetLastModified().
{
try
{
struct stat FileInfo;
if( stat( Path , & FileInfo ) != 0 )
{
throw( nitro::exception( std::string( "GetLastModified( const char * Path )::An error occured while getting info for file/folder" ) , 0 ) );
}
struct tm ModificationDate;
ModificationDate = * localtime( & FileInfo.st_mtime );
return( ModificationDate );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "tm File::GetLastModified( const char * Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "tm File::GetLastModified( const char * Path )::An error occured" ) , 0 ) );
}
}

| void nitro::File::LoadBinDataFromFile | ( | nitro::BinaryData & | BinData, | |
| const char * | Path | |||
| ) | [static] |
Функция чтения бинарных данных из файла.
| BinData | - Сюда будут сохраняться бинарные данные. | |
| Path | - Путь к файлу, из которого будут читаться данные. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 57
Перекрестные ссылки nitro::BinaryData::AppendData(), nitro::exception::code(), nitro::FA_FILE_READ, nitro::FileAbstraction::Open(), nitro::FileAbstraction::Read() и nitro::exception::what().
Используется в nitro::ZIPAbstraction::AddFile(), LoadBinDataFromFile(), nitro::INIFile::LoadINIFile(), nitro::TemplateEngine::LoadTemplateFromFile() и nitro::XMLFile::LoadXML().
{
try
{
nitro::FileAbstraction File;
File.Open( Path , nitro::FA_FILE_READ );
char Buffer[ 1024 ];
std::size_t ReadBytes( 0 );
do
{
ReadBytes = File.Read( Buffer , 1024 );
BinData.AppendData( Buffer , ReadBytes );
}
while( ReadBytes == 1024 );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "void File::LoadBinDataFromFile( BinaryData & BinData , const char * Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "void File::LoadBinDataFromFile( BinaryData & BinData , const char * Path )::An error occured" ) , 0 ) );
}
}

| void nitro::File::LoadBinDataFromFile | ( | nitro::BinaryData & | BinData, | |
| const std::string & | Path | |||
| ) | [static] |
Функция чтения бинарных данных из файла.
| BinData | - Сюда будут сохраняться бинарные данные. | |
| Path | - Путь к файлу, из которого будут читаться данные. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 232
Перекрестные ссылки nitro::exception::code(), LoadBinDataFromFile() и nitro::exception::what().
{
try
{
LoadBinDataFromFile( BinData , Path.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::LoadBinDataFromFile( BinaryData & BinData , const std::string & Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::LoadBinDataFromFile( BinaryData & BinData , const std::string & Path )::An error occured" ) , 0 ) );
}
}

Закрытый оператор присваивания.
| File | - Присваиваемый файл. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.h строка 480
{return( *this );}
| void nitro::File::SaveBinDataToFile | ( | const BinaryData & | BinData, | |
| const char * | Path | |||
| ) | [static] |
Функция сохранения бинарных данных в файл.
| BinData | - Сохраняемые бинарные данные. | |
| Path | - Путь к файлу, в который будут сохраняться данные. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 30
Перекрестные ссылки nitro::exception::code(), nitro::FA_FILE_BINARY, nitro::FA_FILE_TRUNCATE, nitro::FA_FILE_WRITE, ForceCreateFile(), nitro::BinaryData::GetBuffer(), nitro::BinaryData::GetBufferLength(), nitro::FileAbstraction::Open(), nitro::exception::what() и nitro::FileAbstraction::Write().
Используется в nitro::UnTARAbstraction::ExtractFile(), SaveBinDataToFile() и nitro::INIFile::SaveINIFile().
{
try
{
if( Path == NULL || std::string( Path ).size() == 0 )
{
throw( nitro::exception( std::string( "File path was not specified" ) , 1 ) );
}
nitro::FileAbstraction File;
File::ForceCreateFile( Path );
File.Open( Path , nitro::FA_FILE_WRITE | nitro::FA_FILE_BINARY | nitro::FA_FILE_TRUNCATE );
File.Write( BinData.GetBuffer() , ( unsigned int )BinData.GetBufferLength() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "void File::SaveBinDataToFile( const BinaryData & BinData , const char * Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "void File::SaveBinDataToFile( const BinaryData & BinData , const char * Path )::An error occured" ) , 0 ) );
}
}

| void nitro::File::SaveBinDataToFile | ( | const BinaryData & | BinData, | |
| const std::string & | Path | |||
| ) | [static] |
Функция сохранения бинарных данных в файл.
| BinData | - Сохраняемые бинарные данные. | |
| Path | - Путь к файлу, в который будут сохраняться данные. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 211
Перекрестные ссылки nitro::exception::code(), SaveBinDataToFile() и nitro::exception::what().
{
try
{
if( Path.size() == 0 )
{
throw( nitro::exception( std::string( "File path was not specified" ) , 1 ) );
}
SaveBinDataToFile( BinData , Path.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::SaveBinDataToFile( const BinaryData & BinData , const std::string & Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::SaveBinDataToFile( const BinaryData & BinData , const std::string & Path )::An error occured" ) , 0 ) );
}
}

| void nitro::File::Write | ( | const char * | Data | ) |
Функция записи строки в файл.
| Data | - Строка, записываемая в файл. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 133
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
Используется в nitro::UnZIPAbstraction::UnZIPFile() и Write().
{
try
{
nitro::FileAbstraction::Write( Data , strlen( Data ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "void File::Write( const char * Data )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "void File::Write( const char * Data )::An error occured" ) , 0 ) );
}
}

| void nitro::File::Write | ( | const std::string & | Data | ) |
Функция записи строки в файл.
| Data | - Строка, записываемая в файл. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле file_utilities.cpp строка 280
Перекрестные ссылки nitro::exception::code(), nitro::exception::what() и Write().
{
try
{
Write( Data.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "File::Write( const std::string & Data )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "File::Write( const std::string & Data )::An error occured" ) , 0 ) );
}
}

1.6.1