Skip to content

Commit

Permalink
Merge branch 'main' into mmv4-batteryaccuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 authored Dec 22, 2024
2 parents 0e7180c + 75d1639 commit 54b28b1
Show file tree
Hide file tree
Showing 57 changed files with 307 additions and 177 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "third-party/RetroArch"]
path = third-party/RetroArch
url = https://github.com/OnionUI/RetroArch.git
[submodule "third-party/SearchFilter"]
path = third-party/SearchFilter
url = https://github.com/OnionUI/SearchFilter.git
Expand All @@ -10,3 +7,6 @@
[submodule "third-party/DinguxCommander"]
path = third-party/DinguxCommander
url = https://github.com/OnionUI/app-DinguxCommander
[submodule "third-party/RetroArch-patch"]
path = third-party/RetroArch-patch
url = https://github.com/OnionUI/RetroArch-patch
17 changes: 7 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
###########################################################

TARGET=Onion
VERSION=4.3.1-1
RA_SUBVERSION=1.15.0.13
VERSION=4.4.0
RA_SUBVERSION=1.19.1-0

###########################################################

Expand Down Expand Up @@ -170,18 +170,16 @@ apps: $(CACHE)/.setup
@cp -a "$(PACKAGES_APP_DEST)/Tweaks/." $(BUILD_DIR)/
@cp -a "$(PACKAGES_APP_DEST)/ThemeSwitcher/." $(BUILD_DIR)/

$(THIRD_PARTY_DIR)/RetroArch/retroarch_miyoo354:
$(THIRD_PARTY_DIR)/RetroArch-patch/bin/retroarch_miyoo354:
@$(ECHO) $(PRINT_RECIPE)
# RetroArch
@$(ECHO) $(COLOR_BLUE)"\n-- Build RetroArch"$(COLOR_NORMAL)
@cd $(THIRD_PARTY_DIR)/RetroArch && make clean all
@cd $(THIRD_PARTY_DIR)/RetroArch && make clean all MIYOO354=1 PACKAGE_NAME=retroarch_miyoo354
@cd $(THIRD_PARTY_DIR)/RetroArch-patch && make

