fs: Remove cwd from config and clean up fs/config code

This commit is contained in:
Joel16 2022-08-02 15:20:26 -04:00
parent 0a94bd9476
commit ee42d0234c
17 changed files with 259 additions and 260 deletions

View File

@ -1,15 +1,16 @@
#pragma once
#include <string>
#include <switch.h>
typedef struct {
int lang = 1;
bool dev_options = false;
bool image_filename = false;
char cwd[FS_MAX_PATH + 1] = "/";
} config_t;
extern config_t cfg;
extern char cwd[FS_MAX_PATH];
namespace Config {
int Save(config_t &config);

View File

@ -5,7 +5,7 @@
#include <vector>
extern FsFileSystem *fs;
extern FsFileSystem devices[4];
extern std::vector<FsFileSystem> devices;
typedef enum FileType {
FileTypeNone,

View File

@ -6,39 +6,39 @@
#include "fs.hpp"
#include "log.hpp"
#define CONFIG_VERSION 3
#define CONFIG_VERSION 4
config_t cfg;
namespace Config {
static const char *config_file = "{\n\t\"config_ver\": %d,\n\t\"lang\": %d,\n\t\"dev_options\": %d,\n\t\"image_filename\": %d,\n\t\"last_dir\": \"%s\"\n}";
static const char *config_file = "{\n\t\"config_version\": %d,\n\t\"language\": %d,\n\t\"dev_options\": %d,\n\t\"image_filename\": %d\n}";
static int config_version_holder = 0;
static const int buf_size = 128 + FS_MAX_PATH;
static const int buf_size = 128;
int Save(config_t &config) {
Result ret = 0;
char *buf = new char[buf_size];
u64 len = std::snprintf(buf, buf_size, config_file, CONFIG_VERSION, config.lang, config.dev_options, config.image_filename, config.cwd);
u64 len = std::snprintf(buf, buf_size, config_file, CONFIG_VERSION, config.lang, config.dev_options, config.image_filename);
// Delete and re-create the file, we don't care about the return value here.
fsFsDeleteFile(fs, "/switch/NX-Shell/config.json");
fsFsCreateFile(fs, "/switch/NX-Shell/config.json", len, 0);
FsFile file;
if (R_FAILED(ret = fsFsOpenFile(fs, "/switch/NX-Shell/config.json", FsOpenMode_Write, &file))) {
if (R_FAILED(ret = fsFsOpenFile(fs, "/switch/NX-Shell/config.json", FsOpenMode_Write, std::addressof(file)))) {
Log::Error("fsFsOpenFile(/switch/NX-Shell/config.json) failed: 0x%x\n", ret);
delete[] buf;
return ret;
}
if (R_FAILED(ret = fsFileWrite(&file, 0, buf, len, FsWriteOption_Flush))) {
if (R_FAILED(ret = fsFileWrite(std::addressof(file), 0, buf, len, FsWriteOption_Flush))) {
Log::Error("fsFileWrite(/switch/NX-Shell/config.json) failed: 0x%x\n", ret);
delete[] buf;
fsFileClose(&file);
fsFileClose(std::addressof(file));
return ret;
}
fsFileClose(&file);
fsFileClose(std::addressof(file));
delete[] buf;
return 0;
}
@ -47,7 +47,6 @@ namespace Config {
config.lang = 1;
config.dev_options = false;
config.image_filename = false;
std::strncpy(config.cwd, "/", 2);
}
int Load(void) {
@ -64,27 +63,27 @@ namespace Config {
}
FsFile file;
if (R_FAILED(ret = fsFsOpenFile(fs, "/switch/NX-Shell/config.json", FsOpenMode_Read, &file)))
if (R_FAILED(ret = fsFsOpenFile(fs, "/switch/NX-Shell/config.json", FsOpenMode_Read, std::addressof(file))))
return ret;
s64 size = 0;
if (R_FAILED(ret = fsFileGetSize(&file, &size))) {
fsFileClose(&file);
if (R_FAILED(ret = fsFileGetSize(std::addressof(file), std::addressof(size)))) {
fsFileClose(std::addressof(file));
return ret;
}
char *buf = new char[size + 1];
if (R_FAILED(ret = fsFileRead(&file, 0, buf, static_cast<u64>(size) + 1, FsReadOption_None, nullptr))) {
if (R_FAILED(ret = fsFileRead(std::addressof(file), 0, buf, static_cast<u64>(size) + 1, FsReadOption_None, nullptr))) {
delete[] buf;
fsFileClose(&file);
fsFileClose(std::addressof(file));
return ret;
}
fsFileClose(&file);
fsFileClose(std::addressof(file));
json_t *root;
json_error_t error;
root = json_loads(buf, 0, &error);
root = json_loads(buf, 0, std::addressof(error));
delete[] buf;
if (!root) {
@ -92,31 +91,25 @@ namespace Config {
return -1;
}
json_t *config_ver = json_object_get(root, "config_ver");
json_t *config_ver = json_object_get(root, "config_version");
config_version_holder = json_integer_value(config_ver);
json_t *lang = json_object_get(root, "lang");
cfg.lang = json_integer_value(lang);
json_t *dev_options = json_object_get(root, "dev_options");
cfg.dev_options = json_integer_value(dev_options);
json_t *image_filename = json_object_get(root, "image_filename");
cfg.image_filename = json_integer_value(image_filename);
json_t *last_dir = json_object_get(root, "last_dir");
std::strcpy(cfg.cwd, json_string_value(last_dir));
if (!FS::DirExists(cfg.cwd))
std::strcpy(cfg.cwd, "/");
// Delete config file if config file is updated. This will rarely happen.
if (config_version_holder < CONFIG_VERSION) {
fsFsDeleteFile(fs, "/switch/NX-Shell/config.json");
Config::SetDefault(cfg);
return Config::Save(cfg);
}
json_t *language = json_object_get(root, "language");
cfg.lang = json_integer_value(language);
json_t *dev_options = json_object_get(root, "dev_options");
cfg.dev_options = json_integer_value(dev_options);
json_t *image_filename = json_object_get(root, "image_filename");
cfg.image_filename = json_integer_value(image_filename);
json_decref(root);
return 0;
}

View File

@ -11,7 +11,8 @@
// Global vars
FsFileSystem *fs;
FsFileSystem devices[4];
std::vector<FsFileSystem> devices;
char cwd[FS_MAX_PATH] = "/";
namespace FS {
static int PREVIOUS_BROWSE_STATE = 0;
@ -26,8 +27,8 @@ namespace FS {
bool FileExists(const char path[FS_MAX_PATH]) {
FsFile file;
if (R_SUCCEEDED(fsFsOpenFile(fs, path, FsOpenMode_Read, &file))) {
fsFileClose(&file);
if (R_SUCCEEDED(fsFsOpenFile(fs, path, FsOpenMode_Read, std::addressof(file)))) {
fsFileClose(std::addressof(file));
return true;
}
@ -36,8 +37,8 @@ namespace FS {
bool DirExists(const char path[FS_MAX_PATH]) {
FsDir dir;
if (R_SUCCEEDED(fsFsOpenDirectory(fs, path, FsDirOpenMode_ReadDirs, &dir))) {
fsDirClose(&dir);
if (R_SUCCEEDED(fsFsOpenDirectory(fs, path, FsDirOpenMode_ReadDirs, std::addressof(dir)))) {
fsDirClose(std::addressof(dir));
return true;
}
@ -48,18 +49,18 @@ namespace FS {
Result ret = 0;
FsFile file;
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Read, &file))) {
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Read, std::addressof(file)))) {
Log::Error("fsFsOpenFile(%s) failed: 0x%x\n", path, ret);
return ret;
}
if (R_FAILED(ret = fsFileGetSize(&file, &size))) {
if (R_FAILED(ret = fsFileGetSize(std::addressof(file), std::addressof(size)))) {
Log::Error("fsFileGetSize(%s) failed: 0x%x\n", path, ret);
fsFileClose(&file);
fsFileClose(std::addressof(file));
return ret;
}
fsFileClose(&file);
fsFileClose(std::addressof(file));
return 0;
}
@ -97,15 +98,15 @@ namespace FS {
entry.file_size = 0;
entries.push_back(entry);
if (R_FAILED(ret = fsFsOpenDirectory(fs, path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, &dir))) {
if (R_FAILED(ret = fsFsOpenDirectory(fs, path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, std::addressof(dir)))) {
Log::Error("GetDirListfsFsOpenDirectory(%s) failed: 0x%x\n", path, ret);
return ret;
}
while (true) {
FsDirectoryEntry entry;
if (R_FAILED(ret = fsDirRead(&dir, &read_entries, 1, &entry))) {
fsDirClose(&dir);
if (R_FAILED(ret = fsDirRead(std::addressof(dir), &read_entries, 1, std::addressof(entry)))) {
fsDirClose(std::addressof(dir));
Log::Error("fsDirRead(%s) failed: 0x%x\n", path, ret);
return ret;
}
@ -116,7 +117,7 @@ namespace FS {
entries.push_back(entry);
}
fsDirClose(&dir);
fsDirClose(std::addressof(dir));
return 0;
}
@ -129,24 +130,24 @@ namespace FS {
// Apply cd after successfully listing new directory
entries.clear();
std::strncpy(cfg.cwd, path, FS_MAX_PATH);
std::strncpy(cwd, path, FS_MAX_PATH - 1);
Config::Save(cfg);
entries = new_entries;
return 0;
}
static int GetPrevPath(char path[FS_MAX_PATH]) {
if (std::strlen(cfg.cwd) <= 1 && cfg.cwd[0] == '/')
if (std::strlen(cwd) <= 1 && cwd[0] == '/')
return -1;
// Remove upmost directory
bool copy = false;
int len = 0;
for (ssize_t i = std::strlen(cfg.cwd); i >= 0; i--) {
if (cfg.cwd[i] == '/')
for (ssize_t i = std::strlen(cwd); i >= 0; i--) {
if (cwd[i] == '/')
copy = true;
if (copy) {
path[i] = cfg.cwd[i];
path[i] = cwd[i];
len++;
}
}
@ -161,14 +162,14 @@ namespace FS {
Result ChangeDirNext(const char path[FS_MAX_PATH], std::vector<FsDirectoryEntry> &entries) {
char new_cwd[FS_MAX_PATH];
const char *sep = (std::strncmp(cfg.cwd, "/", 2) == 0)? "" : "/"; // Don't append / if at /
const char *sep = (std::strncmp(cwd, "/", 2) == 0)? "" : "/"; // Don't append / if at /
if ((std::snprintf(new_cwd, FS_MAX_PATH, "%s%s%s", cfg.cwd, sep, path)) > 0)
if ((std::snprintf(new_cwd, FS_MAX_PATH, "%s%s%s", cwd, sep, path)) > 0)
return FS::ChangeDir(new_cwd, entries);
return 0;
}
Result ChangeDirPrev(std::vector<FsDirectoryEntry> &entries) {
char new_cwd[FS_MAX_PATH];
if (FS::GetPrevPath(new_cwd) < 0)
@ -177,15 +178,15 @@ namespace FS {
return FS::ChangeDir(new_cwd, entries);
}
static int BuildPath(FsDirectoryEntry &entry, char path[FS_MAX_PATH], const char filename[FS_MAX_PATH]) {
if ((std::snprintf(path, FS_MAX_PATH, "%s%s%s", cfg.cwd, (std::strncmp(cfg.cwd, "/", 2) == 0)? "" : "/", entry.name)) > 0)
static int BuildPath(FsDirectoryEntry &entry, char path[FS_MAX_PATH]) {
if ((std::snprintf(path, FS_MAX_PATH, "%s%s%s", cwd, (std::strncmp(cwd, "/", 2) == 0)? "" : "/", entry.name)) > 0)
return 0;
return -1;
}
static int BuildPath(char path[FS_MAX_PATH], const char filename[FS_MAX_PATH]) {
if ((std::snprintf(path, FS_MAX_PATH, "%s%s%s", cfg.cwd, (std::strncmp(cfg.cwd, "/", 2) == 0)? "" : "/", filename[0] != '\0'? filename : "")) > 0)
if ((std::snprintf(path, FS_MAX_PATH, "%s%s%s", cwd, (std::strncmp(cwd, "/", 2) == 0)? "" : "/", filename[0] != '\0'? filename : "")) > 0)
return 0;
return -1;
@ -195,10 +196,10 @@ namespace FS {
Result ret = 0;
char path[FS_MAX_PATH];
if (R_FAILED(FS::BuildPath(entry, path, "")))
if (R_FAILED(FS::BuildPath(entry, path)))
return -1;
if (R_FAILED(ret = fsFsGetFileTimeStampRaw(fs, path, &timestamp))) {
if (R_FAILED(ret = fsFsGetFileTimeStampRaw(fs, path, std::addressof(timestamp)))) {
Log::Error("fsFsGetFileTimeStampRaw(%s) failed: 0x%x\n", path, ret);
return ret;
}
@ -210,7 +211,7 @@ namespace FS {
Result ret = 0;
char path[FS_MAX_PATH];
if (FS::BuildPath(entry, path, "") < 0)
if (FS::BuildPath(entry, path) < 0)
return -1;
char new_path[FS_MAX_PATH];
@ -237,7 +238,7 @@ namespace FS {
Result ret = 0;
char path[FS_MAX_PATH];
if (FS::BuildPath(entry, path, "") < 0)
if (FS::BuildPath(entry, path) < 0)
return -1;
if (entry.type == FsDirEntryType_Dir) {
@ -260,7 +261,7 @@ namespace FS {
Result ret = 0;
char path[FS_MAX_PATH];
if (FS::BuildPath(entry, path, "") < 0)
if (FS::BuildPath(entry, path) < 0)
return -1;
if (R_FAILED(ret = fsFsSetConcatenationFileAttribute(fs, path))) {
@ -275,24 +276,24 @@ namespace FS {
Result ret = 0;
FsFile src_handle, dest_handle;
if (R_FAILED(ret = fsFsOpenFile(&devices[PREVIOUS_BROWSE_STATE], src_path, FsOpenMode_Read, &src_handle))) {
if (R_FAILED(ret = fsFsOpenFile(std::addressof(devices[PREVIOUS_BROWSE_STATE]), src_path, FsOpenMode_Read, std::addressof(src_handle)))) {
Log::Error("fsFsOpenFile(%s) failed: 0x%x\n", src_path, ret);
return ret;
}
s64 size = 0;
if (R_FAILED(ret = fsFileGetSize(&src_handle, &size))) {
if (R_FAILED(ret = fsFileGetSize(std::addressof(src_handle), std::addressof(size)))) {
Log::Error("fsFileGetSize(%s) failed: 0x%x\n", src_path, ret);
fsFileClose(&src_handle);
fsFileClose(std::addressof(src_handle));
return ret;
}
// This may fail or not, but we don't care -> create the file if it doesn't exist, otherwise continue.
fsFsCreateFile(fs, dest_path, size, 0);
if (R_FAILED(ret = fsFsOpenFile(fs, dest_path, FsOpenMode_Write, &dest_handle))) {
if (R_FAILED(ret = fsFsOpenFile(fs, dest_path, FsOpenMode_Write, std::addressof(dest_handle)))) {
Log::Error("fsFsOpenFile(%s) failed: 0x%x\n", dest_path, ret);
fsFileClose(&src_handle);
fsFileClose(std::addressof(src_handle));
return ret;
}
@ -305,19 +306,19 @@ namespace FS {
do {
std::memset(buf, 0, buf_size);
if (R_FAILED(ret = fsFileRead(&src_handle, offset, buf, buf_size, FsReadOption_None, &bytes_read))) {
if (R_FAILED(ret = fsFileRead(std::addressof(src_handle), offset, buf, buf_size, FsReadOption_None, std::addressof(bytes_read)))) {
Log::Error("fsFileRead(%s) failed: 0x%x\n", src_path, ret);
delete[] buf;
fsFileClose(&src_handle);
fsFileClose(&dest_handle);
fsFileClose(std::addressof(src_handle));
fsFileClose(std::addressof(dest_handle));
return ret;
}
if (R_FAILED(ret = fsFileWrite(&dest_handle, offset, buf, bytes_read, FsWriteOption_Flush))) {
if (R_FAILED(ret = fsFileWrite(std::addressof(dest_handle), offset, buf, bytes_read, FsWriteOption_Flush))) {
Log::Error("fsFileWrite(%s) failed: 0x%x\n", dest_path, ret);
delete[] buf;
fsFileClose(&src_handle);
fsFileClose(&dest_handle);
fsFileClose(std::addressof(src_handle));
fsFileClose(std::addressof(dest_handle));
return ret;
}
@ -326,8 +327,8 @@ namespace FS {
} while(offset < size);
delete[] buf;
fsFileClose(&src_handle);
fsFileClose(&dest_handle);
fsFileClose(std::addressof(src_handle));
fsFileClose(std::addressof(dest_handle));
return 0;
}
@ -335,7 +336,7 @@ namespace FS {
Result ret = 0;
FsDir dir;
if (R_FAILED(ret = fsFsOpenDirectory(&devices[PREVIOUS_BROWSE_STATE], src_path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, &dir))) {
if (R_FAILED(ret = fsFsOpenDirectory(std::addressof(devices[PREVIOUS_BROWSE_STATE]), src_path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, std::addressof(dir)))) {
Log::Error("fsFsOpenDirectory(%s) failed: 0x%x\n", src_path, ret);
return ret;
}
@ -344,13 +345,13 @@ namespace FS {
fsFsCreateDirectory(fs, dest_path);
s64 entry_count = 0;
if (R_FAILED(ret = fsDirGetEntryCount(&dir, &entry_count))) {
if (R_FAILED(ret = fsDirGetEntryCount(std::addressof(dir), std::addressof(entry_count)))) {
Log::Error("fsDirGetEntryCount(%s) failed: 0x%x\n", src_path, ret);
return ret;
}
FsDirectoryEntry *entries = new FsDirectoryEntry[entry_count * sizeof(*entries)];
if (R_FAILED(ret = fsDirRead(&dir, nullptr, static_cast<size_t>(entry_count), entries))) {
if (R_FAILED(ret = fsDirRead(std::addressof(dir), nullptr, static_cast<size_t>(entry_count), entries))) {
Log::Error("fsDirRead(%s) failed: 0x%x\n", src_path, ret);
delete[] entries;
return ret;
@ -378,7 +379,7 @@ namespace FS {
}
delete[] entries;
fsDirClose(&dir);
fsDirClose(std::addressof(dir));
return 0;
}
@ -441,7 +442,7 @@ namespace FS {
Result GetFreeStorageSpace(s64 &size) {
Result ret = 0;
if (R_FAILED(ret = fsFsGetFreeSpace(fs, "/", &size))) {
if (R_FAILED(ret = fsFsGetFreeSpace(fs, "/", std::addressof(size)))) {
Log::Error("fsFsGetFreeSpace() failed: 0x%x\n", ret);
return ret;
}
@ -452,7 +453,7 @@ namespace FS {
Result GetTotalStorageSpace(s64 &size) {
Result ret = 0;
if (R_FAILED(ret = fsFsGetTotalSpace(fs, "/", &size))) {
if (R_FAILED(ret = fsFsGetTotalSpace(fs, "/", std::addressof(size)))) {
Log::Error("fsFsGetTotalSpace() failed: 0x%x\n", ret);
return ret;
}

View File

@ -97,6 +97,61 @@ namespace GUI {
return eglSwapBuffers(s_display, s_surface);
}
void SetDefaultTheme(void) {
ImGui::GetStyle().FrameRounding = 4.0f;
ImGui::GetStyle().GrabRounding = 4.0f;
ImVec4 *colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.36f, 0.42f, 0.47f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.18f, 0.22f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.12f, 0.20f, 0.28f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.09f, 0.12f, 0.14f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.09f, 0.12f, 0.14f, 0.65f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.15f, 0.18f, 0.22f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.39f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.18f, 0.22f, 0.25f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.09f, 0.21f, 0.31f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.28f, 0.56f, 1.00f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.37f, 0.61f, 1.00f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.25f, 0.29f, 0.55f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_Separator] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
colors[ImGuiCol_Tab] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_TabHovered] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_TabActive] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
}
bool Init(void) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
@ -116,10 +171,10 @@ namespace GUI {
PlFontData standard, extended, chinese, korean;
static ImWchar extended_range[] = {0xE000, 0xE152};
if (R_SUCCEEDED(plGetSharedFontByType(&standard, PlSharedFontType_Standard)) &&
if (R_SUCCEEDED(plGetSharedFontByType(&standard, PlSharedFontType_Standard)) &&
R_SUCCEEDED(plGetSharedFontByType(&extended, PlSharedFontType_NintendoExt)) &&
R_SUCCEEDED(plGetSharedFontByType(&chinese, PlSharedFontType_ChineseSimplified)) &&
R_SUCCEEDED(plGetSharedFontByType(&korean, PlSharedFontType_KO))) {
R_SUCCEEDED(plGetSharedFontByType(&chinese, PlSharedFontType_ChineseSimplified)) &&
R_SUCCEEDED(plGetSharedFontByType(&korean, PlSharedFontType_KO))) {
u8 *px = nullptr;
int w = 0, h = 0, bpp = 0;
@ -138,6 +193,7 @@ namespace GUI {
io.Fonts->Build();
}
GUI::SetDefaultTheme();
return true;
}

View File

@ -21,9 +21,9 @@ namespace ImageViewer {
else {
data.selected = index;
char path[FS_MAX_PATH + 1];
if ((std::snprintf(path, FS_MAX_PATH, "%s/%s", cfg.cwd, data.entries[index].name)) > 0) {
bool ret = Textures::LoadImageFile(path, data.textures);
char fs_path[FS_MAX_PATH + 1];
if ((std::snprintf(fs_path, FS_MAX_PATH, "%s/%s", cwd, data.entries[index].name)) > 0) {
bool ret = Textures::LoadImageFile(fs_path, data.textures);
IM_ASSERT(ret);
return ret;
}

View File

@ -22,27 +22,27 @@ namespace Keyboard {
SwkbdConfig swkbd;
static char input_string[256];
if (R_FAILED(ret = swkbdCreate(&swkbd, 0))) {
if (R_FAILED(ret = swkbdCreate(std::addressof(swkbd), 0))) {
Log::Error("swkbdCreate() failed: 0x%x\n", ret);
swkbdClose(&swkbd);
swkbdClose(std::addressof(swkbd));
return std::string();
}
swkbdConfigMakePresetDefault(&swkbd);
swkbdConfigMakePresetDefault(std::addressof(swkbd));
if (!guide_text.empty())
swkbdConfigSetGuideText(&swkbd, guide_text.c_str());
swkbdConfigSetGuideText(std::addressof(swkbd), guide_text.c_str());
if (!initial_text.empty())
swkbdConfigSetInitialText(&swkbd, initial_text.c_str());
swkbdConfigSetInitialText(std::addressof(swkbd), initial_text.c_str());
swkbdConfigSetTextCheckCallback(&swkbd, Keyboard::ValidateText);
if (R_FAILED(ret = swkbdShow(&swkbd, input_string, sizeof(input_string)))) {
swkbdConfigSetTextCheckCallback(std::addressof(swkbd), Keyboard::ValidateText);
if (R_FAILED(ret = swkbdShow(std::addressof(swkbd), input_string, sizeof(input_string)))) {
Log::Error("swkbdShow() failed: 0x%x\n", ret);
swkbdClose(&swkbd);
swkbdClose(std::addressof(swkbd));
return std::string();
}
swkbdClose(&swkbd);
swkbdClose(std::addressof(swkbd));
return input_string;
}
}

View File

@ -4,7 +4,7 @@
#include "fs.hpp"
namespace Log {
static FsFile log_file;
static FsFile file;
static s64 offset = 0;
void Init(void) {
@ -14,17 +14,17 @@ namespace Log {
if (!FS::FileExists("/switch/NX-Shell/debug.log"))
fsFsCreateFile(fs, "/switch/NX-Shell/debug.log", 0, 0);
if (R_FAILED(fsFsOpenFile(fs, "/switch/NX-Shell/debug.log", (FsOpenMode_Read | FsOpenMode_Write | FsOpenMode_Append), &log_file)))
if (R_FAILED(fsFsOpenFile(fs, "/switch/NX-Shell/debug.log", (FsOpenMode_Read | FsOpenMode_Write | FsOpenMode_Append), std::addressof(file))))
return;
s64 size = 0;
if (R_FAILED(fsFileGetSize(&log_file, &size)))
if (R_FAILED(fsFileGetSize(std::addressof(file), std::addressof(size))))
return;
unsigned char *buffer = new unsigned char[size];
u64 bytes_read = 0;
if (R_FAILED(fsFileRead(&log_file, offset, buffer, size, FsReadOption_None, &bytes_read))) {
if (R_FAILED(fsFileRead(std::addressof(file), offset, buffer, size, FsReadOption_None, std::addressof(bytes_read)))) {
delete[] buffer;
return;
}
@ -48,7 +48,7 @@ namespace Log {
std::printf("%s", error_string.c_str());
if (R_FAILED(fsFileWrite(&log_file, offset, error_string.data(), error_string.length(), FsWriteOption_None)))
if (R_FAILED(fsFileWrite(std::addressof(file), offset, error_string.data(), error_string.length(), FsWriteOption_None)))
return;
offset += error_string.length();
@ -58,6 +58,6 @@ namespace Log {
if (!cfg.dev_options)
return;
fsFileClose(&log_file);
fsFileClose(std::addressof(file));
}
}

View File

@ -1,7 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <switch.h>
#include "config.hpp"
@ -13,69 +10,13 @@
#include "windows.hpp"
char __application_path[FS_MAX_PATH];
WindowData data;
namespace Services {
void SetDefaultTheme(void) {
ImGui::GetStyle().FrameRounding = 4.0f;
ImGui::GetStyle().GrabRounding = 4.0f;
ImVec4 *colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.36f, 0.42f, 0.47f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.18f, 0.22f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.12f, 0.20f, 0.28f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.09f, 0.12f, 0.14f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.09f, 0.12f, 0.14f, 0.65f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.15f, 0.18f, 0.22f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.39f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.18f, 0.22f, 0.25f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.09f, 0.21f, 0.31f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.28f, 0.56f, 1.00f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.37f, 0.61f, 1.00f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.25f, 0.29f, 0.55f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_Separator] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
colors[ImGuiCol_Tab] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_TabHovered] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_TabActive] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.00f, 0.50f, 0.50f, 1.0f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
}
int Init(void) {
Result ret = 0;
devices[0] = *fsdevGetDeviceFileSystem("sdmc");
fs = &devices[0];
devices.push_back(*fsdevGetDeviceFileSystem("sdmc"));
fs = std::addressof(devices[0]);
Config::Load();
Log::Init();
@ -98,9 +39,8 @@ namespace Services {
}
if (!GUI::Init())
printf("Failed to init\n");
Services::SetDefaultTheme();
Log::Error("GUI::Init() failed: 0x%x\n", ret);
Textures::Init();
plExit();
romfsExit();
@ -109,8 +49,8 @@ namespace Services {
void Exit(void) {
Textures::Exit();
nifmExit();
GUI::Exit();
nifmExit();
socketExit();
Log::Exit();
}
@ -121,8 +61,8 @@ int main(int argc, char* argv[]) {
u64 key = 0;
Services::Init();
if (R_FAILED(ret = FS::GetDirList(cfg.cwd, data.entries))) {
if (R_FAILED(ret = FS::GetDirList(cwd, data.entries))) {
Services::Exit();
return ret;
}

View File

@ -15,7 +15,7 @@ namespace Net {
bool GetNetworkStatus(void) {
Result ret = 0;
NifmInternetConnectionStatus status;
if (R_FAILED(ret = nifmGetInternetConnectionStatus(nullptr, nullptr, &status))) {
if (R_FAILED(ret = nifmGetInternetConnectionStatus(nullptr, nullptr, std::addressof(status)))) {
Log::Error("nifmGetInternetConnectionStatus() failed: 0x%x\n", ret);
return false;
}
@ -56,13 +56,13 @@ namespace Net {
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, Net::WriteJSONData);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &json);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, std::addressof(json));
curl_easy_perform(handle);
curl_easy_cleanup(handle);
json_t *root;
json_error_t error;
root = json_loads(json.c_str(), JSON_DECODE_ANY, &error);
root = json_loads(json.c_str(), JSON_DECODE_ANY, std::addressof(error));
if (!root) {
Log::Error("json_loads failed on line %d: %s\n", error.line, error.text);
@ -89,7 +89,7 @@ namespace Net {
if (!FS::FileExists(path))
fsFsCreateFile(fs, path, 0, 0);
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Write | FsOpenMode_Append, &file))) {
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Write | FsOpenMode_Append, std::addressof(file)))) {
Log::Error("fsFsOpenFile(%s) failed: 0x%x\n", path, ret);
return;
}
@ -103,13 +103,13 @@ namespace Net {
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, Net::WriteNROData);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &file);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, std::addressof(file));
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
curl_easy_perform(handle);
curl_easy_cleanup(handle);
}
fsFileClose(&file);
fsFileClose(std::addressof(file));
offset = 0;
return;
}

View File

@ -14,7 +14,7 @@ namespace Popups {
if (ImGui::BeginPopupModal(strings[cfg.lang][Lang::OptionsDelete], nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text(strings[cfg.lang][Lang::DeleteMessage]);
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) == 0)) {
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cwd) == 0)) {
ImGui::Text(strings[cfg.lang][Lang::DeleteMultiplePrompt]);
ImGui::Dummy(ImVec2(0.0f, 5.0f)); // Spacing
ImGui::BeginChild("Scrolling", ImVec2(0, 100));
@ -34,7 +34,7 @@ namespace Popups {
if (ImGui::Button(strings[cfg.lang][Lang::ButtonOK], ImVec2(120, 0))) {
Result ret = 0;
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) == 0)) {
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cwd) == 0)) {
std::vector<FsDirectoryEntry> entries;
if (R_FAILED(ret = FS::GetDirList(data.checkbox_data.cwd, entries)))
@ -49,7 +49,7 @@ namespace Popups {
if (data.checkbox_data.checked.at(i)) {
if (R_FAILED(ret = FS::Delete(entries[i]))) {
FS::GetDirList(cfg.cwd, data.entries);
FS::GetDirList(cwd, data.entries);
Windows::ResetCheckbox(data);
break;
}
@ -62,7 +62,7 @@ namespace Popups {
}
if (R_SUCCEEDED(ret)) {
FS::GetDirList(cfg.cwd, data.entries);
FS::GetDirList(cwd, data.entries);
Windows::ResetCheckbox(data);
}

View File

@ -11,8 +11,14 @@
#include "language.hpp"
#include "popups.hpp"
namespace Popups {
static bool copy = false, move = false;
namespace Options {
static void RefreshEntries(bool reset_checkbox_data) {
FS::GetDirList(cwd, data.entries);
if (reset_checkbox_data)
Windows::ResetCheckbox(data);
}
static void HandleMultipleCopy(WindowData &data, Result (*func)()) {
Result ret = 0;
std::vector<FsDirectoryEntry> entries;
@ -30,28 +36,30 @@ namespace Popups {
FS::Copy(entries[i], data.checkbox_data.cwd);
if (R_FAILED((*func)())) {
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
break;
}
}
}
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
sort = -1;
entries.clear();
}
}
namespace Popups {
static bool copy = false, move = false;
void OptionsPopup(WindowData &data) {
Popups::SetupPopup(strings[cfg.lang][Lang::OptionsTitle]);
if (ImGui::BeginPopupModal(strings[cfg.lang][Lang::OptionsTitle], nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::Button(strings[cfg.lang][Lang::OptionsSelectAll], ImVec2(200, 50))) {
if ((std::strlen(data.checkbox_data.cwd) != 0) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) != 0))
if ((std::strlen(data.checkbox_data.cwd) != 0) && (strcasecmp(data.checkbox_data.cwd, cwd) != 0))
Windows::ResetCheckbox(data);
std::strcpy(data.checkbox_data.cwd, cfg.cwd);
std::strcpy(data.checkbox_data.cwd, cwd);
std::fill(data.checkbox_data.checked.begin() + 1, data.checkbox_data.checked.end(), true);
data.checkbox_data.count = data.checkbox_data.checked.size();
}
@ -76,7 +84,7 @@ namespace Popups {
if (ImGui::Button(strings[cfg.lang][Lang::OptionsRename], ImVec2(200, 50))) {
std::string path = Keyboard::GetText(strings[cfg.lang][Lang::OptionsRenamePrompt], data.entries[data.selected].name);
if (R_SUCCEEDED(FS::Rename(data.entries[data.selected], path.c_str()))) {
FS::GetDirList(cfg.cwd, data.entries);
Options::RefreshEntries(false);
sort = -1;
}
@ -89,11 +97,10 @@ namespace Popups {
if (ImGui::Button(strings[cfg.lang][Lang::OptionsNewFolder], ImVec2(200, 50))) {
std::string name = Keyboard::GetText(strings[cfg.lang][Lang::OptionsFolderPrompt], strings[cfg.lang][Lang::OptionsNewFolder]);
char path[FS_MAX_PATH];
std::snprintf(path, FS_MAX_PATH + 2, "%s/%s", cfg.cwd, name.c_str());
std::snprintf(path, FS_MAX_PATH + 2, "%s/%s", cwd, name.c_str());
if (R_SUCCEEDED(fsFsCreateDirectory(fs, path))) {
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
sort = -1;
}
@ -106,11 +113,10 @@ namespace Popups {
if (ImGui::Button(strings[cfg.lang][Lang::OptionsNewFile], ImVec2(200, 50))) {
std::string name = Keyboard::GetText(strings[cfg.lang][Lang::OptionsFilePrompt], strings[cfg.lang][Lang::OptionsNewFile]);
char path[FS_MAX_PATH];
std::snprintf(path, FS_MAX_PATH + 2, "%s/%s", cfg.cwd, name.c_str());
std::snprintf(path, FS_MAX_PATH + 2, "%s/%s", cwd, name.c_str());
if (R_SUCCEEDED(fsFsCreateFile(fs, path, 0, 0))) {
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
sort = -1;
}
@ -122,10 +128,10 @@ namespace Popups {
if (ImGui::Button(!copy? strings[cfg.lang][Lang::OptionsCopy] : strings[cfg.lang][Lang::OptionsPaste], ImVec2(200, 50))) {
if (!copy) {
if ((data.checkbox_data.count >= 1) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) != 0))
if ((data.checkbox_data.count >= 1) && (strcasecmp(data.checkbox_data.cwd, cwd) != 0))
Windows::ResetCheckbox(data);
if (data.checkbox_data.count <= 1)
FS::Copy(data.entries[data.selected], cfg.cwd);
FS::Copy(data.entries[data.selected], cwd);
copy = !copy;
data.state = WINDOW_STATE_FILEBROWSER;
@ -135,12 +141,11 @@ namespace Popups {
ImGui::PopStyleVar();
ImGui::Render();
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) != 0))
Popups::HandleMultipleCopy(data, &FS::Paste);
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cwd) != 0))
Options::HandleMultipleCopy(data, std::addressof(FS::Paste));
else {
if (R_SUCCEEDED(FS::Paste())) {
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
sort = -1;
}
}
@ -156,18 +161,17 @@ namespace Popups {
if (ImGui::Button(!move? strings[cfg.lang][Lang::OptionsMove] : strings[cfg.lang][Lang::OptionsPaste], ImVec2(200, 50))) {
if (!move) {
if ((data.checkbox_data.count >= 1) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) != 0))
if ((data.checkbox_data.count >= 1) && (strcasecmp(data.checkbox_data.cwd, cwd) != 0))
Windows::ResetCheckbox(data);
if (data.checkbox_data.count <= 1)
FS::Copy(data.entries[data.selected], cfg.cwd);
FS::Copy(data.entries[data.selected], cwd);
}
else {
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) != 0))
Popups::HandleMultipleCopy(data, &FS::Move);
if ((data.checkbox_data.count > 1) && (strcasecmp(data.checkbox_data.cwd, cwd) != 0))
Options::HandleMultipleCopy(data, std::addressof(FS::Move));
else {
if (R_SUCCEEDED(FS::Move())) {
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
sort = -1;
}
}
@ -189,8 +193,7 @@ namespace Popups {
if (ImGui::Button(strings[cfg.lang][Lang::OptionsSetArchiveBit], ImVec2(200, 50))) {
if (R_SUCCEEDED(FS::SetArchiveBit(data.entries[data.selected]))) {
FS::GetDirList(cfg.cwd, data.entries);
Windows::ResetCheckbox(data);
Options::RefreshEntries(true);
sort = -1;
}

View File

@ -8,7 +8,7 @@
namespace Popups {
static char *FormatDate(char *string, time_t timestamp) {
strftime(string, 36, "%Y/%m/%d %H:%M:%S", localtime(&timestamp));
strftime(string, 36, "%Y/%m/%d %H:%M:%S", localtime(std::addressof(timestamp)));
return string;
}
@ -61,9 +61,9 @@ namespace Popups {
Popups::SetupPopup(strings[cfg.lang][Lang::OptionsProperties]);
std::string new_width, new_height;
if (ImGui::BeginPopupModal("Properties", &state, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal("Properties", std::addressof(state), ImGuiWindowFlags_AlwaysAutoResize)) {
std::string parent_text = "Parent: ";
parent_text.append(cfg.cwd);
parent_text.append(cwd);
ImGui::Text(parent_text.c_str());
ImGui::Dummy(ImVec2(0.0f, 5.0f)); // Spacing

View File

@ -58,7 +58,7 @@ namespace Tabs {
ImGuiTableSortSpecs *table_sort_specs = ImGui::TableGetSortSpecs();
for (int i = 0; i < table_sort_specs->SpecsCount; ++i) {
const ImGuiTableColumnSortSpecs *column_sort_spec = &table_sort_specs->Specs[i];
const ImGuiTableColumnSortSpecs *column_sort_spec = std::addressof(table_sort_specs->Specs[i]);
descending = (column_sort_spec->SortDirection == ImGuiSortDirection_Descending);
// Make sure ".." stays at the top regardless of sort direction
@ -96,7 +96,7 @@ namespace Tabs {
void FileBrowser(WindowData &data) {
if (ImGui::BeginTabItem("File Browser")) {
// Display current working directory
ImGui::TextColored(ImVec4(1.00f, 1.00f, 1.00f, 1.00f), cfg.cwd);
ImGui::TextColored(ImVec4(1.00f, 1.00f, 1.00f, 1.00f), cwd);
// Draw storage bar
ImGui::ProgressBar(static_cast<float>(data.used_storage) / static_cast<float>(data.total_storage), ImVec2(1265.0f, 6.0f), "");
@ -130,7 +130,7 @@ namespace Tabs {
ImGui::TableNextColumn();
ImGui::PushID(i);
if ((data.checkbox_data.checked.at(i)) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) == 0))
if ((data.checkbox_data.checked.at(i)) && (strcasecmp(data.checkbox_data.cwd, cwd) == 0))
ImGui::Image(reinterpret_cast<ImTextureID>(check_icon.id), tex_size);
else
ImGui::Image(reinterpret_cast<ImTextureID>(uncheck_icon.id), tex_size);
@ -157,12 +157,15 @@ namespace Tabs {
data.checkbox_data.checked.resize(data.entries.size());
}
}
else if (R_SUCCEEDED(FS::ChangeDirNext(data.entries[i].name, data.entries))) {
else if ((FS::ChangeDirNext(data.entries[i].name, data.entries)) >= 0) {
if ((data.checkbox_data.count > 1) && (data.checkbox_data.checked_copy.empty()))
data.checkbox_data.checked_copy = data.checkbox_data.checked;
data.checkbox_data.checked.resize(data.entries.size());
}
else {
std::printf("ChangeDirNext failed?\n");
}
// Reset navigation ID -- TODO: Scroll to top
ImGuiContext& g = *GImGui;
@ -177,7 +180,7 @@ namespace Tabs {
switch (file_type) {
case FileTypeImage:
if ((std::snprintf(path, FS_MAX_PATH, "%s/%s", cfg.cwd, data.entries[i].name)) > 0) {
if ((std::snprintf(path, FS_MAX_PATH, "%s/%s", cwd, data.entries[i].name)) > 0) {
Textures::LoadImageFile(path, data.textures);
data.state = WINDOW_STATE_IMAGEVIEWER;
}

View File

@ -55,7 +55,7 @@ namespace Tabs {
if (ImGui::TreeNode(strings[cfg.lang][Lang::SettingsImageViewTitle])) {
ImGui::Dummy(ImVec2(0.0f, 5.0f)); // Spacing
if (ImGui::Checkbox(strings[cfg.lang][Lang::SettingsImageViewFilenameToggle], &cfg.image_filename))
if (ImGui::Checkbox(strings[cfg.lang][Lang::SettingsImageViewFilenameToggle], std::addressof(cfg.image_filename)))
Config::Save(cfg);
ImGui::TreePop();
@ -66,7 +66,7 @@ namespace Tabs {
if (ImGui::TreeNode(strings[cfg.lang][Lang::SettingsDevOptsTitle])) {
ImGui::Dummy(ImVec2(0.0f, 5.0f)); // Spacing
if (ImGui::Checkbox(strings[cfg.lang][Lang::SettingsDevOptsLogsToggle], &cfg.dev_options))
if (ImGui::Checkbox(strings[cfg.lang][Lang::SettingsDevOptsLogsToggle], std::addressof(cfg.dev_options)))
Config::Save(cfg);
ImGui::TreePop();

View File

@ -83,38 +83,38 @@ namespace Textures {
Result ret = 0;
FsFile file;
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Read, &file))) {
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Read, std::addressof(file)))) {
Log::Error("fsFsOpenFile(%s) failed: 0x%x\n", path, ret);
return ret;
}
if (R_FAILED(ret = fsFileGetSize(&file, &size))) {
if (R_FAILED(ret = fsFileGetSize(std::addressof(file), std::addressof(size)))) {
Log::Error("fsFileGetSize(%s) failed: 0x%x\n", path, ret);
fsFileClose(&file);
fsFileClose(std::addressof(file));
return ret;
}
*buffer = new unsigned char[size];
u64 bytes_read = 0;
if (R_FAILED(ret = fsFileRead(&file, 0, *buffer, static_cast<u64>(size), FsReadOption_None, &bytes_read))) {
if (R_FAILED(ret = fsFileRead(std::addressof(file), 0, *buffer, static_cast<u64>(size), FsReadOption_None, std::addressof(bytes_read)))) {
Log::Error("fsFileRead(%s) failed: 0x%x\n", path, ret);
fsFileClose(&file);
fsFileClose(std::addressof(file));
return ret;
}
if (bytes_read != static_cast<u64>(size)) {
Log::Error("bytes_read(%llu) does not match file size(%llu)\n", bytes_read, size);
fsFileClose(&file);
fsFileClose(std::addressof(file));
return -1;
}
fsFileClose(&file);
fsFileClose(std::addressof(file));
return 0;
}
static bool Create(unsigned char *data, GLint format, Tex &texture) {
glGenTextures(1, &texture.id);
glGenTextures(1, std::addressof(texture.id));
glBindTexture(GL_TEXTURE_2D, texture.id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -133,24 +133,24 @@ namespace Textures {
static bool LoadImageRomfs(const std::string &path, Tex &texture) {
bool ret = false;
png_image image;
std::memset(&image, 0, (sizeof image));
std::memset(std::addressof(image), 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
if (png_image_begin_read_from_file(&image, path.c_str()) != 0) {
if (png_image_begin_read_from_file(std::addressof(image), path.c_str()) != 0) {
png_bytep buffer;
image.format = PNG_FORMAT_RGBA;
buffer = new png_byte[PNG_IMAGE_SIZE(image)];
if (buffer != nullptr && png_image_finish_read(&image, nullptr, buffer, 0, nullptr) != 0) {
if (buffer != nullptr && png_image_finish_read(std::addressof(image), nullptr, buffer, 0, nullptr) != 0) {
texture.width = image.width;
texture.height = image.height;
ret = Textures::Create(buffer, GL_RGBA, texture);
delete[] buffer;
png_image_free(&image);
png_image_free(std::addressof(image));
}
else {
if (buffer == nullptr)
png_image_free(&image);
png_image_free(std::addressof(image));
else
delete[] buffer;
}
@ -169,24 +169,24 @@ namespace Textures {
bmp_result code = BMP_OK;
bmp_image bmp;
bmp_create(&bmp, &bitmap_callbacks);
bmp_create(std::addressof(bmp), std::addressof(bitmap_callbacks));
code = bmp_analyse(&bmp, size, *data);
code = bmp_analyse(std::addressof(bmp), size, *data);
if (code != BMP_OK) {
bmp_finalise(&bmp);
bmp_finalise(std::addressof(bmp));
return false;
}
code = bmp_decode(&bmp);
code = bmp_decode(std::addressof(bmp));
if (code != BMP_OK) {
if ((code != BMP_INSUFFICIENT_DATA) && (code != BMP_DATA_ERROR)) {
bmp_finalise(&bmp);
bmp_finalise(std::addressof(bmp));
return false;
}
/* skip if the decoded image would be ridiculously large */
if ((bmp.width * bmp.height) > 200000) {
bmp_finalise(&bmp);
bmp_finalise(std::addressof(bmp));
return false;
}
}
@ -194,14 +194,14 @@ namespace Textures {
texture.width = bmp.width;
texture.height = bmp.height;
bool ret = Textures::Create(static_cast<unsigned char *>(bmp.bitmap), GL_RGBA, texture);
bmp_finalise(&bmp);
bmp_finalise(std::addressof(bmp));
return ret;
}
static bool LoadImageGIF(const std::string &path, std::vector<Tex> &textures) {
bool ret = false;
int error = 0;
GifFileType *gif = DGifOpenFileName(path.c_str(), &error);
GifFileType *gif = DGifOpenFileName(path.c_str(), std::addressof(error));
if (!gif) {
Log::Error("DGifOpenFileName failed: %d\n", error);
@ -287,7 +287,7 @@ namespace Textures {
ret = Textures::Create(reinterpret_cast<unsigned char*>(pixels.get()), GL_RGBA, textures[i]);
}
if (DGifCloseFile(gif, &error) != GIF_OK) {
if (DGifCloseFile(gif, std::addressof(error)) != GIF_OK) {
Log::Error("DGifCloseFile failed: %d\n", error);
return false;
}
@ -298,7 +298,7 @@ namespace Textures {
static bool LoadImageJPEG(unsigned char **data, s64 &size, Tex &texture) {
tjhandle jpeg = tjInitDecompress();
int jpegsubsamp = 0;
tjDecompressHeader2(jpeg, *data, size, &texture.width, &texture.height, &jpegsubsamp);
tjDecompressHeader2(jpeg, *data, size, std::addressof(texture.width), std::addressof(texture.height), std::addressof(jpegsubsamp));
unsigned char *buffer = new unsigned char[texture.width * texture.height * 3];
tjDecompress2(jpeg, *data, size, buffer, texture.width, 0, texture.height, TJPF_RGB, TJFLAG_FASTDCT);
bool ret = Textures::Create(buffer, GL_RGB, texture);
@ -308,7 +308,7 @@ namespace Textures {
}
static bool LoadImageOther(unsigned char **data, s64 &size, Tex &texture) {
unsigned char *image = stbi_load_from_memory(*data, size, &texture.width, &texture.height, nullptr, STBI_rgb_alpha);
unsigned char *image = stbi_load_from_memory(*data, size, std::addressof(texture.width), std::addressof(texture.height), nullptr, STBI_rgb_alpha);
bool ret = Textures::Create(image, GL_RGBA, texture);
return ret;
}
@ -316,24 +316,24 @@ namespace Textures {
static bool LoadImagePNG(unsigned char **data, s64 &size, Tex &texture) {
bool ret = false;
png_image image;
std::memset(&image, 0, (sizeof image));
std::memset(std::addressof(image), 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
if (png_image_begin_read_from_memory(&image, *data, size) != 0) {
if (png_image_begin_read_from_memory(std::addressof(image), *data, size) != 0) {
png_bytep buffer;
image.format = PNG_FORMAT_RGBA;
buffer = new png_byte[PNG_IMAGE_SIZE(image)];
if (buffer != nullptr && png_image_finish_read(&image, nullptr, buffer, 0, nullptr) != 0) {
if (buffer != nullptr && png_image_finish_read(std::addressof(image), nullptr, buffer, 0, nullptr) != 0) {
texture.width = image.width;
texture.height = image.height;
ret = Textures::Create(buffer, GL_RGBA, texture);
delete[] buffer;
png_image_free(&image);
png_image_free(std::addressof(image));
}
else {
if (buffer == nullptr)
png_image_free(&image);
png_image_free(std::addressof(image));
else
delete[] buffer;
}
@ -343,7 +343,7 @@ namespace Textures {
}
static bool LoadImageWEBP(unsigned char **data, s64 &size, Tex &texture) {
*data = WebPDecodeRGBA(*data, size, &texture.width, &texture.height);
*data = WebPDecodeRGBA(*data, size, std::addressof(texture.width), std::addressof(texture.height));
bool ret = Textures::Create(*data, GL_RGBA, texture);
return ret;
}
@ -379,30 +379,30 @@ namespace Textures {
unsigned char *data = nullptr;
s64 size = 0;
if (R_FAILED(Textures::ReadFile(path, &data, size))) {
if (R_FAILED(Textures::ReadFile(path, std::addressof(data), size))) {
delete[] data;
return ret;
}
switch(type) {
case ImageTypeBMP:
ret = Textures::LoadImageBMP(&data, size, textures[0]);
ret = Textures::LoadImageBMP(std::addressof(data), size, textures[0]);
break;
case ImageTypeJPEG:
ret = Textures::LoadImageJPEG(&data, size, textures[0]);
ret = Textures::LoadImageJPEG(std::addressof(data), size, textures[0]);
break;
case ImageTypePNG:
ret = Textures::LoadImagePNG(&data, size, textures[0]);
ret = Textures::LoadImagePNG(std::addressof(data), size, textures[0]);
break;
case ImageTypeWEBP:
ret = Textures::LoadImageWEBP(&data, size, textures[0]);
ret = Textures::LoadImageWEBP(std::addressof(data), size, textures[0]);
break;
default:
ret = Textures::LoadImageOther(&data, size, textures[0]);
ret = Textures::LoadImageOther(std::addressof(data), size, textures[0]);
break;
}
@ -439,7 +439,7 @@ namespace Textures {
}
void Free(Tex &texture) {
glDeleteTextures(1, &texture.id);
glDeleteTextures(1, std::addressof(texture.id));
}
void Exit(void) {

View File

@ -7,6 +7,8 @@
#include "tabs.hpp"
#include "windows.hpp"
WindowData data;
namespace Windows {
static bool image_properties = false;
@ -70,11 +72,11 @@ namespace Windows {
data.state = WINDOW_STATE_OPTIONS;
if (key & HidNpadButton_Y) {
if ((std::strlen(data.checkbox_data.cwd) != 0) && (strcasecmp(data.checkbox_data.cwd, cfg.cwd) != 0))
if ((std::strlen(data.checkbox_data.cwd) != 0) && (strcasecmp(data.checkbox_data.cwd, cwd) != 0))
Windows::ResetCheckbox(data);
if ((std::strncmp(data.entries[data.selected].name, "..", 2)) != 0) {
std::strcpy(data.checkbox_data.cwd, cfg.cwd);
std::strcpy(data.checkbox_data.cwd, cwd);
data.checkbox_data.checked.at(data.selected) = !data.checkbox_data.checked.at(data.selected);
data.checkbox_data.count = std::count(data.checkbox_data.checked.begin(), data.checkbox_data.checked.end(), true);
}