Skip to content

Commit

Permalink
enh - batch restore - mocked version
Browse files Browse the repository at this point in the history
  • Loading branch information
w3irDv committed Oct 20, 2024
1 parent a70e717 commit 42f6baa
Show file tree
Hide file tree
Showing 15 changed files with 944 additions and 39 deletions.
1 change: 1 addition & 0 deletions include/ApplicationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ class ApplicationState {

virtual void render() = 0;
virtual eSubState update(Input *input) = 0;

};
1 change: 1 addition & 0 deletions include/BackupSetList.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class BackupSetList {

static const std::string ROOT_BS;
static std::string getBackupSetSubPath() { return backupSetSubPath; };
static std::string getBackupSetPath() { return currentBackupSetList->backupSetListRoot+backupSetSubPath; };
static std::string getBackupSetEntry() { return backupSetEntry; };
static std::string getBackupSetSubPath(int i);
static void setBackupSetEntry(int i);
Expand Down
61 changes: 61 additions & 0 deletions include/menu/BRTitleSelectState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <ApplicationState.h>
#include <memory>
#include <savemng.h>
#include <utils/InputUtils.h>
#include <utils/LanguageUtils.h>
#include <vector>

class BRTitleSelectState : public ApplicationState {
public:
BRTitleSelectState(int sduser, int wiiuuser, bool common, bool wipeBeforeRestore, bool fullBackup,Title *titles, int titlesCount);

enum eState {
STATE_BATCH_RESTORE_TITLE_SELECT,
STATE_DO_SUBSTATE,
};

void render() override;
ApplicationState::eSubState update(Input *input) override;

private:
std::unique_ptr<ApplicationState> subState{};
eState state = STATE_BATCH_RESTORE_TITLE_SELECT;


int sduser;
int wiiuuser;
bool common;
bool wipeBeforeRestore;
bool fullBackup;
Title *titles;
int titlesCount;


std::vector<const char *> sortNames = {LanguageUtils::gettext("None"),
LanguageUtils::gettext("Name"),
LanguageUtils::gettext("Storage"),
LanguageUtils::gettext("Storage+Name")};

int titleSort = 1;
int scroll = 0;
int cursorPos = 0;
bool sortAscending = true;
int targ = 0;

bool noTitles = false;

std::vector<int> c2t;
int candidatesCount;

void updateC2t();

std::vector<const char*> titleStateAfterBR = {
" ",
" > Aborted",
" > OK",
" > WR",
" > KO"
};
};
10 changes: 7 additions & 3 deletions include/menu/BackupSetListState.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include <ApplicationState.h>
#include <memory>
#include <savemng.h>
#include <utils/InputUtils.h>




class BackupSetListState : public ApplicationState {
public:
BackupSetListState();
BackupSetListState(Title *titles, int titlesCount);

static void resetCursorPosition();
static void resetCursorAndScroll();
enum eState {
Expand All @@ -29,6 +29,7 @@ class BackupSetListState : public ApplicationState {
std::unique_ptr<ApplicationState> subState{};
eState state = STATE_BACKUPSET_MENU;
eSubstateCalled substateCalled = NONE;
bool finalScreen;

bool sortAscending;

Expand All @@ -39,4 +40,7 @@ class BackupSetListState : public ApplicationState {

std::string tag;
std::string newTag;

Title *titles;
int titlesCount;
};
39 changes: 39 additions & 0 deletions include/menu/BatchRestoreOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <ApplicationState.h>
#include <memory>
#include <set>
#include <algorithm>
#include <utils/InputUtils.h>
#include <savemng.h>

class BatchRestoreOptions : public ApplicationState {
public:
BatchRestoreOptions(Title *titles, int titlesCount);

enum eState {
STATE_BATCH_RESTORE_OPTIONS_MENU,
STATE_DO_SUBSTATE,
};

void render() override;
ApplicationState::eSubState update(Input *input) override;
std::string tag;

private:
std::unique_ptr<ApplicationState> subState{};
eState state = STATE_BATCH_RESTORE_OPTIONS_MENU;

int8_t wiiuuser = -1;
int8_t sduser = -1;
bool common = false;

bool wipeBeforeRestore = true;
bool fullBackup = true;
std::set<std::string,std::less<std::string>> batchSDUsers;

Title *titles;
int titlesCount = 0;

int cursorPos = 0;
};
32 changes: 32 additions & 0 deletions include/menu/BatchRestoreState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <ApplicationState.h>
#include <memory>
#include <savemng.h>
#include <utils/InputUtils.h>

class BatchRestoreState : public ApplicationState {
public:
BatchRestoreState(Title *wiiutitles, Title *wiititles, int wiiuTitlesCount, int vWiiTitlesCount) : wiiutitles(wiiutitles),
wiititles(wiititles),
wiiuTitlesCount(wiiuTitlesCount),
vWiiTitlesCount(vWiiTitlesCount) {}
enum eState {
STATE_BATCH_RESTORE_MENU,
STATE_DO_SUBSTATE,
};

void render() override;
ApplicationState::eSubState update(Input *input) override;
std::string tag;

private:
std::unique_ptr<ApplicationState> subState{};
eState state = STATE_BATCH_RESTORE_MENU;

Title *wiiutitles;
Title *wiititles;

int wiiuTitlesCount;
int vWiiTitlesCount;
};
23 changes: 21 additions & 2 deletions include/savemng.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
#define M_OFF 1
#define Y_OFF 1

enum eBatchRestoreState {
NOT_TRIED = 0,
ABORTED = 1,
OK = 2,
WR = 3,
KO = 4
};

struct backupInfo {
bool hasBatchBackup;
bool candidateToBeRestored;
bool selected;
bool hasUserSavedata;
bool hasCommonSavedata;
eBatchRestoreState batchRestoreState;
};

struct Title {
uint32_t highID;
uint32_t lowID;
Expand All @@ -37,6 +54,7 @@ struct Title {
uint8_t *iconBuf;
uint64_t accountSaveSize;
uint32_t groupID;
backupInfo currentBackup;
};

struct Saves {
Expand Down Expand Up @@ -119,6 +137,7 @@ bool getLoadiineGameSaveDir(char *out, const char *productCode, const char *long
bool getLoadiineSaveVersionList(int *out, const char *gamePath);
bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot);
bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot, const std::string &batchDatetime);
bool folderEmpty(const char *fPath);
bool hasCommonSave(Title *title, bool inSD, bool iine, uint8_t slot, int version);
void copySavedata(Title *title, Title *titled, int8_t wiiuuser, int8_t wiiuuser_d, bool common) __attribute__((hot));
std::string getNowDateForFolder() __attribute__((hot));
Expand All @@ -128,8 +147,8 @@ void writeMetadata(uint32_t highID,uint32_t lowID,uint8_t slot,bool isUSB,const
void writeBackupAllMetadata(const std::string & Date);
void backupAllSave(Title *titles, int count, const std::string &batchDatetime) __attribute__((hot));
void backupSavedata(Title *title, uint8_t slot, int8_t wiiuuser, bool common) __attribute__((hot));
void restoreSavedata(Title *title, uint8_t slot, int8_t sduser, int8_t wiiuuser, bool common) __attribute__((hot));
void wipeSavedata(Title *title, int8_t wiiuuser, bool common) __attribute__((hot));
int restoreSavedata(Title *title, uint8_t slot, int8_t sduser, int8_t wiiuuser, bool common, bool interactive = true) __attribute__((hot));
int wipeSavedata(Title *title, int8_t wiiuuser, bool common, bool interactive = true) __attribute__((hot));
void importFromLoadiine(Title *title, bool common, int version);
void exportToLoadiine(Title *title, bool common, int version);
int checkEntry(const char *fPath);
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <coreinit/mcp.h>
#include <coreinit/screen.h>

//#define DEBUG
#define DEBUG

#ifdef DEBUG
#include <whb/log_udp.h>
Expand Down Expand Up @@ -415,6 +415,7 @@ int main() {

#ifdef DEBUG
WHBLogUdpInit();
WHBLogPrintf("Hello from savemii!");
#endif

AXInit();
Expand Down
Loading

0 comments on commit 42f6baa

Please sign in to comment.