// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#if PLATFORM_ANDROID
#include "Engine/Platform/Unix/UnixFile.h"
typedef struct AAsset AAsset;
///
/// Android platform file object implementation.
///
class AndroidFile : public UnixFile
{
public:
///
/// Initializes a new instance of the class.
///
/// The handle.
AndroidFile(int32 handle);
///
/// Finalizes an instance of the class.
///
~AndroidFile();
public:
///
/// Creates or opens a file.
///
/// The name of the file to be created or opened.
/// An action to take on a file that exists or does not exist.
/// The requested access to the file.
/// The requested sharing mode of the file.
/// Opened file handle or null if cannot.
static AndroidFile* Open(const StringView& path, FileMode mode, FileAccess access = FileAccess::ReadWrite, FileShare share = FileShare::None);
};
///
/// Android platform asset file object implementation (accessed via AAssetManager API).
///
class AndroidAssetFile : public AndroidFile
{
private:
AAsset* _asset;
public:
///
/// Initializes a new instance of the class.
///
/// The Android asset.
AndroidAssetFile(AAsset* asset);
///
/// Finalizes an instance of the class.
///
~AndroidAssetFile();
public:
// [AndroidFile]
bool Read(void* buffer, uint32 bytesToRead, uint32* bytesRead = nullptr) override;
bool Write(const void* buffer, uint32 bytesToWrite, uint32* bytesWritten = nullptr) override;
void Close() override;
uint32 GetSize() const override;
DateTime GetLastWriteTime() const override;
uint32 GetPosition() const override;
void SetPosition(uint32 seek) override;
bool IsOpened() const override;
};
#endif