Updated journal space fix/handling, updated scroll logic, fix a typo

This commit is contained in:
J-D-K 2021-07-15 19:14:01 -04:00
parent 258667a9e3
commit cf832a0f91
7 changed files with 142 additions and 101 deletions

View File

@ -38,7 +38,7 @@ INCLUDES := inc
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK
APP_VERSION := 07.13.2021
APP_VERSION := 07.15.2021
ROMFS := romfs
ICON := icon.jpg

View File

@ -11,7 +11,7 @@
#define curData users[data::selUser].titleInfo[data::selData]
#define BLD_MON 7
#define BLD_DAY 13
#define BLD_DAY 15
#define BLD_YEAR 2021
namespace data

View File

@ -132,7 +132,7 @@ namespace ui
void draw(const SDL_Color *backCol);
private:
int w, h, x = 1280, y, slideSpd = 0;
int w, h, x = 1280, y;
bool open = false;
SDL_Texture *panel;
funcPtr drawFunc, callback = NULL;

View File

@ -307,17 +307,18 @@ bool data::loadUsersTitles(bool clearUsers)
fsSaveDataInfoReaderClose(&it);
}
/*if(data::incDev)
if(data::config["incDev"])
{
//Get reference to device save user
data::user& dev = data::users[data::users.size() - 4];
for(unsigned i = 0; i < users.size() - 4; i++)
unsigned devPos = getUserIndex(util::u128ToAccountUID(3));
data::user& dev = data::users[devPos];
for(unsigned i = 0; i < devPos; i++)
{
//Not needed but makes this easier to read
data::user& u = data::users[i];
u.titles.insert(u.titles.end(), dev.titles.begin(), dev.titles.end());
u.titleInfo.insert(u.titleInfo.end(), dev.titleInfo.begin(), dev.titleInfo.end());
}
}*/
}
for(data::user& u : data::users)
std::sort(u.titleInfo.begin(), u.titleInfo.end(), sortTitles);
@ -359,7 +360,9 @@ void data::exit()
data::titleInfo *data::getTitleInfoByTID(const uint64_t& tid)
{
return &titles[tid];
if(titles.find(tid) != titles.end())
return &titles[tid];
return NULL;
}
std::string data::getTitleNameByTID(const uint64_t& tid)
@ -497,7 +500,7 @@ void data::loadCfg()
fclose(cfg);
data::config["incDev"] = cfgIn >> 63 & 1;
data::config["autoBack"] = cfgIn >> 63 & 1;
data::config["autoBack"] = cfgIn >> 62 & 1;
data::config["ovrClk"] = cfgIn >> 61 & 1;
data::config["holdDel"] = cfgIn >> 60 & 1;
data::config["holdRest"] = cfgIn >> 59 & 1;

View File

@ -16,7 +16,7 @@
#include "gfx.h"
#include "data.h"
#define BUFF_SIZE 0x80000
#define BUFF_SIZE 0xC0000
static std::string wd;
@ -80,29 +80,17 @@ static void mkdirRec(const std::string& _p)
}
}
//This is mostly for Pokemon snap, but it also seems to work better? Stops commit errors from journal space
static bool fwriteCommit(const std::string& _path, const void *buf, size_t _size, const std::string& _dev)
static inline bool commitToDevice(const std::string& dev)
{
size_t written = 0;
if(data::config["directFsCmd"])
bool ret = true;
Result res = fsdevCommitDevice(dev.c_str());
if(R_FAILED(res))
{
FSFILE *out = fsfopen(_path.c_str(), FsOpenMode_Write | FsOpenMode_Append);
written = fsfwrite(buf, 1, _size, out);
fsfclose(out);
fs::logWrite("Error committing to device -> 0x%X", res);
ui::showPopMessage(POP_FRAME_DEFAULT, "Error commmitting file to device!");
ret = false;
}
else
{
FILE *out = fopen(_path.c_str(), "ab");
written = fwrite(buf, 1, _size, out);
fclose(out);
}
Result commit = fsdevCommitDevice(_dev.c_str());
if(R_FAILED(commit) || written == 0)
fs::logWrite("Error writing/committing to file \"%s\"\n", _path.c_str());
return written > 0 && R_SUCCEEDED(commit);
return ret;
}
void fs::init()
@ -181,7 +169,6 @@ Result fs::extendSaveDataFileSystem(FsSaveDataSpaceId _id, uint64_t _saveID, uin
uint64_t expSize;
uint64_t journal;
} in = {(uint8_t)_id, _saveID, _expSize, _journal};
return serviceDispatchIn(fs, 32, in);
}
@ -403,19 +390,20 @@ void fs::copyFile(const std::string& from, const std::string& to)
void copyFileCommit_t(void *a)
{
copyArgs *args = (copyArgs *)a;
data::titleInfo *info = data::getTitleInfoByTID(data::curData.saveID);
uint64_t journalSize = info->nacp.user_account_save_data_journal_size, writeCount = 0;
uint8_t *buff = new uint8_t[BUFF_SIZE];
//Create empty destination file using fs
fsfcreate(args->to.c_str(), 0);
if(data::config["directFsCmd"])
{
FSFILE *in = fsfopen(args->from.c_str(), FsOpenMode_Read);
FSFILE *in = fsfopen(args->from.c_str(), FsOpenMode_Read);
FSFILE *out = fsfopen(args->to.c_str(), FsOpenMode_Write);
if(!in)
if(!in || !out)
{
fsfclose(in);
fsfclose(out);
args->fin = true;
return;
}
@ -423,19 +411,32 @@ void copyFileCommit_t(void *a)
size_t readIn = 0;
while((readIn = fsfread(buff, 1, BUFF_SIZE, in)) > 0)
{
if(!fwriteCommit(args->to, buff, readIn, args->dev))
break;
fsfwrite(buff, 1, readIn, out);
writeCount += readIn;
if(writeCount >= (journalSize - 0x100000))
{
writeCount = 0;
fsfclose(out);
if(!commitToDevice(args->dev))
break;
out = fsfopen(args->to.c_str(), FsOpenMode_Write | FsOpenMode_Append);
}
*args->offset = in->offset;
}
fsfclose(in);
fsfclose(out);
}
else
{
FILE *in = fopen(args->from.c_str(), "rb");
FILE *out = fopen(args->to.c_str(), "wb");
if(!in)
if(!in || !out)
{
fclose(in);
fclose(out);
args->fin = true;
return;
}
@ -443,18 +444,26 @@ void copyFileCommit_t(void *a)
size_t readIn = 0;
while((readIn = fread(buff, 1, BUFF_SIZE, in)) > 0)
{
if(!fwriteCommit(args->to, buff, readIn, args->dev))
break;
fwrite(buff, 1, readIn, out);
writeCount += readIn;
if(writeCount >= (journalSize - 0x100000))
{
writeCount = 0;
fclose(out);
if(!commitToDevice(args->dev))
break;
out = fopen(args->to.c_str(), "ab");
}
*args->offset = ftell(in);
}
fclose(in);
fclose(out);
}
delete[] buff;
Result res = 0;
if(R_FAILED(res = fsdevCommitDevice(args->dev.c_str())))
fs::logWrite("Error committing file \"%s\"\n", args->to.c_str());
commitToDevice(args->dev.c_str());
args->fin = true;
}
@ -574,53 +583,84 @@ void fs::copyDirToZip(const std::string& from, zipFile *to)
void fs::copyZipToDir(unzFile *unz, const std::string& to, const std::string& dev)
{
data::titleInfo *tinfo = data::getTitleInfoByTID(data::curData.saveID);
uint64_t journalSize = tinfo->nacp.user_account_save_data_journal_size, writeCount = 0;
char filename[FS_MAX_PATH];
uint8_t *buff = new uint8_t[BUFF_SIZE];
int readIn = 0;
unz_file_info info;
do
int fCount = 0;
if(unzGoToFirstFile(*unz) == UNZ_OK)
{
unzGetCurrentFileInfo(*unz, &info, filename, FS_MAX_PATH, NULL, 0, NULL, 0);
if(unzOpenCurrentFile(*unz) == UNZ_OK)
do
{
std::string path = to + filename;
mkdirRec(path.substr(0, path.find_last_of('/') + 1));
ui::progBar prog(info.uncompressed_size);
size_t done = 0;
//Create new empty file using FS
fsfcreate(path.c_str(), 0);
if(data::config["directFsCmd"])
unzGetCurrentFileInfo(*unz, &info, filename, FS_MAX_PATH, NULL, 0, NULL, 0);
if(unzOpenCurrentFile(*unz) == UNZ_OK)
{
while((readIn = unzReadCurrentFile(*unz, buff, BUFF_SIZE)) > 0)
std::string path = to + filename;
mkdirRec(path.substr(0, path.find_last_of('/') + 1));
ui::progBar prog(info.uncompressed_size);
size_t done = 0;
if(data::config["directFsCmd"])
{
done += readIn;
fwriteCommit(path, buff, readIn, dev);
prog.update(done);
FSFILE *out = fsfopen(path.c_str(), FsOpenMode_Write);
while((readIn = unzReadCurrentFile(*unz, buff, BUFF_SIZE)) > 0)
{
done += readIn;
writeCount += readIn;
fsfwrite(buff, 1, readIn, out);
if(writeCount >= (journalSize - 0x100000))
{
writeCount = 0;
fsfclose(out);
if(!commitToDevice(dev.c_str()))
break;
prog.draw(filename, ui::copyHead);
gfx::present();
out = fsfopen(path.c_str(), FsOpenMode_Write | FsOpenMode_Append);
}
prog.update(done);
prog.draw(filename, ui::copyHead);
gfx::present();
}
fsfclose(out);
}
}
else
{
while((readIn = unzReadCurrentFile(*unz, buff, BUFF_SIZE)) > 0)
else
{
done += readIn;
fwriteCommit(path, buff, readIn, dev);
prog.update(done);
FILE *out = fopen(path.c_str(), "wb");
prog.draw(filename, ui::copyHead);
gfx::present();
while((readIn = unzReadCurrentFile(*unz, buff, BUFF_SIZE)) > 0)
{
done += readIn;
writeCount += readIn;
fwrite(buff, 1, readIn, out);
if(writeCount >= (journalSize - 0x100000))
{
writeCount = 0;
fclose(out);
if(!commitToDevice(dev.c_str()))
break;
out = fopen(path.c_str(), "ab");
}
prog.update(done);
prog.draw(filename, ui::copyHead);
gfx::present();
}
fclose(out);
}
unzCloseCurrentFile(*unz);
commitToDevice(dev.c_str());
}
unzCloseCurrentFile(*unz);
if(R_FAILED(fsdevCommitDevice(dev.c_str())))
ui::showMessage("*Error*", "Error committing file to device.");
}
while(unzGoToNextFile(*unz) != UNZ_END_OF_LIST_OF_FILE);
}
while(unzGoToNextFile(*unz) != UNZ_END_OF_LIST_OF_FILE);
else
ui::showPopMessage(POP_FRAME_DEFAULT, "ZIP file is empty!");
delete[] buff;
}

