finish refactor, add docs and CI
This commit is contained in:
@@ -28,16 +28,17 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <string>
|
||||
#include <switch.h>
|
||||
#include <vector>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
struct DirectoryEntry {
|
||||
std::string name;
|
||||
bool directory;
|
||||
};
|
||||
|
||||
class Directory {
|
||||
public:
|
||||
public:
|
||||
Directory(const std::string& root);
|
||||
~Directory() = default;
|
||||
|
||||
@@ -47,9 +48,8 @@ public:
|
||||
bool good(void);
|
||||
size_t size(void);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<struct DirectoryEntry> mList;
|
||||
Result mError;
|
||||
bool mGood;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <nxst/domain/account.hpp>
|
||||
#include <switch.h>
|
||||
|
||||
namespace FileSystem {
|
||||
Result mount(FsFileSystem* fileSystem, u64 titleID, AccountUid userID);
|
||||
int mount(FsFileSystem fs);
|
||||
void unmount(void);
|
||||
}
|
||||
#include <nxst/domain/account.hpp>
|
||||
|
||||
namespace FileSystem {
|
||||
Result mount(FsFileSystem* fileSystem, u64 titleID, AccountUid userID);
|
||||
int mount(FsFileSystem fs);
|
||||
void unmount(void);
|
||||
} // namespace FileSystem
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <cstdio>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
namespace nxst {
|
||||
@@ -10,14 +11,21 @@ struct FsFileSystemHandle {
|
||||
bool valid{false};
|
||||
|
||||
FsFileSystemHandle() = default;
|
||||
~FsFileSystemHandle() { if (valid) fsFsClose(&fs); } // NOLINT(modernize-use-equals-default)
|
||||
~FsFileSystemHandle() {
|
||||
if (valid)
|
||||
fsFsClose(&fs);
|
||||
} // NOLINT(modernize-use-equals-default)
|
||||
|
||||
FsFileSystemHandle(const FsFileSystemHandle&) = delete;
|
||||
FsFileSystemHandle(const FsFileSystemHandle&) = delete;
|
||||
FsFileSystemHandle& operator=(const FsFileSystemHandle&) = delete;
|
||||
|
||||
FsFileSystem* get() { return &fs; }
|
||||
FsFileSystem* get() {
|
||||
return &fs;
|
||||
}
|
||||
|
||||
void release() { valid = false; } // transfer ownership to devfs
|
||||
void release() {
|
||||
valid = false;
|
||||
} // transfer ownership to devfs
|
||||
};
|
||||
|
||||
// RAII wrapper for FILE* — auto-fclose on destruction.
|
||||
@@ -25,13 +33,20 @@ struct FileHandle {
|
||||
FILE* ptr{nullptr};
|
||||
|
||||
explicit FileHandle(FILE* file) : ptr(file) {}
|
||||
~FileHandle() { if (ptr != nullptr) fclose(ptr); } // NOLINT(modernize-use-equals-default)
|
||||
~FileHandle() {
|
||||
if (ptr != nullptr)
|
||||
fclose(ptr);
|
||||
} // NOLINT(modernize-use-equals-default)
|
||||
|
||||
FileHandle(const FileHandle&) = delete;
|
||||
FileHandle(const FileHandle&) = delete;
|
||||
FileHandle& operator=(const FileHandle&) = delete;
|
||||
|
||||
explicit operator bool() const { return ptr != nullptr; }
|
||||
FILE* get() const { return ptr; }
|
||||
explicit operator bool() const {
|
||||
return ptr != nullptr;
|
||||
}
|
||||
FILE* get() const {
|
||||
return ptr;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nxst
|
||||
} // namespace nxst
|
||||
|
||||
@@ -25,27 +25,29 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <nxst/domain/account.hpp>
|
||||
#include <nxst/domain/result.hpp>
|
||||
#include <nxst/infra/fs/directory.hpp>
|
||||
#include <nxst/domain/title.hpp>
|
||||
#include <nxst/domain/util.hpp>
|
||||
#include <dirent.h>
|
||||
#include <switch.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#include <nxst/domain/account.hpp>
|
||||
#include <nxst/domain/result.hpp>
|
||||
#include <nxst/domain/title.hpp>
|
||||
#include <nxst/domain/util.hpp>
|
||||
#include <nxst/infra/fs/directory.hpp>
|
||||
|
||||
#define BUFFER_SIZE 0x80000
|
||||
|
||||
namespace io {
|
||||
nxst::Result<std::string> backup(size_t index, AccountUid uid);
|
||||
nxst::Result<std::string> restore(size_t index, AccountUid uid, size_t cellIndex, const std::string& nameFromCell);
|
||||
|
||||
Result copyDirectory(const std::string& srcPath, const std::string& dstPath);
|
||||
void copyFile(const std::string& srcPath, const std::string& dstPath);
|
||||
Result createDirectory(const std::string& path);
|
||||
Result deleteFolderRecursively(const std::string& path);
|
||||
bool directoryExists(const std::string& path);
|
||||
bool fileExists(const std::string& path);
|
||||
}
|
||||
nxst::Result<std::string> backup(size_t index, AccountUid uid);
|
||||
nxst::Result<std::string> restore(size_t index, AccountUid uid, size_t cellIndex,
|
||||
const std::string& nameFromCell);
|
||||
|
||||
Result copyDirectory(const std::string& srcPath, const std::string& dstPath);
|
||||
void copyFile(const std::string& srcPath, const std::string& dstPath);
|
||||
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
|
||||
|
||||
@@ -6,13 +6,24 @@ struct Socket {
|
||||
|
||||
Socket() = default;
|
||||
explicit Socket(int fd) : fd(fd) {}
|
||||
~Socket() { if (fd >= 0) close(fd); }
|
||||
~Socket() {
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
Socket(const Socket&) = delete;
|
||||
Socket(const Socket&) = delete;
|
||||
Socket& operator=(const Socket&) = delete;
|
||||
Socket(Socket&& o) : fd(o.fd) { o.fd = -1; }
|
||||
Socket(Socket&& o) : fd(o.fd) {
|
||||
o.fd = -1;
|
||||
}
|
||||
|
||||
operator int() const { return fd; }
|
||||
bool valid() const { return fd >= 0; }
|
||||
void release() { fd = -1; }
|
||||
operator int() const {
|
||||
return fd;
|
||||
}
|
||||
bool valid() const {
|
||||
return fd >= 0;
|
||||
}
|
||||
void release() {
|
||||
fd = -1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,47 +9,51 @@ 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)));
|
||||
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)));
|
||||
|
||||
// No-op: writes are immediate. Kept for source compatibility during migration.
|
||||
inline void flush() {}
|
||||
|
||||
} // namespace nxst::log
|
||||
} // namespace nxst::log
|
||||
|
||||
// Backward-compat shim — existing Logger::getInstance().log(...) call sites compile
|
||||
// unchanged. Format args are dropped (same behavior as broken original). Migrate
|
||||
// call sites to nxst::log::* in Phase 3.
|
||||
struct Logger {
|
||||
static Logger& getInstance()
|
||||
{
|
||||
static Logger& getInstance() {
|
||||
static Logger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// clang-tidy naming suppressed: these must match existing call sites during migration.
|
||||
static constexpr const char* INFO = "[INFO]"; // NOLINT(readability-identifier-naming)
|
||||
static constexpr const char* INFO = "[INFO]"; // NOLINT(readability-identifier-naming)
|
||||
static constexpr const char* DEBUG = "[DEBUG]"; // NOLINT(readability-identifier-naming)
|
||||
static constexpr const char* ERROR = "[ERROR]"; // NOLINT(readability-identifier-naming)
|
||||
static constexpr const char* WARN = "[WARN]"; // NOLINT(readability-identifier-naming)
|
||||
static constexpr const char* WARN = "[WARN]"; // NOLINT(readability-identifier-naming)
|
||||
|
||||
static void flush() { nxst::log::flush(); }
|
||||
static void flush() {
|
||||
nxst::log::flush();
|
||||
}
|
||||
|
||||
// Args intentionally dropped — format string still logged for visibility.
|
||||
template <typename... Args>
|
||||
void log(const std::string& level, const std::string& fmt, Args&&... /*args*/)
|
||||
{
|
||||
if (level == ERROR) nxst::log::error("%s", fmt.c_str());
|
||||
else if (level == WARN) nxst::log::warn("%s", fmt.c_str());
|
||||
else if (level == DEBUG) nxst::log::debug("%s", fmt.c_str());
|
||||
else nxst::log::info("%s", fmt.c_str());
|
||||
void log(const std::string& level, const std::string& fmt, Args&&... /*args*/) {
|
||||
if (level == ERROR)
|
||||
nxst::log::error("%s", fmt.c_str());
|
||||
else if (level == WARN)
|
||||
nxst::log::warn("%s", fmt.c_str());
|
||||
else if (level == DEBUG)
|
||||
nxst::log::debug("%s", fmt.c_str());
|
||||
else
|
||||
nxst::log::info("%s", fmt.c_str());
|
||||
}
|
||||
|
||||
Logger() = default;
|
||||
Logger() = default;
|
||||
~Logger() = default;
|
||||
|
||||
Logger(const Logger&) = delete; // NOLINT(modernize-use-equals-delete)
|
||||
Logger(const Logger&) = delete; // NOLINT(modernize-use-equals-delete)
|
||||
Logger& operator=(const Logger&) = delete; // NOLINT(modernize-use-equals-delete)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user