Dump files in proper dir tree, add fs_common
This commit is contained in:
parent
f6349215ac
commit
f71096aefe
49
source/fs_common.cpp
Normal file
49
source/fs_common.cpp
Normal file
@ -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 <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <cstdio>
|
||||
|
||||
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;
|
||||
}
|
10
source/fs_common.h
Normal file
10
source/fs_common.h
Normal file
@ -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 <string>
|
||||
|
||||
void SanitizeSeparators(std::string* path);
|
||||
bool CreateFullPath(const std::string& path);
|
@ -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...
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user