add support for backup/restore save to usb

This commit is contained in:
ITotalJustice
2025-06-07 11:45:06 +01:00
parent 0fd5f348e2
commit 74c1cd3be0
3 changed files with 165 additions and 145 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include "fs.hpp"
#include "location.hpp"
#include <switch.h>
#include <vector>
#include <memory>
@@ -30,6 +31,17 @@ enum DumpLocationFlag {
DumpLocationFlag_All = DumpLocationFlag_SdCard | DumpLocationFlag_UsbS2S | DumpLocationFlag_DevNull | DumpLocationFlag_Stdio | DumpLocationFlag_Network,
};
struct DumpEntry {
DumpLocationType type;
s32 index;
};
struct DumpLocation {
DumpEntry entry{};
location::Entries network{};
location::StdioEntries stdio{};
};
struct BaseSource {
virtual ~BaseSource() = default;
virtual Result Read(const std::string& path, void* buf, s64 off, s64 size, u64* bytes_read) = 0;
@@ -40,7 +52,13 @@ struct BaseSource {
// called after dump has finished.
using OnExit = std::function<void(Result rc)>;
using OnLocation = std::function<void(const DumpLocation& loc)>;
// prompts the user to select dump location, calls on_loc on success with the selected location.
void DumpGetLocation(const std::string& title, u32 location_flags, OnLocation on_loc);
// dumps to a fetched location using DumpGetLocation().
void Dump(std::shared_ptr<BaseSource> source, const DumpLocation& location, const std::vector<fs::FsPath>& paths, OnExit on_exit);
// DumpGetLocation() + Dump() all in one.
void Dump(std::shared_ptr<BaseSource> source, const std::vector<fs::FsPath>& paths, OnExit on_exit = [](Result){}, u32 location_flags = DumpLocationFlag_All);
} // namespace sphaira::dump