aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-05-31 01:15:33 +0100
committerdam <dam@gudinoff>2024-06-01 02:23:10 +0100
commitb809105861edc0c639863e2575e61f156c137ae1 (patch)
tree39bfbed94c51acf4ebecb0b25d9d9c29b9ef5df2 /ttt.jai
parent986c0ca11d45e83e97479fcfad5facd1e56b0beb (diff)
downloadtask-time-tracker-b809105861edc0c639863e2575e61f156c137ae1.tar.zst
task-time-tracker-b809105861edc0c639863e2575e61f156c137ae1.zip
Improved data storage path search.v2.1
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai37
1 files changed, 24 insertions, 13 deletions
diff --git a/ttt.jai b/ttt.jai
index 67d6e18..d169ab1 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -14,11 +14,11 @@ DEBUG :: false;
#import "UTF8";
TUI :: #import "TUI"(COLOR_MODE_BITS=4);
-VERSION :: "2.0"; // Use only 3 chars (to fit layouts).
+VERSION :: "2.1"; // Use only 3 chars (to fit layouts).
YEAR :: "2024";
NUM_WEEK_DAYS :: 7;
-APP_FOLDER_NAME :: ".task_time_tracker";
+APP_FOLDER_NAME :: "task_time_tracker";
DB_FILE_NAME :: "database.bin";
AR_FILE_NAME :: "archive.csv";
DB_FILE_SIGN_STR :: "TTT:B:02";
@@ -1168,25 +1168,37 @@ prompt_user_key :: (y: int, message: string) -> TUI.Key {
main :: () {
#if DEBUG { defer report_memory_leaks(); }
-
+
context.logger = print_error;
defer free_memory();
{ // Initialize app directory.
- home_dir, success_dir := get_home_directory(); // Returns system owned memory.
- if success_dir == false {
- home_dir = ".";
- }
+
+ auto_release_temp();
+
+ base_path := "";
+ home_path := get_home_directory();
- home_path, success_path := get_absolute_path(home_dir); // Returns temporary memory.
+ #if OS == {
+ case .LINUX;
+ base_path = join(home_path, "/.local/share",, allocator = temporary_allocator);
- if success_path == false {
- log_error("Failed to find home directory '%'.", home_dir);
- exit(1);
+ case .WINDOWS;
+ base_path = join(home_path, "\\Appdata\\Roaming",, allocator = temporary_allocator);
+ }
+
+ // Try the most specific path.
+ if how_much_of_path_exists_on_the_local_filesystem(parse_path(base_path,, allocator = temporary_allocator)) == false {
+ // Try home path as fallback.
+ base_path = home_path;
+ if how_much_of_path_exists_on_the_local_filesystem(parse_path(base_path,, allocator = temporary_allocator)) == false {
+ // Default to current running executable path.
+ base_path = get_path_of_running_executable();
+ }
}
- app_directory = join(home_path, "/", APP_FOLDER_NAME);
+ app_directory = join(base_path, "/", APP_FOLDER_NAME);
db_file_path = join(app_directory, "/", DB_FILE_NAME);
ar_file_path = join(app_directory, "/", AR_FILE_NAME);
@@ -1265,7 +1277,6 @@ main :: () {
"\n",
"Notes\n");
print("- All data files are stored in '%'.\n", app_directory);
- print(" If the home directory is undefined, './%' will be used.\n", APP_FOLDER_NAME);
write_strings(
" The database tasks are stored in binary format on the 'database.bin' file.\n",
" The archived entries are stored in CSV format on the 'archive.csv' file.\n",