2020-08-27 00:21:44 +08:00
|
|
|
// Copyright (c) 2018-2019 HALX99
|
|
|
|
// Copyright (c) 2020 c4games.com
|
2019-11-24 14:54:45 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
#include <string>
|
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include "platform/CCPlatformMacros.h"
|
|
|
|
|
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
|
|
|
#include "platform/android/CCFileUtils-android.h"
|
|
|
|
#include <jni.h>
|
|
|
|
#include <android/asset_manager.h>
|
|
|
|
#include <android/asset_manager_jni.h>
|
2019-12-01 01:16:46 +08:00
|
|
|
#include "base/ZipUtils.h"
|
2019-11-24 14:54:45 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
struct UnzFileStream;
|
|
|
|
union PXFileHandle {
|
|
|
|
int _fd = -1;
|
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
|
|
|
AAsset* _asset;
|
2019-12-01 01:16:46 +08:00
|
|
|
ZipFileStream _zfs;
|
2019-11-24 14:54:45 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PXIoF;
|
|
|
|
|
2020-08-27 00:21:44 +08:00
|
|
|
class CC_DLL FileStream {
|
2019-11-24 14:54:45 +08:00
|
|
|
public:
|
2020-08-27 00:21:44 +08:00
|
|
|
FileStream();
|
|
|
|
~FileStream();
|
2019-11-24 14:54:45 +08:00
|
|
|
|
2020-08-27 11:35:55 +08:00
|
|
|
FileStream(FileStream&& rhs);
|
|
|
|
FileStream& operator=(FileStream&& rhs);
|
|
|
|
|
2020-08-27 10:19:21 +08:00
|
|
|
enum class Mode {
|
|
|
|
READ,
|
|
|
|
WRITE,
|
|
|
|
APPEND,
|
2019-11-24 14:54:45 +08:00
|
|
|
};
|
|
|
|
|
2020-08-27 10:19:21 +08:00
|
|
|
bool open(const std::string& path, Mode mode);
|
2019-11-24 14:54:45 +08:00
|
|
|
int close();
|
|
|
|
|
|
|
|
int seek(long offset, int origin);
|
|
|
|
int read(void* buf, unsigned int size);
|
|
|
|
|
|
|
|
int write(const void* buf, unsigned int size);
|
|
|
|
|
|
|
|
operator bool() const;
|
|
|
|
|
|
|
|
private:
|
2020-08-27 11:35:55 +08:00
|
|
|
void zeroset();
|
|
|
|
void assign(FileStream&& rhs);
|
|
|
|
|
|
|
|
PXFileHandle _handle;
|
|
|
|
const PXIoF* _iof;
|
2019-11-24 14:54:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|