Skip to content

Commit

Permalink
ini config support
Browse files Browse the repository at this point in the history
  • Loading branch information
HookedBehemoth committed Mar 9, 2021
1 parent 7fefe94 commit aeb6acd
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile.applet
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
APP_TITLE := Studious Pancake
APP_VERSION := 0.1.0
APP_VERSION := 0.2.0

TARGET := applet/$(notdir $(CURDIR))
BUILD := build.nro
Expand Down
2 changes: 1 addition & 1 deletion Makefile.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
APP_TITLE := Studious Pancake
APP_VERSION := 0.1.0
APP_VERSION := 0.2.0

TARGET := overlay/$(notdir $(CURDIR))
BUILD := build.ovl
Expand Down
36 changes: 26 additions & 10 deletions applet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ namespace {
bool selectable;
};

void ConfigCallback(void *user) {
void BootConfigCallback(void *user) {
auto config = reinterpret_cast<Hekate::BootConfig *>(user);

Hekate::RebootToConfig(*config);
Hekate::RebootToConfig(*config, false);
}

void IniConfigCallback(void *user) {
auto config = reinterpret_cast<Hekate::BootConfig *>(user);

Hekate::RebootToConfig(*config, true);
}

void UmsCallback(void *user) {
Expand All @@ -57,18 +63,28 @@ extern "C" void userAppExit(void) {
int main(int argc, char **argv) {
std::vector<TuiItem> items;

/* Load available boot configs */
auto boot_config_list = Hekate::LoadBootConfigList();

/* Load available ini configs */
auto ini_config_list = Hekate::LoadIniConfigList();

/* Build menu item list */
if (util::IsErista()) {
/* Load available boot configs */
auto config_list = Hekate::LoadBootConfigList();

/* TODO: Load available ini configs */
items.reserve(3 + boot_config_list.empty() ? 0 : 1 + boot_config_list.size()
+ ini_config_list.empty() ? 0 : 1 + ini_config_list.size());

items.reserve(config_list.size() + 4);
if (!boot_config_list.empty()) {
items.emplace_back("Boot Configs", nullptr, nullptr, false);
for (auto &entry : boot_config_list)
items.emplace_back(entry.name, BootConfigCallback, &entry, true);
}

items.emplace_back("Configs", nullptr, nullptr, false);
for (auto &entry : config_list)
items.emplace_back(entry.name, ConfigCallback, &entry, true);
if (!ini_config_list.empty()) {
items.emplace_back("Ini Configs", nullptr, nullptr, false);
for (auto &entry : ini_config_list)
items.emplace_back(entry.name, IniConfigCallback, &entry, true);
}

items.emplace_back("Miscellaneous", nullptr, nullptr, false);
items.emplace_back("Reboot to UMS", UmsCallback, nullptr, true);
Expand Down
54 changes: 52 additions & 2 deletions common/hekate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <span>

namespace Hekate {

Expand Down Expand Up @@ -92,6 +94,54 @@ namespace Hekate {
return configs;
}

BootConfigList LoadIniConfigList() {
BootConfigList configs;

if (chdir("sdmc:/bootloader/ini") != 0)
return configs;

/* Open ini folder */
auto dirp = opendir(".");
if (dirp == nullptr)
return configs;

u32 count=0;
char dir_entries[8][0x100];

/* Get entries */
while (auto dent = readdir(dirp)) {
if (dent->d_type != DT_REG)
continue;

std::strcpy(dir_entries[count++], dent->d_name);

if (count == std::size(dir_entries))
break;
}

/* Reorder ini files by ASCII ordering. */
char temp[0x100];
for (size_t i = 0; i < count - 1 ; i++) {
for (size_t j = i + 1; j < count; j++) {
if (std::strcmp(dir_entries[i], dir_entries[j]) > 0) {
std::strcpy(temp, dir_entries[i]);
std::strcpy(dir_entries[i], dir_entries[j]);
std::strcpy(dir_entries[j], temp);
}
}
}

/* parse config */
for (auto &entry : std::span(dir_entries, count))
ini_parse(entry, BootConfigHandler, &configs);

closedir(dirp);

chdir("sdmc:/");

return configs;
}

bool RebootDefault() {
/* Load payload. */
if (!LoadPayload())
Expand All @@ -109,7 +159,7 @@ namespace Hekate {
return true;
}

bool RebootToConfig(BootConfig const &config) {
bool RebootToConfig(BootConfig const &config, bool autoboot_list) {
/* Load payload. */
if (!LoadPayload())
return false;
Expand All @@ -123,7 +173,7 @@ namespace Hekate {
/* Force autoboot and set boot id. */
storage->boot_cfg = BootCfg_ForceAutoBoot;
storage->autoboot = config.index;
storage->autoboot_list = false;
storage->autoboot_list = autoboot_list;

/* Reboot */
reboot_to_payload();
Expand Down
3 changes: 2 additions & 1 deletion common/hekate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ namespace Hekate {
using BootConfigList = std::list<BootConfig>;

BootConfigList LoadBootConfigList();
BootConfigList LoadIniConfigList();
bool RebootDefault();
bool RebootToConfig(BootConfig const &config);
bool RebootToConfig(BootConfig const &config, bool autoboot_list);
bool RebootToUMS(UmsTarget const target);

}
29 changes: 22 additions & 7 deletions overlay/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ namespace {

class PancakeGui : public tsl::Gui {
private:
Hekate::BootConfigList const config_list;
Hekate::BootConfigList const boot_config_list;
Hekate::BootConfigList const ini_config_list;

public:
PancakeGui()
: config_list(Hekate::LoadBootConfigList()) {
: boot_config_list(Hekate::LoadBootConfigList()),
ini_config_list(Hekate::LoadIniConfigList()) {
}

virtual tsl::elm::Element *createUI() override {
Expand All @@ -41,12 +43,25 @@ class PancakeGui : public tsl::Gui {
auto list = new tsl::elm::List();

/* Append boot config entries. */
list->addItem(new tsl::elm::CategoryHeader("Boot configs"));
if (!boot_config_list.empty()) {
list->addItem(new tsl::elm::CategoryHeader("Boot configs"));

for (auto &config : boot_config_list) {
auto entry = new tsl::elm::ListItem(config.name);
entry->setClickListener([&](u64 keys) -> bool { return (keys & HidNpadButton_A) && Hekate::RebootToConfig(config, false); });
list->addItem(entry);
}
}

/* Append ini config entries. */
if (!ini_config_list.empty()) {
list->addItem(new tsl::elm::CategoryHeader("Ini configs"));

for (auto &config : config_list) {
auto entry = new tsl::elm::ListItem(config.name);
entry->setClickListener([&](u64 keys) -> bool { return (keys & HidNpadButton_A) && Hekate::RebootToConfig(config); });
list->addItem(entry);
for (auto &config : ini_config_list) {
auto entry = new tsl::elm::ListItem(config.name);
entry->setClickListener([&](u64 keys) -> bool { return (keys & HidNpadButton_A) && Hekate::RebootToConfig(config, true); });
list->addItem(entry);
}
}

/* Miscellaneous. */
Expand Down

0 comments on commit aeb6acd

Please sign in to comment.