external: $(CACHE)/.setup $(THIRD_PARTY_DIR)/RetroArch/retroarch_miyoo354
external: $(CACHE)/.setup $(THIRD_PARTY_DIR)/RetroArch-patch/bin/retroarch_miyoo354
@$(ECHO) $(PRINT_RECIPE)
# Add RetroArch
@cp $(THIRD_PARTY_DIR)/RetroArch/retroarch $(BUILD_DIR)/RetroArch/
@cp $(THIRD_PARTY_DIR)/RetroArch/retroarch_miyoo354 $(BUILD_DIR)/RetroArch/
@cp $(THIRD_PARTY_DIR)/RetroArch-patch/bin/* $(BUILD_DIR)/RetroArch/
@echo $(RA_SUBVERSION) > $(BUILD_DIR)/RetroArch/onion_ra_version.txt
@$(BUILD_DIR)/.tmp_update/script/build_ext_cache.sh $(BUILD_DIR)/RetroArch/.retroarch
# SearchFilter
Expand Down Expand Up @@ -232,8 +230,7 @@ clean:

deepclean: clean
@rm -rf $(CACHE)
@rm -f $(THIRD_PARTY_DIR)/RetroArch/retroarch_miyoo354
@cd $(THIRD_PARTY_DIR)/RetroArch && make clean
@cd $(THIRD_PARTY_DIR)/RetroArch-patch && make clean
@cd $(THIRD_PARTY_DIR)/SearchFilter && make clean
@cd $(THIRD_PARTY_DIR)/Terminal && make clean
@cd $(THIRD_PARTY_DIR)/DinguxCommander && make clean
Expand Down
2 changes: 1 addition & 1 deletion src/batmon/batmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(int argc, char *argv[])
best_session_time = get_best_session_time();

FILE *fp;
int old_percentage = -1, current_percentage, warn_at = 15;
int old_percentage = -1, current_percentage = 0, warn_at = 15;
int lowest_percentage_after_charge = 500;
atexit(cleanup);
signal(SIGINT, sigHandler);
Expand Down
1 change: 1 addition & 0 deletions src/batmon/batmonDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int get_best_session_time(void)
}
sqlite3_finalize(stmt);
}
close_battery_log_db();
}
return best_time;
}
Expand Down
4 changes: 3 additions & 1 deletion src/bootScreen/bootScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ int main(int argc, char *argv[])
SDL_Color color = theme()->total.color;

if (show_version) {
const char *version_str = file_read("/mnt/SDCARD/.tmp_update/onionVersion/version.txt");
char *version_str = file_read("/mnt/SDCARD/.tmp_update/onionVersion/version.txt");
if (strlen(version_str) > 0) {
SDL_Surface *version = TTF_RenderUTF8_Blended(font, version_str, color);
if (version) {
SDL_BlitSurface(version, NULL, screen, &(SDL_Rect){20, 450 - version->h / 2});
SDL_FreeSurface(version);
}
}
free(version_str);
}

if (strlen(message_str) > 0) {
Expand Down Expand Up @@ -106,6 +107,7 @@ int main(int argc, char *argv[])
sleep(4); // for debugging purposes
#endif

TTF_CloseFont(font);
SDL_FreeSurface(screen);
SDL_FreeSurface(video);
SDL_Quit();
Expand Down
1 change: 1 addition & 0 deletions src/common/components/JsonGameEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ JsonGameEntry JsonGameEntry_fromJson(const char *json_str)
json_getInt(root, "type", &entry.type);
json_getString(root, "rompath", entry.rompath);
json_getString(root, "imgpath", entry.imgpath);
cJSON_Delete(root);

strcpy(entry.emupath, entry.rompath);
str_split(entry.emupath, "/../../");
Expand Down
8 changes: 7 additions & 1 deletion src/common/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ ifeq ($(TEST),1)
CFLAGS := $(CFLAGS) -I../include -I../src/common -I$(GTEST_INCLUDE_DIR)
endif

ifeq ($(SANITIZE),1)
CFILES := $(CFILES) ../common/utils/asan.c
CFLAGS := $(CFLAGS) -fno-omit-frame-pointer -fsanitize=address -static-libasan
LDFLAGS := -fsanitize=address -static-libasan $(LDFLAGS)
endif

CXXFLAGS := $(CFLAGS)
LDFLAGS := -L../../lib -L/usr/local/lib
LDFLAGS := $(LDFLAGS) -L../../lib -L/usr/local/lib

ifeq ($(PLATFORM),miyoomini)
CFLAGS := $(CFLAGS) -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7ve -Wl,-rpath=$(LIB)
Expand Down
2 changes: 1 addition & 1 deletion src/common/recipes.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$(TARGET): $(OFILES)
@$(CXX) $(OFILES) -o "$@" $(LDFLAGS)
@if test -z "$(DEBUG)"; then \
@if test -z "$(DEBUG)" && test -z "$(SANITIZE)"; then \
$(STRIP) "$@"; \
fi
@-mv -f $(TARGET) "$(BUILD_DIR)/$(TARGET)"
Expand Down
2 changes: 1 addition & 1 deletion src/common/system/device_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define MIYOO354 354

static int DEVICE_ID;
static char DEVICE_SN[12];
static char DEVICE_SN[13];

/**
* @brief Get device model
Expand Down
14 changes: 11 additions & 3 deletions src/common/system/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ void lang_removeIconLabels(bool remove_icon_labels, bool remove_hints)
}
}

if (!remove_icon_labels && !remove_hints)
if (!remove_icon_labels && !remove_hints) {
closedir(dp);
return;
}

// backup lang files
if (!exists(LANG_DIR_BACKUP))
Expand All @@ -61,8 +63,9 @@ void lang_removeIconLabels(bool remove_icon_labels, bool remove_hints)
char file_path[STR_MAX * 2];
snprintf(file_path, STR_MAX * 2 - 1, LANG_DIR "/%s", ep->d_name);

const char *json_data = file_read(file_path);
char *json_data = file_read(file_path);
cJSON *root = cJSON_Parse(json_data);
free(json_data);

if (!root)
continue;
Expand Down Expand Up @@ -161,7 +164,12 @@ bool lang_load(void)
return true;
}

void lang_free(void) { free(lang_list); }
void lang_free(void) {
for (int i = 0; i < LANG_MAX; i++) {
free(lang_list[i]);
}
free(lang_list);
}

const char *lang_get(lang_hash key, const char *fallback)
{
Expand Down
13 changes: 9 additions & 4 deletions src/common/system/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool __get_path_romscreen(char *path_out)

bool __get_path_recent(char *path_out)
{
char *fnptr;
char *fnptr, *no_extension;
uint32_t i;

strcpy(path_out, "/mnt/SDCARD/Screenshots/");
Expand All @@ -43,8 +43,11 @@ bool __get_path_recent(char *path_out)

if (system_state == MODE_GAME && (process_searchpid("retroarch") != 0 || process_searchpid("ra32") != 0)) {
char file_path[STR_MAX];
if (history_getRecentPath(file_path) != NULL)
strcat(path_out, file_removeExtension(basename(file_path)));
if (history_getRecentPath(file_path) != NULL) {
no_extension = file_removeExtension(basename(file_path));
strcat(path_out, no_extension);
free(no_extension);
}
}
else if (system_state == MODE_SWITCHER)
strcat(path_out, "GameSwitcher");
Expand All @@ -61,7 +64,9 @@ bool __get_path_recent(char *path_out)
if (strstr(cmd, "; chmod") != NULL)
state_getAppName(app_name, cmd);
else {
strcpy(app_name, file_removeExtension(basename(cmd)));
no_extension = file_removeExtension(basename(cmd));
strcpy(app_name, no_extension);
free(no_extension);
}
printf_debug("app: '%s'\n", app_name);

Expand Down
6 changes: 5 additions & 1 deletion src/common/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct settings_s {
int blue_light_rgb;
char blue_light_time[16];
char blue_light_time_off[16];
bool no_time_restore;

char mainui_button_x[JSON_STRING_LEN];
char mainui_button_y[JSON_STRING_LEN];
Expand Down Expand Up @@ -103,6 +104,7 @@ static settings_s __default_settings = (settings_s){
.vibration = 2,
.startup_tab = 0,
.startup_application = 0,
.no_time_restore = false,
// Menu button actions
.mainui_single_press = 1,
.mainui_long_press = 0,
Expand Down Expand Up @@ -160,12 +162,13 @@ void _settings_load_keymap(void)

void _settings_load_mainui(void)
{
const char *json_str = NULL;
char *json_str = NULL;

if (!(json_str = file_read(MAIN_UI_SETTINGS)))
return;

cJSON *json_root = cJSON_Parse(json_str);
free(json_str);

json_getInt(json_root, "vol", &settings.volume);
json_getInt(json_root, "bgmvol", &settings.bgm_volume);
Expand Down Expand Up @@ -206,6 +209,7 @@ void settings_load(void)
settings.blue_light_schedule = config_flag_get(".blf");
settings.rec_indicator = config_flag_get(".recIndicator");
settings.rec_hotkey = config_flag_get(".recHotkey");
settings.no_time_restore = config_flag_get(".noTimeRestore");

if (config_flag_get(".noLowBatteryAutoSave")) // flag is deprecated, but keep compatibility
settings.low_battery_autosave_at = 0;
Expand Down
12 changes: 8 additions & 4 deletions src/common/system/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ static pid_t system_state_pid = 0;

bool check_isRetroArch(void)
{
bool rc = false;
if (!exists(CMD_TO_RUN_PATH))
return false;
const char *cmd = file_read(CMD_TO_RUN_PATH);
char *cmd = file_read(CMD_TO_RUN_PATH);
if (strstr(cmd, "retroarch") != NULL ||
strstr(cmd, "/mnt/SDCARD/Emu/") != NULL ||
strstr(cmd, "/mnt/SDCARD/RApp/") != NULL) {
pid_t pid;
if ((pid = process_searchpid("retroarch")) != 0 ||
(pid = process_searchpid("ra32")) != 0) {
system_state_pid = pid;
return true;
rc = true;
}
}
return false;
free(cmd);
return rc;
}

bool check_isMainUI(void)
Expand Down Expand Up @@ -390,8 +392,10 @@ void resumeGame(int n)
if (lineCount > 1) {
temp_flag_set("quick_switch", true);

file_add_line_to_beginning(getMiyooRecentFilePath(), file_read_lineN(getMiyooRecentFilePath(), lineCount));
char * line_n = file_read_lineN(getMiyooRecentFilePath(), lineCount);
file_add_line_to_beginning(getMiyooRecentFilePath(), line_n);
file_delete_line(getMiyooRecentFilePath(), lineCount + 1);
free(line_n);
}

file_put_sync(fp, CMD_TO_RUN_PATH, "%s", LaunchCommand);
Expand Down
3 changes: 2 additions & 1 deletion src/common/theme/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ void json_fontStyle(cJSON *root, FontStyle_s *dest, FontStyle_s *fallback)
bool theme_applyConfig(Theme_s *config, const char *config_path,
bool use_fallbacks)
{
const char *json_str = NULL;
char *json_str = NULL;

if (!exists(config_path) || !(json_str = file_read(config_path)))
return false;

// Get JSON objects
cJSON *json_root = cJSON_Parse(json_str);
free(json_str);
cJSON *json_batteryPercentage =
cJSON_GetObjectItem(json_root, "batteryPercentage");
cJSON *json_hideLabels = cJSON_GetObjectItem(json_root, "hideLabels");
Expand Down
5 changes: 4 additions & 1 deletion src/common/theme/load.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "utils/file.h"
#include "utils/str.h"
#include "utils/json.h"

#define SYSTEM_CONFIG "/mnt/SDCARD/system.json"
#define FALLBACK_FONT "/customer/app/Exo-2-Bold-Italic.ttf"
Expand Down Expand Up @@ -66,7 +67,9 @@ TTF_Font *theme_loadFont(const char *theme_path, const char *font, int size)

char *theme_getPath(char *theme_path)
{
file_parseKeyValue(SYSTEM_CONFIG, "theme", theme_path, ':', 0);
cJSON *j = json_load(SYSTEM_CONFIG);
json_getString(j,"theme", theme_path);
cJSON_Delete(j);

if (strcmp(theme_path, "./") == 0 || !is_dir(theme_path)) {
strcpy(theme_path, FALLBACK_THEME_PATH);
Expand Down
15 changes: 10 additions & 5 deletions src/common/utils/apply_icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ bool _apply_singleIconFromPack(const char *config_path,
if (!json_getString(config, "icon", temp_path))
return false;

char icon_name[56];
strncpy(icon_name, file_removeExtension(basename(temp_path)), 55);
char *icon_name = file_removeExtension(basename(temp_path));
str_split(icon_name, "-");

IconMode_e mode = icons_getIconMode(config_path);
Expand All @@ -156,13 +155,16 @@ bool _apply_singleIconFromPack(const char *config_path,
icon_name);
}

if (!is_file(icon_path))
if (!is_file(icon_path)) {
free(icon_name);
return false;
}
}

char sel_path[STR_MAX];
sprintf(sel_path, icons_getSelectedIconPathFormat(mode), icon_pack_path,
icon_name);
free(icon_name);

if (is_file(sel_path))
json_forceSetString(config, "iconsel", sel_path);
Expand All @@ -171,7 +173,9 @@ bool _apply_singleIconFromPack(const char *config_path,

json_forceSetString(config, "icon", icon_path);

_saveConfigFile(config_path, cJSON_Print(config));
char* config_str = cJSON_Print(config);
_saveConfigFile(config_path, config_str);
cJSON_free(config_str);
cJSON_Delete(config);

printf_debug("Applied icon to %s\nicon: %s\niconsel: %s\n", config_path,
Expand All @@ -183,7 +187,7 @@ bool _apply_singleIconFromPack(const char *config_path,
bool apply_singleIcon(const char *config_path)
{
char icon_pack_path[STR_MAX];
const char *active_icon_pack = file_read(ACTIVE_ICON_PACK);
char *active_icon_pack = file_read(ACTIVE_ICON_PACK);

if (active_icon_pack != NULL && is_dir(active_icon_pack))
strncpy(icon_pack_path, active_icon_pack, STR_MAX - 1);
Expand All @@ -199,6 +203,7 @@ bool apply_singleIcon(const char *config_path)
_apply_singleIconFromPack(GUEST_ON_CONFIG, icon_pack_path, false);
}

free(active_icon_pack);
return _apply_singleIconFromPack(config_path, icon_pack_path, false);
}

Expand Down
5 changes: 5 additions & 0 deletions src/common/utils/asan.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

__attribute__((externally_visible))
const char *__asan_default_options() {
return "log_path=/mnt/SDCARD/.tmp_update/logs/ASAN.log:halt_on_error=0";
}
Loading

0 comments on commit 54b28b1

Please sign in to comment.