mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
[FS] Done with CreateFile
This commit is contained in:
parent
93d2d300b9
commit
49dcc25795
15 changed files with 85 additions and 3 deletions
|
@ -3,6 +3,33 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
CreateFileResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
if (size == 0)
|
||||
Helpers::panic("ExtSaveData file does not support size == 0");
|
||||
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in ExtSaveData::CreateFile");
|
||||
|
||||
fs::path p = IOFile::getAppData() / "NAND";
|
||||
p += fs::path(path.utf16_string).make_preferred();
|
||||
|
||||
if (fs::exists(p))
|
||||
return CreateFileResult::AlreadyExists;
|
||||
|
||||
// Create a file of size "size" by creating an empty one, seeking to size - 1 and just writing a 0 there
|
||||
IOFile file(p.string().c_str(), "wb");
|
||||
if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) {
|
||||
return CreateFileResult::Success;
|
||||
}
|
||||
|
||||
return CreateFileResult::FileTooLarge;
|
||||
}
|
||||
|
||||
Helpers::panic("ExtSaveDataArchive::OpenFile: Failed");
|
||||
return CreateFileResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#include "fs/archive_ncch.hpp"
|
||||
#include <memory>
|
||||
|
||||
CreateFileResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SelfNCCH] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
if (!hasRomFS()) {
|
||||
printf("Tried to open a SelfNCCH file without a RomFS\n");
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
CreateFileResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SaveData] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
if (!cartHasSaveData()) {
|
||||
printf("Tried to read SaveData FS without save data\n");
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#include "fs/archive_sdmc.hpp"
|
||||
#include <memory>
|
||||
|
||||
CreateFileResult SDMCArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SDMC] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
printf("SDMCArchive::OpenFile: Failed");
|
||||
return FileError;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue