-
-
Notifications
You must be signed in to change notification settings - Fork 21
New path stuff for package distribuition #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,7 @@ dist/ | |
| /compile_commands.json | ||
|
|
||
| # csv exports | ||
| *.csv | ||
| *.csv | ||
|
|
||
| # ignore CLANGD cache | ||
| .cache | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,9 +217,24 @@ bool add_satellite_from_tle(const char* line0, const char* line1, const char* li | |
| } | ||
|
|
||
| /* bulk loading of celestial junk from flat files */ | ||
| void load_tle_data(const char *filename) | ||
| void load_tle_data(const char *tlefile) | ||
| { | ||
| FILE *file = fopen(filename, "r"); | ||
| char filename[1024]; | ||
|
|
||
| #if defined (BUILD_FOR_DIST) | ||
| //The full path, with /<the tle file> at the end | ||
| char fullPath[1024]; | ||
| const char *homeDir = getenv("XDG_CONFIG_HOME"); | ||
| if (!homeDir) homeDir = getenv("HOME"); | ||
| snprintf(fullPath,sizeof(fullPath),"%s/.config/TLEscope/%s", homeDir,tlefile); | ||
|
|
||
| printf("DEBUG: %s\n", fullPath); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug printfs should be removed or gated behind |
||
| snprintf(filename,sizeof(filename),fullPath); | ||
| #else | ||
| snprintf(filename, sizeof(filename),tlefile); | ||
| #endif | ||
|
|
||
| FILE *file = fopen(filename, "r"); | ||
| if (!file) | ||
| { | ||
| printf("Failed to open %s\n", filename); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
|
|
||
|
|
||
| Marker home_location; | ||
|
|
||
| // turn hex strings into real colors | ||
|
|
@@ -29,7 +31,7 @@ Color ParseHexColor(const char *hexStr, Color fallback) | |
| } | ||
|
|
||
| // read the json file and grab our settings | ||
| void LoadAppConfig(const char *filename, AppConfig *config) | ||
| void LoadAppConfig(const char *resource, AppConfig *config) | ||
| { | ||
| // default theme configuration | ||
| strcpy(config->theme, "default"); | ||
|
|
@@ -42,6 +44,22 @@ void LoadAppConfig(const char *filename, AppConfig *config) | |
| config->show_first_run_dialog = false; //default | ||
| config->hint_vsync = true; // default | ||
| config->custom_tle_source_count = 0; | ||
|
|
||
|
|
||
| char filename[1024]; | ||
|
|
||
| #if defined (BUILD_FOR_DIST) | ||
| //The full path, with /settings.json at the end | ||
| char fullPath[1024]; | ||
| const char *homeDir = getenv("XDG_CONFIG_HOME"); | ||
| if (!homeDir) homeDir = getenv("HOME"); | ||
| snprintf(fullPath,sizeof(fullPath),"%s/.config/TLEscope/%s", homeDir,resource); | ||
|
|
||
| printf("DEBUG: %s\n", fullPath); | ||
| snprintf(filename,sizeof(filename),fullPath); | ||
| #else | ||
| snprintf(filename, sizeof(filename),resource); | ||
| #endif | ||
|
|
||
| if (FileExists(filename)) | ||
| { | ||
|
|
@@ -435,8 +453,11 @@ void LoadAppConfig(const char *filename, AppConfig *config) | |
|
|
||
| // load colors from the selected theme file | ||
| char theme_path[256]; | ||
| #if defined (BUILD_FOR_DIST) | ||
| snprintf(theme_path, sizeof(theme_path), "/usr/share/TLEscope/themes/%s/theme.json", config->theme); | ||
| #else | ||
| snprintf(theme_path, sizeof(theme_path), "themes/%s/theme.json", config->theme); | ||
|
|
||
| #endif | ||
| if (FileExists(theme_path)) | ||
| { | ||
| char *theme_text = LoadFileText(theme_path); | ||
|
|
@@ -487,15 +508,33 @@ void LoadAppConfig(const char *filename, AppConfig *config) | |
|
|
||
| UnloadFileText(theme_text); | ||
| } | ||
| }else { | ||
| printf("ERROR: Theme files could not be found!\n"); | ||
| } | ||
| } | ||
|
|
||
| void SaveAppConfig(const char *filename, AppConfig *config) | ||
| void SaveAppConfig(const char *resource, AppConfig *config) | ||
| { | ||
| char filename[1024]; | ||
|
|
||
| #if defined (BUILD_FOR_DIST) | ||
| //The full path, with /settings.json at the end | ||
| char fullPath[1024]; | ||
| const char *homeDir = getenv("HOME"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| snprintf(fullPath,sizeof(fullPath),"%s/.config/TLEscope/%s", homeDir,resource); | ||
|
|
||
| printf("DEBUG: %s\n", fullPath); | ||
| snprintf(filename,sizeof(filename),fullPath); | ||
| #else | ||
| snprintf(filename, sizeof(filename),resource); | ||
| #endif | ||
|
|
||
| printf("Saving config to %s \n",filename); | ||
| FILE *file = fopen(filename, "w"); | ||
| if (!file) | ||
| if (!file){ | ||
| printf("ERROR couldn't open path: %s \n",filename); | ||
| return; | ||
|
|
||
| } | ||
| fprintf(file, "{\n"); | ||
| fprintf(file, " \"theme\": \"%s\",\n", config->theme); | ||
| fprintf(file, " \"window_width\": %d,\n", config->window_width); | ||
|
|
@@ -513,7 +552,7 @@ void SaveAppConfig(const char *filename, AppConfig *config) | |
| fprintf(file, " \"show_scattering\": %s,\n", config->show_scattering ? "true" : "false"); | ||
| fprintf(file, " \"show_skybox\": %s,\n", config->show_skybox ? "true" : "false"); | ||
| fprintf(file, " \"hint_vsync\": %s,\n", config->hint_vsync ? "true" : "false"); | ||
| fprintf(file, " \"show_first_run_dialog\": %s,\n", config->show_first_run_dialog ? "true" : "false"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| if (config->custom_tle_source_count > 0) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,16 +5,32 @@ | |
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <sys/stat.h> | ||
|
|
||
| #include "astro.h" | ||
| #include "config.h" | ||
|
|
||
| const char* get_resource_path(const char* resource) { | ||
| static char fullPath[512]; | ||
| #if defined (BUILD_FOR_DIST) | ||
| snprintf(fullPath, sizeof(fullPath), "/usr/share/TLEscope/%s", resource); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider a compile-time define ( |
||
| if (FileExists(fullPath)) { | ||
| return fullPath; | ||
| } else { | ||
| printf("ERROR: resource file was not found at %s, trying fallabck path\n",fullPath); | ||
| return resource; | ||
| } | ||
| #else | ||
| return resource; | ||
| #endif | ||
| } | ||
|
|
||
| static const char* GetAssetPath(const char* theme, const char* filename) { | ||
| static char path[256]; | ||
| snprintf(path, sizeof(path), "themes/%s/%s", theme, filename); | ||
| if (FileExists(path)) return path; | ||
| snprintf(path, sizeof(path), "themes/default/%s", filename); | ||
| return path; | ||
| return get_resource_path(path); | ||
| } | ||
| #include "types.h" | ||
| #include "ui.h" | ||
|
|
@@ -493,10 +509,36 @@ static bool GetMouseEarthIntersection(Vector2 mouse, bool is_2d, Camera2D cam2d, | |
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| int main(void) | ||
| { | ||
| LoadAppConfig("settings.json", &cfg); | ||
|
|
||
| #if defined(BUILD_FOR_DIST) | ||
| //The path to the user's .config/TLEscope. Can we expect a path longer than this?? I sure hope not :omba: | ||
| char configPath[1024]; | ||
|
|
||
| const char *homeDir = getenv("HOME"); | ||
| if (!homeDir) { | ||
| printf("The $HOME env variable is not set. Exiting\n"); | ||
| return 1; | ||
| } | ||
| snprintf(configPath,sizeof(configPath),"%s/.config/TLEscope", homeDir); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same XDG issue — hardcodes
|
||
|
|
||
| if (!DirectoryExists(configPath)) { | ||
| //if the config directory is missing in the user's home directory, create it. | ||
| printf("creating config directory, as it didn't exist before at %s \n",configPath); | ||
| int status = mkdir(configPath,S_IRWXU); | ||
| if ( status !=0 ) { | ||
| // Maybe print the meaning of the error code, not just th code itself? | ||
| printf("The config directory couldn't be created, with error code %i. Exiting\n",status); | ||
| return 1; | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
| LoadAppConfig("settings.json", &cfg); | ||
|
|
||
| /* window setup and msaa */ | ||
| SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE); | ||
|
|
||
|
|
@@ -535,15 +577,15 @@ int main(void) | |
| SetExitKey(0); | ||
|
|
||
| /* logo and icon loading */ | ||
| Image logoImg = LoadImage("logo.png"); | ||
| Image logoImg = LoadImage(get_resource_path("logo.png")); //DONE | ||
| Texture2D logoTex = {0}; | ||
| if (logoImg.data != NULL) | ||
| { | ||
| SetWindowIcon(logoImg); | ||
| logoTex = LoadTextureFromImage(logoImg); | ||
| UnloadImage(logoImg); | ||
| } | ||
| Image logoLImg = LoadImage("logo.png"); | ||
| Image logoLImg = LoadImage(get_resource_path("logo_l.png")); //DONE | ||
| Texture2D logoLTex = {0}; | ||
| if (logoLImg.data != NULL) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ | |
| #include <stdlib.h> | ||
| #include <sys/types.h> | ||
|
|
||
| //This is toggled by make options. Only here for convinience. | ||
| //#define BUILD_FOR_DIST | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented-out |
||
|
|
||
| // basic limits and math constants | ||
| #define MAX_SATELLITES 15000 | ||
| #define MAX_MARKERS 100 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XDG_CONFIG_HOMEis already the full base directory (e.g./home/user/.config) per the XDG basedir spec. Appending/.config/unconditionally means that when the var is set, the path becomes/home/user/.config/.config/TLEscope/....Correct handling:
The
[0] == '/'check: spec says relative paths must be treated as invalid.Same bug in every copy of this block across
config.candui.c.