From fc295826389bc4d4469922a6080635f2a45fce64 Mon Sep 17 00:00:00 2001 From: irov Date: Sun, 3 Nov 2024 23:05:29 +0200 Subject: [PATCH] improve NOTIFICATOR_DEBUG_OPEN_FILE improve NOTIFICATOR_DEBUG_CLOSE_FILE --- src/Engine/Application.cpp | 30 +- src/Engine/Application.h | 2 +- src/Interface/NotificatorInterface.h | 5 +- .../Win32FileGroupPlugin/CMakeLists.txt | 27 -- .../Win32ConcatenateFileHelper.cpp | 128 ----- .../Win32ConcatenateFileHelper.h | 15 - .../Win32FileGroupDirectory.cpp | 408 ---------------- .../Win32FileGroupDirectory.h | 69 --- .../Win32FileGroupDirectoryFactory.cpp | 33 -- .../Win32FileGroupDirectoryFactory.h | 22 - .../Win32FileGroupPlugin.cpp | 55 --- .../Win32FileGroupPlugin.def | 3 - .../Win32FileGroupPlugin.h | 20 - .../Win32FileInputStream.cpp | 444 ------------------ .../Win32FileInputStream.h | 79 ---- .../Win32FileGroupPlugin/Win32FileMapped.cpp | 152 ------ .../Win32FileGroupPlugin/Win32FileMapped.h | 44 -- .../Win32FileMappedInputStream.cpp | 186 -------- .../Win32FileMappedInputStream.h | 57 --- .../Win32FileOutputStream.cpp | 189 -------- .../Win32FileOutputStream.h | 53 --- .../Win32MutexFileInputStream.cpp | 331 ------------- .../Win32MutexFileInputStream.h | 73 --- .../AndroidAssetInputStream.cpp | 4 +- .../AndroidFileInputStream.cpp | 4 +- .../AndroidFileInputStream.h | 5 +- .../AndroidFileOutputStream.cpp | 26 + .../AndroidFileOutputStream.h | 8 +- .../AndroidMutexAssetInputStream.h | 5 +- .../AndroidMutexFileInputStream.h | 5 +- .../AppleFileSystem/AppleFileInputStream.mm | 2 +- .../SDLFileSystem/SDLFileInputStream.cpp | 4 +- .../SDLFileSystem/SDLFileInputStream.h | 5 +- .../SDLFileSystem/SDLFileOutputStream.cpp | 18 + .../SDLFileSystem/SDLFileOutputStream.h | 5 +- .../SDLFileSystem/SDLMutexFileInputStream.h | 5 +- .../Win32FileSystem/Win32FileInputStream.cpp | 4 +- .../Win32FileSystem/Win32FileInputStream.h | 7 +- src/Systems/Win32FileSystem/Win32FileMapped.h | 4 +- .../Win32FileMappedInputStream.h | 4 +- .../Win32FileSystem/Win32FileOutputStream.cpp | 21 + .../Win32FileSystem/Win32FileOutputStream.h | 5 +- .../Win32MutexFileInputStream.h | 5 +- 43 files changed, 142 insertions(+), 2429 deletions(-) delete mode 100644 src/Plugins/Win32FileGroupPlugin/CMakeLists.txt delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.def delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileMapped.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileMapped.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.h delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.cpp delete mode 100644 src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.h diff --git a/src/Engine/Application.cpp b/src/Engine/Application.cpp index 603115d19f..a0495af013 100644 --- a/src/Engine/Application.cpp +++ b/src/Engine/Application.cpp @@ -1478,7 +1478,7 @@ namespace Mengine } } ////////////////////////////////////////////////////////////////////////// - void Application::notifyDebugOpenFile_( const Char * _folder, const Char * _filePath, bool _streaming ) + void Application::notifyDebugOpenFile_( const FilePath & _folder, const FilePath & _filePath, bool _read, bool _streaming ) { bool isMainThread = THREAD_SERVICE() ->isMainThread(); @@ -1487,16 +1487,18 @@ namespace Mengine { if( _streaming == false ) { - LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("open %s%s" - , _folder - , _filePath + LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("open %s %s%s" + , _read == true ? "read" : "write" + , _folder.c_str() + , _filePath.c_str() ); } else { - LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("streaming %s%s" - , _folder - , _filePath + LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("streaming %s %s%s" + , _read == true ? "read" : "write" + , _folder.c_str() + , _filePath.c_str() ); } } @@ -1507,18 +1509,20 @@ namespace Mengine if( _streaming == false ) { - LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("open [multithread:%" MENGINE_PRIu64 "] open %s%s" + LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("open [multithread:%" MENGINE_PRIu64 "] open %s %s%s" , tid - , _folder - , _filePath + , _read == true ? "read" : "write" + , _folder.c_str() + , _filePath.c_str() ); } else { - LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("streaming [multithread:%" MENGINE_PRIu64 "] open %s%s" + LOGGER_VERBOSE_LEVEL( "debug", LM_MESSAGE_RELEASE, LFILTER_NONE, LCOLOR_GREEN, nullptr, 0, LFLAG_SHORT )("streaming [multithread:%" MENGINE_PRIu64 "] open %s %s%s" , tid - , _folder - , _filePath + , _read == true ? "read" : "write" + , _folder.c_str() + , _filePath.c_str() ); } } diff --git a/src/Engine/Application.h b/src/Engine/Application.h index 1cabb5e73b..2b24b807ad 100644 --- a/src/Engine/Application.h +++ b/src/Engine/Application.h @@ -179,7 +179,7 @@ namespace Mengine protected: void updateDebugOpenFile_(); - void notifyDebugOpenFile_( const Char * _folder, const Char * _filePath, bool _streaming ); + void notifyDebugOpenFile_( const FilePath & _folder, const FilePath & _filePath, bool _read, bool _streaming ); protected: void updateDebugResourceCompile_(); diff --git a/src/Interface/NotificatorInterface.h b/src/Interface/NotificatorInterface.h index ce9c8a7e9e..8e4cdab71b 100644 --- a/src/Interface/NotificatorInterface.h +++ b/src/Interface/NotificatorInterface.h @@ -5,6 +5,7 @@ #include "Kernel/Tuple.h" #include "Kernel/String.h" #include "Kernel/ConstString.h" +#include "Kernel/FilePath.h" #include "Kernel/Tags.h" #include "Kernel/Factorable.h" #include "Kernel/Resolution.h" @@ -57,8 +58,8 @@ namespace Mengine template<> struct Notificator { typedef Tuple<__VA_ARGS__> args_type; static const Char * getName() { return #NAME; } } ////////////////////////////////////////////////////////////////////////// MENGINE_NOTIFICATOR_DECLARE_BEGIN(); - MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_DEBUG_OPEN_FILE, const Char *, const Char *, bool ); - MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_DEBUG_CLOSE_FILE, const Char *, const Char *, bool ); + MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_DEBUG_OPEN_FILE, const FilePath &, const FilePath &, bool, bool ); + MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_DEBUG_CLOSE_FILE, const FilePath &, const FilePath &, bool, bool ); MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_ASSERTION, const Char *, EAssertionLevel, const Char *, const Char *, int32_t, const Char * ); MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_ABORT, const Char * ); MENGINE_NOTIFICATOR_DECLARE( NOTIFICATOR_CRASH, const Char * ); diff --git a/src/Plugins/Win32FileGroupPlugin/CMakeLists.txt b/src/Plugins/Win32FileGroupPlugin/CMakeLists.txt deleted file mode 100644 index a71a2bf578..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -MENGINE_PROJECT(Win32FileGroupPlugin) - -ADD_FILTER( -src - Win32FileGroupPlugin.h - Win32FileGroupPlugin.cpp - Win32FileGroupDirectory.cpp - Win32FileGroupDirectory.h - Win32FileGroupDirectoryFactory.cpp - Win32FileGroupDirectoryFactory.h - Win32FileInputStream.h - Win32FileInputStream.cpp - Win32MutexFileInputStream.h - Win32MutexFileInputStream.cpp - Win32FileOutputStream.cpp - Win32FileOutputStream.h - Win32FileMapped.h - Win32FileMapped.cpp - Win32FileMappedInputStream.h - Win32FileMappedInputStream.cpp - Win32ConcatenateFileHelper.h - Win32ConcatenateFileHelper.cpp -) - -ADD_MENGINE_PLUGIN(MENGINE_PLUGIN_WIN32_FILEGROUP) - -ADD_DEPENDENCIES(${PROJECT_NAME} Windows) \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.cpp b/src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.cpp deleted file mode 100644 index 901d313f50..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "Win32ConcatenateFileHelper.h" - -#include "Interface/UnicodeSystemInterface.h" - -#include "Kernel/PathHelper.h" -#include "Kernel/Logger.h" -#include "Kernel/MemoryCopy.h" - -#include "Config/StdString.h" - -namespace Mengine -{ - namespace Helper - { - ////////////////////////////////////////////////////////////////////////// - size_t Win32ConcatenateFilePathA( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, Char * const _concatenatePath, size_t _capacity ) - { - FilePath::size_type relationSize = _relationPath.size(); - FilePath::size_type folderSize = _folderPath.size(); - FilePath::size_type fileSize = _filePath.size(); - - FilePath::size_type filePathSize = relationSize + folderSize + fileSize; - - if( filePathSize >= MENGINE_MAX_PATH ) - { - LOGGER_ERROR( "invalid full path max size:\nrelation: %s\nfolder: %s\nfile: %s\ntotal size %u [max size: %zu]" - , _relationPath.c_str() - , _folderPath.c_str() - , _filePath.c_str() - , filePathSize - , _capacity - ); - - return MENGINE_PATH_INVALID_LENGTH; - } - - Helper::memoryCopySafe( _concatenatePath, 0, _capacity, _relationPath.c_str(), 0, relationSize ); - Helper::memoryCopySafe( _concatenatePath, relationSize, _capacity, _folderPath.c_str(), 0, folderSize ); - Helper::memoryCopySafe( _concatenatePath, relationSize + folderSize, _capacity, _filePath.c_str(), 0, fileSize ); - - _concatenatePath[filePathSize] = '\0'; - - Helper::pathCorrectBackslashA( _concatenatePath ); - - return filePathSize; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32ConcatenateFilePathW( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, WChar * const _concatenatePath, size_t _capacity ) - { - Char utf8_filePath[MENGINE_MAX_PATH + 1] = {'\0'}; - size_t utf8_filePathLen = Helper::Win32ConcatenateFilePathA( _relationPath, _folderPath, _filePath, utf8_filePath, MENGINE_MAX_PATH ); - - if( utf8_filePathLen == MENGINE_PATH_INVALID_LENGTH ) - { - return MENGINE_PATH_INVALID_LENGTH; - } - - if( UNICODE_SYSTEM() - ->utf8ToUnicode( utf8_filePath, utf8_filePathLen, _concatenatePath, _capacity, nullptr ) == false ) - { - LOGGER_ERROR( "invalid utf8 '%s' to unicode" - , utf8_filePath - ); - - return MENGINE_PATH_INVALID_LENGTH; - } - - return utf8_filePathLen; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32ConcatenateFilePathTempA( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, Char * const _concatenatePath, size_t _capacity ) - { - FilePath::size_type relationSize = _relationPath.size(); - FilePath::size_type folderSize = _folderPath.size(); - FilePath::size_type fileSize = _filePath.size(); - - FilePath::size_type filePathSize = relationSize + folderSize + fileSize + 5; - - if( filePathSize >= MENGINE_MAX_PATH ) - { - LOGGER_ERROR( "invalid full path max size:\nrelation: %s\nfolder: %s\nfile: %s\ntotal size %u [max size: %zu]" - , _relationPath.c_str() - , _folderPath.c_str() - , _filePath.c_str() - , filePathSize - , _capacity - ); - - return MENGINE_PATH_INVALID_LENGTH; - } - - Helper::memoryCopySafe( _concatenatePath, 0, _capacity, _relationPath.c_str(), 0, relationSize ); - Helper::memoryCopySafe( _concatenatePath, relationSize, _capacity, _folderPath.c_str(), 0, folderSize ); - Helper::memoryCopySafe( _concatenatePath, relationSize + folderSize, _capacity, _filePath.c_str(), 0, fileSize ); - Helper::memoryCopySafe( _concatenatePath, relationSize + folderSize + fileSize, _capacity, ".~tmp", 0, 5 ); - - _concatenatePath[filePathSize] = '\0'; - - Helper::pathCorrectBackslashA( _concatenatePath ); - - return filePathSize; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32ConcatenateFilePathTempW( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, WChar * const _concatenatePath, size_t _capacity ) - { - Char utf8_filePath[MENGINE_MAX_PATH + 1] = {'\0'}; - size_t utf8_filePathLen = Helper::Win32ConcatenateFilePathTempA( _relationPath, _folderPath, _filePath, utf8_filePath, MENGINE_MAX_PATH ); - - if( utf8_filePathLen == MENGINE_PATH_INVALID_LENGTH ) - { - return MENGINE_PATH_INVALID_LENGTH; - } - - if( UNICODE_SYSTEM() - ->utf8ToUnicode( utf8_filePath, utf8_filePathLen, _concatenatePath, _capacity, nullptr ) == false ) - { - LOGGER_ERROR( "invalid utf8 '%s' to unicode" - , utf8_filePath - ); - - return MENGINE_PATH_INVALID_LENGTH; - } - - return utf8_filePathLen; - } - ////////////////////////////////////////////////////////////////////////// - } -} \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.h b/src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.h deleted file mode 100644 index 8eb5875d01..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32ConcatenateFileHelper.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "Kernel/FilePath.h" -#include "Config/Char.h" - -namespace Mengine -{ - namespace Helper - { - size_t Win32ConcatenateFilePathA( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, Char * const _concatenatePath, size_t _capacity ); - size_t Win32ConcatenateFilePathW( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, WChar * const _concatenatePath, size_t _capacity ); - size_t Win32ConcatenateFilePathTempA( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, Char * const _concatenatePath, size_t _capacity ); - size_t Win32ConcatenateFilePathTempW( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, WChar * const _concatenatePath, size_t _capacity ); - } -} \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.cpp deleted file mode 100644 index 41af1e01e5..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.cpp +++ /dev/null @@ -1,408 +0,0 @@ -#include "Win32FileGroupDirectory.h" - -#include "Interface/MemoryInterface.h" -#include "Interface/PlatformServiceInterface.h" - -#include "Win32ConcatenateFileHelper.h" -#include "Win32FileInputStream.h" -#include "Win32FileOutputStream.h" -#include "Win32MutexFileInputStream.h" -#include "Win32FileMapped.h" - -#include "Kernel/PathString.h" -#include "Kernel/FactoryPool.h" -#include "Kernel/Assertion.h" -#include "Kernel/AssertionFactory.h" -#include "Kernel/AssertionMemoryPanic.h" -#include "Kernel/PathHelper.h" -#include "Kernel/Logger.h" -#include "Kernel/Stringalized.h" - -#include "Environment/Windows/WindowsIncluder.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - Win32FileGroupDirectory::Win32FileGroupDirectory() - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileGroupDirectory::~Win32FileGroupDirectory() - { - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::_initialize() - { - m_factoryInputStreamFile = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); - m_factoryInputStreamMutexFile = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); - m_factoryOutputStreamFile = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); - m_factoryMappedFile = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileGroupDirectory::_finalize() - { - MENGINE_ASSERTION_FACTORY_EMPTY( m_factoryInputStreamFile ); - MENGINE_ASSERTION_FACTORY_EMPTY( m_factoryInputStreamMutexFile ); - MENGINE_ASSERTION_FACTORY_EMPTY( m_factoryOutputStreamFile ); - MENGINE_ASSERTION_FACTORY_EMPTY( m_factoryMappedFile ); - - m_factoryInputStreamFile = nullptr; - m_factoryInputStreamMutexFile = nullptr; - m_factoryOutputStreamFile = nullptr; - m_factoryMappedFile = nullptr; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::isPacked() const - { - return false; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileGroupDirectory::getFullPath( const FilePath & _filePath, Char * const _fullPath ) const - { - size_t fullPathLen = Helper::Win32ConcatenateFilePathA( m_relationPath, m_folderPath, _filePath, _fullPath, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathLen ); - - MENGINE_ASSERTION_FATAL( fullPathLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate fullPath '%s:%s'" - , m_folderPath.c_str() - , _filePath.c_str() - ); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::existFile( const FilePath & _filePath, bool _recursive ) const - { - Char utf8_filePath[MENGINE_MAX_PATH + 1] = {'\0'}; - this->getFullPath( _filePath, utf8_filePath ); - - bool result = PLATFORM_SERVICE() - ->existFile( utf8_filePath ); - - if( _recursive == true && result == false && m_parentFileGroup != nullptr ) - { - result = m_parentFileGroup->existFile( _filePath, true ); - } - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::removeFile( const FilePath & _filePath ) const - { - const FilePath & relationPath = this->getRelationPath(); - const FilePath & folderPath = this->getFolderPath(); - - PathString filePathString; - filePathString.append( relationPath ); - filePathString.append( folderPath ); - filePathString.append( _filePath ); - - bool successful = PLATFORM_SERVICE() - ->removeFile( filePathString.c_str() ); - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::existDirectory( const FilePath & _folderPath, bool _recursive ) const - { - const FilePath & relationPath = this->getRelationPath(); - const FilePath & folderPath = this->getFolderPath(); - - PathString basePath; - basePath.append( relationPath ); - basePath.append( folderPath ); - - if( PLATFORM_SERVICE() - ->existDirectory( basePath.c_str(), _folderPath.c_str() ) == true ) - { - return true; - } - - if( _recursive == true && m_parentFileGroup != nullptr ) - { - if( m_parentFileGroup->existDirectory( _folderPath, true ) == true ) - { - return true; - } - } - - return false; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::createDirectory( const FilePath & _folderName ) const - { - const FilePath & relationPath = this->getRelationPath(); - const FilePath & folderPath = this->getFolderPath(); - - PathString basePath; - basePath.append( relationPath ); - basePath.append( folderPath ); - - if( PLATFORM_SERVICE() - ->existDirectory( basePath.c_str(), _folderName.c_str() ) == true ) - { - return true; - } - - if( PLATFORM_SERVICE() - ->createDirectory( basePath.c_str(), _folderName.c_str() ) == false ) - { - return false; - } - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::moveFile( const FilePath & _oldFilePath, const FilePath & _newFilePath ) const - { - const FilePath & relationPath = this->getRelationPath(); - const FilePath & folderPath = this->getFolderPath(); - - PathString oldFilePathString; - oldFilePathString.append( relationPath ); - oldFilePathString.append( folderPath ); - oldFilePathString.append( _oldFilePath ); - - PathString newFilePathString; - newFilePathString.append( relationPath ); - newFilePathString.append( folderPath ); - newFilePathString.append( _newFilePath ); - - bool successful = PLATFORM_SERVICE() - ->moveFile( oldFilePathString.c_str(), newFilePathString.c_str() ); - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::findFiles( const FilePath & _filePath, const Char * _mask, const LambdaFilePath & _lambda ) const - { - Char fullPathBase[MENGINE_MAX_PATH + 1] = {'\0'}; - this->getFullPath( FilePath::none(), fullPathBase ); - - Helper::pathCorrectForwardslashA( fullPathBase ); - - PLATFORM_SERVICE() - ->findFiles( fullPathBase, _filePath.c_str(), _mask, _lambda ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - InputStreamInterfacePtr Win32FileGroupDirectory::createInputFile( const FilePath & _filePath, bool _streaming, FileGroupInterface ** const _fileGroup, const DocumentInterfacePtr & _doc ) - { - MENGINE_UNUSED( _filePath ); - MENGINE_UNUSED( _streaming ); - - if( m_parentFileGroup != nullptr ) - { - if( this->existFile( _filePath, false ) == false ) - { - InputStreamInterfacePtr stream = m_parentFileGroup->createInputFile( _filePath, _streaming, _fileGroup, _doc ); - - return stream; - } - } - - Win32FileInputStreamPtr stream = m_factoryInputStreamFile->createObject( _doc ); - - MENGINE_ASSERTION_MEMORY_PANIC( stream, "invalid create input file" ); - - if( _fileGroup != nullptr ) - { - *_fileGroup = this; - } - - return stream; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::openInputFile( const FilePath & _filePath, const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size, bool _streaming, bool _share ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileInputStreamInterface * file = _stream.getT(); - - bool result = file->open( m_relationPath, m_folderPath, _filePath, _offset, _size, _streaming, _share ); - - MENGINE_ASSERTION( result == true, "failed open file '%s:%s'" - , m_folderPath.c_str() - , _filePath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::closeInputFile( const InputStreamInterfacePtr & _stream ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileInputStreamInterface * file = _stream.getT(); - - bool result = file->close(); - - MENGINE_ASSERTION( result == true, "failed close file '%s'" - , m_folderPath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - InputStreamInterfacePtr Win32FileGroupDirectory::createInputMutexFile( const FilePath & _filePath, const InputStreamInterfacePtr & _stream, const ThreadMutexInterfacePtr & _mutex, FileGroupInterface ** const _fileGroup, const DocumentInterfacePtr & _doc ) - { - if( m_parentFileGroup != nullptr ) - { - if( this->existFile( _filePath, false ) == false ) - { - InputStreamInterfacePtr stream = m_parentFileGroup->createInputMutexFile( _filePath, _stream, _mutex, _fileGroup, _doc ); - - return stream; - } - } - - Win32MutexFileInputStreamPtr stream = m_factoryInputStreamMutexFile->createObject( _doc ); - - MENGINE_ASSERTION_MEMORY_PANIC( stream, "invalid create input mutex file" ); - - stream->setFileInputStream( _stream ); - stream->setThreadMutex( _mutex ); - - if( _fileGroup != nullptr ) - { - *_fileGroup = this; - } - - return stream; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::openInputMutexFile( const FilePath & _filePath, const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileInputStreamInterface * file = _stream.getT(); - - bool result = file->open( m_relationPath, m_folderPath, _filePath, _offset, _size, false, false ); - - MENGINE_ASSERTION( result == true, "failed open file '%s:%s'" - , m_folderPath.c_str() - , _filePath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::closeInputMutexFile( const InputStreamInterfacePtr & _stream ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileInputStreamInterface * file = _stream.getT(); - - bool result = file->close(); - - MENGINE_ASSERTION( result == true, "failed close file '%s'" - , m_folderPath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - OutputStreamInterfacePtr Win32FileGroupDirectory::createOutputFile( const DocumentInterfacePtr & _doc ) - { - Win32FileOutputStreamPtr stream = m_factoryOutputStreamFile->createObject( _doc ); - - MENGINE_ASSERTION_MEMORY_PANIC( stream, "invalid create output file" ); - - return stream; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::openOutputFile( const FilePath & _filePath, const OutputStreamInterfacePtr & _stream, bool _withTemp ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileOutputStreamInterface * file = _stream.getT(); - - bool result = file->open( m_relationPath, m_folderPath, _filePath, _withTemp ); - - MENGINE_ASSERTION( result == true, "failed open file '%s:%s'" - , m_folderPath.c_str() - , _filePath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::closeOutputFile( const OutputStreamInterfacePtr & _stream ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileOutputStreamInterface * file = _stream.getT(); - - bool result = file->close(); - - MENGINE_ASSERTION( result == true, "failed close file '%s'" - , m_folderPath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::isAvailableMappedFile() const - { - return true; - } - ////////////////////////////////////////////////////////////////////////// - MappedInterfacePtr Win32FileGroupDirectory::createMappedFile( const FilePath & _filePath, FileGroupInterface ** const _fileGroup, const DocumentInterfacePtr & _doc ) - { - MENGINE_UNUSED( _filePath ); - - if( m_parentFileGroup != nullptr ) - { - if( this->existFile( _filePath, false ) == false ) - { - MappedInterfacePtr mapped = m_parentFileGroup->createMappedFile( _filePath, _fileGroup, _doc ); - - return mapped; - } - } - - Win32FileMappedPtr mapped = m_factoryMappedFile->createObject( _doc ); - - MENGINE_ASSERTION_MEMORY_PANIC( mapped, "invalid create mapped file" ); - - if( _fileGroup != nullptr ) - { - *_fileGroup = this; - } - - return mapped; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::openMappedFile( const FilePath & _filePath, const MappedInterfacePtr & _stream, bool _shared ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileMappedInterface * mapped = _stream.getT(); - - bool result = mapped->open( m_relationPath, m_folderPath, _filePath, _shared ); - - MENGINE_ASSERTION( result == true, "failed mapped file '%s:%s'" - , m_folderPath.c_str() - , _filePath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupDirectory::closeMappedFile( const MappedInterfacePtr & _stream ) - { - MENGINE_ASSERTION_MEMORY_PANIC( _stream, "failed _stream == nullptr" ); - - FileMappedInterface * mapped = _stream.getT(); - - bool result = mapped->close(); - - MENGINE_ASSERTION( result == true, "failed close file '%s'" - , m_folderPath.c_str() - ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.h b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.h deleted file mode 100644 index b355dc8b0f..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectory.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include "Interface/FactoryInterface.h" - -#include "Kernel/BaseFileGroup.h" - -namespace Mengine -{ - class Win32FileGroupDirectory - : public BaseFileGroup - { - DECLARE_FACTORABLE( Win32FileGroupDirectory ); - - public: - Win32FileGroupDirectory(); - ~Win32FileGroupDirectory() override; - - public: - bool _initialize() override; - void _finalize() override; - - public: - bool isPacked() const override; - - public: - void getFullPath( const FilePath & _filePath, Char * const _fullPath ) const override; - - public: - bool existDirectory( const FilePath & _folderPath, bool _recursive ) const override; - bool createDirectory( const FilePath & _folderPath ) const override; - - public: - bool existFile( const FilePath & _filePath, bool _recursive ) const override; - bool removeFile( const FilePath & _filePath ) const override; - bool moveFile( const FilePath & _oldFilePath, const FilePath & _newFilePath ) const override; - - public: - bool findFiles( const FilePath & _filePath, const Char * _mask, const LambdaFilePath & _lambda ) const override; - - public: - InputStreamInterfacePtr createInputFile( const FilePath & _filePath, bool _streaming, FileGroupInterface ** const _fileGroup, const DocumentInterfacePtr & _doc ) override; - bool openInputFile( const FilePath & _filePath, const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size, bool _streaming, bool _share ) override; - bool closeInputFile( const InputStreamInterfacePtr & _stream ) override; - - public: - InputStreamInterfacePtr createInputMutexFile( const FilePath & _filePath, const InputStreamInterfacePtr & _stream, const ThreadMutexInterfacePtr & _mutex, FileGroupInterface ** const _fileGroup, const DocumentInterfacePtr & _doc ) override; - bool openInputMutexFile( const FilePath & _filePath, const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size ) override; - bool closeInputMutexFile( const InputStreamInterfacePtr & _stream ) override; - - public: - OutputStreamInterfacePtr createOutputFile( const DocumentInterfacePtr & _doc ) override; - bool openOutputFile( const FilePath & _filePath, const OutputStreamInterfacePtr & _stream, bool _withTemp ) override; - bool closeOutputFile( const OutputStreamInterfacePtr & _stream ) override; - - public: - bool isAvailableMappedFile() const override; - - public: - MappedInterfacePtr createMappedFile( const FilePath & _filePath, FileGroupInterface ** const _fileGroup, const DocumentInterfacePtr & _doc ) override; - bool openMappedFile( const FilePath & _filePath, const MappedInterfacePtr & _stream, bool _shared ) override; - bool closeMappedFile( const MappedInterfacePtr & _stream ) override; - - protected: - FactoryInterfacePtr m_factoryInputStreamFile; - FactoryInterfacePtr m_factoryInputStreamMutexFile; - FactoryInterfacePtr m_factoryOutputStreamFile; - FactoryInterfacePtr m_factoryMappedFile; - }; -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.cpp deleted file mode 100644 index f9514c72b0..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "Win32FileGroupDirectoryFactory.h" - -#include "Win32FileGroupDirectory.h" - -#include "Kernel/Typename.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - Win32FileGroupDirectoryFactory::Win32FileGroupDirectoryFactory( const FilePath & _relationPath ) - : m_relationPath( _relationPath ) - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileGroupDirectoryFactory::~Win32FileGroupDirectoryFactory() - { - } - ////////////////////////////////////////////////////////////////////////// - Factorable * Win32FileGroupDirectoryFactory::_createObject() - { - Win32FileGroupDirectory * t = Helper::newT(); - - t->setRelationPath( m_relationPath ); - - return t; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileGroupDirectoryFactory::_destroyObject( Factorable * _obj ) - { - Helper::deleteT( static_cast(_obj) ); - } - ////////////////////////////////////////////////////////////////////////// -} \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.h b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.h deleted file mode 100644 index de74c22e05..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupDirectoryFactory.h +++ /dev/null @@ -1,22 +0,0 @@ -#include "Kernel/FactoryWithMutex.h" -#include "Kernel/FilePath.h" - -namespace Mengine -{ - class Win32FileGroupDirectoryFactory - : public FactoryWithMutex - { - DECLARE_FACTORABLE( Win32FileGroupDirectoryFactory ); - - public: - Win32FileGroupDirectoryFactory( const FilePath & _relationPath ); - ~Win32FileGroupDirectoryFactory() override; - - protected: - Factorable * _createObject() override; - void _destroyObject( Factorable * _obj ) override; - - protected: - FilePath m_relationPath; - }; -} \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.cpp deleted file mode 100644 index 7c924690ba..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "Win32FileGroupPlugin.h" - -#include "Interface/FileServiceInterface.h" -#include "Interface/PlatformServiceInterface.h" - -#include "Win32FileGroupDirectoryFactory.h" -#include "Win32FileGroupDirectory.h" - -#include "Kernel/FactoryHelper.h" -#include "Kernel/FilePath.h" -#include "Kernel/ConstStringHelper.h" -#include "Kernel/FilePathHelper.h" -#include "Kernel/VocabularyHelper.h" -#include "Kernel/PluginHelper.h" - -////////////////////////////////////////////////////////////////////////// -PLUGIN_FACTORY( Win32FileGroup, Mengine::Win32FileGroupPlugin ); -////////////////////////////////////////////////////////////////////////// -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - Win32FileGroupPlugin::Win32FileGroupPlugin() - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileGroupPlugin::~Win32FileGroupPlugin() - { - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileGroupPlugin::_initializePlugin() - { - FactoryInterfacePtr factoryGlobalFileGroupDirectory = Helper::makeFactory( MENGINE_DOCUMENT_FACTORABLE, FilePath::none() ); - - VOCABULARY_SET( FactoryInterface, STRINGIZE_STRING_LOCAL( "FileGroupFactory" ), STRINGIZE_STRING_LOCAL( "global" ), factoryGlobalFileGroupDirectory, MENGINE_DOCUMENT_FACTORABLE ); - - Char currentPath[MENGINE_MAX_PATH + 1] = {'\0'}; - size_t currentPathLen = PLATFORM_SERVICE() - ->getCurrentPath( currentPath ); - - FilePath relationPath = Helper::stringizeFilePathSize( currentPath, (FilePath::size_type)currentPathLen ); - - FactoryInterfacePtr factoryDirFileGroupDirectory = Helper::makeFactory( MENGINE_DOCUMENT_FACTORABLE, relationPath ); - - VOCABULARY_SET( FactoryInterface, STRINGIZE_STRING_LOCAL( "FileGroupFactory" ), STRINGIZE_STRING_LOCAL( "dir" ), factoryDirFileGroupDirectory, MENGINE_DOCUMENT_FACTORABLE ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileGroupPlugin::_finalizePlugin() - { - VOCABULARY_REMOVE( STRINGIZE_STRING_LOCAL( "FileGroupFactory" ), STRINGIZE_STRING_LOCAL( "global" ) ); - VOCABULARY_REMOVE( STRINGIZE_STRING_LOCAL( "FileGroupFactory" ), STRINGIZE_STRING_LOCAL( "dir" ) ); - } - ////////////////////////////////////////////////////////////////////////// -} \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.def b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.def deleted file mode 100644 index 7ad7782fcd..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.def +++ /dev/null @@ -1,3 +0,0 @@ -LIBRARY "Win32FileGroupPlugin" -EXPORTS - dllCreatePlugin @1 \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.h b/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.h deleted file mode 100644 index 3302a9b2ee..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileGroupPlugin.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Kernel/PluginBase.h" - -namespace Mengine -{ - class Win32FileGroupPlugin - : public PluginBase - { - PLUGIN_DECLARE( "Win32FileGroup" ) - - public: - Win32FileGroupPlugin(); - ~Win32FileGroupPlugin() override; - - protected: - bool _initializePlugin() override; - void _finalizePlugin() override; - }; -} \ No newline at end of file diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.cpp deleted file mode 100644 index ac0707d15e..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.cpp +++ /dev/null @@ -1,444 +0,0 @@ -#include "Win32FileInputStream.h" - -#include "Interface/UnicodeSystemInterface.h" -#include "Interface/PlatformServiceInterface.h" - -#include "Environment/Windows/Win32FileHelper.h" -#include "Environment/Windows/Win32Helper.h" -#include "Environment/Windows/Win32PlatformServiceExtensionInterface.h" - -#include "Win32ConcatenateFileHelper.h" - -#include "Kernel/StatisticHelper.h" -#include "Kernel/Assertion.h" -#include "Kernel/Logger.h" -#include "Kernel/NotificationHelper.h" -#include "Kernel/MemoryCopy.h" -#include "Kernel/DebugFileHelper.h" - -#include "Config/Algorithm.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - // cppcheck-suppress uninitMemberVar - Win32FileInputStream::Win32FileInputStream() - : m_hFile( INVALID_HANDLE_VALUE ) - , m_size( 0 ) - , m_offset( 0 ) - , m_carriage( 0 ) - , m_capacity( 0 ) - , m_reading( 0 ) - , m_streaming( false ) - , m_share( false ) - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileInputStream::~Win32FileInputStream() - { - this->close(); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, size_t _offset, size_t _size, bool _streaming, bool _share ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - -#if defined(MENGINE_DEBUG) - this->setDebugRelationPath( _relationPath ); - this->setDebugFolderPath( _folderPath ); - this->setDebugFilePath( _filePath ); -#endif - - m_streaming = _streaming; - m_share = _share; - - WChar fullPath[MENGINE_MAX_PATH + 1] = {L'\0'}; - if( this->openFile_( _relationPath, _folderPath, _filePath, fullPath ) == false ) - { - return false; - } - - LARGE_INTEGER lpFileSize; - if( ::GetFileSizeEx( m_hFile, &lpFileSize ) == FALSE ) - { - LOGGER_ERROR( "invalid file '%ls' size get error %ls" - , fullPath - , Helper::Win32GetLastErrorMessageW() - ); - - this->close(); - - return false; - } - - size_t size = (size_t)lpFileSize.QuadPart; - - if( _size != MENGINE_UNKNOWN_SIZE ) - { - if( _offset + _size > size ) - { - LOGGER_ERROR( "invalid file '%ls' range %zu:%zu size %zu" - , fullPath - , _offset - , _size - , size - ); - - this->close(); - - return false; - } - - m_size = _size; - } - else - { - m_size = size; - } - - m_offset = _offset; - - m_carriage = 0; - m_capacity = 0; - m_reading = 0; - - if( m_offset != 0 ) - { - LARGE_INTEGER liDistanceToMove; - liDistanceToMove.QuadPart = m_offset; - - LARGE_INTEGER dwPtr; - if( ::SetFilePointerEx( m_hFile, liDistanceToMove, &dwPtr, FILE_BEGIN ) == FALSE ) - { - LOGGER_ERROR( "seek file '%ls' offset %zu size %zu get error %ls" - , fullPath - , m_offset - , m_size - , Helper::Win32GetLastErrorMessageW() - ); - - this->close(); - - return false; - } - } - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::close() - { - if( m_hFile == INVALID_HANDLE_VALUE ) - { - return true; - } - -#if defined(MENGINE_DEBUG) - if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) - { - const FilePath & folderPath = this->getDebugFolderPath(); - const FilePath & filePath = this->getDebugFilePath(); - - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); - } -#endif - - BOOL successful = ::CloseHandle( m_hFile ); - m_hFile = INVALID_HANDLE_VALUE; - - if( successful == FALSE ) - { - LOGGER_ERROR( "invalid close file '%s' handle get error %ls" - , Helper::getDebugFullPath( this ).c_str() - , Helper::Win32GetLastErrorMessageW() - ); - } - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::openFile_( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, WChar * const _fullPath ) - { - size_t fullPathLen = Helper::Win32ConcatenateFilePathW( _relationPath, _folderPath, _filePath, _fullPath, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathLen ); - - MENGINE_ASSERTION_FATAL( fullPathLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate filePath '%s:%s'" - , _folderPath.c_str() - , _filePath.c_str() - ); - - DWORD sharedMode = FILE_SHARE_READ; - - if( m_share == true ) - { - sharedMode |= FILE_SHARE_WRITE | FILE_SHARE_DELETE; - } - - HANDLE hFile = Helper::Win32CreateFile( - _fullPath, // file to open - GENERIC_READ, // open for reading - sharedMode, // share for reading, exclusive for mapping - OPEN_EXISTING // existing file only - ); - - if( hFile == INVALID_HANDLE_VALUE ) - { - LOGGER_ERROR( "file '%ls' invalid open" - , _fullPath - ); - - return false; - } - - m_hFile = hFile; - -#if defined(MENGINE_DEBUG) - if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) - { - const FilePath & folderPath = this->getDebugFolderPath(); - const FilePath & filePath = this->getDebugFilePath(); - - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); - } -#endif - - STATISTIC_INC_INTEGER( STATISTIC_OPEN_FILE_COUNT ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileInputStream::read( void * const _buf, size_t _count ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - size_t pos = m_reading - m_capacity + m_carriage; - - size_t correct_count = _count; - - if( pos + _count > m_size ) - { - correct_count = m_size - pos; - } - - if( correct_count > MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE ) - { - size_t tail = m_capacity - m_carriage; - - if( tail != 0 ) - { - Helper::memoryCopy( _buf, 0, m_readCache, m_carriage, tail ); - } - - size_t toRead = correct_count - tail; - - size_t bytesRead; - if( this->read_( _buf, tail, toRead, &bytesRead ) == false ) - { - return 0; - } - - m_carriage = 0; - m_capacity = 0; - - m_reading += bytesRead; - - return bytesRead + tail; - } - - if( m_carriage + correct_count <= m_capacity ) - { - Helper::memoryCopy( _buf, 0, m_readCache, m_carriage, correct_count ); - - m_carriage += correct_count; - - return correct_count; - } - - size_t tail = m_capacity - m_carriage; - - if( tail != 0 ) - { - Helper::memoryCopy( _buf, 0, m_readCache, m_carriage, tail ); - } - - size_t bytesRead; - if( this->read_( m_readCache, 0, MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE, &bytesRead ) == false ) - { - return 0; - } - - size_t readSize = MENGINE_MIN( correct_count - tail, bytesRead ); - - Helper::memoryCopy( _buf, tail, m_readCache, 0, readSize ); - - m_carriage = readSize; - m_capacity = bytesRead; - - m_reading += bytesRead; - - return readSize + tail; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::read_( void * const _buf, size_t _offset, size_t _size, size_t * const _read ) - { - uint8_t * buf_offset = MENGINE_PVOID_OFFSET( _buf, _offset ); - - DWORD bytesRead = 0; - if( ::ReadFile( m_hFile, buf_offset, static_cast(_size), &bytesRead, NULL ) == FALSE ) - { - LOGGER_ERROR( "read file '%s' offset %zu size %zu:%zu get error %ls" - , Helper::getDebugFullPath( this ).c_str() - , _offset - , _size - , m_size - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - *_read = (size_t)bytesRead; - - STATISTIC_ADD_INTEGER( STATISTIC_OPEN_FILE_READ_BYTES, bytesRead ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::seek( size_t _pos ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - bool successful = this->seek_( _pos ); - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileInputStream::rewind() - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - this->seek_( 0 ); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::rseek( size_t _pos ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - bool successful = this->seek_( m_size - _pos ); - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::seek_( size_t _pos ) - { - if( _pos >= m_reading - m_capacity && _pos <= m_reading ) - { - m_carriage = m_capacity - (m_reading - _pos); - } - else - { - LARGE_INTEGER liDistanceToMove; - liDistanceToMove.QuadPart = m_offset + _pos; - - LARGE_INTEGER dwPtr; - if( ::SetFilePointerEx( m_hFile, liDistanceToMove, &dwPtr, FILE_BEGIN ) == FALSE ) - { - LOGGER_ERROR( "seek file '%s' %zu:%zu get error %ls" - , Helper::getDebugFullPath( this ).c_str() - , _pos - , m_size - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - m_carriage = 0; - m_capacity = 0; - - size_t dwPtrSizet = static_cast(dwPtr.QuadPart); - - m_reading = dwPtrSizet - m_offset; - } - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::skip( size_t _pos ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - size_t current = m_reading - m_capacity + m_carriage; - - size_t seek_pos = current + _pos; - - bool result = this->seek_( seek_pos ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileInputStream::tell() const - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - size_t current = m_reading - m_capacity + m_carriage; - - return current; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileInputStream::size() const - { - return m_size; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::eof() const - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileInputStream, this ); - - size_t current = m_reading - m_capacity + m_carriage; - - return current == m_size; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::time( uint64_t * const _time ) const - { -#if defined(MENGINE_PLATFORM_WINDOWS) - FILETIME creation; - FILETIME access; - FILETIME write; - - if( ::GetFileTime( m_hFile, &creation, &access, &write ) == FALSE ) - { - LOGGER_ERROR( "invalid get file '%s' time get error %ls" - , Helper::getDebugFullPath( this ).c_str() - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - time_t time = Helper::Win32FileTimeToUnixTime( &write ); - - *_time = (uint64_t)time; - - return true; -#else - return false; -#endif - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileInputStream::memory( void ** const _memory, size_t * const _size ) - { - MENGINE_UNUSED( _memory ); - MENGINE_UNUSED( _size ); - - return false; - } - ////////////////////////////////////////////////////////////////////////// - HANDLE Win32FileInputStream::getHandleFile() const - { - return m_hFile; - } - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.h b/src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.h deleted file mode 100644 index a379d8eaad..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileInputStream.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -#include "Interface/FileInputStreamInterface.h" - -#include "Kernel/Factorable.h" -#include "Kernel/ThreadGuardScope.h" -#include "Kernel/BaseDebugFile.h" - -#include "Environment/Windows/WindowsIncluder.h" - -#ifndef MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE -#define MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE 4096 -#endif - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - class Win32FileInputStream - : public FileInputStreamInterface - , public Factorable -#if defined(MENGINE_DEBUG) - , public BaseDebugFile -#endif - { - DECLARE_FACTORABLE( Win32FileInputStream ); - - public: - Win32FileInputStream(); - ~Win32FileInputStream() override; - - public: - bool open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, size_t _offset, size_t _size, bool _streaming, bool _share ) override; - bool close() override; - - public: - size_t read( void * const _buf, size_t _count ) override; - bool seek( size_t _pos ) override; - void rewind() override; - bool rseek( size_t _pos ) override; - bool skip( size_t _pos ) override; - size_t tell() const override; - size_t size() const override; - bool eof() const override; - - public: - bool time( uint64_t * const _time ) const override; - - public: - bool memory( void ** const _memory, size_t * const _size ) override; - - public: - HANDLE getHandleFile() const; - - protected: - bool openFile_( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, WChar * const _fullPath ); - bool read_( void * const _buf, size_t _offset, size_t _size, size_t * const _read ); - bool seek_( size_t _pos ); - - protected: - HANDLE m_hFile; - - size_t m_size; - size_t m_offset; - - size_t m_carriage; - size_t m_capacity; - size_t m_reading; - - uint8_t m_readCache[MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE]; - - MENGINE_THREAD_GUARD_INIT( Win32FileInputStream ); - - bool m_streaming; - bool m_share; - }; - ////////////////////////////////////////////////////////////////////////// - typedef IntrusivePtr Win32FileInputStreamPtr; - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileMapped.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileMapped.cpp deleted file mode 100644 index 4d6b60e0df..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileMapped.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "Win32FileMapped.h" - -#include "Interface/MemoryServiceInterface.h" -#include "Interface/UnicodeSystemInterface.h" - -#include "Environment/Windows/Win32FileHelper.h" -#include "Environment/Windows/Win32Helper.h" - -#include "Win32ConcatenateFileHelper.h" -#include "Win32FileMappedInputStream.h" - -#include "Kernel/Assertion.h" -#include "Kernel/AssertionFactory.h" -#include "Kernel/Logger.h" -#include "Kernel/AssertionMemoryPanic.h" -#include "Kernel/FactoryPool.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - Win32FileMapped::Win32FileMapped() - : m_hFile( INVALID_HANDLE_VALUE ) - , m_hMapping( INVALID_HANDLE_VALUE ) - , m_liSize() - , m_dwAllocationGranularity( 0 ) - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileMapped::~Win32FileMapped() - { - this->close(); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMapped::open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, bool _share ) - { - WChar fullPath[MENGINE_MAX_PATH + 1] = {L'\0'}; - size_t fullPathLen = Helper::Win32ConcatenateFilePathW( _relationPath, _folderPath, _filePath, fullPath, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathLen ); - - MENGINE_ASSERTION_FATAL( fullPathLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate filePath '%s:%s'" - , _folderPath.c_str() - , _filePath.c_str() - ); - - DWORD sharedMode = FILE_SHARE_READ; - - if( _share == true ) - { - sharedMode |= FILE_SHARE_WRITE | FILE_SHARE_DELETE; - } - - HANDLE hFile = Helper::Win32CreateFile( - fullPath, // file to open - GENERIC_READ, // open for reading - FILE_SHARE_READ, // share for reading, exclusive for mapping - OPEN_EXISTING // existing file only - ); - - if( hFile == INVALID_HANDLE_VALUE ) - { - LOGGER_ERROR( "file '%ls' invalid open" - , fullPath - ); - - return false; - } - - m_hFile = hFile; - - if( ::GetFileSizeEx( m_hFile, &m_liSize ) == FALSE ) - { - LOGGER_ERROR( "invalid file '%ls' size get error %ls" - , fullPath - , Helper::Win32GetLastErrorMessageW() - ); - - ::CloseHandle( m_hFile ); - m_hFile = INVALID_HANDLE_VALUE; - - return false; - } - - HANDLE hMapping = ::CreateFileMapping( m_hFile, NULL, PAGE_READONLY, 0, 0, NULL ); - - if( hMapping == NULL ) - { - LOGGER_ERROR( "invalid create file mapping '%ls' get error %ls" - , fullPath - , Helper::Win32GetLastErrorMessageW() - ); - - ::CloseHandle( m_hFile ); - m_hFile = INVALID_HANDLE_VALUE; - - return false; - } - - m_hMapping = hMapping; - - SYSTEM_INFO si; - ::GetSystemInfo( &si ); - - m_dwAllocationGranularity = si.dwAllocationGranularity; - - m_factoryFileMappedInputStream = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMapped::close() - { - if( m_hMapping != INVALID_HANDLE_VALUE ) - { - ::CloseHandle( m_hMapping ); - m_hMapping = INVALID_HANDLE_VALUE; - } - - if( m_hFile != INVALID_HANDLE_VALUE ) - { - ::CloseHandle( m_hFile ); - m_hFile = INVALID_HANDLE_VALUE; - } - - MENGINE_ASSERTION_FACTORY_EMPTY( m_factoryFileMappedInputStream ); - - m_factoryFileMappedInputStream = nullptr; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - InputStreamInterfacePtr Win32FileMapped::createInputStream( const DocumentInterfacePtr & _doc ) - { - Win32FileMappedInputStreamPtr stream = m_factoryFileMappedInputStream->createObject( _doc ); - - MENGINE_ASSERTION_MEMORY_PANIC( stream, "invalid create input stream" ); - - return stream; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMapped::openInputStream( const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size ) - { - Win32FileMappedInputStream * stream = _stream.getT(); - - size_t size = _size == MENGINE_UNKNOWN_SIZE ? (size_t)m_liSize.QuadPart : _size; - - bool result = stream->mapViewOfFile( m_hMapping, m_dwAllocationGranularity, _offset, size ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileMapped.h b/src/Plugins/Win32FileGroupPlugin/Win32FileMapped.h deleted file mode 100644 index 57d2866fff..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileMapped.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "Interface/FileMappedInterface.h" -#include "Interface/FactoryInterface.h" - -#include "Kernel/Factorable.h" - -#include "Environment/Windows/WindowsIncluder.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - class Win32FileMapped - : public FileMappedInterface - , public Factorable - { - DECLARE_FACTORABLE( Win32FileMapped ); - - public: - Win32FileMapped(); - ~Win32FileMapped() override; - - public: - bool open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, bool _share ) override; - bool close() override; - - public: - InputStreamInterfacePtr createInputStream( const DocumentInterfacePtr & _doc ) override; - bool openInputStream( const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size ) override; - - protected: - HANDLE m_hFile; - HANDLE m_hMapping; - - LARGE_INTEGER m_liSize; - - DWORD m_dwAllocationGranularity; - - FactoryInterfacePtr m_factoryFileMappedInputStream; - }; - ////////////////////////////////////////////////////////////////////////// - typedef IntrusivePtr Win32FileMappedPtr; - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.cpp deleted file mode 100644 index 4ada37d09f..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include "Win32FileMappedInputStream.h" - -#include "Environment/Windows/Win32Helper.h" - -#include "Kernel/Logger.h" -#include "Kernel/ThreadGuardScope.h" -#include "Kernel/MemoryCopy.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - Win32FileMappedInputStream::Win32FileMappedInputStream() - : m_memoryGranularity( NULL ) - , m_size( 0 ) - , m_base( nullptr ) - , m_pos( nullptr ) - , m_end( nullptr ) - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileMappedInputStream::~Win32FileMappedInputStream() - { - this->unmap(); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::mapViewOfFile( HANDLE _hMapping, DWORD _dwAllocationGranularity, size_t _offset, size_t _size ) - { - DWORD64 offset = (DWORD64)_offset; - DWORD offsetHigh = (offset >> 32) & 0xFFFFFFFFlu; - DWORD offsetLow = (offset >> 0) & 0xFFFFFFFFlu; - - DWORD offsetLowGranularity = offsetLow / _dwAllocationGranularity * _dwAllocationGranularity; - DWORD offsetLowResidue = offsetLow - offsetLowGranularity; - - LPVOID memory = ::MapViewOfFile( _hMapping, FILE_MAP_READ, offsetHigh, offsetLowGranularity, (DWORD)_size + offsetLowResidue ); - - if( memory == NULL ) - { - LOGGER_ERROR( "invalid map view of file get error %ls" - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - m_memoryGranularity = memory; - - m_base = MENGINE_PVOID_OFFSET( m_memoryGranularity, offsetLowResidue ); - m_size = _size; - - m_pos = m_base; - m_end = m_base + m_size; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileMappedInputStream::unmap() - { - if( ::UnmapViewOfFile( m_memoryGranularity ) == FALSE ) - { - LOGGER_ERROR( "invalid UnmapViewOfFile [%p] get error %ls" - , m_base - , Helper::Win32GetLastErrorMessageW() - ); - } - - m_memoryGranularity = NULL; - - m_size = 0; - - m_base = nullptr; - m_pos = nullptr; - m_end = nullptr; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileMappedInputStream::read( void * const _buf, size_t _count ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - size_t cnt = _count; - - if( m_pos + cnt > m_end ) - { - cnt = m_end - m_pos; - } - - if( cnt == 0 ) - { - return 0; - } - - Helper::memoryCopy( _buf, 0, m_pos, 0, cnt ); - - m_pos += cnt; - - return cnt; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::seek( size_t _pos ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - if( _pos > m_size ) - { - _pos = m_size; - } - - m_pos = m_base + _pos; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - void Win32FileMappedInputStream::rewind() - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - m_pos = m_base; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::rseek( size_t _pos ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - if( _pos > m_size ) - { - _pos = m_size; - } - - m_pos = m_base + m_size - _pos; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::skip( size_t _pos ) - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - if( m_pos + _pos > m_end ) - { - _pos = 0; - } - - m_pos += _pos; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileMappedInputStream::size() const - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - return m_size; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::eof() const - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - return m_pos == m_end; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileMappedInputStream::tell() const - { - MENGINE_THREAD_GUARD_SCOPE( Win32FileMappedInputStream, this ); - - size_t distance = m_pos - m_base; - - return distance; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::time( uint64_t * const _time ) const - { - MENGINE_UNUSED( _time ); - - return false; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileMappedInputStream::memory( void ** const _memory, size_t * const _size ) - { - *_memory = m_base; - *_size = m_size; - - return true; - } - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.h b/src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.h deleted file mode 100644 index 3750f99b01..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileMappedInputStream.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include "Interface/InputStreamInterface.h" - -#include "Kernel/Factorable.h" -#include "Kernel/ThreadGuard.h" - -#include "Environment/Windows/WindowsIncluder.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - class Win32FileMappedInputStream - : public InputStreamInterface - , public Factorable - { - DECLARE_FACTORABLE( Win32FileMappedInputStream ); - - public: - Win32FileMappedInputStream(); - ~Win32FileMappedInputStream() override; - - public: - bool mapViewOfFile( HANDLE _hMapping, DWORD _dwAllocationGranularity, size_t _offset, size_t _size ); - void unmap(); - - public: - size_t read( void * const _buffer, size_t _size ) override; - bool seek( size_t _pos ) override; - void rewind() override; - bool rseek( size_t _pos ) override; - bool skip( size_t _pos ) override; - size_t tell() const override; - size_t size() const override; - bool eof() const override; - - public: - bool time( uint64_t * const _time ) const override; - - public: - bool memory( void ** const _memory, size_t * const _size ) override; - - protected: - LPVOID m_memoryGranularity; - - size_t m_size; - - uint8_t * m_base; - uint8_t * m_pos; - uint8_t * m_end; - - MENGINE_THREAD_GUARD_INIT( Win32FileMappedInputStream ); - }; - ////////////////////////////////////////////////////////////////////////// - typedef IntrusivePtr Win32FileMappedInputStreamPtr; - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.cpp b/src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.cpp deleted file mode 100644 index 7938648c0f..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "Win32FileOutputStream.h" - -#include "Interface/UnicodeSystemInterface.h" -#include "Interface/PlatformServiceInterface.h" - -#include "Environment/Windows/Win32FileHelper.h" -#include "Environment/Windows/Win32Helper.h" - -#include "Win32ConcatenateFileHelper.h" - -#include "Kernel/StatisticHelper.h" -#include "Kernel/Assertion.h" -#include "Kernel/Logger.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - Win32FileOutputStream::Win32FileOutputStream() - : m_hFile( INVALID_HANDLE_VALUE ) - , m_size( 0 ) - , m_withTemp( true ) - { - } - ////////////////////////////////////////////////////////////////////////// - Win32FileOutputStream::~Win32FileOutputStream() - { - this->close(); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileOutputStream::open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, bool _withTemp ) - { -#if defined(MENGINE_DEBUG) - this->setDebugRelationPath( _relationPath ); - this->setDebugFolderPath( _folderPath ); - this->setDebugFilePath( _filePath ); -#endif - - m_relationPath = _relationPath; - m_folderPath = _folderPath; - m_filePath = _filePath; - - m_withTemp = _withTemp; - - WChar fullPathTemp[MENGINE_MAX_PATH + 1] = {L'\0'}; - - if( m_withTemp == true ) - { - size_t fullPathTempLen = Helper::Win32ConcatenateFilePathTempW( m_relationPath, m_folderPath, m_filePath, fullPathTemp, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathTempLen ); - - MENGINE_ASSERTION_FATAL( fullPathTempLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate filePathTemp '%s:%s'" - , m_folderPath.c_str() - , m_filePath.c_str() - ); - } - else - { - size_t fullPathTempLen = Helper::Win32ConcatenateFilePathW( m_relationPath, m_folderPath, m_filePath, fullPathTemp, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathTempLen ); - - MENGINE_ASSERTION_FATAL( fullPathTempLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate filePathTemp '%s:%s'" - , m_folderPath.c_str() - , m_filePath.c_str() - ); - } - - HANDLE hFile = Helper::Win32CreateFile( - fullPathTemp - , GENERIC_WRITE - , FILE_SHARE_READ | FILE_SHARE_WRITE - , CREATE_ALWAYS - ); - - if( hFile == INVALID_HANDLE_VALUE ) - { - LOGGER_ERROR( "invalid open '%ls'" - , fullPathTemp - ); - - return false; - } - - m_hFile = hFile; - - STATISTIC_INC_INTEGER( STATISTIC_OPEN_FILE_COUNT ); - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileOutputStream::close() - { - if( m_hFile == INVALID_HANDLE_VALUE ) - { - return true; - } - - bool successful = this->flush(); - - ::CloseHandle( m_hFile ); - m_hFile = INVALID_HANDLE_VALUE; - - if( m_withTemp == true ) - { - Char fullPathTemp[MENGINE_MAX_PATH + 1] = {'\0'}; - size_t fullPathTempLen = Helper::Win32ConcatenateFilePathTempA( m_relationPath, m_folderPath, m_filePath, fullPathTemp, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathTempLen ); - - MENGINE_ASSERTION_FATAL( fullPathTempLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate filePathTemp '%s:%s'" - , m_folderPath.c_str() - , m_filePath.c_str() - ); - - Char fullPath[MENGINE_MAX_PATH + 1] = {'\0'}; - size_t fullPathLen = Helper::Win32ConcatenateFilePathA( m_relationPath, m_folderPath, m_filePath, fullPath, MENGINE_MAX_PATH ); - - MENGINE_UNUSED( fullPathLen ); - - MENGINE_ASSERTION_FATAL( fullPathLen != MENGINE_PATH_INVALID_LENGTH, "invlalid concatenate filePath '%s:%s'" - , m_folderPath.c_str() - , m_filePath.c_str() - ); - - if( PLATFORM_SERVICE() - ->moveFile( fullPathTemp, fullPath ) == false ) - { - LOGGER_ERROR( "invalid move close file from '%s' to '%s'" - , fullPathTemp - , fullPath - ); - - return false; - } - } - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileOutputStream::write( const void * _data, size_t _size ) - { - DWORD bytesWritten = 0; - if( ::WriteFile( m_hFile, _data, (DWORD)_size, &bytesWritten, NULL ) == FALSE ) - { - LOGGER_ERROR( "invalid write %zu filePath '%s:%s' get error %ls" - , _size - , m_folderPath.c_str() - , m_filePath.c_str() - , Helper::Win32GetLastErrorMessageW() - ); - - return 0; - } - - m_size += (size_t)bytesWritten; - - STATISTIC_ADD_INTEGER( STATISTIC_OPEN_FILE_WRITE_BYTES, bytesWritten ); - - return (size_t)bytesWritten; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32FileOutputStream::size() const - { - return m_size; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32FileOutputStream::flush() - { - if( ::FlushFileBuffers( m_hFile ) == FALSE ) - { - LOGGER_ERROR( "invalid FlushFileBuffers filePath '%s:%s' get error %ls" - , m_folderPath.c_str() - , m_filePath.c_str() - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - return true; - } - ////////////////////////////////////////////////////////////////////////// - HANDLE Win32FileOutputStream::getHandleFile() const - { - return m_hFile; - } - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.h b/src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.h deleted file mode 100644 index d8baaa81d1..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32FileOutputStream.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "Interface/FileOutputStreamInterface.h" - -#include "Environment/Windows/WindowsIncluder.h" - -#include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" - -namespace Mengine -{ - class Win32FileOutputStream - : public FileOutputStreamInterface - , public Factorable -#if defined(MENGINE_DEBUG) - , public BaseDebugFile -#endif - { - DECLARE_FACTORABLE( Win32FileOutputStream ); - - public: - Win32FileOutputStream(); - ~Win32FileOutputStream() override; - - public: - bool open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, bool _withTemp ) override; - bool close() override; - - public: - size_t write( const void * _data, size_t _size ) override; - size_t size() const override; - - public: - bool flush() override; - - public: - HANDLE getHandleFile() const; - - protected: - HANDLE m_hFile; - - size_t m_size; - - FilePath m_relationPath; - FilePath m_folderPath; - FilePath m_filePath; - - bool m_withTemp; - }; - ////////////////////////////////////////////////////////////////////////// - typedef IntrusivePtr Win32FileOutputStreamPtr; - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.cpp b/src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.cpp deleted file mode 100644 index 2aa8f9fbbd..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.cpp +++ /dev/null @@ -1,331 +0,0 @@ -#include "Win32MutexFileInputStream.h" - -#include "Interface/UnicodeSystemInterface.h" -#include "Interface/PlatformServiceInterface.h" - -#include "Environment/Windows/Win32Helper.h" -#include "Environment/Windows/Win32FileHelper.h" -#include "Environment/Windows/Win32PlatformServiceExtensionInterface.h" - -#include "Win32ConcatenateFileHelper.h" - -#include "Kernel/ThreadMutexScope.h" -#include "Kernel/Assertion.h" -#include "Kernel/Logger.h" -#include "Kernel/MemoryCopy.h" - -#include "Config/Algorithm.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - // cppcheck-suppress uninitMemberVar - Win32MutexFileInputStream::Win32MutexFileInputStream() - : m_size( 0 ) - , m_offset( 0 ) - , m_carriage( 0 ) - , m_capacity( 0 ) - , m_reading( 0 ) - { - } - ////////////////////////////////////////////////////////////////////////// - Win32MutexFileInputStream::~Win32MutexFileInputStream() - { - this->close(); - } - ////////////////////////////////////////////////////////////////////////// - void Win32MutexFileInputStream::setFileInputStream( const Win32FileInputStreamPtr & _stream ) - { - m_stream = _stream; - } - ////////////////////////////////////////////////////////////////////////// - void Win32MutexFileInputStream::setThreadMutex( const ThreadMutexInterfacePtr & _mutex ) - { - m_mutex = _mutex; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, size_t _offset, size_t _size, bool _streaming, bool _share ) - { - MENGINE_UNUSED( _relationPath ); - MENGINE_UNUSED( _folderPath ); - MENGINE_UNUSED( _filePath ); - MENGINE_UNUSED( _streaming ); - MENGINE_UNUSED( _share ); - -#if defined(MENGINE_DEBUG) - this->setDebugRelationPath( _relationPath ); - this->setDebugFolderPath( _folderPath ); - this->setDebugFilePath( _filePath ); -#endif - - size_t size = m_stream->size(); - - if( _size != MENGINE_UNKNOWN_SIZE ) - { - if( _offset + _size > size ) - { - LOGGER_ERROR( "invalid file '%s' range %zu:%zu size %zu" - , _filePath.c_str() - , _offset - , _size - , size - ); - - this->close(); - - return false; - } - - m_size = _size; - } - else - { - m_size = size; - } - - m_offset = _offset; - - m_carriage = 0; - m_capacity = 0; - m_reading = 0; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::close() - { - m_stream = nullptr; - m_mutex = nullptr; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32MutexFileInputStream::read( void * const _buf, size_t _count ) - { - size_t pos = m_reading - m_capacity + m_carriage; - - size_t correct_count = _count; - - if( pos + _count > m_size ) - { - correct_count = m_size - pos; - } - - if( correct_count > MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE ) - { - size_t tail = m_capacity - m_carriage; - - if( tail != 0 ) - { - Helper::memoryCopy( _buf, 0, m_readCache, m_carriage, tail ); - } - - size_t toRead = correct_count - tail; - - size_t bytesRead; - if( this->read_( _buf, tail, toRead, &bytesRead ) == false ) - { - return 0; - } - - m_carriage = 0; - m_capacity = 0; - - m_reading += bytesRead; - - return bytesRead + tail; - } - - if( m_carriage + correct_count <= m_capacity ) - { - Helper::memoryCopy( _buf, 0, m_readCache, m_carriage, correct_count ); - - m_carriage += correct_count; - - return correct_count; - } - - size_t tail = m_capacity - m_carriage; - - if( tail != 0 ) - { - Helper::memoryCopy( _buf, 0, m_readCache, m_carriage, tail ); - } - - size_t bytesRead; - if( this->read_( m_readCache, 0, MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE, &bytesRead ) == false ) - { - return 0; - } - - size_t readSize = MENGINE_MIN( correct_count - tail, bytesRead ); - - Helper::memoryCopy( _buf, tail, m_readCache, 0, readSize ); - - m_carriage = readSize; - m_capacity = bytesRead; - - m_reading += bytesRead; - - return readSize + tail; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::read_( void * const _buf, size_t _offset, size_t _size, size_t * const _read ) - { - if( _size == 0 ) - { - *_read = 0; - - return true; - } - - MENGINE_THREAD_MUTEX_SCOPE( m_mutex ); - - HANDLE hFile = m_stream->getHandleFile(); - - size_t current = m_reading - m_capacity + m_carriage; - - size_t pos = m_offset + current; - - LARGE_INTEGER liDistanceToMove; - liDistanceToMove.QuadPart = pos; - - LARGE_INTEGER dwPtr; - if( ::SetFilePointerEx( hFile, liDistanceToMove, &dwPtr, FILE_BEGIN ) == FALSE ) - { - LOGGER_ERROR( "seek %zu:%zu get %ls" - , pos - , m_size - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - uint8_t * buf_offset = MENGINE_PVOID_OFFSET( _buf, _offset ); - - DWORD bytesRead = 0; - if( ::ReadFile( hFile, buf_offset, static_cast(_size), &bytesRead, NULL ) == FALSE ) - { - LOGGER_ERROR( "read offset %zu size %zu:%zu %ls" - , _offset - , _size - , m_size - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - *_read = (size_t)bytesRead; - - return true; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::seek( size_t _pos ) - { - size_t carriage = _pos; - - bool successful = this->seek_( carriage ); - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - void Win32MutexFileInputStream::rewind() - { - this->seek_( 0 ); - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::rseek( size_t _pos ) - { - size_t carriage = m_size - _pos; - - bool successful = this->seek_( carriage ); - - return successful; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::skip( size_t _pos ) - { - size_t current = m_reading - m_capacity + m_carriage; - - size_t carriage = current + _pos; - - bool result = this->seek_( carriage ); - - return result; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::seek_( size_t _pos ) - { - if( _pos >= m_reading - m_capacity && _pos <= m_reading ) - { - m_carriage = m_capacity - (m_reading - _pos); - } - else - { - m_carriage = 0; - m_capacity = 0; - - m_reading = _pos; - } - - return true; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32MutexFileInputStream::tell() const - { - size_t carriage = m_reading - m_capacity + m_carriage; - - return carriage; - } - ////////////////////////////////////////////////////////////////////////// - size_t Win32MutexFileInputStream::size() const - { - return m_size; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::eof() const - { - size_t carriage = m_reading - m_capacity + m_carriage; - - return carriage == m_size; - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::time( uint64_t * const _time ) const - { -#if defined(MENGINE_PLATFORM_WINDOWS) - FILETIME creation; - FILETIME access; - FILETIME write; - - HANDLE hFile = m_stream->getHandleFile(); - - if( ::GetFileTime( hFile, &creation, &access, &write ) == FALSE ) - { - LOGGER_ERROR( "invalid GetFileTime get error %ls" - , Helper::Win32GetLastErrorMessageW() - ); - - return false; - } - - time_t time = Helper::Win32FileTimeToUnixTime( &write ); - - *_time = (uint64_t)time; - - return true; -#else - return false; -#endif - } - ////////////////////////////////////////////////////////////////////////// - bool Win32MutexFileInputStream::memory( void ** const _memory, size_t * const _size ) - { - MENGINE_UNUSED( _memory ); - MENGINE_UNUSED( _size ); - - return false; - } - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.h b/src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.h deleted file mode 100644 index cdf065a82a..0000000000 --- a/src/Plugins/Win32FileGroupPlugin/Win32MutexFileInputStream.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include "Interface/FileInputStreamInterface.h" -#include "Interface/ThreadMutexInterface.h" - -#include "Win32FileInputStream.h" - -#include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" - -#include "Environment/Windows/WindowsIncluder.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - class Win32MutexFileInputStream - : public FileInputStreamInterface - , public Factorable -#if defined(MENGINE_DEBUG) - , public BaseDebugFile -#endif - { - DECLARE_FACTORABLE( Win32MutexFileInputStream ); - - public: - Win32MutexFileInputStream(); - ~Win32MutexFileInputStream() override; - - public: - void setFileInputStream( const Win32FileInputStreamPtr & _stream ); - void setThreadMutex( const ThreadMutexInterfacePtr & _mutex ); - - public: - bool open( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, size_t _offset, size_t _size, bool _streaming, bool _share ) override; - bool close() override; - - public: - size_t read( void * const _buf, size_t _count ) override; - bool seek( size_t _pos ) override; - void rewind() override; - bool rseek( size_t _pos ) override; - bool skip( size_t _pos ) override; - size_t tell() const override; - size_t size() const override; - bool eof() const override; - - public: - bool time( uint64_t * const _time ) const override; - - public: - bool memory( void ** const _memory, size_t * const _size ) override; - - protected: - bool read_( void * const _buf, size_t _offset, size_t _size, size_t * const _read ); - bool seek_( size_t _pos ); - - protected: - Win32FileInputStreamPtr m_stream; - ThreadMutexInterfacePtr m_mutex; - - size_t m_size; - size_t m_offset; - - size_t m_carriage; - size_t m_capacity; - size_t m_reading; - - uint8_t m_readCache[MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE]; - }; - ////////////////////////////////////////////////////////////////////////// - typedef IntrusivePtr Win32MutexFileInputStreamPtr; - ////////////////////////////////////////////////////////////////////////// -} diff --git a/src/Systems/AndroidFileSystem/AndroidAssetInputStream.cpp b/src/Systems/AndroidFileSystem/AndroidAssetInputStream.cpp index ee6279cf87..8fd7c46a62 100644 --- a/src/Systems/AndroidFileSystem/AndroidAssetInputStream.cpp +++ b/src/Systems/AndroidFileSystem/AndroidAssetInputStream.cpp @@ -136,7 +136,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath, filePath, true, m_streaming ); } #endif @@ -158,7 +158,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, false, m_streaming ); } #endif diff --git a/src/Systems/AndroidFileSystem/AndroidFileInputStream.cpp b/src/Systems/AndroidFileSystem/AndroidFileInputStream.cpp index 9d8d902d55..382b9486a1 100644 --- a/src/Systems/AndroidFileSystem/AndroidFileInputStream.cpp +++ b/src/Systems/AndroidFileSystem/AndroidFileInputStream.cpp @@ -136,7 +136,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath, filePath, true, m_streaming ); } #endif @@ -156,7 +156,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, true, m_streaming ); } #endif diff --git a/src/Systems/AndroidFileSystem/AndroidFileInputStream.h b/src/Systems/AndroidFileSystem/AndroidFileInputStream.h index af2766812f..1f87f505c0 100644 --- a/src/Systems/AndroidFileSystem/AndroidFileInputStream.h +++ b/src/Systems/AndroidFileSystem/AndroidFileInputStream.h @@ -4,7 +4,10 @@ #include "Kernel/Factorable.h" #include "Kernel/ThreadGuard.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif #ifndef MENGINE_FILE_STREAM_BUFFER_SIZE #define MENGINE_FILE_STREAM_BUFFER_SIZE 4096 diff --git a/src/Systems/AndroidFileSystem/AndroidFileOutputStream.cpp b/src/Systems/AndroidFileSystem/AndroidFileOutputStream.cpp index b23563cc9e..f1d1df6473 100644 --- a/src/Systems/AndroidFileSystem/AndroidFileOutputStream.cpp +++ b/src/Systems/AndroidFileSystem/AndroidFileOutputStream.cpp @@ -5,6 +5,8 @@ #include "Kernel/Logger.h" #include "Kernel/DebugFileHelper.h" +#include "Kernel/ThreadGuardScope.h" +#include "Kernel/NotificationHelper.h" namespace Mengine { @@ -24,6 +26,8 @@ namespace Mengine { MENGINE_UNUSED( _withTemp ); + MENGINE_THREAD_GUARD_SCOPE( AndroidFileOutputStream, this ); + #if defined(MENGINE_DEBUG) this->setDebugRelationPath( _relationPath ); this->setDebugFolderPath( _folderPath ); @@ -56,16 +60,38 @@ namespace Mengine m_size = 0; +#if defined(MENGINE_DEBUG) + if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) + { + const FilePath & folderPath = this->getDebugFolderPath(); + const FilePath & filePath = this->getDebugFilePath(); + + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath, filePath, false, false ); + } +#endif + return true; } ////////////////////////////////////////////////////////////////////////// bool AndroidFileOutputStream::close() { + MENGINE_THREAD_GUARD_SCOPE( AndroidFileOutputStream, this ); + if( m_file == nullptr ) { return false; } +#if defined(MENGINE_DEBUG) + if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) + { + const FilePath & folderPath = this->getDebugFolderPath(); + const FilePath & filePath = this->getDebugFilePath(); + + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, false, false ); + } +#endif + ::fclose( m_file ); m_file = nullptr; diff --git a/src/Systems/AndroidFileSystem/AndroidFileOutputStream.h b/src/Systems/AndroidFileSystem/AndroidFileOutputStream.h index 5b18e60d60..853ecf2a4f 100644 --- a/src/Systems/AndroidFileSystem/AndroidFileOutputStream.h +++ b/src/Systems/AndroidFileSystem/AndroidFileOutputStream.h @@ -3,7 +3,11 @@ #include "Interface/FileOutputStreamInterface.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" +#include "Kernel/ThreadGuard.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif namespace Mengine { @@ -36,6 +40,8 @@ namespace Mengine FILE * m_file; size_t m_size; + + MENGINE_THREAD_GUARD_INIT( AndroidFileOutputStream ); }; ////////////////////////////////////////////////////////////////////////// typedef IntrusivePtr AndroidFileOutputStreamPtr; diff --git a/src/Systems/AndroidFileSystem/AndroidMutexAssetInputStream.h b/src/Systems/AndroidFileSystem/AndroidMutexAssetInputStream.h index 31ac85e624..2f216e8b64 100644 --- a/src/Systems/AndroidFileSystem/AndroidMutexAssetInputStream.h +++ b/src/Systems/AndroidFileSystem/AndroidMutexAssetInputStream.h @@ -6,7 +6,10 @@ #include "AndroidAssetInputStream.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif namespace Mengine { diff --git a/src/Systems/AndroidFileSystem/AndroidMutexFileInputStream.h b/src/Systems/AndroidFileSystem/AndroidMutexFileInputStream.h index caafed5f6a..eab7cca234 100644 --- a/src/Systems/AndroidFileSystem/AndroidMutexFileInputStream.h +++ b/src/Systems/AndroidFileSystem/AndroidMutexFileInputStream.h @@ -6,7 +6,10 @@ #include "AndroidFileInputStream.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif namespace Mengine { diff --git a/src/Systems/AppleFileSystem/AppleFileInputStream.mm b/src/Systems/AppleFileSystem/AppleFileInputStream.mm index ae286b2a26..2fa8cbc846 100644 --- a/src/Systems/AppleFileSystem/AppleFileInputStream.mm +++ b/src/Systems/AppleFileSystem/AppleFileInputStream.mm @@ -141,7 +141,7 @@ #if defined(MENGINE_DEBUG) if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) { - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, _folderPath.c_str(), _filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, _folderPath, _filePath, m_streaming ); } #endif diff --git a/src/Systems/SDLFileSystem/SDLFileInputStream.cpp b/src/Systems/SDLFileSystem/SDLFileInputStream.cpp index 2cb1b7a823..2d6dc07db3 100644 --- a/src/Systems/SDLFileSystem/SDLFileInputStream.cpp +++ b/src/Systems/SDLFileSystem/SDLFileInputStream.cpp @@ -141,7 +141,7 @@ namespace Mengine #if defined(MENGINE_DEBUG) if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) { - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, _folderPath.c_str(), _filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, _folderPath, _filePath, true, m_streaming ); } #endif @@ -161,7 +161,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, true, m_streaming ); } #endif diff --git a/src/Systems/SDLFileSystem/SDLFileInputStream.h b/src/Systems/SDLFileSystem/SDLFileInputStream.h index eebbd3ad85..538cb7dd9f 100644 --- a/src/Systems/SDLFileSystem/SDLFileInputStream.h +++ b/src/Systems/SDLFileSystem/SDLFileInputStream.h @@ -4,7 +4,10 @@ #include "Kernel/Factorable.h" #include "Kernel/ThreadGuard.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif #include "SDL_rwops.h" diff --git a/src/Systems/SDLFileSystem/SDLFileOutputStream.cpp b/src/Systems/SDLFileSystem/SDLFileOutputStream.cpp index 89acd27795..ce191c7815 100644 --- a/src/Systems/SDLFileSystem/SDLFileOutputStream.cpp +++ b/src/Systems/SDLFileSystem/SDLFileOutputStream.cpp @@ -5,6 +5,7 @@ #include "Kernel/Logger.h" #include "Kernel/PathHelper.h" #include "Kernel/FilePathHelper.h" +#include "Kernel/NotificationHelper.h" namespace Mengine { @@ -84,6 +85,13 @@ namespace Mengine m_size = 0; +#if defined(MENGINE_DEBUG) + if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) + { + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, _folderPath, _filePath, false, false ); + } +#endif + return true; } ////////////////////////////////////////////////////////////////////////// @@ -94,6 +102,16 @@ namespace Mengine return true; } +#if defined(MENGINE_DEBUG) + if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) + { + const FilePath & folderPath = this->getDebugFolderPath(); + const FilePath & filePath = this->getDebugFilePath(); + + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, false, false ); + } +#endif + SDL_RWclose( m_rwops ); m_rwops = nullptr; diff --git a/src/Systems/SDLFileSystem/SDLFileOutputStream.h b/src/Systems/SDLFileSystem/SDLFileOutputStream.h index 73e1396b04..8372c91671 100644 --- a/src/Systems/SDLFileSystem/SDLFileOutputStream.h +++ b/src/Systems/SDLFileSystem/SDLFileOutputStream.h @@ -3,7 +3,10 @@ #include "Interface/FileOutputStreamInterface.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif #include "SDL_rwops.h" diff --git a/src/Systems/SDLFileSystem/SDLMutexFileInputStream.h b/src/Systems/SDLFileSystem/SDLMutexFileInputStream.h index b2e9cc21d5..93187cbe09 100644 --- a/src/Systems/SDLFileSystem/SDLMutexFileInputStream.h +++ b/src/Systems/SDLFileSystem/SDLMutexFileInputStream.h @@ -6,7 +6,10 @@ #include "SDLFileInputStream.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif #include "SDL_rwops.h" diff --git a/src/Systems/Win32FileSystem/Win32FileInputStream.cpp b/src/Systems/Win32FileSystem/Win32FileInputStream.cpp index ac0707d15e..bb2dddb33a 100644 --- a/src/Systems/Win32FileSystem/Win32FileInputStream.cpp +++ b/src/Systems/Win32FileSystem/Win32FileInputStream.cpp @@ -139,7 +139,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, true, m_streaming ); } #endif @@ -199,7 +199,7 @@ namespace Mengine const FilePath & folderPath = this->getDebugFolderPath(); const FilePath & filePath = this->getDebugFilePath(); - NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath.c_str(), filePath.c_str(), m_streaming ); + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath, filePath, true, m_streaming ); } #endif diff --git a/src/Systems/Win32FileSystem/Win32FileInputStream.h b/src/Systems/Win32FileSystem/Win32FileInputStream.h index a379d8eaad..e9ac1ac5f5 100644 --- a/src/Systems/Win32FileSystem/Win32FileInputStream.h +++ b/src/Systems/Win32FileSystem/Win32FileInputStream.h @@ -2,11 +2,14 @@ #include "Interface/FileInputStreamInterface.h" +#include "Environment/Windows/WindowsIncluder.h" + #include "Kernel/Factorable.h" #include "Kernel/ThreadGuardScope.h" -#include "Kernel/BaseDebugFile.h" -#include "Environment/Windows/WindowsIncluder.h" +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif #ifndef MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE #define MENGINE_WIN32_FILE_STREAM_BUFFER_SIZE 4096 diff --git a/src/Systems/Win32FileSystem/Win32FileMapped.h b/src/Systems/Win32FileSystem/Win32FileMapped.h index 57d2866fff..1a638cb7a8 100644 --- a/src/Systems/Win32FileSystem/Win32FileMapped.h +++ b/src/Systems/Win32FileSystem/Win32FileMapped.h @@ -3,10 +3,10 @@ #include "Interface/FileMappedInterface.h" #include "Interface/FactoryInterface.h" -#include "Kernel/Factorable.h" - #include "Environment/Windows/WindowsIncluder.h" +#include "Kernel/Factorable.h" + namespace Mengine { ////////////////////////////////////////////////////////////////////////// diff --git a/src/Systems/Win32FileSystem/Win32FileMappedInputStream.h b/src/Systems/Win32FileSystem/Win32FileMappedInputStream.h index 3750f99b01..0efa524872 100644 --- a/src/Systems/Win32FileSystem/Win32FileMappedInputStream.h +++ b/src/Systems/Win32FileSystem/Win32FileMappedInputStream.h @@ -2,11 +2,11 @@ #include "Interface/InputStreamInterface.h" +#include "Environment/Windows/WindowsIncluder.h" + #include "Kernel/Factorable.h" #include "Kernel/ThreadGuard.h" -#include "Environment/Windows/WindowsIncluder.h" - namespace Mengine { ////////////////////////////////////////////////////////////////////////// diff --git a/src/Systems/Win32FileSystem/Win32FileOutputStream.cpp b/src/Systems/Win32FileSystem/Win32FileOutputStream.cpp index 7938648c0f..e6740a2367 100644 --- a/src/Systems/Win32FileSystem/Win32FileOutputStream.cpp +++ b/src/Systems/Win32FileSystem/Win32FileOutputStream.cpp @@ -8,6 +8,7 @@ #include "Win32ConcatenateFileHelper.h" +#include "Kernel/NotificationHelper.h" #include "Kernel/StatisticHelper.h" #include "Kernel/Assertion.h" #include "Kernel/Logger.h" @@ -86,6 +87,16 @@ namespace Mengine STATISTIC_INC_INTEGER( STATISTIC_OPEN_FILE_COUNT ); +#if defined(MENGINE_DEBUG) + if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) + { + const FilePath & folderPath = this->getDebugFolderPath(); + const FilePath & filePath = this->getDebugFilePath(); + + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_OPEN_FILE, folderPath, filePath, false, false ); + } +#endif + return true; } ////////////////////////////////////////////////////////////////////////// @@ -96,6 +107,16 @@ namespace Mengine return true; } +#if defined(MENGINE_DEBUG) + if( SERVICE_IS_INITIALIZE( NotificationServiceInterface ) == true ) + { + const FilePath & folderPath = this->getDebugFolderPath(); + const FilePath & filePath = this->getDebugFilePath(); + + NOTIFICATION_NOTIFY( NOTIFICATOR_DEBUG_CLOSE_FILE, folderPath, filePath, false, false ); + } +#endif + bool successful = this->flush(); ::CloseHandle( m_hFile ); diff --git a/src/Systems/Win32FileSystem/Win32FileOutputStream.h b/src/Systems/Win32FileSystem/Win32FileOutputStream.h index d8baaa81d1..94e78304ca 100644 --- a/src/Systems/Win32FileSystem/Win32FileOutputStream.h +++ b/src/Systems/Win32FileSystem/Win32FileOutputStream.h @@ -5,7 +5,10 @@ #include "Environment/Windows/WindowsIncluder.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" + +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif namespace Mengine { diff --git a/src/Systems/Win32FileSystem/Win32MutexFileInputStream.h b/src/Systems/Win32FileSystem/Win32MutexFileInputStream.h index cdf065a82a..6410965758 100644 --- a/src/Systems/Win32FileSystem/Win32MutexFileInputStream.h +++ b/src/Systems/Win32FileSystem/Win32MutexFileInputStream.h @@ -6,9 +6,10 @@ #include "Win32FileInputStream.h" #include "Kernel/Factorable.h" -#include "Kernel/BaseDebugFile.h" -#include "Environment/Windows/WindowsIncluder.h" +#if defined(MENGINE_DEBUG) +# include "Kernel/BaseDebugFile.h" +#endif namespace Mengine {