better data management
This commit is contained in:
1 parent
4eb7b5f19b
commit
4db5c1dcf7
12 files changed
+1723
-1547
No files matched your search
@@ -30,6 +30,11 @@ FLINT_SRCS := $(filter-out $(FLINT_ICON_ASSETS_C),$(wildcard $(FLINT_DIR)/src/*.
|
||||
FLINT_INCLUDE := -I$(FLINT_DIR)/include
|
||||
FLINT_CURL_CFLAGS ?= $(shell pkg-config --cflags libcurl 2>/dev/null)
|
||||
FLINT_CURL_LDLIBS ?= $(shell pkg-config --libs libcurl 2>/dev/null)
|
||||
SQLITE_CFLAGS ?= $(shell pkg-config --cflags sqlite3 2>/dev/null)
|
||||
SQLITE_LDLIBS ?= $(shell pkg-config --libs sqlite3 2>/dev/null)
|
||||
ifeq ($(strip $(SQLITE_LDLIBS)),)
|
||||
SQLITE_LDLIBS := -lsqlite3
|
||||
endif
|
||||
ifneq ($(strip $(FLINT_CURL_LDLIBS)),)
|
||||
FLINT_RUNTIME_ASSET_CFLAGS := -DFLINT_HAS_LIBCURL=1 $(FLINT_CURL_CFLAGS)
|
||||
FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
|
||||
@@ -49,6 +54,7 @@ APP_SRCS := \
|
||||
src/theme_meta.c \
|
||||
src/theme.c \
|
||||
src/data.c \
|
||||
src/storage.c \
|
||||
src/miniz.c \
|
||||
src/tabs/history_tab.c \
|
||||
src/tabs/language_tab.c \
|
||||
@@ -68,7 +74,7 @@ SRC := $(APP_SRCS) $(EMBEDDED_ASSETS_C)
|
||||
|
||||
APP_INCLUDE := -Isrc -Isrc/android
|
||||
APP_RAYLIB_CONFIG := $(filter-out -DSUPPORT_MODULE_RAUDIO=0 -DSUPPORT_FILEFORMAT_PNG=0 -DSUPPORT_FILEFORMAT_JPG=0 -DSUPPORT_FILEFORMAT_OGG=0 -DSUPPORT_FILEFORMAT_MP3=0,$(RAY_RAYLIB_CONFIG)) -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1 -DSUPPORT_FILEFORMAT_MP3=1
|
||||
CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1 -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_EMBEDDED_ONLY=1 $(FLINT_RUNTIME_ASSET_CFLAGS)
|
||||
CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1 -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_EMBEDDED_ONLY=1 $(FLINT_RUNTIME_ASSET_CFLAGS) $(SQLITE_CFLAGS)
|
||||
LDFLAGS := -Wl,--gc-sections -s
|
||||
|
||||
BINARY_NAME := $(APP_NAME)-linux-$(ARCH)
|
||||
@@ -133,6 +139,7 @@ $(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(
|
||||
$(RAYLIB_A) \
|
||||
$(RAY_LDLIBS) \
|
||||
$(FLINT_RUNTIME_ASSET_LDLIBS) \
|
||||
$(SQLITE_LDLIBS) \
|
||||
-lm -lpthread -ldl -lrt \
|
||||
$(LDFLAGS)
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/theme_meta.c"
|
||||
"${SRC_DIR}/theme.c"
|
||||
"${SRC_DIR}/data.c"
|
||||
"${SRC_DIR}/storage.c"
|
||||
"${SRC_DIR}/miniz.c"
|
||||
"${SRC_DIR}/android/android_import.c"
|
||||
"${SRC_DIR}/android/android_runtime_assets.c"
|
||||
@@ -137,6 +138,7 @@ target_link_libraries(main
|
||||
android
|
||||
log
|
||||
OpenSLES
|
||||
sqlite
|
||||
EGL
|
||||
GLESv2
|
||||
m
|
||||
|
||||
@@ -112,7 +112,9 @@ public class MainActivity extends NativeActivity {
|
||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {
|
||||
"application/zip",
|
||||
"application/octet-stream",
|
||||
"application/x-zip-compressed"
|
||||
"application/x-zip-compressed",
|
||||
"application/vnd.sqlite3",
|
||||
"application/x-sqlite3"
|
||||
});
|
||||
startActivityForResult(intent, REQUEST_IMPORT_ZIP);
|
||||
} catch (Exception e) {
|
||||
@@ -136,7 +138,7 @@ public class MainActivity extends NativeActivity {
|
||||
|
||||
Uri uri = data.getData();
|
||||
File importDir = new File(getCacheDir(), "imports");
|
||||
File importFile = new File(importDir, "inbe-import.zip");
|
||||
File importFile = new File(importDir, "inbe-import");
|
||||
|
||||
try {
|
||||
if (!importDir.exists() && !importDir.mkdirs()) {
|
||||
|
||||
+33
-118
@@ -1,6 +1,7 @@
|
||||
#include "android_share.h"
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
#include "storage.h"
|
||||
#include "version.h"
|
||||
#include "raylib.h"
|
||||
#include "miniz.h"
|
||||
@@ -16,34 +17,14 @@
|
||||
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
|
||||
static int is_session_file(const char *path)
|
||||
{
|
||||
const char *filename;
|
||||
|
||||
if(path == NULL)
|
||||
return 0;
|
||||
|
||||
filename = GetFileName(path);
|
||||
return strncmp(filename, "inbe-", 5) == 0;
|
||||
}
|
||||
|
||||
int android_share_export(const char *filename)
|
||||
{
|
||||
struct android_app *app;
|
||||
mz_zip_archive archive;
|
||||
void *zip_data;
|
||||
char export_path[FS_PATH_MAX];
|
||||
FILE *fp;
|
||||
char *zip_data;
|
||||
size_t zip_size;
|
||||
int year, month, day;
|
||||
FilePathList files;
|
||||
int session_count = 0;
|
||||
char metadata[512];
|
||||
char metadata_header[128];
|
||||
char metadata_version[128];
|
||||
char metadata_date[128];
|
||||
char metadata_count[128];
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
char date_str[64];
|
||||
long file_size;
|
||||
|
||||
app = GetAndroidApp();
|
||||
if(app == NULL || app->activity == NULL) {
|
||||
@@ -56,99 +37,34 @@ int android_share_export(const char *filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&archive, 0, sizeof(archive));
|
||||
if(!mz_zip_writer_init_heap(&archive, 0, 0)) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: failed to initialize ZIP archive");
|
||||
snprintf(export_path, sizeof(export_path), "%s/%s", data_root(), filename);
|
||||
if(!inbe_storage_export_zip(export_path)) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: failed to export SQLite ZIP");
|
||||
return 0;
|
||||
}
|
||||
|
||||
session_count = data_get_session_count();
|
||||
|
||||
now = time(NULL);
|
||||
tm = localtime(&now);
|
||||
if(tm != NULL) {
|
||||
snprintf(date_str, sizeof(date_str), "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
} else {
|
||||
strcpy(date_str, "Unknown");
|
||||
}
|
||||
|
||||
locale_format(metadata_header, sizeof(metadata_header), "export_metadata_header");
|
||||
locale_format(metadata_version, sizeof(metadata_version), "export_metadata_version", INBE_VERSION_STRING);
|
||||
locale_format(metadata_date, sizeof(metadata_date), "export_metadata_date", date_str);
|
||||
locale_format(metadata_count, sizeof(metadata_count), "export_metadata_count", session_count);
|
||||
|
||||
snprintf(metadata, sizeof(metadata), "%s\n%s\n%s\n%s\n",
|
||||
metadata_header,
|
||||
metadata_version,
|
||||
metadata_date,
|
||||
metadata_count);
|
||||
|
||||
if(!mz_zip_writer_add_mem(&archive, "lotus-data/metadata.txt", metadata, strlen(metadata), MZ_NO_COMPRESSION)) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: failed to write metadata");
|
||||
mz_zip_writer_end(&archive);
|
||||
fp = fopen(export_path, "rb");
|
||||
if(fp == NULL)
|
||||
return 0;
|
||||
fseek(fp, 0, SEEK_END);
|
||||
file_size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if(file_size <= 0) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(year = 1970; year <= 2100; year++) {
|
||||
char year_path[FS_PATH_MAX];
|
||||
snprintf(year_path, sizeof(year_path), "%s/%04d", data_root(), year);
|
||||
|
||||
if(!DirectoryExists(year_path))
|
||||
continue;
|
||||
|
||||
for(month = 1; month <= 12; month++) {
|
||||
char month_path[FS_PATH_MAX];
|
||||
snprintf(month_path, sizeof(month_path), "%s/%02d", year_path, month);
|
||||
|
||||
if(!DirectoryExists(month_path))
|
||||
continue;
|
||||
|
||||
for(day = 1; day <= 31; day++) {
|
||||
char day_path[FS_PATH_MAX];
|
||||
snprintf(day_path, sizeof(day_path), "%s/%02d", month_path, day);
|
||||
|
||||
if(!DirectoryExists(day_path))
|
||||
continue;
|
||||
|
||||
files = LoadDirectoryFiles(day_path);
|
||||
for(unsigned int i = 0; i < files.count; i++) {
|
||||
if(is_session_file(files.paths[i])) {
|
||||
char *content;
|
||||
char zip_path[FS_PATH_MAX];
|
||||
const char *fname = GetFileName(files.paths[i]);
|
||||
|
||||
snprintf(zip_path, sizeof(zip_path),
|
||||
"lotus-data/sessions/%04d/%02d/%02d/%s",
|
||||
year, month, day, fname);
|
||||
|
||||
content = LoadFileText(files.paths[i]);
|
||||
if(content != NULL) {
|
||||
size_t size = strlen(content);
|
||||
if(!mz_zip_writer_add_mem(&archive, zip_path, content, size, MZ_NO_COMPRESSION)) {
|
||||
TraceLog(LOG_WARNING, "ANDROID_SHARE: failed to add file: %s", files.paths[i]);
|
||||
}
|
||||
UnloadFileText(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
UnloadDirectoryFiles(files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!mz_zip_writer_finalize_heap_archive(&archive, &zip_data, &zip_size)) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: failed to finalize ZIP archive");
|
||||
mz_zip_writer_end(&archive);
|
||||
zip_size = (size_t)file_size;
|
||||
zip_data = malloc(zip_size);
|
||||
if(zip_data == NULL) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(zip_data == NULL || zip_size == 0) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: failed to get ZIP data");
|
||||
mz_zip_writer_end(&archive);
|
||||
if(fread(zip_data, 1, zip_size, fp) != zip_size) {
|
||||
fclose(fp);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
TraceLog(LOG_INFO, "ANDROID_SHARE: calling Java to share %zu bytes", zip_size);
|
||||
|
||||
@@ -158,7 +74,7 @@ int android_share_export(const char *filename)
|
||||
|
||||
if((*jvm)->AttachCurrentThread(jvm, &env, NULL) != JNI_OK) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: failed to attach thread");
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -167,7 +83,7 @@ int android_share_export(const char *filename)
|
||||
if(!activity_class) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: Activity class not found");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -175,7 +91,7 @@ int android_share_export(const char *filename)
|
||||
if(!get_class_loader) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: getClassLoader method not found");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -183,7 +99,7 @@ int android_share_export(const char *filename)
|
||||
if(!class_loader) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: getClassLoader returned null");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -191,7 +107,7 @@ int android_share_export(const char *filename)
|
||||
if(!class_loader_class) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: ClassLoader class not found");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -199,7 +115,7 @@ int android_share_export(const char *filename)
|
||||
if(!load_class) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: loadClass method not found");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -210,7 +126,7 @@ int android_share_export(const char *filename)
|
||||
if(!share_helper_class) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: ShareHelper class not found via class loader");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -220,7 +136,7 @@ int android_share_export(const char *filename)
|
||||
if(!method) {
|
||||
TraceLog(LOG_ERROR, "ANDROID_SHARE: shareZipFile method not found");
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -236,8 +152,7 @@ int android_share_export(const char *filename)
|
||||
(*env)->DeleteLocalRef(env, jtitle);
|
||||
(*env)->DeleteLocalRef(env, class_loader);
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
|
||||
mz_zip_writer_end(&archive);
|
||||
free(zip_data);
|
||||
|
||||
TraceLog(LOG_INFO, "ANDROID_SHARE: share sheet triggered");
|
||||
return 1;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "tabs/settings_tab.h"
|
||||
#include "app_session.h"
|
||||
#include "meditation_music.h"
|
||||
#include "storage.h"
|
||||
#include "theme.h"
|
||||
#include "theme_meta.h"
|
||||
#if defined(LOTUS_BUILD)
|
||||
@@ -23,7 +24,6 @@
|
||||
#endif
|
||||
#include "../vendor/rini/src/rini.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -372,12 +372,6 @@ refresh_theme_colors(int theme_id, int dark_mode)
|
||||
ui_set_colors(text, bg, circle, button, button_hover, icon);
|
||||
}
|
||||
|
||||
static void
|
||||
inbe_settings_path(char *out, size_t out_size)
|
||||
{
|
||||
snprintf(out, out_size, "%s/settings.ini", data_root());
|
||||
}
|
||||
|
||||
static void
|
||||
register_all_themes(void)
|
||||
{
|
||||
@@ -464,71 +458,36 @@ reset_settings_preview(InbeApp *app)
|
||||
void
|
||||
save_settings(InbeApp *app)
|
||||
{
|
||||
char text[1900];
|
||||
char settings_path[FS_PATH_MAX];
|
||||
inbe_settings_path(settings_path, sizeof(settings_path));
|
||||
#ifdef __ANDROID__
|
||||
snprintf(text, sizeof(text),
|
||||
"speed %d\nmax_rounds %d\nmax_breaths %d\npause_seconds %d\nsound_volume %d\ntutorial_seen %d\nexercise_manual_seen_mask %d\ntheme %d\ndark_mode %d\nfullscreen %d\non_screen_keyboard %d\nprogressive_speed %d\nprogressive_start_speed %d\nadvanced_session_controls %d\nhold_display_mode %d\nexercise_type %d\nmeditation_music_enabled %d\nmeditation_music_shuffle %d\nmeditation_music_track %d\nplay_in_background %d\nlanguage %s\n",
|
||||
app->inbe.speed_level,
|
||||
app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths),
|
||||
app->inbe.pause_seconds,
|
||||
app->sound_volume,
|
||||
app->tutorial_seen ? 1 : 0,
|
||||
app->exercise_manual_seen_mask,
|
||||
app->theme_id,
|
||||
app->dark_mode,
|
||||
app->fullscreen_enabled ? 1 : 0,
|
||||
app->on_screen_keyboard_enabled ? 1 : 0,
|
||||
app->inbe.progressive_speed,
|
||||
app->inbe.progressive_start_speed,
|
||||
app->advanced_session_controls ? 1 : 0,
|
||||
app->hold_display_mode,
|
||||
app->exercise_type,
|
||||
app->meditation_music_enabled ? 1 : 0,
|
||||
app->meditation_music_shuffle ? 1 : 0,
|
||||
app->meditation_music_track,
|
||||
app->inbe.play_in_background,
|
||||
(app->language_selected && app->language[0] != '\0')
|
||||
? app->language
|
||||
: "");
|
||||
#else
|
||||
snprintf(text, sizeof(text),
|
||||
"speed %d\nmax_rounds %d\nmax_breaths %d\npause_seconds %d\nsound_volume %d\ntutorial_seen %d\nexercise_manual_seen_mask %d\ntheme %d\ndark_mode %d\nfullscreen %d\non_screen_keyboard %d\nprogressive_speed %d\nprogressive_start_speed %d\nadvanced_session_controls %d\nhold_display_mode %d\nexercise_type %d\nmeditation_music_enabled %d\nmeditation_music_shuffle %d\nmeditation_music_track %d\nlanguage %s\n",
|
||||
app->inbe.speed_level,
|
||||
app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths),
|
||||
app->inbe.pause_seconds,
|
||||
app->sound_volume,
|
||||
app->tutorial_seen ? 1 : 0,
|
||||
app->exercise_manual_seen_mask,
|
||||
app->theme_id,
|
||||
app->dark_mode,
|
||||
app->fullscreen_enabled ? 1 : 0,
|
||||
app->on_screen_keyboard_enabled ? 1 : 0,
|
||||
app->inbe.progressive_speed,
|
||||
app->inbe.progressive_start_speed,
|
||||
app->advanced_session_controls ? 1 : 0,
|
||||
app->hold_display_mode,
|
||||
app->exercise_type,
|
||||
app->meditation_music_enabled ? 1 : 0,
|
||||
app->meditation_music_shuffle ? 1 : 0,
|
||||
app->meditation_music_track,
|
||||
(app->language_selected && app->language[0] != '\0')
|
||||
? app->language
|
||||
: "");
|
||||
#endif
|
||||
snprintf(text + strlen(text), sizeof(text) - strlen(text),
|
||||
"practice_tab_enabled_mask %d\npractice_tab_mind_theme %d\npractice_tab_yoga_theme %d\npractice_tab_fitness_theme %d\npractice_category_tab %d\n",
|
||||
(app->practice_tab_enabled[PRACTICE_CATEGORY_MIND] ? 1 : 0) |
|
||||
(app->practice_tab_enabled[PRACTICE_CATEGORY_YOGA] ? 2 : 0) |
|
||||
(app->practice_tab_enabled[PRACTICE_CATEGORY_FITNESS] ? 4 : 0),
|
||||
app->practice_tab_theme[PRACTICE_CATEGORY_MIND],
|
||||
app->practice_tab_theme[PRACTICE_CATEGORY_YOGA],
|
||||
app->practice_tab_theme[PRACTICE_CATEGORY_FITNESS],
|
||||
app->practice_category_tab);
|
||||
SaveFileText(settings_path, text);
|
||||
inbe_storage_set_setting_int("speed", app->inbe.speed_level);
|
||||
inbe_storage_set_setting_int("max_rounds", app->inbe.max_rounds);
|
||||
inbe_storage_set_setting_int("max_breaths", int_from_count(app->inbe.maxbreaths));
|
||||
inbe_storage_set_setting_int("pause_seconds", app->inbe.pause_seconds);
|
||||
inbe_storage_set_setting_int("sound_volume", app->sound_volume);
|
||||
inbe_storage_set_setting_int("tutorial_seen", app->tutorial_seen ? 1 : 0);
|
||||
inbe_storage_set_setting_int("exercise_manual_seen_mask", app->exercise_manual_seen_mask);
|
||||
inbe_storage_set_setting_int("theme", app->theme_id);
|
||||
inbe_storage_set_setting_int("dark_mode", app->dark_mode);
|
||||
inbe_storage_set_setting_int("fullscreen", app->fullscreen_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("on_screen_keyboard", app->on_screen_keyboard_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("progressive_speed", app->inbe.progressive_speed);
|
||||
inbe_storage_set_setting_int("progressive_start_speed", app->inbe.progressive_start_speed);
|
||||
inbe_storage_set_setting_int("advanced_session_controls", app->advanced_session_controls ? 1 : 0);
|
||||
inbe_storage_set_setting_int("hold_display_mode", app->hold_display_mode);
|
||||
inbe_storage_set_setting_int("exercise_type", app->exercise_type);
|
||||
inbe_storage_set_setting_int("meditation_music_enabled", app->meditation_music_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("meditation_music_shuffle", app->meditation_music_shuffle ? 1 : 0);
|
||||
inbe_storage_set_setting_int("meditation_music_track", app->meditation_music_track);
|
||||
inbe_storage_set_setting_int("play_in_background", app->inbe.play_in_background);
|
||||
inbe_storage_set_setting_text("language",
|
||||
(app->language_selected && app->language[0] != '\0') ? app->language : "");
|
||||
inbe_storage_set_setting_int("practice_tab_enabled_mask",
|
||||
(app->practice_tab_enabled[PRACTICE_CATEGORY_MIND] ? 1 : 0) |
|
||||
(app->practice_tab_enabled[PRACTICE_CATEGORY_YOGA] ? 2 : 0) |
|
||||
(app->practice_tab_enabled[PRACTICE_CATEGORY_FITNESS] ? 4 : 0));
|
||||
inbe_storage_set_setting_int("practice_tab_mind_theme", app->practice_tab_theme[PRACTICE_CATEGORY_MIND]);
|
||||
inbe_storage_set_setting_int("practice_tab_yoga_theme", app->practice_tab_theme[PRACTICE_CATEGORY_YOGA]);
|
||||
inbe_storage_set_setting_int("practice_tab_fitness_theme", app->practice_tab_theme[PRACTICE_CATEGORY_FITNESS]);
|
||||
inbe_storage_set_setting_int("practice_category_tab", app->practice_category_tab);
|
||||
#if defined(PLATFORM_WEB)
|
||||
sync_web_storage();
|
||||
#endif
|
||||
@@ -538,46 +497,42 @@ save_settings(InbeApp *app)
|
||||
static void
|
||||
load_settings(InbeApp *app)
|
||||
{
|
||||
char settings_path[FS_PATH_MAX];
|
||||
inbe_settings_path(settings_path, sizeof(settings_path));
|
||||
rini_data settings = rini_load(settings_path);
|
||||
int settings_missing = settings.count == 0;
|
||||
|
||||
int speed = rini_get_value_fallback(settings, "speed", DefaultSpeedLevel);
|
||||
int max_rounds = rini_get_value_fallback(settings, "max_rounds", DefaultMaxRounds);
|
||||
int max_breaths = rini_get_value_fallback(settings, "max_breaths", DefaultMaxBreaths);
|
||||
int pause_seconds = rini_get_value_fallback(settings, "pause_seconds", DefaultPauseSeconds);
|
||||
int sound_volume = rini_get_value_fallback(settings, "sound_volume", 100);
|
||||
int settings_missing = inbe_storage_settings_empty();
|
||||
int speed = inbe_storage_get_setting_int("speed", DefaultSpeedLevel);
|
||||
int max_rounds = inbe_storage_get_setting_int("max_rounds", DefaultMaxRounds);
|
||||
int max_breaths = inbe_storage_get_setting_int("max_breaths", DefaultMaxBreaths);
|
||||
int pause_seconds = inbe_storage_get_setting_int("pause_seconds", DefaultPauseSeconds);
|
||||
int sound_volume = inbe_storage_get_setting_int("sound_volume", 100);
|
||||
int manual_seen_mask;
|
||||
int practice_enabled_mask;
|
||||
|
||||
app->tutorial_seen = rini_get_value_fallback(settings, "tutorial_seen", 0) != 0;
|
||||
manual_seen_mask = rini_get_value_fallback(settings, "exercise_manual_seen_mask", -1);
|
||||
app->tutorial_seen = inbe_storage_get_setting_int("tutorial_seen", 0) != 0;
|
||||
manual_seen_mask = inbe_storage_get_setting_int("exercise_manual_seen_mask", -1);
|
||||
if(manual_seen_mask < 0)
|
||||
manual_seen_mask = app->tutorial_seen ? exercise_manual_seen_bit(EXERCISE_WIM_HOF) : 0;
|
||||
app->exercise_manual_seen_mask = manual_seen_mask & ((1 << EXERCISE_COUNT) - 1);
|
||||
app->theme_id = clampi(rini_get_value_fallback(settings, "theme", 0), 0, THEME_COUNT - 1);
|
||||
app->dark_mode = rini_get_value_fallback(settings, "dark_mode", 0) != 0;
|
||||
app->fullscreen_enabled = rini_get_value_fallback(settings, "fullscreen", 0) != 0;
|
||||
app->theme_id = clampi(inbe_storage_get_setting_int("theme", 0), 0, THEME_COUNT - 1);
|
||||
app->dark_mode = inbe_storage_get_setting_int("dark_mode", 0) != 0;
|
||||
app->fullscreen_enabled = inbe_storage_get_setting_int("fullscreen", 0) != 0;
|
||||
#ifdef __ANDROID__
|
||||
app->on_screen_keyboard_enabled = rini_get_value_fallback(settings, "on_screen_keyboard", 1) != 0;
|
||||
app->on_screen_keyboard_enabled = inbe_storage_get_setting_int("on_screen_keyboard", 1) != 0;
|
||||
#else
|
||||
app->on_screen_keyboard_enabled = rini_get_value_fallback(settings, "on_screen_keyboard", 0) != 0;
|
||||
app->on_screen_keyboard_enabled = inbe_storage_get_setting_int("on_screen_keyboard", 0) != 0;
|
||||
#endif
|
||||
app->sound_volume = clampi(sound_volume, SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX);
|
||||
app->inbe.progressive_speed = rini_get_value_fallback(settings, "progressive_speed", 1) != 0;
|
||||
app->inbe.progressive_start_speed = clampi(rini_get_value_fallback(settings, "progressive_start_speed", DefaultProgressiveStartSpeed),
|
||||
app->inbe.progressive_speed = inbe_storage_get_setting_int("progressive_speed", 1) != 0;
|
||||
app->inbe.progressive_start_speed = clampi(inbe_storage_get_setting_int("progressive_start_speed", DefaultProgressiveStartSpeed),
|
||||
SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
app->advanced_session_controls = rini_get_value_fallback(settings, "advanced_session_controls", 0) != 0;
|
||||
app->hold_display_mode = clampi(rini_get_value_fallback(settings, "hold_display_mode", HOLD_DISPLAY_CIRCLE),
|
||||
app->advanced_session_controls = inbe_storage_get_setting_int("advanced_session_controls", 0) != 0;
|
||||
app->hold_display_mode = clampi(inbe_storage_get_setting_int("hold_display_mode", HOLD_DISPLAY_CIRCLE),
|
||||
HOLD_DISPLAY_CIRCLE, HOLD_DISPLAY_STOPWATCH);
|
||||
app->exercise_type = clampi(rini_get_value_fallback(settings, "exercise_type", EXERCISE_WIM_HOF),
|
||||
app->exercise_type = clampi(inbe_storage_get_setting_int("exercise_type", EXERCISE_WIM_HOF),
|
||||
EXERCISE_WIM_HOF, EXERCISE_COUNT - 1);
|
||||
app->meditation_music_enabled = rini_get_value_fallback(settings, "meditation_music_enabled", 1) != 0;
|
||||
app->meditation_music_shuffle = rini_get_value_fallback(settings, "meditation_music_shuffle", 1) != 0;
|
||||
app->meditation_music_track = clampi(rini_get_value_fallback(settings, "meditation_music_track", 0),
|
||||
app->meditation_music_enabled = inbe_storage_get_setting_int("meditation_music_enabled", 1) != 0;
|
||||
app->meditation_music_shuffle = inbe_storage_get_setting_int("meditation_music_shuffle", 1) != 0;
|
||||
app->meditation_music_track = clampi(inbe_storage_get_setting_int("meditation_music_track", 0),
|
||||
0, MEDITATION_MUSIC_TRACK_COUNT - 1);
|
||||
practice_enabled_mask = rini_get_value_fallback(settings, "practice_tab_enabled_mask", 7);
|
||||
practice_enabled_mask = inbe_storage_get_setting_int("practice_tab_enabled_mask", 7);
|
||||
if((practice_enabled_mask & 7) == 0)
|
||||
practice_enabled_mask = 1;
|
||||
for(int i = 0; i < PRACTICE_CATEGORY_COUNT; i++) {
|
||||
@@ -585,22 +540,22 @@ load_settings(InbeApp *app)
|
||||
app->practice_tab_theme[i] = g_practice_category_default_themes[i];
|
||||
}
|
||||
app->practice_tab_theme[PRACTICE_CATEGORY_MIND] =
|
||||
clampi(rini_get_value_fallback(settings, "practice_tab_mind_theme", ThemeSky), 0, THEME_COUNT - 1);
|
||||
clampi(inbe_storage_get_setting_int("practice_tab_mind_theme", ThemeSky), 0, THEME_COUNT - 1);
|
||||
app->practice_tab_theme[PRACTICE_CATEGORY_YOGA] =
|
||||
clampi(rini_get_value_fallback(settings, "practice_tab_yoga_theme", ThemeSunset), 0, THEME_COUNT - 1);
|
||||
clampi(inbe_storage_get_setting_int("practice_tab_yoga_theme", ThemeSunset), 0, THEME_COUNT - 1);
|
||||
app->practice_tab_theme[PRACTICE_CATEGORY_FITNESS] =
|
||||
clampi(rini_get_value_fallback(settings, "practice_tab_fitness_theme", ThemeCherry), 0, THEME_COUNT - 1);
|
||||
clampi(inbe_storage_get_setting_int("practice_tab_fitness_theme", ThemeCherry), 0, THEME_COUNT - 1);
|
||||
app->practice_tab_enabled[PRACTICE_CATEGORY_YOGA] = 0;
|
||||
app->practice_tab_enabled[PRACTICE_CATEGORY_FITNESS] = 0;
|
||||
app->practice_category_tab =
|
||||
clampi(rini_get_value_fallback(settings, "practice_category_tab", PRACTICE_CATEGORY_MIND),
|
||||
clampi(inbe_storage_get_setting_int("practice_category_tab", PRACTICE_CATEGORY_MIND),
|
||||
0, PRACTICE_CATEGORY_COUNT - 1);
|
||||
if(!app->practice_tab_enabled[app->practice_category_tab])
|
||||
app->practice_category_tab = PRACTICE_CATEGORY_MIND;
|
||||
app->theme_id = clampi(app->practice_tab_theme[app->practice_category_tab], 0, THEME_COUNT - 1);
|
||||
app->language_needs_save = 0;
|
||||
{
|
||||
const char *language = rini_get_value_text(settings, "language");
|
||||
const char *language = inbe_storage_get_setting_text("language");
|
||||
if(language != NULL && language[0] != '\0') {
|
||||
snprintf(app->language, sizeof(app->language), "%s", language);
|
||||
app->language_selected = 1;
|
||||
@@ -623,7 +578,7 @@ load_settings(InbeApp *app)
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
app->inbe.play_in_background = rini_get_value_fallback(settings, "play_in_background",
|
||||
app->inbe.play_in_background = inbe_storage_get_setting_int("play_in_background",
|
||||
1 // Default to enabled on Android
|
||||
);
|
||||
TraceLog(LOG_INFO, "INBE: Loaded play_in_background setting = %d", app->inbe.play_in_background);
|
||||
@@ -635,7 +590,6 @@ load_settings(InbeApp *app)
|
||||
refresh_theme_colors(app->theme_id, app->dark_mode);
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
refresh_locale_dependent_text(app);
|
||||
rini_unload(&settings);
|
||||
if(settings_missing)
|
||||
save_settings(app);
|
||||
}
|
||||
@@ -791,6 +745,7 @@ inbe_app_init(void *vapp) {
|
||||
inbeinit(&app->inbe);
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + flint_px(80));
|
||||
data_init();
|
||||
load_settings(app);
|
||||
if(app->language_needs_save) {
|
||||
save_settings(app);
|
||||
@@ -798,7 +753,6 @@ inbe_app_init(void *vapp) {
|
||||
}
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + 80);
|
||||
data_init();
|
||||
inbe_habits_init(&app->habits);
|
||||
init_audio(app);
|
||||
meditation_music_init(app);
|
||||
|
||||
+126
-1053
File diff suppressed because it is too large.
Load diff
@@ -21,7 +21,16 @@ int data_import(const char *path);
|
||||
int data_validate_import_file(const char *path);
|
||||
typedef void (*data_session_callback)(const char *date, const char *time,
|
||||
int rounds, int best, void *user);
|
||||
typedef void (*data_history_callback)(const char *path,
|
||||
int year, int month, int day,
|
||||
int hour, int minute, int second,
|
||||
const int *round_times, int round_count,
|
||||
void *user);
|
||||
|
||||
void data_list_sessions(data_session_callback callback, void *user);
|
||||
void data_list_history(data_history_callback callback, void *user);
|
||||
int data_load_session(const char *path, int *round_times, int max_rounds,
|
||||
int *year, int *month, int *day,
|
||||
int *hour, int *minute, int *second);
|
||||
|
||||
#endif
|
||||
+18
-160
@@ -1,31 +1,12 @@
|
||||
#include "habits/habits.h"
|
||||
|
||||
#include "data.h"
|
||||
#include "flint_runtime_assets.h"
|
||||
#include "../../vendor/rini/src/rini.h"
|
||||
#include "storage.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
enum {
|
||||
HABITS_PATH_SIZE = 512
|
||||
};
|
||||
|
||||
static void
|
||||
habits_path(char *out, size_t out_size)
|
||||
{
|
||||
snprintf(out, out_size, "%s/apps/habits/habits.ini", data_root());
|
||||
}
|
||||
|
||||
static void
|
||||
habits_ensure_dir(void)
|
||||
{
|
||||
char path[HABITS_PATH_SIZE];
|
||||
snprintf(path, sizeof(path), "%s/apps/habits", data_root());
|
||||
flint_runtime_asset_ensure_dir(path);
|
||||
}
|
||||
|
||||
static void
|
||||
copy_text(char *dst, size_t dst_size, const char *src)
|
||||
{
|
||||
@@ -74,51 +55,8 @@ inbe_habit_completed_today(const InbeHabit *habit)
|
||||
void
|
||||
inbe_habits_save(const InbeHabits *habits)
|
||||
{
|
||||
rini_data data;
|
||||
char path[HABITS_PATH_SIZE];
|
||||
|
||||
if(habits == NULL)
|
||||
return;
|
||||
|
||||
habits_ensure_dir();
|
||||
habits_path(path, sizeof(path));
|
||||
data = rini_load(NULL);
|
||||
rini_set_value(&data, "count", habits->count, NULL);
|
||||
rini_set_value(&data, "selected", habits->selected, NULL);
|
||||
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
const InbeHabit *habit = &habits->items[i];
|
||||
char key[96];
|
||||
|
||||
snprintf(key, sizeof(key), "habit_%d_id", i);
|
||||
rini_set_value_text(&data, key, habit->id, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_name", i);
|
||||
rini_set_value_text(&data, key, habit->name, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_color_r", i);
|
||||
rini_set_value(&data, key, habit->color.r, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_color_g", i);
|
||||
rini_set_value(&data, key, habit->color.g, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_color_b", i);
|
||||
rini_set_value(&data, key, habit->color.b, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_sync_mode", i);
|
||||
rini_set_value(&data, key, habit->sync_mode, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_sync_topic", i);
|
||||
rini_set_value(&data, key, habit->sync_topic, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_sync_activity", i);
|
||||
rini_set_value(&data, key, habit->sync_activity, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_day_count", i);
|
||||
rini_set_value(&data, key, habit->day_count, NULL);
|
||||
|
||||
for(int d = 0; d < habit->day_count; d++) {
|
||||
snprintf(key, sizeof(key), "habit_%d_day_%d_index", i, d);
|
||||
rini_set_value(&data, key, habit->days[d].day_index, NULL);
|
||||
snprintf(key, sizeof(key), "habit_%d_day_%d_completed", i, d);
|
||||
rini_set_value(&data, key, habit->days[d].completed, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
rini_save(data, path);
|
||||
rini_unload(&data);
|
||||
inbe_storage_habits_save(habits);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -209,105 +147,25 @@ inbe_habits_add_seed(InbeHabits *habits, const char *id, const char *name,
|
||||
void
|
||||
inbe_habits_init(InbeHabits *habits)
|
||||
{
|
||||
rini_data data;
|
||||
char path[HABITS_PATH_SIZE];
|
||||
int needs_save = 0;
|
||||
|
||||
if(habits == NULL)
|
||||
return;
|
||||
|
||||
data_init();
|
||||
if(inbe_storage_habits_load(habits)) {
|
||||
if(habits->selected < 0 || habits->selected >= habits->count)
|
||||
habits->selected = 0;
|
||||
habits->loaded = 1;
|
||||
return;
|
||||
}
|
||||
memset(habits, 0, sizeof(*habits));
|
||||
habits_path(path, sizeof(path));
|
||||
data = rini_load(path);
|
||||
|
||||
habits->count = rini_get_value_fallback(data, "count", 0);
|
||||
if(habits->count < 0 || habits->count > INBE_HABIT_MAX)
|
||||
habits->count = 0;
|
||||
habits->selected = rini_get_value_fallback(data, "selected", 0);
|
||||
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
InbeHabit *habit = &habits->items[i];
|
||||
char key[96];
|
||||
const char *text;
|
||||
|
||||
snprintf(key, sizeof(key), "habit_%d_id", i);
|
||||
text = rini_get_value_text(data, key);
|
||||
copy_text(habit->id, sizeof(habit->id), text != NULL && text[0] != '\0' ? text : "habit");
|
||||
|
||||
snprintf(key, sizeof(key), "habit_%d_name", i);
|
||||
text = rini_get_value_text(data, key);
|
||||
copy_text(habit->name, sizeof(habit->name), text != NULL && text[0] != '\0' ? text : habit->id);
|
||||
|
||||
snprintf(key, sizeof(key), "habit_%d_color_r", i);
|
||||
habit->color.r = (unsigned char)rini_get_value_fallback(data, key, 99);
|
||||
snprintf(key, sizeof(key), "habit_%d_color_g", i);
|
||||
habit->color.g = (unsigned char)rini_get_value_fallback(data, key, 196);
|
||||
snprintf(key, sizeof(key), "habit_%d_color_b", i);
|
||||
habit->color.b = (unsigned char)rini_get_value_fallback(data, key, 165);
|
||||
habit->color.a = 255;
|
||||
|
||||
snprintf(key, sizeof(key), "habit_%d_sync_mode", i);
|
||||
text = rini_get_value_text(data, key);
|
||||
habit->sync_mode = text != NULL
|
||||
? rini_get_value_fallback(data, key, INBE_HABIT_SYNC_NONE)
|
||||
: INBE_HABIT_SYNC_NONE;
|
||||
if(habit->sync_mode < INBE_HABIT_SYNC_NONE || habit->sync_mode > INBE_HABIT_SYNC_ACTIVITY)
|
||||
habit->sync_mode = INBE_HABIT_SYNC_NONE;
|
||||
snprintf(key, sizeof(key), "habit_%d_sync_topic", i);
|
||||
habit->sync_topic = rini_get_value_fallback(data, key, INBE_HABIT_TOPIC_MIND);
|
||||
if(habit->sync_topic < 0 || habit->sync_topic >= INBE_HABIT_TOPIC_COUNT)
|
||||
habit->sync_topic = INBE_HABIT_TOPIC_MIND;
|
||||
snprintf(key, sizeof(key), "habit_%d_sync_activity", i);
|
||||
habit->sync_activity = rini_get_value_fallback(data, key, 0);
|
||||
if(habit->sync_activity < 0)
|
||||
habit->sync_activity = 0;
|
||||
if(text == NULL) {
|
||||
if(strcmp(habit->id, "mind") == 0 || strcmp(habit->name, "Mind") == 0) {
|
||||
habit->sync_mode = INBE_HABIT_SYNC_TOPIC;
|
||||
habit->sync_topic = INBE_HABIT_TOPIC_MIND;
|
||||
needs_save = 1;
|
||||
} else if(strcmp(habit->id, "yoga") == 0 || strcmp(habit->name, "Yoga") == 0) {
|
||||
habit->sync_mode = INBE_HABIT_SYNC_TOPIC;
|
||||
habit->sync_topic = INBE_HABIT_TOPIC_YOGA;
|
||||
needs_save = 1;
|
||||
} else if(strcmp(habit->id, "fitness") == 0 || strcmp(habit->name, "Fitness") == 0) {
|
||||
habit->sync_mode = INBE_HABIT_SYNC_TOPIC;
|
||||
habit->sync_topic = INBE_HABIT_TOPIC_FITNESS;
|
||||
needs_save = 1;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(key, sizeof(key), "habit_%d_day_count", i);
|
||||
habit->day_count = rini_get_value_fallback(data, key, 0);
|
||||
if(habit->day_count < 0 || habit->day_count > INBE_HABIT_MAX_DAYS)
|
||||
habit->day_count = 0;
|
||||
|
||||
for(int d = 0; d < habit->day_count; d++) {
|
||||
snprintf(key, sizeof(key), "habit_%d_day_%d_index", i, d);
|
||||
habit->days[d].day_index = rini_get_value_fallback(data, key, 0);
|
||||
snprintf(key, sizeof(key), "habit_%d_day_%d_completed", i, d);
|
||||
habit->days[d].completed = rini_get_value_fallback(data, key, 0) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
rini_unload(&data);
|
||||
|
||||
if(habits->count == 0) {
|
||||
inbe_habits_add_seed(habits, "mind", "Mind", (Color){126, 183, 230, 255},
|
||||
INBE_HABIT_TOPIC_MIND);
|
||||
inbe_habits_add_seed(habits, "yoga", "Yoga", (Color){208, 128, 80, 255},
|
||||
INBE_HABIT_TOPIC_YOGA);
|
||||
inbe_habits_add_seed(habits, "fitness", "Fitness", (Color){208, 96, 128, 255},
|
||||
INBE_HABIT_TOPIC_FITNESS);
|
||||
habits->selected = 0;
|
||||
inbe_habits_save(habits);
|
||||
}
|
||||
|
||||
if(habits->selected < 0 || habits->selected >= habits->count)
|
||||
habits->selected = 0;
|
||||
if(needs_save)
|
||||
inbe_habits_save(habits);
|
||||
inbe_habits_add_seed(habits, "mind", "Mind", (Color){126, 183, 230, 255},
|
||||
INBE_HABIT_TOPIC_MIND);
|
||||
inbe_habits_add_seed(habits, "yoga", "Yoga", (Color){208, 128, 80, 255},
|
||||
INBE_HABIT_TOPIC_YOGA);
|
||||
inbe_habits_add_seed(habits, "fitness", "Fitness", (Color){208, 96, 128, 255},
|
||||
INBE_HABIT_TOPIC_FITNESS);
|
||||
habits->selected = 0;
|
||||
habits->loaded = 1;
|
||||
inbe_habits_save(habits);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+1343
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,49 @@
|
||||
#ifndef INBE_STORAGE_H
|
||||
#define INBE_STORAGE_H
|
||||
|
||||
#include "raylib.h"
|
||||
#include <stddef.h>
|
||||
|
||||
enum {
|
||||
INBE_STORAGE_PATH_SIZE = 512,
|
||||
INBE_STORAGE_ID_SIZE = 64
|
||||
};
|
||||
|
||||
typedef void (*InbeStorageHistoryCallback)(const char *id,
|
||||
int year, int month, int day,
|
||||
int hour, int minute, int second,
|
||||
const int *rounds, int round_count,
|
||||
void *user);
|
||||
|
||||
int inbe_storage_init(const char *root);
|
||||
void inbe_storage_close(void);
|
||||
const char *inbe_storage_db_path(void);
|
||||
|
||||
int inbe_storage_get_setting_int(const char *key, int fallback);
|
||||
const char *inbe_storage_get_setting_text(const char *key);
|
||||
void inbe_storage_set_setting_int(const char *key, int value);
|
||||
void inbe_storage_set_setting_text(const char *key, const char *value);
|
||||
int inbe_storage_settings_empty(void);
|
||||
|
||||
int inbe_storage_save_session(const int *round_times, int round_count,
|
||||
char *out_id, size_t out_id_size);
|
||||
int inbe_storage_replace_session(const char *id, const int *round_times, int round_count);
|
||||
int inbe_storage_rename_session_time(const char *id, int hour, int minute);
|
||||
int inbe_storage_delete_session(const char *id);
|
||||
int inbe_storage_load_session(const char *id, int *round_times, int max_rounds,
|
||||
int *year, int *month, int *day,
|
||||
int *hour, int *minute, int *second);
|
||||
void inbe_storage_list_history(InbeStorageHistoryCallback callback, void *user);
|
||||
int inbe_storage_has_any(void);
|
||||
int inbe_storage_session_count(void);
|
||||
long long inbe_storage_total_size(void);
|
||||
long long inbe_storage_delete_all_sessions(void);
|
||||
|
||||
int inbe_storage_habits_empty(void);
|
||||
int inbe_storage_habits_load(void *habits);
|
||||
void inbe_storage_habits_save(const void *habits);
|
||||
|
||||
int inbe_storage_export_zip(const char *path);
|
||||
int inbe_storage_import_zip(const char *path);
|
||||
|
||||
#endif
|
||||
+69
-106
@@ -5,11 +5,9 @@
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#define FS_PATH_MAX 512
|
||||
@@ -51,110 +49,65 @@ extern Color c_text, c_bg, c_circle, c_button, c_button_hover, c_icon;
|
||||
* INTERNAL HELPER FUNCTIONS
|
||||
* ================================================================ */
|
||||
|
||||
/* Check if a directory name consists only of digits */
|
||||
static int
|
||||
name_is_digits(const char *name, int len)
|
||||
{
|
||||
int i;
|
||||
if(name == NULL)
|
||||
return 0;
|
||||
for(i = 0; i < len; i++) {
|
||||
if(name[i] == '\0' || name[i] < '0' || name[i] > '9')
|
||||
return 0;
|
||||
}
|
||||
return name[len] == '\0';
|
||||
}
|
||||
|
||||
/* Compare two history entries for sorting (newest first) */
|
||||
static int
|
||||
compare_history_entries(const void *a, const void *b)
|
||||
{
|
||||
const HistoryEntry *ea = a;
|
||||
const HistoryEntry *eb = b;
|
||||
return strcmp(eb->path, ea->path);
|
||||
if(ea->year != eb->year) return eb->year - ea->year;
|
||||
if(ea->month != eb->month) return eb->month - ea->month;
|
||||
if(ea->day != eb->day) return eb->day - ea->day;
|
||||
if(ea->hour != eb->hour) return eb->hour - ea->hour;
|
||||
if(ea->minute != eb->minute) return eb->minute - ea->minute;
|
||||
return eb->second - ea->second;
|
||||
}
|
||||
|
||||
/* Scan a day directory for session files */
|
||||
typedef struct ScanHistoryContext {
|
||||
HistoryEntry *entries;
|
||||
int *count;
|
||||
} ScanHistoryContext;
|
||||
|
||||
static void
|
||||
scan_history_day(HistoryEntry *entries, int *count, int year, int month, int day, const char *path)
|
||||
scan_history_callback(const char *path, int year, int month, int day,
|
||||
int hour, int minute, int second,
|
||||
const int *round_times, int round_count, void *user)
|
||||
{
|
||||
DIR *dir = opendir(path);
|
||||
struct dirent *ent;
|
||||
char child[FS_PATH_MAX];
|
||||
ScanHistoryContext *ctx = user;
|
||||
HistoryEntry entry;
|
||||
int total = 0;
|
||||
|
||||
if(dir == NULL)
|
||||
if(ctx == NULL || *ctx->count >= HISTORY_MAX_SESSIONS || round_times == NULL || round_count <= 0)
|
||||
return;
|
||||
|
||||
while((ent = readdir(dir)) != NULL && *count < HISTORY_MAX_SESSIONS) {
|
||||
if(ent->d_name[0] == '.')
|
||||
continue;
|
||||
snprintf(child, sizeof(child), "%s/%s", path, ent->d_name);
|
||||
if(strncmp(ent->d_name, "inbe-", 5) == 0) {
|
||||
/* Parse filename and add entry */
|
||||
const char *name = ent->d_name;
|
||||
int hh = 0, mm = 0, ss = 0;
|
||||
if(sscanf(name, "inbe-%2d%2d%2d", &hh, &mm, &ss) == 3) {
|
||||
HistoryEntry entry;
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
snprintf(entry.path, sizeof(entry.path), "%s", child);
|
||||
entry.year = year;
|
||||
entry.month = month;
|
||||
entry.day = day;
|
||||
entry.hour = hh;
|
||||
entry.minute = mm;
|
||||
entry.second = ss;
|
||||
history_load_session_file(child, &entry);
|
||||
if(entry.round_count > 0) {
|
||||
entries[*count] = entry;
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
snprintf(entry.path, sizeof(entry.path), "%s", path);
|
||||
entry.year = year;
|
||||
entry.month = month;
|
||||
entry.day = day;
|
||||
entry.hour = hour;
|
||||
entry.minute = minute;
|
||||
entry.second = second;
|
||||
entry.round_count = round_count > MaxRounds ? MaxRounds : round_count;
|
||||
for(int i = 0; i < entry.round_count; i++) {
|
||||
entry.rounds[i] = round_times[i];
|
||||
total += round_times[i];
|
||||
if(round_times[i] > entry.best)
|
||||
entry.best = round_times[i];
|
||||
}
|
||||
closedir(dir);
|
||||
entry.avg_seconds = entry.round_count > 0 ? total / entry.round_count : 0;
|
||||
ctx->entries[*ctx->count] = entry;
|
||||
(*ctx->count)++;
|
||||
}
|
||||
|
||||
/* Scan entire history tree and populate entries array */
|
||||
static void
|
||||
scan_history_tree(HistoryEntry *entries, int *count)
|
||||
{
|
||||
DIR *years = opendir(data_root());
|
||||
struct dirent *year;
|
||||
char ypath[FS_PATH_MAX];
|
||||
char mpath[FS_PATH_MAX];
|
||||
char dpath[FS_PATH_MAX];
|
||||
|
||||
ScanHistoryContext ctx;
|
||||
*count = 0;
|
||||
if(years == NULL)
|
||||
return;
|
||||
|
||||
while((year = readdir(years)) != NULL && *count < HISTORY_MAX_SESSIONS) {
|
||||
if(!name_is_digits(year->d_name, 4))
|
||||
continue;
|
||||
snprintf(ypath, sizeof(ypath), "%s/%s", data_root(), year->d_name);
|
||||
DIR *months = opendir(ypath);
|
||||
struct dirent *month;
|
||||
if(months == NULL)
|
||||
continue;
|
||||
while((month = readdir(months)) != NULL && *count < HISTORY_MAX_SESSIONS) {
|
||||
if(!name_is_digits(month->d_name, 2))
|
||||
continue;
|
||||
snprintf(mpath, sizeof(mpath), "%s/%s", ypath, month->d_name);
|
||||
DIR *days = opendir(mpath);
|
||||
struct dirent *day;
|
||||
if(days == NULL)
|
||||
continue;
|
||||
while((day = readdir(days)) != NULL && *count < HISTORY_MAX_SESSIONS) {
|
||||
if(!name_is_digits(day->d_name, 2))
|
||||
continue;
|
||||
snprintf(dpath, sizeof(dpath), "%s/%s", mpath, day->d_name);
|
||||
scan_history_day(entries, count, atoi(year->d_name), atoi(month->d_name), atoi(day->d_name), dpath);
|
||||
}
|
||||
closedir(days);
|
||||
}
|
||||
closedir(months);
|
||||
}
|
||||
closedir(years);
|
||||
ctx.entries = entries;
|
||||
ctx.count = count;
|
||||
data_list_history(scan_history_callback, &ctx);
|
||||
}
|
||||
|
||||
/* Check if history has entry for specific year */
|
||||
@@ -533,12 +486,14 @@ history_commit_edit(InbeApp *app, const HistoryEntry *entry)
|
||||
|
||||
snprintf(dir, sizeof(dir), "%s", entry->path);
|
||||
slash = strrchr(dir, '/');
|
||||
if(slash == NULL)
|
||||
return 0;
|
||||
*slash = '\0';
|
||||
|
||||
snprintf(new_path, sizeof(new_path), "%s/inbe-%02d%02d%02d",
|
||||
dir, hour, minute, entry->second);
|
||||
if(slash == NULL) {
|
||||
snprintf(new_path, sizeof(new_path), "inbe-%02d%02d%02d",
|
||||
hour, minute, entry->second);
|
||||
} else {
|
||||
*slash = '\0';
|
||||
snprintf(new_path, sizeof(new_path), "%s/inbe-%02d%02d%02d",
|
||||
dir, hour, minute, entry->second);
|
||||
}
|
||||
if(!data_rename_session(entry->path, new_path))
|
||||
return 0;
|
||||
|
||||
@@ -1022,10 +977,14 @@ history_open_latest(InbeApp *app)
|
||||
void
|
||||
history_load_session_file(const char *path, HistoryEntry *entry)
|
||||
{
|
||||
FILE *file;
|
||||
int value;
|
||||
int total = 0;
|
||||
int count = 0;
|
||||
int count;
|
||||
int year = 0;
|
||||
int month = 0;
|
||||
int day = 0;
|
||||
int hour = 0;
|
||||
int minute = 0;
|
||||
int second = 0;
|
||||
|
||||
if(entry == NULL)
|
||||
return;
|
||||
@@ -1035,20 +994,24 @@ history_load_session_file(const char *path, HistoryEntry *entry)
|
||||
for(int i = 0; i < MaxRounds; i++)
|
||||
entry->rounds[i] = 0;
|
||||
|
||||
file = fopen(path, "r");
|
||||
if(file == NULL)
|
||||
count = data_load_session(path, entry->rounds, MaxRounds,
|
||||
&year, &month, &day, &hour, &minute, &second);
|
||||
if(count <= 0)
|
||||
return;
|
||||
|
||||
while(count < MaxRounds && fscanf(file, "%d", &value) == 1) {
|
||||
if(value <= 0)
|
||||
continue;
|
||||
entry->rounds[count] = value;
|
||||
total += value;
|
||||
count++;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
snprintf(entry->path, sizeof(entry->path), "%s", path);
|
||||
entry->year = year;
|
||||
entry->month = month;
|
||||
entry->day = day;
|
||||
entry->hour = hour;
|
||||
entry->minute = minute;
|
||||
entry->second = second;
|
||||
entry->round_count = count;
|
||||
for(int i = 0; i < count; i++) {
|
||||
total += entry->rounds[i];
|
||||
if(entry->rounds[i] > entry->best)
|
||||
entry->best = entry->rounds[i];
|
||||
}
|
||||
if(count > 0)
|
||||
entry->avg_seconds = total / count;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "language_tab.h"
|
||||
#include "meditation_music.h"
|
||||
#include "locale.h"
|
||||
#include "storage.h"
|
||||
#include "flint_ui.h"
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(_WIN32) && !defined(PLATFORM_WEB)
|
||||
#define INBE_HAS_FLINT_FILE_DIALOG 1
|
||||
@@ -259,7 +260,7 @@ settings_draw_data_stats(int x, int y, int w)
|
||||
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID)
|
||||
{
|
||||
const char *storage_path = data_root();
|
||||
const char *storage_path = inbe_storage_db_path();
|
||||
const char *display_path = storage_path;
|
||||
char home_buf[FS_PATH_MAX];
|
||||
char storage_text[FS_PATH_MAX + 32];
|
||||
|
||||
Reference in new issue
Block a user