mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
Add SystemSaveData::OpenFile and split up frd:u and frd:a
This commit is contained in:
parent
c48f8327c6
commit
7c2167e0f2
7 changed files with 61 additions and 12 deletions
|
@ -26,10 +26,7 @@ class SystemSaveDataArchive : public ArchiveBase {
|
||||||
Rust::Result<ArchiveBase*, HorizonResult> openArchive(const FSPath& path) override;
|
Rust::Result<ArchiveBase*, HorizonResult> openArchive(const FSPath& path) override;
|
||||||
//Rust::Result<DirectorySession, HorizonResult> openDirectory(const FSPath& path) override;
|
//Rust::Result<DirectorySession, HorizonResult> openDirectory(const FSPath& path) override;
|
||||||
|
|
||||||
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override {
|
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
||||||
Helpers::panic("Unimplemented OpenFile for SystemSaveData archive");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override {
|
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override {
|
||||||
Helpers::panic("Unimplemented ReadFile for SystemSaveData archive");
|
Helpers::panic("Unimplemented ReadFile for SystemSaveData archive");
|
||||||
|
|
|
@ -25,7 +25,8 @@ namespace KernelHandles {
|
||||||
HID, // HID service (Handles input-related things including gyro. Does NOT handle New3DS controls or CirclePadPro)
|
HID, // HID service (Handles input-related things including gyro. Does NOT handle New3DS controls or CirclePadPro)
|
||||||
HTTP, // HTTP service (Handles HTTP requests)
|
HTTP, // HTTP service (Handles HTTP requests)
|
||||||
IR_USER, // One of 3 infrared communication services
|
IR_USER, // One of 3 infrared communication services
|
||||||
FRD, // Friend service (Miiverse friend service)
|
FRD_A, // Friend service (Miiverse friend service)
|
||||||
|
FRD_U,
|
||||||
FS, // Filesystem service
|
FS, // Filesystem service
|
||||||
GPU, // GPU service
|
GPU, // GPU service
|
||||||
LCD, // LCD service (Used for configuring the displays)
|
LCD, // LCD service (Used for configuring the displays)
|
||||||
|
@ -82,7 +83,8 @@ namespace KernelHandles {
|
||||||
case HID: return "HID";
|
case HID: return "HID";
|
||||||
case HTTP: return "HTTP";
|
case HTTP: return "HTTP";
|
||||||
case IR_USER: return "IR:USER";
|
case IR_USER: return "IR:USER";
|
||||||
case FRD: return "FRD";
|
case FRD_A: return "FRD:A";
|
||||||
|
case FRD_U: return "FRD:U";
|
||||||
case FS: return "FS";
|
case FS: return "FS";
|
||||||
case GPU: return "GSP::GPU";
|
case GPU: return "GSP::GPU";
|
||||||
case LCD: return "GSP::LCD";
|
case LCD: return "GSP::LCD";
|
||||||
|
|
|
@ -15,7 +15,6 @@ struct FriendKey {
|
||||||
static_assert(sizeof(FriendKey) == 16);
|
static_assert(sizeof(FriendKey) == 16);
|
||||||
|
|
||||||
class FRDService {
|
class FRDService {
|
||||||
Handle handle = KernelHandles::FRD;
|
|
||||||
Memory& mem;
|
Memory& mem;
|
||||||
MAKE_LOG_FUNCTION(log, frdLogger)
|
MAKE_LOG_FUNCTION(log, frdLogger)
|
||||||
|
|
||||||
|
@ -48,7 +47,13 @@ class FRDService {
|
||||||
static_assert(sizeof(Profile) == 8);
|
static_assert(sizeof(Profile) == 8);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class Type {
|
||||||
|
A, // frd:a
|
||||||
|
N, // frd:n
|
||||||
|
U, // frd:u
|
||||||
|
};
|
||||||
|
|
||||||
FRDService(Memory& mem) : mem(mem) {}
|
FRDService(Memory& mem) : mem(mem) {}
|
||||||
void reset();
|
void reset();
|
||||||
void handleSyncRequest(u32 messagePointer);
|
void handleSyncRequest(u32 messagePointer, Type type);
|
||||||
};
|
};
|
|
@ -4,9 +4,47 @@
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
Rust::Result<ArchiveBase*, HorizonResult> SystemSaveDataArchive::openArchive(const FSPath& path) {
|
Rust::Result<ArchiveBase*, HorizonResult> SystemSaveDataArchive::openArchive(const FSPath& path) {
|
||||||
if (path.type != PathType::Empty) {
|
if (path.type != PathType::Binary) {
|
||||||
Helpers::panic("Unimplemented path type for SystemSaveData::OpenArchive");
|
Helpers::panic("Unimplemented path type for SystemSaveData::OpenArchive");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok((ArchiveBase*)this);
|
return Ok((ArchiveBase*)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileDescriptor SystemSaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||||
|
// TODO: Validate this. Temporarily copied from SaveData archive
|
||||||
|
|
||||||
|
if (path.type == PathType::UTF16) {
|
||||||
|
if (!isPathSafe<PathType::UTF16>(path)) {
|
||||||
|
Helpers::panic("Unsafe path in SystemSaveData::OpenFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (perms.raw == 0 || (perms.create() && !perms.write())) {
|
||||||
|
Helpers::panic("[SystemSaveData] Unsupported flags for OpenFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::path p = IOFile::getAppData() / ".." / "SharedFiles" / "SystemSaveData";
|
||||||
|
p += fs::path(path.utf16_string).make_preferred();
|
||||||
|
|
||||||
|
const char* permString = perms.write() ? "r+b" : "rb";
|
||||||
|
|
||||||
|
if (fs::exists(p)) { // Return file descriptor if the file exists
|
||||||
|
IOFile file(p.string().c_str(), permString);
|
||||||
|
return file.isOpen() ? file.getHandle() : FileError;
|
||||||
|
} else {
|
||||||
|
// If the file is not found, create it if the create flag is on
|
||||||
|
if (perms.create()) {
|
||||||
|
IOFile file(p.string().c_str(), "wb"); // Create file
|
||||||
|
file.close(); // Close it
|
||||||
|
|
||||||
|
file.open(p.string().c_str(), permString); // Reopen with proper perms
|
||||||
|
return file.isOpen() ? file.getHandle() : FileError;
|
||||||
|
} else {
|
||||||
|
return FileError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Helpers::panic("SystemSaveData::OpenFile: Failed");
|
||||||
|
return FileError;
|
||||||
}
|
}
|
|
@ -27,7 +27,7 @@ namespace FRDCommands {
|
||||||
|
|
||||||
void FRDService::reset() { loggedIn = false; }
|
void FRDService::reset() { loggedIn = false; }
|
||||||
|
|
||||||
void FRDService::handleSyncRequest(u32 messagePointer) {
|
void FRDService::handleSyncRequest(u32 messagePointer, FRDService::Type type) {
|
||||||
const u32 command = mem.read32(messagePointer);
|
const u32 command = mem.read32(messagePointer);
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case FRDCommands::AttachToEventNotification: attachToEventNotification(messagePointer); break;
|
case FRDCommands::AttachToEventNotification: attachToEventNotification(messagePointer); break;
|
||||||
|
|
|
@ -53,6 +53,7 @@ void FSService::initializeFilesystem() {
|
||||||
|
|
||||||
const auto savePath = IOFile::getAppData() / "SaveData"; // Create SaveData
|
const auto savePath = IOFile::getAppData() / "SaveData"; // Create SaveData
|
||||||
const auto formatPath = IOFile::getAppData() / "FormatInfo"; // Create folder for storing archive formatting info
|
const auto formatPath = IOFile::getAppData() / "FormatInfo"; // Create folder for storing archive formatting info
|
||||||
|
const auto systemSaveDataPath = IOFile::getAppData() / ".." / "SharedFiles" / "SystemSaveData";
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,6 +72,10 @@ void FSService::initializeFilesystem() {
|
||||||
if (!fs::is_directory(formatPath)) {
|
if (!fs::is_directory(formatPath)) {
|
||||||
fs::create_directories(formatPath);
|
fs::create_directories(formatPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fs::is_directory(systemSaveDataPath)) {
|
||||||
|
fs::create_directories(systemSaveDataPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveBase* FSService::getArchiveFromID(u32 id, const FSPath& archivePath) {
|
ArchiveBase* FSService::getArchiveFromID(u32 id, const FSPath& archivePath) {
|
||||||
|
|
|
@ -111,7 +111,8 @@ static std::map<std::string, Handle> serviceMap = {
|
||||||
{ "hid:USER", KernelHandles::HID },
|
{ "hid:USER", KernelHandles::HID },
|
||||||
{ "http:C", KernelHandles::HTTP },
|
{ "http:C", KernelHandles::HTTP },
|
||||||
{ "ir:USER", KernelHandles::IR_USER },
|
{ "ir:USER", KernelHandles::IR_USER },
|
||||||
{ "frd:u", KernelHandles::FRD },
|
{ "frd:a", KernelHandles::FRD_A },
|
||||||
|
{ "frd:u", KernelHandles::FRD_U },
|
||||||
{ "fs:USER", KernelHandles::FS },
|
{ "fs:USER", KernelHandles::FS },
|
||||||
{ "gsp::Gpu", KernelHandles::GPU },
|
{ "gsp::Gpu", KernelHandles::GPU },
|
||||||
{ "gsp::Lcd", KernelHandles::LCD },
|
{ "gsp::Lcd", KernelHandles::LCD },
|
||||||
|
@ -211,7 +212,8 @@ void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
|
||||||
case KernelHandles::HID: hid.handleSyncRequest(messagePointer); break;
|
case KernelHandles::HID: hid.handleSyncRequest(messagePointer); break;
|
||||||
case KernelHandles::HTTP: http.handleSyncRequest(messagePointer); break;
|
case KernelHandles::HTTP: http.handleSyncRequest(messagePointer); break;
|
||||||
case KernelHandles::IR_USER: ir_user.handleSyncRequest(messagePointer); break;
|
case KernelHandles::IR_USER: ir_user.handleSyncRequest(messagePointer); break;
|
||||||
case KernelHandles::FRD: frd.handleSyncRequest(messagePointer); break;
|
case KernelHandles::FRD_A: frd.handleSyncRequest(messagePointer, FRDService::Type::A); break;
|
||||||
|
case KernelHandles::FRD_U: frd.handleSyncRequest(messagePointer, FRDService::Type::U); break;
|
||||||
case KernelHandles::LCD: gsp_lcd.handleSyncRequest(messagePointer); break;
|
case KernelHandles::LCD: gsp_lcd.handleSyncRequest(messagePointer); break;
|
||||||
case KernelHandles::LDR_RO: ldr.handleSyncRequest(messagePointer); break;
|
case KernelHandles::LDR_RO: ldr.handleSyncRequest(messagePointer); break;
|
||||||
case KernelHandles::MCU_HWC: mcu_hwc.handleSyncRequest(messagePointer); break;
|
case KernelHandles::MCU_HWC: mcu_hwc.handleSyncRequest(messagePointer); break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue