mirror of
https://github.com/joel16/3DShell.git
synced 2024-11-23 11:39:47 +00:00
gui: Display and recalculate storage bar after copy/delete operations
This commit is contained in:
parent
b3fce86af8
commit
ad3648cd7b
@ -20,6 +20,8 @@ namespace FS {
|
||||
bool FileExists(FS_Archive archive, const std::string &path);
|
||||
bool DirExists(FS_Archive archive, const std::string &path);
|
||||
std::string GetFileExt(const std::string &filename);
|
||||
u64 GetTotalStorage(FS_SystemMediaType mediatype);
|
||||
u64 GetUsedStorage(FS_SystemMediaType mediatype);
|
||||
FileType GetFileType(const std::string &filename);
|
||||
Result GetDirList(const std::string &path, std::vector<FS_DirectoryEntry> &entries);
|
||||
Result ChangeDirNext(const std::string &path, std::vector<FS_DirectoryEntry> &entries);
|
||||
|
@ -31,6 +31,7 @@ typedef struct {
|
||||
|
||||
namespace GUI {
|
||||
void ResetCheckbox(MenuItem *item);
|
||||
void RecalcStorageSize(MenuItem *item);
|
||||
Result Loop(void);
|
||||
|
||||
// Windows
|
||||
|
@ -85,6 +85,43 @@ namespace FS {
|
||||
return FileTypeNone;
|
||||
}
|
||||
|
||||
static u64 GetFreeStorage(FS_SystemMediaType mediatype) {
|
||||
Result ret = 0;
|
||||
FS_ArchiveResource resource = { 0 };
|
||||
|
||||
if (R_FAILED(ret = FSUSER_GetArchiveResource(&resource, mediatype))) {
|
||||
Log::Error("FSUSER_GetArchiveResource(GetFreeStorage) failed: 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return (static_cast<u64>(resource.freeClusters) * static_cast<u64>(resource.clusterSize));
|
||||
}
|
||||
|
||||
u64 GetTotalStorage(FS_SystemMediaType mediatype) {
|
||||
Result ret = 0;
|
||||
FS_ArchiveResource resource = { 0 };
|
||||
|
||||
if (R_FAILED(ret = FSUSER_GetArchiveResource(&resource, mediatype))) {
|
||||
Log::Error("FSUSER_GetArchiveResource(GetTotalStorage) failed: 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return (static_cast<u64>(resource.totalClusters) * static_cast<u64>(resource.clusterSize));
|
||||
}
|
||||
|
||||
u64 GetUsedStorage(FS_SystemMediaType mediatype) {
|
||||
Result ret = 0;
|
||||
FS_ArchiveResource resource = { 0 };
|
||||
|
||||
if (R_FAILED(ret = FSUSER_GetArchiveResource(&resource, mediatype))) {
|
||||
Log::Error("FSUSER_GetArchiveResource(GetUsedStorage) failed: 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ((static_cast<u64>(resource.totalClusters) * static_cast<u64>(resource.clusterSize)) -
|
||||
(static_cast<u64>(resource.freeClusters) * static_cast<u64>(resource.clusterSize)));
|
||||
}
|
||||
|
||||
static bool Sort(const FS_DirectoryEntry &entryA, const FS_DirectoryEntry &entryB) {
|
||||
if ((entryA.attributes & FS_ATTRIBUTE_DIRECTORY) && !(entryB.attributes & FS_ATTRIBUTE_DIRECTORY))
|
||||
return true;
|
||||
@ -248,6 +285,13 @@ namespace FS {
|
||||
FSFILE_Close(src_handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Make sure we have enough storage to carry out this operation
|
||||
if (FS::GetFreeStorage(src_archive == sdmc_archive? SYSTEM_MEDIATYPE_SD : SYSTEM_MEDIATYPE_CTR_NAND) < size) {
|
||||
Log::Error("Not enough storage is available to process this command 0x%x\n", src_path.c_str(), ret);
|
||||
FSFILE_Close(src_handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// This may fail or not, but we don't care -> create the file if it doesn't exist, otherwise continue.
|
||||
FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, dest_path.c_str()), 0, size);
|
||||
|
@ -63,7 +63,8 @@ namespace GUI {
|
||||
FS::GetDirList(cfg.cwd, item->entries);
|
||||
GUI::ResetCheckbox(item);
|
||||
}
|
||||
|
||||
|
||||
GUI::RecalcStorageSize(item);
|
||||
Log::Open();
|
||||
selection = 0;
|
||||
item->state = MENU_STATE_OPTIONS;
|
||||
|
@ -22,7 +22,12 @@ namespace GUI {
|
||||
void DisplayFileBrowser(MenuItem *item) {
|
||||
float filename_height = 0.0f;
|
||||
C2D::GetTextSize(0.45f, nullptr, &filename_height, cfg.cwd.c_str());
|
||||
C2D::Text(35, 15 + ((25 - filename_height) / 2), 0.45f, WHITE, cfg.cwd.c_str());
|
||||
C2D::Text(5, 15 + ((25 - filename_height) / 2), 0.45f, WHITE, cfg.cwd.c_str());
|
||||
|
||||
// Storage bar
|
||||
C2D::Rect(5, 28 + ((25 - filename_height) / 2), 390, 2, cfg.dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
|
||||
float fill = (static_cast<double>(item->used_storage)/static_cast<double>(item->total_storage)) * 390.0;
|
||||
C2D::Rect(5, 28 + ((25 - filename_height) / 2), fill, 2, cfg.dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR);
|
||||
|
||||
if (item->entries.empty()) {
|
||||
C2D::GetTextSize(0.50f, &empty_dir_width, &empty_dir_height, empty_dir.c_str());
|
||||
|
@ -20,6 +20,11 @@ namespace GUI {
|
||||
item->checked_count = 0;
|
||||
};
|
||||
|
||||
void RecalcStorageSize(MenuItem *item) {
|
||||
item->total_storage = FS::GetTotalStorage(archive == sdmc_archive? SYSTEM_MEDIATYPE_SD : SYSTEM_MEDIATYPE_CTR_NAND);
|
||||
item->used_storage = FS::GetUsedStorage(archive == sdmc_archive? SYSTEM_MEDIATYPE_SD : SYSTEM_MEDIATYPE_CTR_NAND);
|
||||
}
|
||||
|
||||
static void DisplayStatusBar(void) {
|
||||
const std::time_t time = std::time(nullptr);
|
||||
const std::tm calendar_time = *std::localtime(std::addressof(time));
|
||||
@ -69,6 +74,7 @@ namespace GUI {
|
||||
return ret;
|
||||
|
||||
GUI::ResetCheckbox(&item);
|
||||
GUI::RecalcStorageSize(&item);
|
||||
|
||||
while(aptMainLoop()) {
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
|
@ -134,6 +134,7 @@ namespace GUI {
|
||||
}
|
||||
}
|
||||
|
||||
GUI::RecalcStorageSize(item);
|
||||
copy = !copy;
|
||||
item->state = MENU_STATE_FILEBROWSER;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user