mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-25 16:15:11 -05:00
147 lines
4.3 KiB
C++
147 lines
4.3 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <cstdio>
|
|
#include <vector>
|
|
#include <switch.h>
|
|
#include <dirent.h>
|
|
#include <minizip/zip.h>
|
|
#include <minizip/unzip.h>
|
|
|
|
#include "fsfile.h"
|
|
#include "data.h"
|
|
#include "miscui.h"
|
|
|
|
namespace fs
|
|
{
|
|
void init();
|
|
void exit();
|
|
|
|
//Mounts usr's save data for open. Returns false it fails
|
|
bool mountSave(const FsSaveDataInfo& _m);
|
|
inline bool unmountSave() { return fsdevUnmountDevice("sv") == 0; }
|
|
Result extendSaveDataFileSystem(FsSaveDataSpaceId _id, uint64_t _saveID, uint64_t _expSize, uint64_t _journal);
|
|
|
|
void copyFile(const std::string& from, const std::string& to);
|
|
void copyFileCommit(const std::string& from, const std::string& to, const std::string& dev);
|
|
|
|
//Recursively copies 'from' to 'to'
|
|
void copyDirToDir(const std::string& from, const std::string& to);
|
|
|
|
//Copies from to zipFile to
|
|
void copyDirToZip(const std::string& from, zipFile *to);
|
|
|
|
//Same as above, but commits data to 'dev' after every file is closed
|
|
void copyDirToDirCommit(const std::string& from, const std::string& to, const std::string& dev);
|
|
|
|
//Copies unzfile to 'to'
|
|
void copyZipToDir(unzFile *unz, const std::string& to, const std::string& dev);
|
|
|
|
//deletes file
|
|
void delfile(const std::string& path);
|
|
//Recursively deletes 'path'
|
|
void delDir(const std::string& path);
|
|
|
|
//Loads paths to filter from backup/deletion
|
|
void loadPathFilters(const std::string& _file);
|
|
bool pathIsFiltered(const std::string& _path);
|
|
void freePathFilters();
|
|
|
|
inline void wipeSave()
|
|
{
|
|
fs::delDir("sv:/");
|
|
fsdevCommitDevice("sv");
|
|
}
|
|
|
|
//Dumps all titles for 'user'. returns false to bail
|
|
bool dumpAllUserSaves(const data::user& u);
|
|
|
|
//returns file properties as C++ string
|
|
std::string getFileProps(const std::string& _path);
|
|
|
|
//Recursively retrieves info about dir _path
|
|
void getDirProps(const std::string& _path, uint32_t& dirCount, uint32_t& fileCount, uint64_t& totalSize);
|
|
|
|
bool fileExists(const std::string& _path);
|
|
//Returns file size
|
|
size_t fsize(const std::string& _f);
|
|
bool isDir(const std::string& _path);
|
|
|
|
std::string getWorkDir();
|
|
|
|
class dirItem
|
|
{
|
|
public:
|
|
dirItem(const std::string& pathTo, const std::string& sItem);
|
|
std::string getItm() const { return itm; }
|
|
std::string getName() const;
|
|
std::string getExt() const;
|
|
bool isDir() const { return dir; }
|
|
|
|
private:
|
|
std::string itm;
|
|
bool dir = false;
|
|
};
|
|
|
|
//Just retrieves a listing for _path and stores it in item vector
|
|
class dirList
|
|
{
|
|
public:
|
|
dirList() = default;
|
|
dirList(const std::string& _path);
|
|
void reassign(const std::string& _path);
|
|
void rescan();
|
|
|
|
std::string getItem(int index) const { return item[index].getItm(); }
|
|
std::string getItemExt(int index) const { return item[index].getExt(); }
|
|
bool isDir(int index) const { return item[index].isDir(); }
|
|
unsigned getCount() const { return item.size(); }
|
|
|
|
private:
|
|
DIR *d;
|
|
struct dirent *ent;
|
|
std::string path;
|
|
std::vector<dirItem> item;
|
|
};
|
|
|
|
class dataFile
|
|
{
|
|
public:
|
|
dataFile(const std::string& _path);
|
|
~dataFile();
|
|
|
|
bool isOpen() const { return opened; }
|
|
|
|
bool readNextLine(bool proc);
|
|
//Finds where variable name ends. When a '(' or '=' is hit. Strips spaces
|
|
void procLine();
|
|
std::string getLine() const { return line; }
|
|
std::string getName() const { return name; }
|
|
//Reads until ';', ',', or '\n' is hit and returns as string.
|
|
std::string getNextValueStr();
|
|
int getNextValueInt();
|
|
|
|
private:
|
|
FILE *f;
|
|
std::string line, name;
|
|
size_t lPos = 0;
|
|
bool opened = false;
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
ui::menu *m;
|
|
fs::dirList *d;
|
|
} backupArgs;
|
|
|
|
//Take a pointer to backupArgs^
|
|
void createNewBackup(void *a);
|
|
void overwriteBackup(void *a);
|
|
void restoreBackup(void *a);
|
|
void deleteBackup(void *a);
|
|
|
|
void logOpen();
|
|
void logWrite(const char *fmt, ...);
|
|
void logClose();
|
|
}
|