intial work on listing directories
This commit is contained in:
parent
0f59f4a745
commit
461215a6f5
|
@ -1,16 +1,13 @@
|
||||||
#include "common/fs_file.h"
|
#include "common/fs_file.h"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace Common::FS {
|
namespace Common::FS {
|
||||||
|
|
||||||
File::File() = default;
|
File::File() = default;
|
||||||
|
|
||||||
File::File(const std::string& path, OpenMode mode) {
|
File::File(const std::string& path, OpenMode mode) { open(path, mode); }
|
||||||
open(path, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
File::~File() {
|
File::~File() { close(); }
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool File::open(const std::string& path, OpenMode mode) {
|
bool File::open(const std::string& path, OpenMode mode) {
|
||||||
close();
|
close();
|
||||||
|
@ -32,13 +29,9 @@ bool File::close() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::write(std::span<const u08> data) {
|
bool File::write(std::span<const u08> data) { return isOpen() && std::fwrite(data.data(), 1, data.size(), m_file) == data.size(); }
|
||||||
return isOpen() && std::fwrite(data.data(), 1, data.size(), m_file) == data.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool File::read(void* data, u64 size) const {
|
bool File::read(void* data, u64 size) const { return isOpen() && std::fread(data, 1, size, m_file) == size; }
|
||||||
return isOpen() && std::fread(data, 1, size, m_file) == size;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool File::seek(s64 offset, SeekMode mode) {
|
bool File::seek(s64 offset, SeekMode mode) {
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
|
@ -65,6 +58,19 @@ u64 File::tell() const {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<DirEntry> File::getDirectoryEntries(const std::string& path) {
|
||||||
|
std::vector < DirEntry> files;
|
||||||
|
|
||||||
|
for (const auto& entry : std::filesystem::directory_iterator(path)) {
|
||||||
|
if (std::filesystem::is_regular_file(path)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
//entry.path()
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
u64 File::getFileSize() {
|
u64 File::getFileSize() {
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
const u64 pos = _ftelli64(m_file);
|
const u64 pos = _ftelli64(m_file);
|
||||||
|
|
|
@ -2,19 +2,15 @@
|
||||||
|
|
||||||
#include <bit>
|
#include <bit>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
|
|
||||||
namespace Common::FS {
|
namespace Common::FS {
|
||||||
|
|
||||||
enum class OpenMode : u32 {
|
enum class OpenMode : u32 { Read = 0x1, Write = 0x2, ReadWrite = Read | Write };
|
||||||
Read = 0x1,
|
|
||||||
Write = 0x2,
|
|
||||||
ReadWrite = Read | Write
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SeekMode : u32 {
|
enum class SeekMode : u32 {
|
||||||
Set,
|
Set,
|
||||||
|
@ -22,6 +18,11 @@ enum class SeekMode : u32 {
|
||||||
End,
|
End,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DirEntry {
|
||||||
|
std::string name;
|
||||||
|
bool isFile;
|
||||||
|
};
|
||||||
|
|
||||||
class File {
|
class File {
|
||||||
public:
|
public:
|
||||||
File();
|
File();
|
||||||
|
@ -46,39 +47,28 @@ class File {
|
||||||
return read(data.data(), data.size() * sizeof(T));
|
return read(data.data(), data.size() * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isOpen() const {
|
bool isOpen() const { return m_file != nullptr; }
|
||||||
return m_file != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* getOpenMode(OpenMode mode) const {
|
const char* getOpenMode(OpenMode mode) const {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case OpenMode::Read:
|
case OpenMode::Read: return "rb";
|
||||||
return "rb";
|
case OpenMode::Write: return "wb";
|
||||||
case OpenMode::Write:
|
case OpenMode::ReadWrite: return "r+b";
|
||||||
return "wb";
|
default: return "r";
|
||||||
case OpenMode::ReadWrite:
|
|
||||||
return "r+b";
|
|
||||||
default:
|
|
||||||
return "r";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSeekMode(SeekMode mode) const {
|
int getSeekMode(SeekMode mode) const {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SeekMode::Set:
|
case SeekMode::Set: return SEEK_SET;
|
||||||
return SEEK_SET;
|
case SeekMode::Cur: return SEEK_CUR;
|
||||||
case SeekMode::Cur:
|
case SeekMode::End: return SEEK_END;
|
||||||
return SEEK_CUR;
|
default: return SEEK_SET;
|
||||||
case SeekMode::End:
|
|
||||||
return SEEK_END;
|
|
||||||
default:
|
|
||||||
return SEEK_SET;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::FILE* fileDescr() const {
|
[[nodiscard]] std::FILE* fileDescr() const { return m_file; }
|
||||||
return m_file;
|
static std::vector<DirEntry> getDirectoryEntries(const std::string& path);
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::FILE* m_file{};
|
std::FILE* m_file{};
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/fs_file.h"
|
||||||
|
|
||||||
namespace Core::FileSys {
|
namespace Core::FileSys {
|
||||||
|
|
||||||
class MntPoints {
|
class MntPoints {
|
||||||
|
@ -29,6 +31,9 @@ struct File {
|
||||||
std::atomic_bool isDirectory;
|
std::atomic_bool isDirectory;
|
||||||
std::string m_host_name;
|
std::string m_host_name;
|
||||||
std::string m_guest_name;
|
std::string m_guest_name;
|
||||||
|
Common::FS::File f;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
class HandleTable {
|
class HandleTable {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue