Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some config options #35

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ name: Build sys-tune and overlay
on: [push]
jobs:
build:

runs-on: ubuntu-latest
container: devkitpro/devkita64
container: devkitpro/devkita64:latest

steps:
- uses: actions/checkout@v1
- name: Checkout
uses: actions/checkout@master
with:
submodules: recursive

- name: Building libnx-Ext
- name: Build
run: |
make -j$(nproc) -C sys-tune/nxExt
make -j$(nproc)
mkdir -p dist/switch/.overlays
mkdir -p dist/atmosphere/contents/4200000000000000/flags
touch dist/atmosphere/contents/4200000000000000/flags/boot2.flag
cp sys-tune/sys-tune.nsp dist/atmosphere/contents/4200000000000000/exefs.nsp
cp sys-tune/toolbox.json dist/atmosphere/contents/4200000000000000/
cp overlay/sys-tune-overlay.ovl dist/switch/.overlays/

- name: Building sys-tune
run: |
API_VERSION=9 make -j$(nproc)
- uses: actions/upload-artifact@master
with:
name: sys-tune
path: dist
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*.nacp
*.npdm
*.ovl
.vscode
.vscode/settings.json
build
dist
*.zip
24 changes: 24 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations": [
{
"name": "switch",
"includePath": [
"${default}",
"${workspaceFolder}/**",
"${DEVKITPRO}/libnx/include/",
"${DEVKITPRO}/portlibs/switch/include/",
"${workspaceFolder}/sys-tune/nxExt/include/",
"${workspaceFolder}/sys-tune/source/",
"${workspaceFolder}/overlay/lib/include/",
"${workspaceFolder}/overlay/source/",
ITotalJustice marked this conversation as resolved.
Show resolved Hide resolved
"${workspaceFolder}/ipc/",
"${workspaceFolder}/common/"
],
"defines": ["__SWITCH__", "WANT_MP3", "WANT_FLAC", "WANT_WAV"],
"cStandard": "gnu17",
"cppStandard": "gnu++23",
"compilerPath": "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc"
}
],
"version": 4
}
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export GITHASH := $(shell git rev-parse --short HEAD)
export VERSION := 1.2.2
export VERSION := 2.0.0
export API_VERSION := 3
ITotalJustice marked this conversation as resolved.
Show resolved Hide resolved
export WANT_FLAC := 1
export WANT_MP3 := 1
Expand All @@ -12,7 +12,7 @@ clean:
$(MAKE) -C overlay clean
$(MAKE) -C sys-tune clean
rm -rf dist
rm sys-tune-*-*.zip
rm -f sys-tune-*-*.zip
ITotalJustice marked this conversation as resolved.
Show resolved Hide resolved

overlay:
$(MAKE) -C overlay
Expand All @@ -28,6 +28,7 @@ dist: all
mkdir -p dist/atmosphere/contents/4200000000000000
cp sys-tune/sys-tune.nsp dist/atmosphere/contents/4200000000000000/exefs.nsp
cp overlay/sys-tune-overlay.ovl dist/switch/.overlays/
cp sys-tune/toolbox.json dist/atmosphere/contents/4200000000000000/
cd dist; zip -r sys-tune-$(VERSION)-$(GITHASH).zip ./**/; cd ../;
hactool -t nso sys-tune/sys-tune.nso

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can manage playback via the Tesla overlay in the release.
## Special thanks to:
- [mackron](http://mackron.github.io/) who made the awesome [audio decoders used here.](https://github.com/mackron/dr_libs/)
- [WerWolv](https://werwolv.net/) for making libtesla, the UI library used for the control overlay.
- [TotalJustice](https://github.com/ITotalJustice) for bug fixes, adding some features and bad code.

## Info for developers
I implemented an IPC interface accessible via service wrappers [here](/ipc/).
Expand Down
114 changes: 114 additions & 0 deletions common/config/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "config.hpp"
#include "sdmc/sdmc.hpp"
#include "minIni/minIni.h"
#include <cstdio>

namespace config {

namespace {

const char CONFIG_PATH[]{"/config/sys-tune/config.ini"};
// blacklist uses it's own config file because eventually a database
// may be setup and users can easily update their blacklist by downloading
// an updated blacklist.ini.
// Also, the blacklist lookup needs to be as fast as possible
// (literally a race until the title opens audren), so a seperate, smaller file is ideal.
const char BLACKLIST_PATH[]{"/config/sys-tune/blacklist.ini"};

void create_config_dir() {
/* Creating directory on every set call looks sus, but the user may delete the dir */
/* whilst the sys-mod is running and then any changes made via the overlay */
/* is lost, which sucks. */
sdmc::CreateFolder("/config");
sdmc::CreateFolder("/config/sys-tune");
}

auto get_tid_str(u64 tid) -> const char* {
static char buf[21]{};
std::sprintf(buf, "%016lX", tid);
return buf;
}

} // namespace
ITotalJustice marked this conversation as resolved.
Show resolved Hide resolved

auto get_shuffle() -> bool {
return ini_getbool("config", "shuffle", false, CONFIG_PATH);
}

void set_shuffle(bool value) {
create_config_dir();
ini_putl("config", "shuffle", value, CONFIG_PATH);
}

auto get_repeat() -> int {
return ini_getl("config", "repeat", 1, CONFIG_PATH);
}

void set_repeat(int value) {
create_config_dir();
ini_putl("config", "repeat", value, CONFIG_PATH);
}

auto get_volume() -> float {
return ini_getf("config", "volume", 1.f, CONFIG_PATH);
}

void set_volume(float value) {
create_config_dir();
ini_putf("config", "volume", value, CONFIG_PATH);
}

auto has_title_enabled(u64 tid) -> bool {
return ini_haskey("title", get_tid_str(tid), CONFIG_PATH);
}

auto get_title_enabled(u64 tid) -> bool {
return ini_getbool("title", get_tid_str(tid), true, CONFIG_PATH);
}

void set_title_enabled(u64 tid, bool value) {
create_config_dir();
ini_putl("title", get_tid_str(tid), value, CONFIG_PATH);
}

auto get_title_enabled_default() -> bool {
return ini_getbool("title", "default", true, CONFIG_PATH);
}

void set_title_enabled_default(bool value) {
create_config_dir();
ini_putl("title", "default", value, CONFIG_PATH);
}

auto has_title_volume(u64 tid) -> bool {
return ini_haskey("volume", get_tid_str(tid), CONFIG_PATH);
}

auto get_title_volume(u64 tid) -> float {
return ini_getf("volume", get_tid_str(tid), 1.f, CONFIG_PATH);
}

void set_title_volume(u64 tid, float value) {
create_config_dir();
ini_putf("volume", get_tid_str(tid), value, CONFIG_PATH);
}

auto get_default_title_volume() -> float {
return ini_getf("config", "global_volume", 1.f, CONFIG_PATH);
}

void set_default_title_volume(float value) {
create_config_dir();
ini_putf("config", "global_volume", value, CONFIG_PATH);
}

auto get_title_blacklist(u64 tid) -> bool {
return ini_getbool("blacklist", get_tid_str(tid), false, BLACKLIST_PATH);
}

void set_title_blacklist(u64 tid, bool value) {
create_config_dir();
ini_putl("blacklist", get_tid_str(tid), value, BLACKLIST_PATH);
}

} // namespace config
41 changes: 41 additions & 0 deletions common/config/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <switch.h>

namespace config {

// tune shuffle
auto get_shuffle() -> bool;
void set_shuffle(bool value);

// tune repeat
auto get_repeat() -> int;
void set_repeat(int value);

// tune volume
auto get_volume() -> float;
void set_volume(float value);

// per title tune enable
auto has_title_enabled(u64 tid) -> bool;
auto get_title_enabled(u64 tid) -> bool;
void set_title_enabled(u64 tid, bool value);

// default for tune for every title
auto get_title_enabled_default() -> bool;
void set_title_enabled_default(bool value);

// per title volume
auto has_title_volume(u64 tid) -> bool;
auto get_title_volume(u64 tid) -> float;
void set_title_volume(u64 tid, float value);

// default volume for every title
auto get_default_title_volume() -> float;
void set_default_title_volume(float value);

// returns true if title causes a fatal on launch
auto get_title_blacklist(u64 tid) -> bool;
void set_title_blacklist(u64 tid, bool value);

} // namespace config
138 changes: 138 additions & 0 deletions common/minIni/minGlue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "minGlue.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

static bool ini_open(const char* filename, struct NxFile* nxfile, u32 mode) {
Result rc = {0};
char filename_buf[FS_MAX_PATH] = {0};

if (R_FAILED(rc = fsOpenSdCardFileSystem(&nxfile->system))) {
return false;
}

strcpy(filename_buf, filename);

if (R_FAILED(rc = fsFsOpenFile(&nxfile->system, filename_buf, mode, &nxfile->file))) {
if (mode & FsOpenMode_Write) {
if (R_FAILED(rc = fsFsCreateFile(&nxfile->system, filename_buf, 0, 0))) {
fsFsClose(&nxfile->system);
return false;
} else {
if (R_FAILED(rc = fsFsOpenFile(&nxfile->system, filename_buf, mode, &nxfile->file))) {
fsFsClose(&nxfile->system);
return false;
}
}
} else {
fsFsClose(&nxfile->system);
return false;
}
}

nxfile->offset = 0;
return true;
}

bool ini_openread(const char* filename, struct NxFile* nxfile) {
return ini_open(filename, nxfile, FsOpenMode_Read);
}

bool ini_openwrite(const char* filename, struct NxFile* nxfile) {
return ini_open(filename, nxfile, FsOpenMode_Write|FsOpenMode_Append);
}

bool ini_openrewrite(const char* filename, struct NxFile* nxfile) {
return ini_open(filename, nxfile, FsOpenMode_Read|FsOpenMode_Write|FsOpenMode_Append);
}

bool ini_close(struct NxFile* nxfile) {
fsFileClose(&nxfile->file);
fsFsClose(&nxfile->system);
return true;
}

bool ini_read(char* buffer, u64 size, struct NxFile* nxfile) {
u64 bytes_read = {0};
if (R_FAILED(fsFileRead(&nxfile->file, nxfile->offset, buffer, size, FsReadOption_None, &bytes_read))) {
return false;
}

if (!bytes_read) {
return false;
}

char *eol = {0};

if ((eol = strchr(buffer, '\n')) == NULL) {
eol = strchr(buffer, '\r');
}

if (eol != NULL) {
*++eol = '\0';
bytes_read = eol - buffer;
}

nxfile->offset += bytes_read;
return true;
}

bool ini_write(const char* buffer, struct NxFile* nxfile) {
const size_t size = strlen(buffer);
if (R_FAILED(fsFileWrite(&nxfile->file, nxfile->offset, buffer, size, FsWriteOption_None))) {
return false;
}
nxfile->offset += size;
return true;
}

bool ini_tell(struct NxFile* nxfile, s64* pos) {
*pos = nxfile->offset;
return true;
}

bool ini_seek(struct NxFile* nxfile, s64* pos) {
nxfile->offset = *pos;
return true;
}

bool ini_rename(const char* src, const char* dst) {
Result rc = {0};
FsFileSystem fs = {0};
char src_buf[FS_MAX_PATH] = {0};
char dst_buf[FS_MAX_PATH] = {0};

if (R_FAILED(rc = fsOpenSdCardFileSystem(&fs))) {
return false;
}

strcpy(src_buf, src);
strcpy(dst_buf, dst);
rc = fsFsRenameFile(&fs, src_buf, dst_buf);
fsFsClose(&fs);
return R_SUCCEEDED(rc);
}

bool ini_remove(const char* filename) {
Result rc = {0};
FsFileSystem fs = {0};
char filename_buf[FS_MAX_PATH] = {0};

if (R_FAILED(rc = fsOpenSdCardFileSystem(&fs))) {
return false;
}

strcpy(filename_buf, filename);
rc = fsFsDeleteFile(&fs, filename_buf);
fsFsClose(&fs);
return R_SUCCEEDED(rc);
}

bool ini_ftoa(char* string, INI_REAL value) {
sprintf(string,"%f",value);
return true;
}

INI_REAL ini_atof(const char* string) {
return strtof(string, NULL);
}
Loading