bool QFileStream::_OpenPlatformImplementation(const QPath &filePath, const EQFileOpenMode &eOpenMode, const bool bIsWritingAllowed, QFileStream::NativeHandle &handle, EQFileSystemError &eErrorInfo)
{
    bool bSuccess = true;

    using Kinesis::QuimeraEngine::Common::DataTypes::QArrayResult;
    using Kinesis::QuimeraEngine::Common::DataTypes::i8_q;
    using Kinesis::QuimeraEngine::Common::DataTypes::EQTextEncoding;

    QArrayResult<i8_q> szPath = filePath.ToString().ToBytes(EQTextEncoding::E_UTF8);
        
    int nAccess = bIsWritingAllowed ? O_RDWR: 
                                      O_RDONLY;
    int nPermissions = S_IRWXU; // Read, write and execution permissions for the owner
    int nOpenMode = 0;

    switch(eOpenMode)
    {
    case EQFileOpenMode::E_Append:
    case EQFileOpenMode::E_Open:
        nOpenMode = 0;
        break;
    case EQFileOpenMode::E_Create:
        nOpenMode = O_CREAT | O_EXCL;
        break;
    case EQFileOpenMode::E_CreateOrOverwrite:
        nOpenMode = O_CREAT | O_TRUNC;
        break;
    case EQFileOpenMode::E_OpenOrCreate:
        nOpenMode = O_CREAT;
        break;
    default:
        break;
    }
        
    handle = open(szPath.Get(), nAccess | nOpenMode, nPermissions);

    const bool FILE_OPENED_SUCCESSFULLY = handle >= 0;
        
    if(!FILE_OPENED_SUCCESSFULLY)
    {
        bSuccess = false;
        error_t lastError = errno;
        QE_ASSERT_ERROR(handle >= 0, string_q("An unexpected error occurred when opening the file \"") + filePath.GetAbsolutePath() + "\". The error code was: " + string_q::FromInteger(lastError) + ".");
            
        if(lastError == EACCES)
            eErrorInfo = EQFileSystemError::E_NoPermissions;
        else
            eErrorInfo = EQFileSystemError::E_Unknown;
    }

    return bSuccess;
}
bool QFileStream::_OpenPlatformImplementation(const QPath &filePath, const EQFileOpenMode &eOpenMode, const bool bIsWritingAllowed, QFileStream::NativeHandle &handle, EQFileSystemError &eErrorInfo)
{
    bool bSuccess = true;

    using Kinesis::QuimeraEngine::Common::DataTypes::QArrayResult;
    using Kinesis::QuimeraEngine::Common::DataTypes::i8_q;

    QArrayResult<i8_q> arPath = filePath.ToString().ToBytes(string_q::GetLocalEncodingUTF16());
    const wchar_t* szPath = rcast_q(arPath.Get(), wchar_t*);
    DWORD uAccess = bIsWritingAllowed ? GENERIC_READ | GENERIC_WRITE : 
                                        GENERIC_READ;
    DWORD uOpenMode = 0;

    switch(eOpenMode)
    {
    case EQFileOpenMode::E_Append:
    case EQFileOpenMode::E_Open:
        uOpenMode = OPEN_EXISTING;
        break;
    case EQFileOpenMode::E_Create:
        uOpenMode = CREATE_NEW;
        break;
    case EQFileOpenMode::E_CreateOrOverwrite:
        uOpenMode = CREATE_ALWAYS;
        break;
    case EQFileOpenMode::E_OpenOrCreate:
        uOpenMode = OPEN_ALWAYS;
        break;
    default:
        break;
    }

    handle = ::CreateFileW(szPath, uAccess, FILE_SHARE_READ, NULL, uOpenMode, FILE_FLAG_RANDOM_ACCESS, NULL);

    const bool FILE_OPENED_SUCCESSFULLY = handle != INVALID_HANDLE_VALUE;

    if(!FILE_OPENED_SUCCESSFULLY)
    {
        bSuccess = false;
        DWORD uCreateFileWLastError = ::GetLastError();
        QE_ASSERT_ERROR(handle != INVALID_HANDLE_VALUE, string_q("An unexpected error occurred when opening the file \"") + filePath.GetAbsolutePath() + "\". The error code was: " + string_q::FromInteger(uCreateFileWLastError) + ".");

        if(uCreateFileWLastError == ERROR_ACCESS_DENIED)
            eErrorInfo = EQFileSystemError::E_NoPermissions;
        else
            eErrorInfo = EQFileSystemError::E_Unknown;
    }

    return bSuccess;
}