refactoring
Co-authored-by: n.fedorov <mail@nfedorov.dev> Co-committed-by: n.fedorov <mail@nfedorov.dev>
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2024-2026 NXST contributors
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
class Directory {
|
||||
public:
|
||||
explicit Directory(const std::string& path);
|
||||
|
||||
bool good() const {
|
||||
return m_good;
|
||||
}
|
||||
Result error() const {
|
||||
return m_error;
|
||||
}
|
||||
size_t size() const {
|
||||
return m_entries.size();
|
||||
}
|
||||
std::string entry(size_t i) const;
|
||||
bool folder(size_t i) const;
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
std::string name;
|
||||
bool is_dir;
|
||||
};
|
||||
std::vector<Entry> m_entries;
|
||||
Result m_error{0};
|
||||
bool m_good{false};
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2024-2026 NXST contributors
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
namespace file_system {
|
||||
Result mount(FsFileSystem* fs, u64 title_id, AccountUid uid);
|
||||
int mount(FsFileSystem fs);
|
||||
void unmount();
|
||||
} // namespace file_system
|
||||
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
#include <cstdio>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
namespace nxst {
|
||||
|
||||
// RAII wrapper for FsFileSystem — auto-closes on destruction.
|
||||
struct FsFileSystemHandle {
|
||||
FsFileSystem fs{};
|
||||
bool valid{false};
|
||||
|
||||
FsFileSystemHandle() = default;
|
||||
~FsFileSystemHandle() {
|
||||
if (valid)
|
||||
fsFsClose(&fs);
|
||||
} // NOLINT(modernize-use-equals-default)
|
||||
|
||||
FsFileSystemHandle(const FsFileSystemHandle&) = delete;
|
||||
FsFileSystemHandle& operator=(const FsFileSystemHandle&) = delete;
|
||||
|
||||
FsFileSystem* get() {
|
||||
return &fs;
|
||||
}
|
||||
|
||||
void release() {
|
||||
valid = false;
|
||||
} // transfer ownership to devfs
|
||||
};
|
||||
|
||||
// RAII wrapper for FILE* — auto-fclose on destruction.
|
||||
struct FileHandle {
|
||||
FILE* ptr{nullptr};
|
||||
|
||||
explicit FileHandle(FILE* file) : ptr(file) {}
|
||||
~FileHandle() {
|
||||
if (ptr != nullptr)
|
||||
fclose(ptr);
|
||||
} // NOLINT(modernize-use-equals-default)
|
||||
|
||||
FileHandle(const FileHandle&) = delete;
|
||||
FileHandle& operator=(const FileHandle&) = delete;
|
||||
|
||||
explicit operator bool() const {
|
||||
return ptr != nullptr;
|
||||
}
|
||||
FILE* get() const {
|
||||
return ptr;
|
||||
}
|
||||
};
|
||||
|
||||
// RAII wrapper for AccountProfile — auto-closes on destruction.
|
||||
struct AccountProfileHandle {
|
||||
AccountProfile profile{};
|
||||
bool valid{false};
|
||||
|
||||
AccountProfileHandle() = default;
|
||||
~AccountProfileHandle() {
|
||||
if (valid)
|
||||
accountProfileClose(&profile);
|
||||
} // NOLINT(modernize-use-equals-default)
|
||||
|
||||
AccountProfileHandle(const AccountProfileHandle&) = delete;
|
||||
AccountProfileHandle& operator=(const AccountProfileHandle&) = delete;
|
||||
|
||||
AccountProfile* get() {
|
||||
return &profile;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nxst
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2024-2026 NXST contributors
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#include <nxst/domain/result.hpp>
|
||||
|
||||
namespace io {
|
||||
nxst::Result<std::string> backup(size_t index, AccountUid uid);
|
||||
nxst::Result<std::string> restore(size_t index, AccountUid uid, const std::string& title_name);
|
||||
|
||||
Result copyDirectory(const std::string& src, const std::string& dst);
|
||||
void copyFile(const std::string& src, const std::string& dst);
|
||||
Result createDirectory(const std::string& path);
|
||||
Result deleteFolderRecursively(const std::string& path);
|
||||
bool directoryExists(const std::string& path);
|
||||
bool fileExists(const std::string& path);
|
||||
} // namespace io
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
|
||||
struct Socket {
|
||||
int fd = -1;
|
||||
|
||||
Socket() = default;
|
||||
explicit Socket(int fd) : fd(fd) {}
|
||||
~Socket() {
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
Socket(const Socket&) = delete;
|
||||
Socket& operator=(const Socket&) = delete;
|
||||
Socket(Socket&& o) : fd(o.fd) {
|
||||
o.fd = -1;
|
||||
}
|
||||
|
||||
operator int() const {
|
||||
return fd;
|
||||
}
|
||||
bool valid() const {
|
||||
return fd >= 0;
|
||||
}
|
||||
void release() {
|
||||
fd = -1;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
// New API — use these going forward.
|
||||
namespace nxst::log {
|
||||
|
||||
enum class Level { Debug, Info, Warn, Error };
|
||||
|
||||
void write(Level level, const char* fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
void debug(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
void info(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
void warn(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
void error(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
} // namespace nxst::log
|
||||
Reference in New Issue
Block a user