Skip to content

Commit

Permalink
ref-in FileSystemInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Nov 4, 2024
1 parent 64b3380 commit 8afde37
Show file tree
Hide file tree
Showing 70 changed files with 1,630 additions and 1,610 deletions.
5 changes: 5 additions & 0 deletions src/Environment/SDL/SDLIncluder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@

#include "SDL.h"
#include "SDL_syswm.h"
#include "SDL_loadso.h"
#include "SDL_filesystem.h"
#include "SDL_video.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
142 changes: 137 additions & 5 deletions src/Environment/Windows/Win32FileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ namespace Mengine
return handle;
}
//////////////////////////////////////////////////////////////////////////
bool Win32ValidateFile( const WChar * _path )
bool Win32ValidateFile( const WChar * _filePath )
{
WChar pathCorrect[MENGINE_MAX_PATH + 1] = {L'\0'};
Helper::pathCorrectBackslashToW( pathCorrect, _filePath );

WIN32_FIND_DATA wfd;
HANDLE hFind = ::FindFirstFile( _path, &wfd );
HANDLE hFind = ::FindFirstFile( pathCorrect, &wfd );

if( hFind == INVALID_HANDLE_VALUE )
{
LOGGER_ERROR( "file invalid find ??? (%ls) get error %ls"
, _path
, pathCorrect
, Helper::Win32GetLastErrorMessageW()
);

Expand All @@ -122,12 +125,12 @@ namespace Mengine

::FindClose( hFind );

const WChar * filename = ::PathFindFileNameW( _path );
const WChar * filename = ::PathFindFileNameW( pathCorrect );

if( StdString::wcscmp( filename, wfd.cFileName ) != 0 )
{
LOGGER_ERROR( "file invalid name lowercase|upcase:\npath - '%ls'\nneed file name - '%ls'\ncurrent file name - '%ls'\n\n"
, _path
, pathCorrect
, filename
, wfd.cFileName
);
Expand All @@ -138,6 +141,135 @@ namespace Mengine
return true;
}
//////////////////////////////////////////////////////////////////////////
bool Win32ExistFile( const WChar * _filePath )
{
WChar pathCorrect[MENGINE_MAX_PATH + 1] = {L'\0'};
Helper::pathCorrectBackslashToW( pathCorrect, _filePath );

size_t len = StdString::wcslen( pathCorrect );

if( len == 0 )
{
return false;
}

if( pathCorrect[len - 1] == L':' )
{
return true;
}

DWORD attributes = ::GetFileAttributesW( pathCorrect );

if( attributes == INVALID_FILE_ATTRIBUTES )
{
return false;
}

if( (attributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY )
{
return false;
}

return true;
}
//////////////////////////////////////////////////////////////////////////
bool Win32CreateDirectory( const WChar * _basePath, const WChar * _directory )
{
size_t unicode_directorySize = StdString::wcslen( _directory );

if( unicode_directorySize == 0 )
{
return true;
}

WChar pathDirectory[MENGINE_MAX_PATH + 1] = {L'\0'};
Helper::pathCorrectBackslashToW( pathDirectory, _directory );

Helper::pathRemoveFileSpecW( pathDirectory );

if( StdString::wcslen( pathDirectory ) == 0 )
{
return true;
}

WChar pathTestDirectory[MENGINE_MAX_PATH + 1] = {L'\0'};
StdString::wcsncpy( pathTestDirectory, _basePath, MENGINE_MAX_PATH );
StdString::wcsncat( pathTestDirectory, pathDirectory, MENGINE_MAX_PATH );

if( ::PathIsDirectoryW( pathTestDirectory ) == FILE_ATTRIBUTE_DIRECTORY )
{
return true;
}

Helper::pathRemoveBackslashW( pathDirectory );

uint32_t paths_count = 0;
WChar paths[MENGINE_MAX_PATH + 1][16];

for( ;; )
{
StdString::wcsncpy( paths[paths_count++], pathDirectory, MENGINE_MAX_PATH );

if( Helper::pathRemoveFileSpecW( pathDirectory ) == false )
{
break;
}

Helper::pathRemoveBackslashW( pathDirectory );

StdString::wcsncpy( pathTestDirectory, _basePath, MENGINE_MAX_PATH );
StdString::wcsncat( pathTestDirectory, pathDirectory, MENGINE_MAX_PATH );

if( ::PathIsDirectoryW( pathTestDirectory ) == FILE_ATTRIBUTE_DIRECTORY )
{
break;
}
}

for( uint32_t index = paths_count; index != 0; --index )
{
const WChar * path = paths[index - 1];

WChar pathCreateDirectory[MENGINE_MAX_PATH + 1] = {L'\0'};
StdString::wcsncpy( pathCreateDirectory, _basePath, MENGINE_MAX_PATH );
StdString::wcsncat( pathCreateDirectory, path, MENGINE_MAX_PATH );

BOOL successful = ::CreateDirectory( pathCreateDirectory, NULL );

if( successful == FALSE )
{
DWORD error = ::GetLastError();

switch( error )
{
case ERROR_ALREADY_EXISTS:
{
continue;
}break;
case ERROR_PATH_NOT_FOUND:
{
LOGGER_ERROR( "directory '%ls' not found"
, pathCreateDirectory
);

return false;
}break;
default:
{
LOGGER_ERROR( "directory '%ls' unknown %ls"
, pathCreateDirectory
, Helper::Win32GetLastErrorMessageW()
);

return false;
}break;
}
}
}

return true;
}
//////////////////////////////////////////////////////////////////////////
bool Win32ListDirectory( const WChar * _dir, const WChar * _mask, const WChar * _path, const LambdaListDirectoryFilePath & _lambda, bool * const _stop )
{
{
Expand Down
5 changes: 4 additions & 1 deletion src/Environment/Windows/Win32FileHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ namespace Mengine
time_t Win32FileTimeToUnixTime( const FILETIME * _filetime );

HANDLE Win32CreateFile( const WChar * _filePath, DWORD _desiredAccess, DWORD _sharedMode, DWORD _creationDisposition );
bool Win32ValidateFile( const WChar * _path );
bool Win32ValidateFile( const WChar * _filePath );
bool Win32ExistFile( const WChar * _filePath );

bool Win32CreateDirectory( const WChar * _basePath, const WChar * _directory );

typedef Lambda<bool(const WChar *)> LambdaListDirectoryFilePath;
bool Win32ListDirectory( const WChar * _dir, const WChar * _mask, const WChar * _path, const LambdaListDirectoryFilePath & _lambda, bool * const _stop );
Expand Down
14 changes: 14 additions & 0 deletions src/Interface/FileSystemInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ namespace Mengine
{
SERVICE_DECLARE( "FileSystem" )

public:
virtual bool existDirectory( const Char * _directoryPath, const Char * _directory ) const = 0;
virtual bool createDirectory( const Char * _directoryPath, const Char * _directory ) = 0;

public:
virtual bool existFile( const Char * _filePath ) = 0;
virtual bool removeFile( const Char * _filePath ) = 0;
virtual bool moveFile( const Char * _oldFilePath, const Char * _newFilePath ) = 0;

public:
virtual bool findFiles( const Char * _base, const Char * _path, const Char * _mask, const LambdaFilePath & _lambda ) const = 0;

public:
virtual uint64_t getFileTime( const Char * _filePath ) const = 0;
};
}
//////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 0 additions & 15 deletions src/Interface/PlatformServiceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,6 @@ namespace Mengine
virtual bool openMail( const Char * _email, const Char * _subject, const Char * _body ) = 0;
virtual bool openDeleteAccount() = 0;

public:
virtual bool existDirectory( const Char * _directoryPath, const Char * _directory ) const = 0;
virtual bool createDirectory( const Char * _directoryPath, const Char * _directory ) = 0;

public:
virtual bool existFile( const Char * _filePath ) = 0;
virtual bool removeFile( const Char * _filePath ) = 0;
virtual bool moveFile( const Char * _oldFilePath, const Char * _newFilePath ) = 0;

public:
virtual bool findFiles( const Char * _base, const Char * _path, const Char * _mask, const LambdaFilePath & _lambda ) const = 0;

public:
virtual uint64_t getFileTime( const Char * _filePath ) const = 0;

public:
virtual bool updateDesktopWallpaper( const Char * _directoryPath, const Char * _filePath ) = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Interface/ThreadTaskInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Mengine

public:
virtual void preparation() = 0;
virtual void main() = 0;
virtual void process() = 0;
virtual void finish() = 0;
virtual void finally() = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/ThreadTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Mengine
this->_onThreadTaskPreparation();
}
//////////////////////////////////////////////////////////////////////////
void ThreadTask::main()
void ThreadTask::process()
{
if( m_run == false ||
m_finish == true ||
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/ThreadTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Mengine

public:
void preparation() override;
void main() override;
void process() override;

public:
bool run( const ThreadMutexInterfacePtr & _mutex ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/ThreadTaskPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Mengine
for( const ThreadTaskPtr & task : m_tasks )
{
m_childMutex->lock();
task->main();
task->process();
m_childMutex->unlock();
}

Expand Down
Loading

0 comments on commit 8afde37

Please sign in to comment.