Compare commits

...
3 Commits
Author SHA1 Message Date
waozixyz f12ef05421 update version 2026-06-17 18:50:36 -03:00
waozixyz 1732b31031 improve and fix improt 2026-06-17 18:50:24 -03:00
waozixyz b14ca1c8c9 fix issues with runtime assets 2026-06-17 16:43:48 -03:00
31 changed files with 1292 additions and 45 deletions

No files matched your search

+5
View File
@@ -1,8 +1,13 @@
# Changelog
## [1.3.3] - 2026-06-17
### Fixed
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
## [1.3.2] - 2026-06-17
### Fixed
- Unified scroll containers so content stays out of scrollbar tracks and scroll positions clamp cleanly at the bottom.
- Android meditation audio downloads now show a localized network-permission/connectivity modal when the host cannot be resolved.
- Windows builds now support runtime meditation audio downloads.
## [1.3.1] - 2026-06-17
### Fixed
+10 -5
View File
@@ -72,6 +72,7 @@ SQLITE_INCLUDE := -I$(SQLITE_BUILD_DIR)
TEST_BIN_DIR := $(BUILD_BIN_DIR)/tests
STORAGE_IMPORT_TEST := $(TEST_BIN_DIR)/storage_import_test
FLINT_TEXT_SCALING_TEST := $(TEST_BIN_DIR)/flint_text_scaling_test
LOCALE_KEYS_TEST := $(TEST_BIN_DIR)/locale_keys_test
FLINT_RUNTIME_ASSET_CFLAGS := -DFLINT_HAS_LIBCURL=1 $(FLINT_CURL_CFLAGS)
FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
@@ -112,7 +113,7 @@ WINDOWS_CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ff
WEB_CFLAGS := $(filter-out -std=c99,$(CFLAGS)) -std=gnu99
LDFLAGS := -Wl,--gc-sections -s
WINDOWS_LDFLAGS := -Wl,--gc-sections -static -static-libgcc -mwindows
WINDOWS_LDLIBS := -lgdi32 -lwinmm -lopengl32 -luser32 -lshell32 -lole32 -lcomdlg32 -lcomctl32 -luuid -lm
WINDOWS_LDLIBS := -lgdi32 -lwinmm -lopengl32 -luser32 -lshell32 -lole32 -lcomdlg32 -lcomctl32 -luuid -lwininet -lm
ifneq ($(strip $(MCFGTHREADS)),)
WIN64_THREAD_LDFLAGS := -L$(MCFGTHREADS)/lib
else
@@ -175,9 +176,10 @@ appimage: $(APPIMAGE_TARGET)
run: $(TARGET)
./$(TARGET)
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST)
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST)
$(STORAGE_IMPORT_TEST)
$(FLINT_TEXT_SCALING_TEST)
$(LOCALE_KEYS_TEST)
$(STORAGE_IMPORT_TEST): tests/storage_import_test.c src/storage/storage.c src/storage/storage.h src/screens/habits_screen.c src/screens/habits_screen.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -ffunction-sections -fdata-sections \
@@ -193,6 +195,11 @@ $(FLINT_TEXT_SCALING_TEST): tests/flint_text_scaling_test.c flint/src/flint_text
tests/flint_text_scaling_test.c flint/src/flint_text.c flint/src/flint_clip.c flint/src/flint_scaling.c \
-Wl,--gc-sections -lm
$(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE \
-o $@ \
tests/locale_keys_test.c
$(BUILD_OBJ_DIR) $(LINUX_BIN_DIR) $(LINUX_DIST_DIR) $(LINUX_APPIMAGE_BUILD_DIR) $(WINDOWS_DIST_DIR) $(ANDROID_BUILD_DIR) $(TEST_BIN_DIR) $(WEB_OBJ_DIR) $(WEB_DIST_DIR):
mkdir -p $@
@@ -526,9 +533,7 @@ package-unpackaged-assets:
cd $(UNPACKAGED_AUDIO_DIR) && find . -mindepth 2 -type f -name '*.ogg' -exec zip -9 -r $(abspath $(MEDITATION_AUDIO_ZIP)) {} + && zip -9 -r $(abspath $(MEDITATION_AUDIO_ZIP)) LICENSE.md MANIFEST.txt
windows-runtime-assets-check:
@echo "Windows runtime asset downloads are not wired into this build yet"; \
echo "Refusing to build Windows binaries that cannot download meditation audio."; \
exit 1
@:
windows64: windows-runtime-assets-check $(WIN64_TARGET)
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 76 KiB

+2 -2
View File
@@ -35,8 +35,8 @@ android {
defaultConfig {
minSdk 19
targetSdk 35
versionCode 30
versionName "1.3.2"
versionCode 31
versionName "1.3.3"
}
@@ -0,0 +1,2 @@
### Fixed
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
+145 -1
View File
@@ -7,6 +7,8 @@
#if defined(_WIN32)
#include <direct.h>
#include <windows.h>
#include <wininet.h>
#define FLINT_MKDIR(path) _mkdir(path)
#else
#include <errno.h>
@@ -208,6 +210,128 @@ fetch_failed(emscripten_fetch_t *fetch)
}
#endif
#if defined(_WIN32) && !defined(__EMSCRIPTEN__)
typedef struct WindowsDownloadContext {
FlintRuntimeAssetDownload *download;
} WindowsDownloadContext;
static void
windows_set_last_error(FlintRuntimeAssetDownload *download, const char *prefix)
{
DWORD err = GetLastError();
if(download == NULL)
return;
snprintf(download->error, sizeof(download->error), "%s (%lu)",
prefix != NULL ? prefix : "Windows download failed",
(unsigned long)err);
}
static DWORD WINAPI
windows_download_thread_main(void *user_data)
{
WindowsDownloadContext *ctx = (WindowsDownloadContext *)user_data;
FlintRuntimeAssetDownload *download = ctx != NULL ? ctx->download : NULL;
HINTERNET internet = NULL;
HINTERNET request = NULL;
FILE *file = NULL;
char status_buf[32];
DWORD status_len = sizeof(status_buf);
DWORD status_index = 0;
char length_buf[64];
DWORD length_len = sizeof(length_buf);
DWORD length_index = 0;
BYTE buffer[32768];
DWORD bytes_read = 0;
BOOL read_ok;
free(ctx);
if(download == NULL)
return 0;
file = fopen(download->path, "wb");
if(file == NULL) {
snprintf(download->error, sizeof(download->error), "failed to open %.200s", download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
internet = InternetOpenA("flint-runtime-assets/1",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if(internet == NULL) {
fclose(file);
windows_set_last_error(download, "failed to initialize Windows networking");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
request = InternetOpenUrlA(internet, download->url, NULL, 0,
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_PRAGMA_NOCACHE,
0);
if(request == NULL) {
fclose(file);
InternetCloseHandle(internet);
remove(download->path);
windows_set_last_error(download, "Windows download failed");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
if(HttpQueryInfoA(request, HTTP_QUERY_STATUS_CODE, status_buf, &status_len, &status_index)) {
status_buf[sizeof(status_buf) - 1] = '\0';
download->http_status = strtol(status_buf, NULL, 10);
}
if(download->http_status < 200 || download->http_status >= 300) {
snprintf(download->error, sizeof(download->error), "HTTP %ld", download->http_status);
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
remove(download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
if(HttpQueryInfoA(request, HTTP_QUERY_CONTENT_LENGTH, length_buf, &length_len, &length_index)) {
length_buf[sizeof(length_buf) - 1] = '\0';
download->total_bytes = (size_t)strtoull(length_buf, NULL, 10);
}
while((read_ok = InternetReadFile(request, buffer, sizeof(buffer), &bytes_read)) && bytes_read > 0) {
if(fwrite(buffer, 1, bytes_read, file) != bytes_read) {
snprintf(download->error, sizeof(download->error), "failed to write %.200s", download->path);
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
remove(download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
download->bytes += (size_t)bytes_read;
}
if(!read_ok) {
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
remove(download->path);
windows_set_last_error(download, "Windows download failed");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
if(download->total_bytes == 0)
download->total_bytes = download->bytes;
download->status = FLINT_RUNTIME_ASSET_READY;
return 0;
}
#endif
#if defined(FLINT_HAS_LIBCURL) && !defined(__EMSCRIPTEN__)
typedef struct NativeDownloadContext {
FlintRuntimeAssetDownload *download;
@@ -251,7 +375,7 @@ curl_thread_main(void *user_data)
file = fopen(download->path, "wb");
if(file == NULL) {
snprintf(download->error, sizeof(download->error), "failed to open %s", download->path);
snprintf(download->error, sizeof(download->error), "failed to open %.200s", download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return NULL;
}
@@ -348,6 +472,26 @@ flint_runtime_asset_download(FlintRuntimeAssetDownload *download,
emscripten_fetch(&attr, download->url);
return 1;
}
#elif defined(_WIN32)
{
HANDLE thread;
WindowsDownloadContext *ctx = (WindowsDownloadContext *)calloc(1, sizeof(*ctx));
if(ctx == NULL) {
snprintf(download->error, sizeof(download->error), "out of memory");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
ctx->download = download;
thread = CreateThread(NULL, 0, windows_download_thread_main, ctx, 0, NULL);
if(thread == NULL) {
free(ctx);
windows_set_last_error(download, "failed to create download thread");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
CloseHandle(thread);
return 1;
}
#elif defined(FLINT_HAS_LIBCURL)
{
pthread_t thread;
+36
View File
@@ -303,6 +303,9 @@ Importovat data
[import_failed]
Import selhal
---
[imported_data]
Data importována
---
[imported_sessions]
Importováno %d sezení
---
@@ -312,6 +315,18 @@ Neplatný exportní soubor
[import_cancelled]
Import zrušen
---
[import_choice_title]
Importovat nastavení?
---
[import_choice_message]
Nalezeny data a nastavení.
---
[import_data_only_button]
Data
---
[import_data_settings_button]
Data+Nastavení
---
[export_cancelled]
Export cancelled
---
@@ -455,3 +470,24 @@ Smazat toto kolo? Tuto akci nelze vrátit.
[delete_button]
Smazat
---
[meditation_music_attribution]
Hudba od Elijah_K.
---
[theme_system]
Systém
---
[orientation_label]
Orientace
---
[orientation_system]
Systém
---
[orientation_portrait]
Na výšku
---
[orientation_landscape]
Na šířku
---
[orientation_sensor]
Senzor
---
+36
View File
@@ -303,6 +303,9 @@ Daten importieren
[import_failed]
Import fehlgeschlagen
---
[imported_data]
Daten importiert
---
[imported_sessions]
%d Sitzungen importiert
---
@@ -312,6 +315,18 @@ Ungültige Exportdatei
[import_cancelled]
Import cancelled
---
[import_choice_title]
Einstellungen importieren?
---
[import_choice_message]
Daten und Einstellungen gefunden.
---
[import_data_only_button]
Daten
---
[import_data_settings_button]
Daten+Einstellungen
---
[export_cancelled]
Export cancelled
---
@@ -455,3 +470,24 @@ Diese Runde löschen? Das kann nicht rückgängig gemacht werden.
[delete_button]
Löschen
---
[meditation_music_attribution]
Musik von Elijah_K.
---
[theme_system]
System
---
[orientation_label]
Ausrichtung
---
[orientation_system]
System
---
[orientation_portrait]
Hochformat
---
[orientation_landscape]
Querformat
---
[orientation_sensor]
Sensor
---
+15
View File
@@ -324,6 +324,9 @@ Import Data
[import_failed]
Import failed
---
[imported_data]
Imported data
---
[imported_sessions]
Imported %d sessions
---
@@ -333,6 +336,18 @@ Invalid export file
[import_cancelled]
Import cancelled
---
[import_choice_title]
Import settings?
---
[import_choice_message]
Data and settings found.
---
[import_data_only_button]
Data
---
[import_data_settings_button]
Data+Settings
---
[export_cancelled]
Export cancelled
---
+36
View File
@@ -303,6 +303,9 @@ Importar datos
[import_failed]
Error al importar
---
[imported_data]
Datos importados
---
[imported_sessions]
%d sesiones importadas
---
@@ -312,6 +315,18 @@ Archivo de exportación no válido
[import_cancelled]
Import cancelled
---
[import_choice_title]
¿Importar ajustes?
---
[import_choice_message]
Datos y ajustes encontrados.
---
[import_data_only_button]
Datos
---
[import_data_settings_button]
Datos+Ajustes
---
[export_cancelled]
Export cancelled
---
@@ -455,3 +470,24 @@ Recuento de sesiones: %d
[delete_button]
Eliminar
---
[meditation_music_attribution]
Música de Elijah_K.
---
[theme_system]
Sistema
---
[orientation_label]
Orientación
---
[orientation_system]
Sistema
---
[orientation_portrait]
Vertical
---
[orientation_landscape]
Horizontal
---
[orientation_sensor]
Sensor
---
+36
View File
@@ -303,6 +303,9 @@ Importer les données
[import_failed]
Échec de l'import
---
[imported_data]
Données importées
---
[imported_sessions]
%d sessions importées
---
@@ -312,6 +315,18 @@ Fichier d'export invalide
[import_cancelled]
Import annulé
---
[import_choice_title]
Importer les réglages ?
---
[import_choice_message]
Données et réglages trouvés.
---
[import_data_only_button]
Données
---
[import_data_settings_button]
Données+Réglages
---
[export_cancelled]
Export cancelled
---
@@ -455,3 +470,24 @@ Supprimer ce cycle ? Cette action est irréversible.
[delete_button]
Supprimer
---
[meditation_music_attribution]
Musique par Elijah_K.
---
[theme_system]
Système
---
[orientation_label]
Orientation
---
[orientation_system]
Système
---
[orientation_portrait]
Portrait
---
[orientation_landscape]
Paysage
---
[orientation_sensor]
Capteur
---
+36
View File
@@ -303,6 +303,9 @@ Impor Data
[import_failed]
Impor gagal
---
[imported_data]
Data diimpor
---
[imported_sessions]
Mengimpor %d sesi
---
@@ -312,6 +315,18 @@ File ekspor tidak valid
[import_cancelled]
Impor dibatalkan
---
[import_choice_title]
Impor pengaturan?
---
[import_choice_message]
Data dan pengaturan ditemukan.
---
[import_data_only_button]
Data
---
[import_data_settings_button]
Data+Pengaturan
---
[export_cancelled]
Export cancelled
---
@@ -455,3 +470,24 @@ Hapus ronde ini? Tidak dapat dibatalkan.
[delete_button]
Hapus
---
[meditation_music_attribution]
Musik oleh Elijah_K.
---
[theme_system]
Sistem
---
[orientation_label]
Orientasi
---
[orientation_system]
Sistem
---
[orientation_portrait]
Potret
---
[orientation_landscape]
Lanskap
---
[orientation_sensor]
Sensor
---
+18
View File
@@ -319,6 +319,9 @@ Importa Dati
[import_failed]
Importazione fallita
---
[imported_data]
Dati importati
---
[imported_sessions]
Importate %d sessioni
---
@@ -328,6 +331,18 @@ File di esportazione non valido
[import_cancelled]
Importazione annullata
---
[import_choice_title]
Importare impostazioni?
---
[import_choice_message]
Dati e impostazioni trovati.
---
[import_data_only_button]
Dati
---
[import_data_settings_button]
Dati+Impostazioni
---
[export_cancelled]
Esportazione annullata
---
@@ -471,3 +486,6 @@ Eliminare questo round? Questa azione non può essere annullata.
[delete_button]
Elimina
---
[meditation_music_attribution]
Musica di Elijah_K.
---
+37
View File
@@ -303,6 +303,9 @@ In / Out
[import_failed]
インポートに失敗しました
---
[imported_data]
データをインポートしました
---
[imported_sessions]
%dセッションをインポートしました
---
@@ -312,6 +315,18 @@ In / Out
[import_cancelled]
Import cancelled
---
[import_choice_title]
設定もインポートしますか?
---
[import_choice_message]
データと設定があります。
---
[import_data_only_button]
データ
---
[import_data_settings_button]
データ+設定
---
[export_cancelled]
Export cancelled
---
@@ -448,3 +463,25 @@ Inner Breeze データ書き出し
---
[delete_button]
削除
---
[meditation_music_attribution]
音楽: Elijah_K.
---
[theme_system]
システム
---
[orientation_label]
向き
---
[orientation_system]
システム
---
[orientation_portrait]
縦向き
---
[orientation_landscape]
横向き
---
[orientation_sensor]
センサー
---
+18
View File
@@ -319,6 +319,9 @@ In / Out
[import_failed]
가져오기 실패
---
[imported_data]
데이터를 가져왔습니다
---
[imported_sessions]
%d개 세션을 가져왔습니다
---
@@ -328,6 +331,18 @@ In / Out
[import_cancelled]
가져오기 취소됨
---
[import_choice_title]
설정을 가져올까요?
---
[import_choice_message]
데이터와 설정을 찾았습니다.
---
[import_data_only_button]
데이터
---
[import_data_settings_button]
데이터+설정
---
[export_cancelled]
내보내기 취소됨
---
@@ -470,3 +485,6 @@ Inner Breeze 데이터 내보내기
[delete_button]
삭제
---
[meditation_music_attribution]
음악: Elijah_K.
---
+36
View File
@@ -303,6 +303,9 @@ Importar dados
[import_failed]
Falha ao importar
---
[imported_data]
Dados importados
---
[imported_sessions]
%d sessões importadas
---
@@ -312,6 +315,18 @@ Arquivo de exportação inválido
[import_cancelled]
Importação cancelada
---
[import_choice_title]
Importar configurações?
---
[import_choice_message]
Dados e configurações encontrados.
---
[import_data_only_button]
Dados
---
[import_data_settings_button]
Dados+Config.
---
[export_cancelled]
Export cancelled
---
@@ -455,3 +470,24 @@ Excluir esta rodada? Isso não pode ser desfeito.
[delete_button]
Excluir
---
[meditation_music_attribution]
Música por Elijah_K.
---
[theme_system]
Sistema
---
[orientation_label]
Orientação
---
[orientation_system]
Sistema
---
[orientation_portrait]
Retrato
---
[orientation_landscape]
Paisagem
---
[orientation_sensor]
Sensor
---
+37
View File
@@ -303,6 +303,9 @@ In / Out
[import_failed]
导入失败
---
[imported_data]
数据已导入
---
[imported_sessions]
已导入 %d 个会话
---
@@ -312,6 +315,18 @@ In / Out
[import_cancelled]
Import cancelled
---
[import_choice_title]
导入设置?
---
[import_choice_message]
找到数据和设置。
---
[import_data_only_button]
数据
---
[import_data_settings_button]
数据+设置
---
[export_cancelled]
Export cancelled
---
@@ -446,3 +461,25 @@ Inner Breeze 数据导出
---
[delete_button]
删除
---
[meditation_music_attribution]
音乐来自 Elijah_K。
---
[theme_system]
系统
---
[orientation_label]
方向
---
[orientation_system]
系统
---
[orientation_portrait]
竖屏
---
[orientation_landscape]
横屏
---
[orientation_sensor]
传感器
---
+21
View File
@@ -673,6 +673,27 @@ load_settings(InbeApp *app)
save_settings(app);
}
void
app_reload_after_import(InbeApp *app, int reload_settings)
{
if(app == NULL)
return;
if(reload_settings) {
load_settings(app);
reset_settings_preview(app);
update_session_sounds(app);
}
inbe_habits_init(&app->habits);
if(app->habit_detail_index >= app->habits.count)
app->habit_detail_index = -1;
if(app->habits.selected < 0 || app->habits.selected >= app->habits.count)
app->habits.selected = app->habits.count > 0 ? 0 : -1;
app->habit_session_edit_active = 0;
app->habit_edit_active = 0;
}
static Texture2D
load_pixel_texture_from_asset(const char *path)
{
+2
View File
@@ -60,6 +60,7 @@ typedef enum {
UIModalConfirmDeleteHabit,
UIModalEditProgressiveStartSpeed,
UIModalMeditationNetworkError,
UIModalConfirmImportDataSettings,
} UIModalType;
typedef struct {
@@ -243,6 +244,7 @@ int clampi(int x, int min, int max);
int int_from_count(const char src[4]);
void count_from_int(char dst[4], int value);
void save_settings(InbeApp *app);
void app_reload_after_import(InbeApp *app, int reload_settings);
void reset_settings_preview(InbeApp *app);
void update_preview_bounds(Inbe *inbe, int content_w, int max_h);
void apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds);
+2 -2
View File
@@ -3,7 +3,7 @@
#define INBE_VERSION_MAJOR 1
#define INBE_VERSION_MINOR 3
#define INBE_VERSION_PATCH 2
#define INBE_VERSION_STRING "1.3.2"
#define INBE_VERSION_PATCH 3
#define INBE_VERSION_STRING "1.3.3"
#endif
+129 -21
View File
@@ -153,6 +153,8 @@ settings_draw_progressive_start_speed_editor(InbeApp *app)
static char unified_status[256] = "";
static char unified_detail[256] = "";
static int unified_status_type = 0;
static char pending_import_path[FS_PATH_MAX] = "";
static DataImportInfo pending_import_info;
/* Helper functions for unified status system */
void settings_screen_set_status_success(const char *message, const char *detail) {
@@ -190,6 +192,109 @@ settings_screen_clear_status(void)
unified_status_type = 0;
}
static void
settings_clear_pending_import(void)
{
pending_import_path[0] = '\0';
memset(&pending_import_info, 0, sizeof(pending_import_info));
}
static void
settings_import_success(InbeApp *app, int imported_settings)
{
app_reload_after_import(app, imported_settings);
settings_screen_set_status_success(locale_get("imported_data"), NULL);
TraceLog(LOG_INFO, "DATA: Import successful");
}
static int
settings_perform_import(InbeApp *app, const char *path, DataImportMode mode)
{
if(app == NULL || path == NULL || path[0] == '\0') {
settings_screen_set_status_error(locale_get("import_invalid_file"));
return 0;
}
if(data_import_with_mode(path, mode)) {
settings_import_success(app, mode == DATA_IMPORT_DATA_AND_SETTINGS);
return 1;
}
settings_screen_set_status_error(locale_get("import_failed"));
TraceLog(LOG_ERROR, "DATA: Import failed");
return 0;
}
static void
settings_begin_import_for_path(InbeApp *app, const char *path)
{
DataImportInfo info;
if(app == NULL || path == NULL || path[0] == '\0') {
settings_screen_set_status_error(locale_get("import_invalid_file"));
return;
}
memset(&info, 0, sizeof(info));
if(!data_inspect_import(path, &info) || !info.valid) {
settings_screen_set_status_error(locale_get("import_invalid_file"));
TraceLog(LOG_WARNING, "DATA: Invalid import file selected");
return;
}
if((info.has_sessions || info.has_habits) && info.has_settings) {
snprintf(pending_import_path, sizeof(pending_import_path), "%s", path);
pending_import_info = info;
app->modal.active = 1;
app->modal.type = UIModalConfirmImportDataSettings;
app->modal.selected_button = 0;
settings_screen_clear_status();
return;
}
settings_perform_import(app, path, DATA_IMPORT_DATA_ONLY);
}
static int
settings_draw_import_choice_modal(InbeApp *app)
{
FlintUIPanelFrame frame;
int font = flint_ui_font();
int msg_y;
int msg_x;
const char *message = locale_get("import_choice_message");
int row_gap = flint_px(10);
int btn_h = flint_px(36);
int btn_y;
int btn_w;
int hover = 0;
(void)app;
frame = ui_draw_modal_frame(flint_px(320), flint_px(232),
locale_get("import_choice_title"),
(Texture2D){0}, (Texture2D){0});
msg_x = frame.content_x;
msg_y = frame.content_y;
flint_text_draw(message, msg_x, msg_y, font, theme_get_text());
btn_y = frame.y + frame.h - flint_px(24) - btn_h * 2 - row_gap;
btn_w = (frame.content_w - row_gap) / 2;
if(ui_draw_generic_button(frame.content_x, btn_y, btn_w, btn_h,
locale_get("cancel_button"),
UI_BUTTON_STYLE_SECONDARY, 0, &hover))
return 1;
if(ui_draw_generic_button(frame.content_x + btn_w + row_gap, btn_y, btn_w, btn_h,
locale_get("import_data_only_button"),
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
return 2;
if(ui_draw_generic_button(frame.content_x, btn_y + btn_h + row_gap,
frame.content_w, btn_h,
locale_get("import_data_settings_button"),
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
return 3;
return 0;
}
static void
settings_draw_status(int x, int *y)
{
@@ -362,7 +467,7 @@ settings_apply_file_dialog_theme(InbeApp *app)
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
static void
settings_screen_handle_android_import(void)
settings_screen_handle_android_import(InbeApp *app)
{
char import_path[FS_PATH_MAX];
int import_result = android_import_poll_result(import_path, sizeof(import_path));
@@ -380,15 +485,7 @@ settings_screen_handle_android_import(void)
return;
}
if(data_import(import_path)) {
char import_message[128];
locale_format(import_message, sizeof(import_message), "imported_sessions", data_get_session_count());
settings_screen_set_status_success(import_message, NULL);
TraceLog(LOG_INFO, "DATA: Android import successful");
} else {
settings_screen_set_status_error(locale_get("import_failed"));
TraceLog(LOG_ERROR, "DATA: Android import failed");
}
settings_begin_import_for_path(app, import_path);
}
#endif
@@ -472,16 +569,7 @@ settings_draw_pending_file_dialog(InbeApp *app)
if(result == 1) {
const char *path = flint_file_dialog_get_path(&import_dlg);
if(path != NULL && path[0] != '\0') {
if(data_import(path)) {
char import_message[128];
locale_format(import_message, sizeof(import_message),
"imported_sessions", data_get_session_count());
settings_screen_set_status_success(import_message, NULL);
TraceLog(LOG_INFO, "DATA: Import successful");
} else {
settings_screen_set_status_error(locale_get("import_failed"));
TraceLog(LOG_ERROR, "DATA: Import failed");
}
settings_begin_import_for_path(app, path);
} else {
settings_screen_set_status_error(locale_get("import_invalid_file"));
TraceLog(LOG_WARNING, "DATA: No file selected for import");
@@ -924,7 +1012,7 @@ settings_screen_draw(InbeApp *app)
#endif
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
settings_screen_handle_android_import();
settings_screen_handle_android_import(app);
#endif
if(content_viewport_h < 0)
@@ -1128,6 +1216,26 @@ settings_screen_draw(InbeApp *app)
}
ui_set_dropdown_clip_top(0);
if(app->modal.active && app->modal.type == UIModalConfirmImportDataSettings) {
int modal_result = settings_draw_import_choice_modal(app);
if(modal_result == 1) {
app->modal.active = 0;
app->modal.type = UIModalNone;
settings_clear_pending_import();
settings_screen_set_status_error(locale_get("import_cancelled"));
} else if(modal_result == 2 || modal_result == 3) {
char import_path[FS_PATH_MAX];
DataImportMode mode = modal_result == 3
? DATA_IMPORT_DATA_AND_SETTINGS
: DATA_IMPORT_DATA_ONLY;
snprintf(import_path, sizeof(import_path), "%s", pending_import_path);
app->modal.active = 0;
app->modal.type = UIModalNone;
settings_clear_pending_import();
settings_perform_import(app, import_path, mode);
}
}
if(app->modal.active && app->modal.type == UIModalConfirmDeleteData) {
int modal_result = ui_draw_modal(locale_get("delete_all_data_title"),
locale_get("delete_all_data_message"),
+33 -1
View File
@@ -235,9 +235,41 @@ data_validate_import_file(const char *path)
int
data_import(const char *path)
{
return data_import_with_mode(path, DATA_IMPORT_DATA_ONLY);
}
int
data_import_with_mode(const char *path, DataImportMode mode)
{
data_init();
return inbe_storage_import_zip(path);
return inbe_storage_import_zip_ex(
path,
mode == DATA_IMPORT_DATA_AND_SETTINGS
? INBE_STORAGE_IMPORT_DATA_AND_SETTINGS
: INBE_STORAGE_IMPORT_DATA_ONLY);
}
int
data_inspect_import(const char *path, DataImportInfo *info)
{
InbeStorageImportInfo storage_info;
data_init();
if(info != NULL)
memset(info, 0, sizeof(*info));
if(!inbe_storage_inspect_import(path, &storage_info))
return 0;
if(info != NULL) {
info->valid = storage_info.valid;
info->has_sessions = storage_info.has_sessions;
info->has_habits = storage_info.has_habits;
info->has_settings = storage_info.has_settings;
info->session_count = storage_info.session_count;
info->habit_count = storage_info.habit_count;
info->setting_count = storage_info.setting_count;
}
return 1;
}
typedef struct DbListSessionContext {
+17
View File
@@ -4,6 +4,21 @@
#include <stddef.h>
#include "breath_engine.h"
typedef enum DataImportMode {
DATA_IMPORT_DATA_ONLY = 0,
DATA_IMPORT_DATA_AND_SETTINGS = 1
} DataImportMode;
typedef struct DataImportInfo {
int valid;
int has_sessions;
int has_habits;
int has_settings;
int session_count;
int habit_count;
int setting_count;
} DataImportInfo;
void data_init(void);
const char *data_root(void);
const char *data_today_dir(void);
@@ -22,6 +37,8 @@ long long data_delete_all(void);
void data_default_export_filename(char *out, size_t out_size);
int data_export(const char *path);
int data_import(const char *path);
int data_import_with_mode(const char *path, DataImportMode mode);
int data_inspect_import(const char *path, DataImportInfo *info);
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);
+260 -9
View File
@@ -198,6 +198,100 @@ source_table_has_column(sqlite3 *db, const char *table, const char *column)
return found;
}
static int
source_table_exists(sqlite3 *db, const char *table)
{
sqlite3_stmt *stmt = NULL;
int found = 0;
if(db == NULL || table == NULL)
return 0;
if(sqlite3_prepare_v2(db,
"SELECT 1 FROM sqlite_master WHERE type='table' AND name=?1 LIMIT 1",
-1, &stmt, NULL) != SQLITE_OK)
return 0;
sqlite3_bind_text(stmt, 1, table, -1, SQLITE_TRANSIENT);
found = sqlite3_step(stmt) == SQLITE_ROW;
sqlite3_finalize(stmt);
return found;
}
static int
source_count_rows(sqlite3 *db, const char *sql)
{
sqlite3_stmt *stmt = NULL;
int count = 0;
if(db == NULL || sql == NULL)
return 0;
if(sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK)
return 0;
if(sqlite3_step(stmt) == SQLITE_ROW)
count = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
return count;
}
static const char *const importable_setting_keys[] = {
"speed",
"max_rounds",
"max_breaths",
"pause_seconds",
"sound_volume",
"tutorial_seen",
"exercise_manual_seen_mask",
"theme",
"dark_mode",
"theme_mode",
"orientation_mode",
"main_tab",
"fullscreen",
"on_screen_keyboard",
"progressive_speed",
"progressive_start_speed",
"breath_animation",
"advanced_session_controls",
"hold_display_mode",
"exercise_type",
"meditation_music_enabled",
"meditation_music_shuffle",
"meditation_music_track",
"play_in_background",
"language",
"practice_category_tab"
};
static int
setting_key_importable(const char *key)
{
if(key == NULL || key[0] == '\0')
return 0;
for(size_t i = 0; i < sizeof(importable_setting_keys) / sizeof(importable_setting_keys[0]); i++) {
if(strcmp(key, importable_setting_keys[i]) == 0)
return 1;
}
return 0;
}
static int
source_count_importable_settings(sqlite3 *db)
{
sqlite3_stmt *stmt = NULL;
int count = 0;
if(db == NULL || !source_table_exists(db, "settings"))
return 0;
if(sqlite3_prepare_v2(db, "SELECT DISTINCT key FROM settings", -1, &stmt, NULL) != SQLITE_OK)
return 0;
while(sqlite3_step(stmt) == SQLITE_ROW) {
const char *key = (const char *)sqlite3_column_text(stmt, 0);
if(setting_key_importable(key))
count++;
}
sqlite3_finalize(stmt);
return count;
}
static long long
now_seconds(void)
{
@@ -1448,12 +1542,94 @@ import_tickmate_db(sqlite3 *src)
}
static int
import_sqlite_db_file(const char *db_path)
import_settings_from_source(sqlite3 *src)
{
sqlite3_stmt *stmt = NULL;
sqlite3_stmt *write_stmt = NULL;
int imported = 0;
long long imported_at = now_seconds();
if(src == NULL || g_storage.db == NULL || !source_table_exists(src, "settings"))
return 0;
if(sqlite3_prepare_v2(src, "SELECT key,value FROM settings", -1, &stmt, NULL) != SQLITE_OK)
return 0;
exec_sql("BEGIN IMMEDIATE");
while(sqlite3_step(stmt) == SQLITE_ROW) {
const char *key = (const char *)sqlite3_column_text(stmt, 0);
const char *value = (const char *)sqlite3_column_text(stmt, 1);
if(!setting_key_importable(key))
continue;
if(sqlite3_prepare_v2(g_storage.db,
"INSERT INTO settings(user_id,key,value,updated_at) VALUES(?1,?2,?3,?4) "
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value,updated_at=excluded.updated_at",
-1, &write_stmt, NULL) != SQLITE_OK)
continue;
bind_text(write_stmt, 1, g_storage.user_id);
bind_text(write_stmt, 2, key);
bind_text(write_stmt, 3, value != NULL ? value : "");
sqlite3_bind_int64(write_stmt, 4, imported_at);
if(sqlite3_step(write_stmt) == SQLITE_DONE)
imported++;
sqlite3_finalize(write_stmt);
write_stmt = NULL;
}
sqlite3_finalize(stmt);
sqlite3_finalize(write_stmt);
exec_sql("COMMIT");
return imported;
}
static int
inspect_sqlite_db_file(const char *db_path, InbeStorageImportInfo *info)
{
sqlite3 *src = NULL;
int ok = 0;
if(info != NULL)
memset(info, 0, sizeof(*info));
if(db_path == NULL || db_path[0] == '\0' || info == NULL)
return 0;
if(sqlite3_open(db_path, &src) != SQLITE_OK)
goto done;
if(source_table_exists(src, "sessions") && source_table_exists(src, "session_rounds")) {
info->session_count = source_count_rows(src, "SELECT COUNT(*) FROM sessions WHERE deleted_at=0");
info->habit_count = source_table_exists(src, "habits")
? source_count_rows(src, "SELECT COUNT(*) FROM habits WHERE deleted_at=0")
: 0;
info->setting_count = source_count_importable_settings(src);
info->has_sessions = info->session_count > 0;
info->has_habits = info->habit_count > 0;
info->has_settings = info->setting_count > 0;
info->valid = info->has_sessions || info->has_habits || info->has_settings;
ok = info->valid;
goto done;
}
if(source_table_has_column(src, "tracks", "name") &&
source_table_has_column(src, "ticks", "_track_id")) {
info->habit_count = source_count_rows(src, "SELECT COUNT(*) FROM tracks WHERE enabled!=0");
info->has_habits = info->habit_count > 0;
info->valid = info->has_habits;
ok = info->valid;
}
done:
if(src != NULL)
sqlite3_close(src);
return ok;
}
static int
import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
{
sqlite3 *src = NULL;
sqlite3_stmt *stmt = NULL;
sqlite3_stmt *hstmt = NULL;
int ok = 0;
int imported_settings = 0;
if(db_path == NULL || db_path[0] == '\0')
return 0;
@@ -1494,15 +1670,21 @@ import_sqlite_db_file(const char *db_path)
sqlite3_finalize(stmt);
stmt = NULL;
if(sqlite3_prepare_v2(src,
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order "
"FROM habits WHERE deleted_at=0 ORDER BY sort_order,id",
-1, &stmt, NULL) == SQLITE_OK) {
if(source_table_exists(src, "habits")) {
int has_sync_activity = source_table_has_column(src, "habits", "sync_activity");
const char *habit_sql =
has_sync_activity
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
: "SELECT id,name,color_r,color_g,color_b,sync_mode,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id";
if(sqlite3_prepare_v2(src, habit_sql, -1, &stmt, NULL) != SQLITE_OK)
goto after_habits;
exec_sql("BEGIN IMMEDIATE");
while(sqlite3_step(stmt) == SQLITE_ROW) {
const char *import_habit_id = (const char *)sqlite3_column_text(stmt, 0);
const char *name = (const char *)sqlite3_column_text(stmt, 1);
char local_habit_id[INBE_STORAGE_ID_SIZE];
int sync_activity = has_sync_activity ? sqlite3_column_int(stmt, 6) : 0;
int sort_order = has_sync_activity ? sqlite3_column_int(stmt, 7) : sqlite3_column_int(stmt, 6);
if(import_habit_id == NULL || import_habit_id[0] == '\0' ||
name == NULL || name[0] == '\0')
@@ -1522,8 +1704,8 @@ import_sqlite_db_file(const char *db_path)
sqlite3_bind_int(hstmt, 5, sqlite3_column_int(stmt, 3));
sqlite3_bind_int(hstmt, 6, sqlite3_column_int(stmt, 4));
sqlite3_bind_int(hstmt, 7, sqlite3_column_int(stmt, 5));
sqlite3_bind_int(hstmt, 8, sqlite3_column_int(stmt, 6));
sqlite3_bind_int(hstmt, 9, sqlite3_column_int(stmt, 7));
sqlite3_bind_int(hstmt, 8, sync_activity);
sqlite3_bind_int(hstmt, 9, sort_order);
if(sqlite3_step(hstmt) == SQLITE_DONE)
ok = 1;
sqlite3_finalize(hstmt);
@@ -1553,6 +1735,12 @@ import_sqlite_db_file(const char *db_path)
}
exec_sql("COMMIT");
}
after_habits:
if(mode == INBE_STORAGE_IMPORT_DATA_AND_SETTINGS)
imported_settings = import_settings_from_source(src);
if(imported_settings > 0)
ok = 1;
goto done;
@@ -1575,6 +1763,12 @@ done:
int
inbe_storage_import_zip(const char *path)
{
return inbe_storage_import_zip_ex(path, INBE_STORAGE_IMPORT_DATA_ONLY);
}
int
inbe_storage_import_zip_ex(const char *path, InbeStorageImportMode mode)
{
mz_zip_archive archive;
int ok = 0;
@@ -1589,7 +1783,7 @@ inbe_storage_import_zip(const char *path)
}
memset(&archive, 0, sizeof(archive));
if(!mz_zip_reader_init_file(&archive, path, 0)) {
return import_sqlite_db_file(path);
return import_sqlite_db_file(path, mode);
}
if(mz_zip_reader_locate_file(&archive, "inbe-data/inbe.db", NULL, 0) >= 0) {
char *db_bytes;
@@ -1602,7 +1796,7 @@ inbe_storage_import_zip(const char *path)
if(db_bytes != NULL && fp != NULL && fwrite(db_bytes, 1, db_size, fp) == db_size) {
fclose(fp);
fp = NULL;
ok = import_sqlite_db_file(temp_path);
ok = import_sqlite_db_file(temp_path, mode);
remove(temp_path);
if(!ok)
TraceLog(LOG_ERROR, "DATA: archive contained inbe-data/inbe.db but sqlite import failed");
@@ -1621,6 +1815,63 @@ inbe_storage_import_zip(const char *path)
return ok;
}
int
inbe_storage_inspect_import(const char *path, InbeStorageImportInfo *info)
{
mz_zip_archive archive;
int ok = 0;
if(info != NULL)
memset(info, 0, sizeof(*info));
if(path == NULL || path[0] == '\0' || info == NULL || !path_exists(path))
return 0;
memset(&archive, 0, sizeof(archive));
if(!mz_zip_reader_init_file(&archive, path, 0))
return inspect_sqlite_db_file(path, info);
if(mz_zip_reader_locate_file(&archive, "inbe-data/inbe.db", NULL, 0) >= 0) {
char *db_bytes;
size_t db_size = 0;
char temp_path[INBE_STORAGE_PATH_SIZE];
FILE *fp;
db_bytes = mz_zip_reader_extract_file_to_heap(&archive, "inbe-data/inbe.db", &db_size, 0);
snprintf(temp_path, sizeof(temp_path), "%s/import-inspect-inbe.db", g_storage.root);
fp = fopen(temp_path, "wb");
if(db_bytes != NULL && fp != NULL && fwrite(db_bytes, 1, db_size, fp) == db_size) {
fclose(fp);
fp = NULL;
ok = inspect_sqlite_db_file(temp_path, info);
remove(temp_path);
}
if(fp != NULL)
fclose(fp);
free(db_bytes);
} else {
mz_uint file_count = mz_zip_reader_get_num_files(&archive);
for(mz_uint i = 0; i < file_count; i++) {
mz_zip_archive_file_stat stat;
int year;
int month;
int day;
int hour;
int minute;
int second;
if(!mz_zip_reader_file_stat(&archive, i, &stat) || stat.m_is_directory)
continue;
if(parse_legacy_session_filename(stat.m_filename, &year, &month, &day,
&hour, &minute, &second))
info->session_count++;
}
info->has_sessions = info->session_count > 0;
info->valid = info->has_sessions;
ok = info->valid;
}
mz_zip_reader_end(&archive);
return ok;
}
int
inbe_storage_init(const char *root)
{
+17
View File
@@ -16,6 +16,21 @@ typedef void (*InbeStorageSessionRecordCallback)(const char *id,
const int *rounds, int round_count,
void *user);
typedef enum InbeStorageImportMode {
INBE_STORAGE_IMPORT_DATA_ONLY = 0,
INBE_STORAGE_IMPORT_DATA_AND_SETTINGS = 1
} InbeStorageImportMode;
typedef struct InbeStorageImportInfo {
int valid;
int has_sessions;
int has_habits;
int has_settings;
int session_count;
int habit_count;
int setting_count;
} InbeStorageImportInfo;
int inbe_storage_init(const char *root);
void inbe_storage_close(void);
const char *inbe_storage_db_path(void);
@@ -53,5 +68,7 @@ void inbe_storage_mark_habits_initialized(void);
int inbe_storage_export_zip(const char *path);
int inbe_storage_import_zip(const char *path);
int inbe_storage_import_zip_ex(const char *path, InbeStorageImportMode mode);
int inbe_storage_inspect_import(const char *path, InbeStorageImportInfo *info);
#endif
+181
View File
@@ -0,0 +1,181 @@
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
MAX_KEYS = 1024,
MAX_KEY_LEN = 128,
MAX_PATH_LEN = 512
};
typedef struct LocaleKeys {
char keys[MAX_KEYS][MAX_KEY_LEN];
int count;
} LocaleKeys;
static int failures = 0;
static void
trim_newline(char *text)
{
size_t len;
if(text == NULL)
return;
len = strlen(text);
while(len > 0 && (text[len - 1] == '\n' || text[len - 1] == '\r')) {
text[len - 1] = '\0';
len--;
}
}
static int
parse_key_line(const char *line, char *out, size_t out_size)
{
const char *end;
size_t len;
if(line == NULL || out == NULL || out_size == 0 || line[0] != '[')
return 0;
end = strchr(line, ']');
if(end == NULL || end == line + 1)
return 0;
len = (size_t)(end - line - 1);
if(len >= out_size)
len = out_size - 1;
memcpy(out, line + 1, len);
out[len] = '\0';
return 1;
}
static int
keys_contains(const LocaleKeys *keys, const char *key)
{
if(keys == NULL || key == NULL)
return 0;
for(int i = 0; i < keys->count; i++) {
if(strcmp(keys->keys[i], key) == 0)
return 1;
}
return 0;
}
static void
keys_add(LocaleKeys *keys, const char *key)
{
if(keys == NULL || key == NULL || key[0] == '\0')
return;
if(keys_contains(keys, key))
return;
if(keys->count >= MAX_KEYS) {
fprintf(stderr, "FAIL too many locale keys\n");
failures++;
return;
}
snprintf(keys->keys[keys->count], sizeof(keys->keys[keys->count]), "%s", key);
keys->count++;
}
static int
line_has_value(const char *line)
{
if(line == NULL)
return 0;
while(*line == ' ' || *line == '\t')
line++;
return line[0] != '\0' && strcmp(line, "---") != 0;
}
static int
load_locale_keys(const char *path, LocaleKeys *keys)
{
FILE *fp;
char line[512];
char pending_key[MAX_KEY_LEN] = "";
int ok = 1;
if(keys == NULL)
return 0;
memset(keys, 0, sizeof(*keys));
fp = fopen(path, "rb");
if(fp == NULL) {
fprintf(stderr, "FAIL open %s\n", path);
failures++;
return 0;
}
while(fgets(line, sizeof(line), fp) != NULL) {
char key[MAX_KEY_LEN];
trim_newline(line);
if(parse_key_line(line, key, sizeof(key))) {
if(pending_key[0] != '\0') {
fprintf(stderr, "FAIL %s key [%s] has no value\n", path, pending_key);
failures++;
ok = 0;
}
keys_add(keys, key);
snprintf(pending_key, sizeof(pending_key), "%s", key);
} else if(pending_key[0] != '\0' && line_has_value(line)) {
pending_key[0] = '\0';
}
}
if(pending_key[0] != '\0') {
fprintf(stderr, "FAIL %s key [%s] has no value\n", path, pending_key);
failures++;
ok = 0;
}
fclose(fp);
return ok;
}
static void
check_locale_file(const LocaleKeys *english, const char *path)
{
LocaleKeys translated;
load_locale_keys(path, &translated);
for(int i = 0; i < english->count; i++) {
if(!keys_contains(&translated, english->keys[i])) {
fprintf(stderr, "FAIL %s missing [%s]\n", path, english->keys[i]);
failures++;
}
}
}
int
main(void)
{
LocaleKeys english;
DIR *dir;
struct dirent *entry;
if(!load_locale_keys("locales/en.txt", &english))
return 1;
dir = opendir("locales");
if(dir == NULL) {
fprintf(stderr, "FAIL open locales directory\n");
return 1;
}
while((entry = readdir(dir)) != NULL) {
char path[MAX_PATH_LEN];
const char *name = entry->d_name;
size_t len = strlen(name);
if(len <= 4 || strcmp(name + len - 4, ".txt") != 0)
continue;
if(strcmp(name, "en.txt") == 0 || strcmp(name, "index.txt") == 0)
continue;
snprintf(path, sizeof(path), "locales/%s", name);
check_locale_file(&english, path);
}
closedir(dir);
if(failures != 0) {
fprintf(stderr, "%d locale key test failure(s)\n", failures);
return 1;
}
printf("locale key tests passed\n");
return 0;
}
+121
View File
@@ -42,6 +42,18 @@ check_true(const char *label, int ok)
g_failures++;
}
static void
check_str(const char *label, const char *got, const char *want)
{
if(got == NULL && want == NULL)
return;
if(got != NULL && want != NULL && strcmp(got, want) == 0)
return;
fprintf(stderr, "FAIL %s: got %s, want %s\n",
label, got != NULL ? got : "(null)", want != NULL ? want : "(null)");
g_failures++;
}
static int
ascii_equal_ci(const char *a, const char *b)
{
@@ -326,6 +338,114 @@ test_habit_name_merge_import(void)
remove_tree(dest);
}
static void
write_multi_habit_source_database(const char *root, const char *zip_path)
{
int rounds[] = {77};
InbeHabits habits;
check_true("init multi habit source", inbe_storage_init(root));
check_true("save multi habit source session",
inbe_storage_save_session_for_activity(rounds, 1, 0, 1, NULL, 0));
memset(&habits, 0, sizeof(habits));
check_int("add meditation habit",
inbe_habits_add_custom(&habits, "Meditation",
(Color){224, 124, 104, 255},
INBE_HABIT_SYNC_ACTIVITIES,
(1 << 0) | (1 << 1)),
0);
check_int("add push ups habit",
inbe_habits_add_custom(&habits, "Push ups",
(Color){180, 132, 220, 255},
INBE_HABIT_SYNC_NONE, 0),
1);
check_int("add cold shower habit",
inbe_habits_add_custom(&habits, "Cold Shower",
(Color){99, 196, 165, 255},
INBE_HABIT_SYNC_NONE, 0),
2);
inbe_habit_set_day(&habits, 0, 20260617, 1);
inbe_habit_set_day(&habits, 1, 20260617, 1);
inbe_habit_set_day(&habits, 2, 20260617, 1);
inbe_storage_set_setting_int("speed", 7);
inbe_storage_set_setting_text("language", "en");
inbe_storage_set_setting_text("future_unknown_key", "ignore-me");
check_true("export multi habit source", inbe_storage_export_zip(zip_path));
inbe_storage_close();
}
static void
assert_multi_habits_imported(const char *root, int want_speed)
{
InbeHabits habits;
InbeHabit *habit;
check_true("init multi habit import db", inbe_storage_init(root));
check_int("multi habit imported sessions", inbe_storage_session_count(), 1);
memset(&habits, 0, sizeof(habits));
check_true("multi habit load", inbe_storage_habits_load(&habits));
check_int("multi habit count", habits.count, 3);
habit = find_habit_ci(&habits, "Meditation");
check_true("multi meditation exists", habit != NULL);
check_int("multi meditation sync mode",
habit != NULL ? habit->sync_mode : -1,
INBE_HABIT_SYNC_ACTIVITIES);
check_int("multi meditation sync activity",
habit != NULL ? habit->sync_activity : -1,
(1 << 0) | (1 << 1));
check_true("multi meditation day",
habit != NULL && inbe_habit_completed_day(habit, 20260617));
habit = find_habit_ci(&habits, "Push ups");
check_true("multi push ups day",
habit != NULL && inbe_habit_completed_day(habit, 20260617));
habit = find_habit_ci(&habits, "Cold Shower");
check_true("multi cold shower day",
habit != NULL && inbe_habit_completed_day(habit, 20260617));
check_int("multi import speed setting",
inbe_storage_get_setting_int("speed", -1), want_speed);
check_str("multi import unknown setting",
inbe_storage_get_setting_text("future_unknown_key"), NULL);
inbe_storage_close();
}
static void
test_import_modes_preserve_habits_and_settings_choice(void)
{
char source[512], dest_data[512], dest_settings[512], zip_path[512];
InbeStorageImportInfo info;
make_clean_root(source, sizeof(source), "multi-source");
make_clean_root(dest_data, sizeof(dest_data), "multi-dest-data");
make_clean_root(dest_settings, sizeof(dest_settings), "multi-dest-settings");
make_path(zip_path, sizeof(zip_path), source, "multi-export.zip");
write_multi_habit_source_database(source, zip_path);
check_true("init inspect dest", inbe_storage_init(dest_data));
memset(&info, 0, sizeof(info));
check_true("inspect multi export", inbe_storage_inspect_import(zip_path, &info));
check_true("inspect valid", info.valid);
check_true("inspect sessions", info.has_sessions);
check_true("inspect habits", info.has_habits);
check_true("inspect settings", info.has_settings);
check_int("inspect habit count", info.habit_count, 3);
inbe_storage_set_setting_int("speed", 1);
check_true("multi data only import",
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_ONLY));
inbe_storage_close();
assert_multi_habits_imported(dest_data, 1);
check_true("init settings import dest", inbe_storage_init(dest_settings));
inbe_storage_set_setting_int("speed", 1);
check_true("multi data settings import",
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
inbe_storage_close();
assert_multi_habits_imported(dest_settings, 7);
remove_tree(source);
remove_tree(dest_data);
remove_tree(dest_settings);
}
static void
write_legacy_zip(const char *path, const char *prefix)
{
@@ -469,6 +589,7 @@ main(void)
test_raw_db_import();
test_zip_db_import();
test_habit_name_merge_import();
test_import_modes_preserve_habits_and_settings_choice();
test_legacy_zip_import();
test_legacy_file_startup_migration();
test_tickmate_db_import();
+4 -4
View File
@@ -3,8 +3,8 @@
IDI_APP_ICON ICON "inbe.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,2,0
PRODUCTVERSION 1,3,2,0
FILEVERSION 1,3,3,0
PRODUCTVERSION 1,3,3,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -21,11 +21,11 @@ BEGIN
BEGIN
VALUE "CompanyName", "waozi"
VALUE "FileDescription", "Inner Breeze"
VALUE "FileVersion", "1.3.2"
VALUE "FileVersion", "1.3.3"
VALUE "InternalName", "inbe"
VALUE "OriginalFilename", "inbe-windows-x86_64.exe"
VALUE "ProductName", "Inner Breeze"
VALUE "ProductVersion", "1.3.2"
VALUE "ProductVersion", "1.3.3"
END
END
BLOCK "VarFileInfo"