From f71096aefea8fdc265e41c2dc4e31140245a7800 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 14 Jun 2015 17:07:08 -0700 Subject: [PATCH] Dump files in proper dir tree, add fs_common --- source/fs_common.cpp | 49 ++++++++++++++++++++ source/fs_common.h | 10 ++++ source/utils/savedatacheck/savedatacheck.cpp | 15 ++++-- source/utils/shared_font/shared_font.cpp | 14 ++++-- 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 source/fs_common.cpp create mode 100644 source/fs_common.h diff --git a/source/fs_common.cpp b/source/fs_common.cpp new file mode 100644 index 0000000..27ca581 --- /dev/null +++ b/source/fs_common.cpp @@ -0,0 +1,49 @@ +// Copyright 2013 Dolphin Emulator Project / 2014-2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "fs_common.h" + +#include +#include +#include + +void SanitizeSeparators(std::string* path) +{ + size_t position = 0; + while ((position = path->find("//", 0)) != path->npos) { + path->erase(position, 1); + } +} + +bool CreateFullPath(const std::string& path) +{ + struct stat st; + if (stat(path.c_str(), &st) == 0) { + if (S_ISDIR(st.st_mode) == 0) { + // Not a directory + return false; + } + // Dir already exists + return true; + } + + for (size_t position = 0; ; position++) { + // Find next sub path + position = path.find('/', position); + if (position == path.npos) + return true; + + // Include the '/' so the first call is CreateDir("/") rather than CreateDir("") + std::string const subPath(path.substr(0, position + 1)); + + if (stat(subPath.c_str(), &st) != 0) { + if (mkdir(subPath.c_str(), 0755) != 0 && errno != EEXIST) + return false; + } else if (!S_ISDIR(st.st_mode)) { + return false; + } + } + + return true; +} diff --git a/source/fs_common.h b/source/fs_common.h new file mode 100644 index 0000000..20b76fd --- /dev/null +++ b/source/fs_common.h @@ -0,0 +1,10 @@ +// Copyright 2013 Dolphin Emulator Project / 2014-2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +void SanitizeSeparators(std::string* path); +bool CreateFullPath(const std::string& path); diff --git a/source/utils/savedatacheck/savedatacheck.cpp b/source/utils/savedatacheck/savedatacheck.cpp index 636e62e..dcc92ce 100644 --- a/source/utils/savedatacheck/savedatacheck.cpp +++ b/source/utils/savedatacheck/savedatacheck.cpp @@ -8,20 +8,29 @@ #include <3ds.h> +#include "fs_common.h" #include "utils/shared_font/shared_font.h" +#define TITLE_PATH "/3dsutils/nand/00000000000000000000000000000000/title/" + namespace SaveDataCheck { -std::string BuildSharedRomFSFilename(u32* lowpath) { +std::string BuildSharedRomFSDirname(u32* lowpath) { char* filename_buffer; - asprintf(&filename_buffer, "/%08lx%08lx.bin", lowpath[1], lowpath[0]); + asprintf(&filename_buffer, "%s/%08lx/%08lx/content/", TITLE_PATH, lowpath[1], lowpath[0]); std::string filename(filename_buffer); free(filename_buffer); return filename; } void DumpSharedRomFS(u32* archive_binary_lowpath) { - std::string output_file = BuildSharedRomFSFilename(archive_binary_lowpath); + std::string output_dir = BuildSharedRomFSDirname(archive_binary_lowpath); + SanitizeSeparators(&output_dir); + if (!CreateFullPath(output_dir)) { + printf("Creating path (%s) failed! Aborting!\n", output_dir.c_str()); + return; + } + std::string output_file = output_dir + "00000000.app.romfs"; // Read RomFS bin from SaveDataCheck... diff --git a/source/utils/shared_font/shared_font.cpp b/source/utils/shared_font/shared_font.cpp index 0780f82..881c731 100644 --- a/source/utils/shared_font/shared_font.cpp +++ b/source/utils/shared_font/shared_font.cpp @@ -6,16 +6,24 @@ #include <3ds.h> +#include "fs_common.h" #include "utils/shared_font/shared_font.h" +#define SYSDATA_PATH "/3dsutils/sysdata/" + namespace SharedFont { static const u32 SHARED_FONT_SIZE = 0x300000; void Dump() { - static const char* path = "/shared_font.bin"; + if (!CreateFullPath(SYSDATA_PATH)) { + printf("Creating path (%s) failed! Aborting!\n", SYSDATA_PATH); + return; + } + std::string path = SYSDATA_PATH "/shared_font.bin"; + SanitizeSeparators(&path); - printf("Dumping shared system font (%s)... ", path); + printf("Dumping shared system font (%s)... ", path.c_str()); // Connect to APT service... @@ -41,7 +49,7 @@ void Dump() { // Dump shared font to SDMC... - FILE* out_file = fopen(path, "wb"); + FILE* out_file = fopen(path.c_str(), "wb"); size_t bytes_written = fwrite(shared_font_addr, 1, SHARED_FONT_SIZE, out_file); fclose(out_file);