View File

@ -1,5 +1,6 @@
#include <cstring>
#include <cstdarg>
#include <cmath>
#include <switch.h>
#include "gfx.h"
@ -7,10 +8,7 @@
#include "miscui.h"
#include "util.h"
static bool popDraw = false;
static std::string popText;
static const char *okt = "OK \ue0e0";
static unsigned popY, popX, popWidth, popState, frameCount, frameHold;
static const SDL_Color divLight = {0x6D, 0x6D, 0x6D, 0xFF};
static const SDL_Color divDark = {0xCC, 0xCC, 0xCC, 0xFF};
@ -23,13 +21,6 @@ static const SDL_Color fillDark = {0x32, 0x50, 0xF0, 0xFF};
static const SDL_Color menuColorLight = {0x32, 0x50, 0xF0, 0xFF};
static const SDL_Color menuColorDark = {0x00, 0xFF, 0xC5, 0xFF};
enum popStates
{
popRise,
popShow,
popFall
};
//8
static const std::string loadGlyphArray[] =
{
@ -315,10 +306,6 @@ ui::slideOutPanel::slideOutPanel(int _w, int _h, int _y, funcPtr _draw)
drawFunc = _draw;
panel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetTextureBlendMode(panel, SDL_BLENDMODE_BLEND);
int getDiv = 99;
while(w % getDiv != 0) { getDiv--; }
slideSpd = getDiv;
}
ui::slideOutPanel::~slideOutPanel()
@ -338,11 +325,13 @@ void ui::slideOutPanel::draw(const SDL_Color *backCol)
if(open && x > 1280 - w)
{
x -= slideSpd;
float add = ((1280 - (float)w) - (float)x) / 2;
x += round(add);
}
else if(!open && x < 1280)
{
x += slideSpd;
float add = (1280 - (float)x) / 2;
x += round(add);
}
//don't waste time drawing if you can't even see it.
@ -464,14 +453,19 @@ void ui::titleview::update()
void ui::titleview::draw(SDL_Texture *target)
{
if(selRectY > 264)
y -= 48;
else if(selRectY > 144)
y -= 24;
else if(selRectY < -82)
y += 48;
int tH = 0, tY = 0;
SDL_QueryTexture(target, NULL, NULL, NULL, &tH);
tY = tH - 214;
if(selRectY > tY)
{
float add = ((float)tY - (float)selRectY) / 2;
y += round(add);
}
else if(selRectY < 38)
y += 24;
{
float add = (38.0f - (float)selRectY) / 2;
y += round(add);
}
if(clrAdd)
{

View File

@ -106,7 +106,7 @@ static void infoPanelCallback(void *a)
infoPanel->closePanel();
ttlOptsPanel->openPanel();
ttlOpts->setActive(true);
ttlViews[data::selUser]->setActive(true, true);
ui::updateInput();
break;
}
}
@ -212,8 +212,12 @@ static void ttlOptsExtendSaveData(void *a)
ui::showPopMessage(POP_FRAME_DEFAULT, "Save data expanded for %s!", extend->title.c_str());
else
{
int64_t totalSize = 0;
fs::mountSave(data::curData.saveInfo);
fsFsGetTotalSpace(fsdevGetDeviceFileSystem("sv"), "/", &totalSize);
fs::logWrite("Extend Failed: %uMB to %uMB -> %X\n", totalSize / 1024 / 1024, expSize / 1024 / 1024, res);
ui::showPopMessage(POP_FRAME_DEFAULT, "Failed to expand save data.");
fs::logWrite("Extend Failed: %u -> %X\n", expSize, res);
fs::unmountSave();
}
}
}