Compare commits
7 Commits
e613a525a5
...
fc697af002
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc697af002 | ||
| 0a23b20f6e | |||
| a8cc3ebfc3 | |||
| b1454bf2a1 | |||
| 1a2efdc129 | |||
| 11113bbc07 | |||
| 7182fd9078 |
@@ -28,6 +28,7 @@
|
||||
#define COLORS_H
|
||||
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
typedef u32 Color;
|
||||
|
||||
|
||||
45
include/config.h
Normal file
45
include/config.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2024 Contributors in CONTRIBUTORS.md
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include "common.h"
|
||||
#include "fs.h"
|
||||
#include <jansson.h>
|
||||
|
||||
typedef struct {
|
||||
u32 background_color;
|
||||
u32 accent_color;
|
||||
u32 red_color;
|
||||
u32 yellow_color;
|
||||
} Config_s;
|
||||
|
||||
extern Config_s config;
|
||||
|
||||
void load_config(void);
|
||||
|
||||
#endif
|
||||
@@ -29,8 +29,9 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "badges.h"
|
||||
#include "config.h"
|
||||
|
||||
#define ILLEGAL_CHARS "><\"?;:/\\+,.|[=]*"
|
||||
#define ILLEGAL_CHARS "><\"?;:/\\+,.|[=]*\n\r"
|
||||
|
||||
extern FS_Archive ArchiveSD;
|
||||
extern FS_Archive ArchiveHomeExt;
|
||||
@@ -54,6 +55,7 @@ typedef struct {
|
||||
u32 coppa : 1;
|
||||
} Parental_Restrictions_s;
|
||||
|
||||
Result init_sd(void);
|
||||
Result open_archives(void);
|
||||
Result open_badge_extdata(void);
|
||||
Result close_archives(void);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void replace_chars(u16 *input, char *remove, u16 with);
|
||||
size_t strulen(const u16 *, ssize_t);
|
||||
void struacat(u16 * input, const char * addition);
|
||||
void printu(u16 * input);
|
||||
|
||||
@@ -115,7 +115,7 @@ u64 getShortcut(char *filename)
|
||||
if (sscanf(p1, "%08x", &lowpath) != 1) return shortcut;
|
||||
|
||||
shortcut = 0x0004001000000000 + lowpath;
|
||||
DEBUG("Shortcut %08lx found for %s\n", shortcut, filename);
|
||||
DEBUG("Shortcut %16llx found for %s\n", shortcut, filename);
|
||||
return shortcut;
|
||||
}
|
||||
|
||||
@@ -353,6 +353,7 @@ SetNode * extract_sets(char *badgeMngBuffer, Handle backupDataHandle)
|
||||
DEBUG("Processing icon for set %lu at index %lu\n", cursor->set_id, cursor->set_index);
|
||||
u16 utf16SetName[0x46] = {0};
|
||||
FSFILE_Read(backupDataHandle, NULL, cursor->set_index * 16 * 0x8A, utf16SetName, 0x8A);
|
||||
replace_chars(utf16SetName, ILLEGAL_CHARS, u'-');
|
||||
u16 set_path[256] = {0};
|
||||
struacat(set_path, "/3ds/" APP_TITLE "/BadgeBackups/");
|
||||
size_t set_name_len = strucat(set_path, utf16SetName);
|
||||
@@ -431,6 +432,7 @@ Result extract_badges(void)
|
||||
|
||||
u16 utf16Name[0x46] = {0};
|
||||
FSFILE_Read(backupDataHandle, NULL, 0x35E80 + i * 16 * 0x8A, utf16Name, 0x8A);
|
||||
replace_chars(utf16Name, ILLEGAL_CHARS, u'-');
|
||||
char utf8Name[256] = {0};
|
||||
res = utf16_to_utf8((u8 *) utf8Name, utf16Name, 256);
|
||||
|
||||
@@ -444,6 +446,7 @@ Result extract_badges(void)
|
||||
{
|
||||
u16 utf16SetName[0x46] = {0};
|
||||
FSFILE_Read(backupDataHandle, NULL, set_index * 16 * 0x8A, utf16SetName, 0x8A);
|
||||
replace_chars(utf16SetName, ILLEGAL_CHARS, u'-');
|
||||
char utf8SetName[128] = {0};
|
||||
res = utf16_to_utf8((u8 *) utf8SetName, utf16SetName, 128);
|
||||
if (!res)
|
||||
@@ -477,12 +480,89 @@ Result extract_badges(void)
|
||||
return res;
|
||||
}
|
||||
|
||||
Result backup_badges_fast(void)
|
||||
{
|
||||
char *badgeMng = NULL;
|
||||
|
||||
DEBUG("writing badge data: making files...\n");
|
||||
char mng_path[128] = "/3ds/" APP_TITLE "/BadgeMngFile.dat";
|
||||
char data_path[128] = "/3ds/" APP_TITLE "/BadgeData.dat";
|
||||
DEBUG("mng_path: %s, data_path: %s\n", mng_path, data_path);
|
||||
|
||||
Handle dataHandle = 0;
|
||||
Handle sdHandle = 0;
|
||||
|
||||
DEBUG("loading existing badge mng file...\n");
|
||||
u32 mngRead = file_to_buf(fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), ArchiveBadgeExt, &badgeMng);
|
||||
DEBUG("loading existing badge data file\n");
|
||||
Result res = FSUSER_OpenFile(&dataHandle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), FS_OPEN_READ, 0);
|
||||
if (mngRead != BADGE_MNG_SIZE || R_FAILED(res))
|
||||
{
|
||||
char err_string[128] = {0};
|
||||
sprintf(err_string, language.badges.extdata_locked, res);
|
||||
throw_error(err_string, ERROR_LEVEL_WARNING);
|
||||
if (badgeMng) free(badgeMng);
|
||||
if (dataHandle) FSFILE_Close(dataHandle);
|
||||
FSFILE_Close(sdHandle);
|
||||
return -1;
|
||||
}
|
||||
remake_file(fsMakePath(PATH_ASCII, mng_path), ArchiveSD, BADGE_MNG_SIZE);
|
||||
|
||||
FSUSER_CreateFile(ArchiveSD, fsMakePath(PATH_ASCII, data_path), 0, BADGE_DATA_SIZE);
|
||||
FSUSER_OpenFile(&sdHandle, ArchiveSD, fsMakePath(PATH_ASCII, data_path), FS_OPEN_WRITE, 0);
|
||||
|
||||
DEBUG("writing badge data: writing BadgeMngFile...\n");
|
||||
res = buf_to_file(mngRead, fsMakePath(PATH_ASCII, mng_path), ArchiveSD, badgeMng);
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
DEBUG("Failed to write badgemngfile: 0x%08lx\n", res);
|
||||
free(badgeMng);
|
||||
FSFILE_Close(dataHandle);
|
||||
FSFILE_Close(sdHandle);
|
||||
return -1;
|
||||
}
|
||||
DEBUG("writing badge data: writing badgedata...\n");
|
||||
char *buf = malloc(0x10000);
|
||||
u64 size = BADGE_DATA_SIZE;
|
||||
u64 cur = 0;
|
||||
while (size > 0)
|
||||
{
|
||||
u32 read = 0;
|
||||
res = FSFILE_Read(dataHandle, &read, cur, buf, min(0x10000, size));
|
||||
res = FSFILE_Write(sdHandle, NULL, cur, buf, read, FS_WRITE_FLUSH);
|
||||
size -= read;
|
||||
cur += read;
|
||||
}
|
||||
|
||||
free(badgeMng);
|
||||
free(buf);
|
||||
FSFILE_Close(dataHandle);
|
||||
FSFILE_Close(sdHandle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result install_badges(void)
|
||||
{
|
||||
Handle handle = 0;
|
||||
Handle folder = 0;
|
||||
Result res = 0;
|
||||
draw_loading_bar(0, 1, INSTALL_BADGES);
|
||||
{
|
||||
char testpath[128] = "/3ds/" APP_TITLE "/BadgeData.dat";
|
||||
if (R_FAILED(res = FSUSER_OpenFile(&handle, ArchiveSD, fsMakePath(PATH_ASCII, testpath), FS_OPEN_READ, 0)))
|
||||
{
|
||||
if (R_SUMMARY(res) == RS_NOTFOUND)
|
||||
{
|
||||
res = backup_badges_fast();
|
||||
if (R_FAILED(res)) return res;
|
||||
} else
|
||||
{
|
||||
DEBUG("????: 0x%08lx\n", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handle) FSFILE_Close(handle);
|
||||
|
||||
DEBUG("Initializing ACT\n");
|
||||
res = actInit();
|
||||
|
||||
@@ -30,11 +30,11 @@ Color colors[COLOR_AMOUNT] = {0};
|
||||
|
||||
void init_colors(void)
|
||||
{
|
||||
colors[COLOR_BACKGROUND] = C2D_Color32(35, 28, 32, 255); //silver-y black
|
||||
colors[COLOR_ACCENT] = C2D_Color32(12, 58, 111, 255);
|
||||
colors[COLOR_BACKGROUND] = config.background_color;
|
||||
colors[COLOR_ACCENT] = config.accent_color;
|
||||
colors[COLOR_WHITE] = C2D_Color32(255, 255, 255, 255);
|
||||
colors[COLOR_CURSOR] = C2D_Color32(200, 200, 200, 255);
|
||||
colors[COLOR_BLACK] = C2D_Color32(0, 0, 0, 255);
|
||||
colors[COLOR_RED] = C2D_Color32(229, 66, 66, 255);
|
||||
colors[COLOR_YELLOW] = C2D_Color32(239, 220, 11, 255);
|
||||
colors[COLOR_RED] = config.red_color;
|
||||
colors[COLOR_YELLOW] = config.yellow_color;
|
||||
}
|
||||
117
source/config.c
Normal file
117
source/config.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2024 Contributors in CONTRIBUTORS.md
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
Config_s config;
|
||||
|
||||
void load_config(void)
|
||||
{
|
||||
memset(&config, 0, sizeof(Config_s));
|
||||
char *json_buf = NULL;
|
||||
u32 json_len = file_to_buf(fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/config.json"), ArchiveSD, &json_buf);
|
||||
if (json_len)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root = json_loadb(json_buf, json_len, 0, &error);
|
||||
if (root)
|
||||
{
|
||||
const char *key;
|
||||
json_t *value;
|
||||
json_object_foreach(root, key, value)
|
||||
{
|
||||
if (json_is_array(value) && !strcmp(key, "Accent Color") && json_array_size(value) == 4)
|
||||
{
|
||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
||||
{
|
||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
||||
|
||||
config.accent_color = C2D_Color32(r, g, b, a);
|
||||
}
|
||||
}
|
||||
else if (json_is_array(value) && !strcmp(key, "Background Color") && json_array_size(value) == 4)
|
||||
{
|
||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
||||
{
|
||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
||||
|
||||
config.background_color = C2D_Color32(r, g, b, a);
|
||||
}
|
||||
}
|
||||
else if (json_is_array(value) && !strcmp(key, "Red Color") && json_array_size(value) == 4)
|
||||
{
|
||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
||||
{
|
||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
||||
|
||||
config.red_color = C2D_Color32(r, g, b, a);
|
||||
}
|
||||
}
|
||||
else if (json_is_array(value) && !strcmp(key, "Yellow Color") && json_array_size(value) == 4)
|
||||
{
|
||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
||||
{
|
||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
||||
|
||||
config.yellow_color = C2D_Color32(r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
DEBUG(error.text);
|
||||
}
|
||||
}
|
||||
if (config.accent_color == 0)
|
||||
config.accent_color = C2D_Color32(12, 58, 111, 255);
|
||||
|
||||
if (config.background_color == 0)
|
||||
config.background_color = C2D_Color32(35, 28, 32, 255); //silver-y black
|
||||
|
||||
if (config.red_color == 0)
|
||||
config.red_color = C2D_Color32(229, 66, 66, 255);
|
||||
|
||||
if (config.yellow_color == 0)
|
||||
config.yellow_color = C2D_Color32(239, 220, 11, 255);
|
||||
|
||||
if (json_buf) free(json_buf);
|
||||
}
|
||||
23
source/fs.c
23
source/fs.c
@@ -67,6 +67,20 @@ Result createExtSaveData(u32 extdataID)
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result init_sd(void)
|
||||
{
|
||||
Result res;
|
||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")))) return res;
|
||||
load_config();
|
||||
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/cache"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/BadgeBackups"), FS_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result open_archives(void)
|
||||
{
|
||||
romfsInit();
|
||||
@@ -103,16 +117,10 @@ Result open_archives(void)
|
||||
archive2 = 0x00;
|
||||
}
|
||||
|
||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")))) return res;
|
||||
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Themes"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Splashes"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Badges"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Badges/ThemePlaza Badges"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/cache"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/BadgeBackups"), FS_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
||||
home.type = PATH_BINARY;
|
||||
@@ -504,7 +512,8 @@ void remake_file(FS_Path path, FS_Archive archive, u32 size)
|
||||
FSFILE_Close(handle);
|
||||
FSUSER_DeleteFile(archive, path);
|
||||
}
|
||||
FSUSER_CreateFile(archive, path, 0, size);
|
||||
Result res = FSUSER_CreateFile(archive, path, 0, size);
|
||||
DEBUG("Remake file res: 0x%08lx\n", res);
|
||||
char * buf = calloc(size, 1);
|
||||
if (buf == NULL)
|
||||
{
|
||||
|
||||
@@ -88,6 +88,7 @@ static void init_services(void)
|
||||
APT_GetAppCpuTimeLimit(&old_time_limit);
|
||||
APT_SetAppCpuTimeLimit(30);
|
||||
httpcInit(0);
|
||||
init_sd();
|
||||
archive_result = open_archives();
|
||||
badge_archive_result = open_badge_extdata();
|
||||
if(envIsHomebrew())
|
||||
|
||||
@@ -26,6 +26,17 @@
|
||||
|
||||
#include "unicode.h"
|
||||
|
||||
void replace_chars(u16 *input, char *remove, u16 with)
|
||||
{
|
||||
for (u16 *cursor = input; *cursor != '\0'; cursor++)
|
||||
{
|
||||
if (strchr(remove, (char) (*cursor & 0xFF)))
|
||||
{
|
||||
*cursor = with;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t strulen(const u16 * input, ssize_t max_len)
|
||||
{
|
||||
for (int i = 0; i < max_len; i++) if (input[i] == 0) return i;
|
||||
|
||||
Reference in New Issue
Block a user