intial work on listing directories

This commit is contained in:
georgemoralis 2023-11-07 07:59:14 +02:00
parent 0f59f4a745
commit 461215a6f5
3 changed files with 51 additions and 50 deletions

View File

@ -1,16 +1,13 @@
#include "common/fs_file.h"
#include <filesystem>
namespace Common::FS {
File::File() = default;
File::File(const std::string& path, OpenMode mode) {
open(path, mode);
}
File::File(const std::string& path, OpenMode mode) { open(path, mode); }
File::~File() {
close();
}
File::~File() { close(); }
bool File::open(const std::string& path, OpenMode mode) {
close();
@ -32,13 +29,9 @@ bool File::close() {
return true;
}
bool File::write(std::span<const u08> data) {
return isOpen() && std::fwrite(data.data(), 1, data.size(), m_file) == data.size();
}
bool File::write(std::span<const u08> data) { return isOpen() && std::fwrite(data.data(), 1, data.size(), m_file) == data.size(); }
bool File::read(void* data, u64 size) const {
return isOpen() && std::fread(data, 1, size, m_file) == size;
}
bool File::read(void* data, u64 size) const { return isOpen() && std::fread(data, 1, size, m_file) == size; }
bool File::seek(s64 offset, SeekMode mode) {
#ifdef _WIN64
@ -65,6 +58,19 @@ u64 File::tell() const {
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() {
#ifdef _WIN64
const u64 pos = _ftelli64(m_file);

View File

@ -2,19 +2,15 @@
#include <bit>
#include <cstdio>
#include <string>
#include <span>
#include <string>
#include <vector>
#include "common/types.h"
namespace Common::FS {
enum class OpenMode : u32 {
Read = 0x1,
Write = 0x2,
ReadWrite = Read | Write
};
enum class OpenMode : u32 { Read = 0x1, Write = 0x2, ReadWrite = Read | Write };
enum class SeekMode : u32 {
Set,
@ -22,6 +18,11 @@ enum class SeekMode : u32 {
End,
};
struct DirEntry {
std::string name;
bool isFile;
};
class File {
public:
File();
@ -46,39 +47,28 @@ class File {
return read(data.data(), data.size() * sizeof(T));
}
bool isOpen() const {
return m_file != nullptr;
}
bool isOpen() const { return m_file != nullptr; }
const char* getOpenMode(OpenMode mode) const {
switch (mode) {
case OpenMode::Read:
return "rb";
case OpenMode::Write:
return "wb";
case OpenMode::ReadWrite:
return "r+b";
default:
return "r";
case OpenMode::Read: return "rb";
case OpenMode::Write: return "wb";
case OpenMode::ReadWrite: return "r+b";
default: return "r";
}
}
int getSeekMode(SeekMode mode) const {
switch (mode) {
case SeekMode::Set:
return SEEK_SET;
case SeekMode::Cur:
return SEEK_CUR;
case SeekMode::End:
return SEEK_END;
default:
return SEEK_SET;
case SeekMode::Set: return SEEK_SET;
case SeekMode::Cur: return SEEK_CUR;
case SeekMode::End: return SEEK_END;
default: return SEEK_SET;
}
}
[[nodiscard]] std::FILE* fileDescr() const {
return m_file;
}
[[nodiscard]] std::FILE* fileDescr() const { return m_file; }
static std::vector<DirEntry> getDirectoryEntries(const std::string& path);
private:
std::FILE* m_file{};

View File

@ -3,6 +3,8 @@
#include <string>
#include <vector>
#include "common/fs_file.h"
namespace Core::FileSys {
class MntPoints {
@ -29,6 +31,9 @@ struct File {
std::atomic_bool isDirectory;
std::string m_host_name;
std::string m_guest_name;
Common::FS::File f;
};
class HandleTable {
public: