From 64eb0b165d1f91ae8ac71f1722d0e89977666381 Mon Sep 17 00:00:00 2001 From: Puechberty Arthur Date: Fri, 26 Jun 2026 22:20:46 +0200 Subject: [PATCH] fix pc install --- Makefile | 2 -- main.c | 64 ++++++++++++++++++++++---------------------------------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 71cd10f..4389e46 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,6 @@ install: $(TARGET) cp $(TARGET) $(DESTDIR)/usr/bin/ mkdir -p $(DESTDIR)/usr/share/optifetch/logos cp -r logos/*.txt $(DESTDIR)/usr/share/optifetch/logos/ 2>/dev/null || true - mkdir -p $(DESTDIR)/etc - cp optifetch.conf $(DESTDIR)/etc/optifetch.conf 2>/dev/null || touch $(DESTDIR)/etc/optifetch.conf uninstall: rm -f $(DESTDIR)/usr/bin/$(TARGET) diff --git a/main.c b/main.c index 308b19a..61d37c2 100644 --- a/main.c +++ b/main.c @@ -1,8 +1,7 @@ #include "optifetch.h" -#include // Nécessaire pour mkdir() +#include // Pour mkdir() -void print_help() -{ +void print_help() { printf("Optifetch - Lightweight system info tool\n\n"); printf("Usage: optifetch [options]\n\n"); printf("Options:\n"); @@ -11,9 +10,9 @@ void print_help() printf("Configuration:\n"); printf(" Config file is searched in:\n"); printf(" 1. ./optifetch.conf\n"); - printf(" 2. ~/.config/optifetch.conf\n"); + printf(" 2. ~/.config/optifetch/optifetch.conf\n"); printf(" 3. /etc/optifetch.conf\n"); - printf(" It is generated on first run if not found.\n\n"); + printf(" It is generated on first run in ~/.config/optifetch/ if not found.\n\n"); printf("Available Variables:\n"); printf(" {logo} {small_logo} {distro_color} {user} {host} {os} {kernel} {uptime} {arch}\n"); printf(" {shell} {cpu} {cores} {cpu_max_freq} {gpu} {de} {wm} {term}\n"); @@ -38,10 +37,8 @@ void print_help() printf(" {if:wifi} ... {endif} Show only if connected to wifi\n"); } -int main(int argc, char *argv[]) -{ - if (argc > 1 && (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)) - { +int main(int argc, char *argv[]) { + if (argc > 1 && (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)) { print_help(); return 0; } @@ -53,52 +50,41 @@ int main(int argc, char *argv[]) int config_found = 0; // 1. Cherche dans le dossier local - if (access(config_path, F_OK) == 0) - { + if (access(config_path, F_OK) == 0) { config_found = 1; } - // 2. Cherche dans ~/.config/optifetch.conf - if (!config_found) - { + // 2. Cherche dans ~/.config/optifetch/optifetch.conf + if (!config_found) { const char *home = getenv("HOME"); - if (home) - { - snprintf(config_path, sizeof(config_path), "%s/.config/optifetch.conf", home); - if (access(config_path, F_OK) == 0) - { + if (home) { + snprintf(config_path, sizeof(config_path), "%s/.config/optifetch/optifetch.conf", home); + if (access(config_path, F_OK) == 0) { config_found = 1; } } } - // 3. Cherche dans /etc/optifetch.conf - if (!config_found) - { + // 3. Cherche dans /etc/optifetch.conf (si un admin l'a mis) + if (!config_found) { snprintf(config_path, sizeof(config_path), "/etc/optifetch.conf"); - if (access(config_path, F_OK) == 0) - { + if (access(config_path, F_OK) == 0) { config_found = 1; } } - // 4. Si toujours pas trouvé, on le génère - if (!config_found) - { + // 4. Si toujours pas trouvé, on le génère dans ~/.config/optifetch/ + if (!config_found) { const char *home = getenv("HOME"); - if (home) - { - // S'assurer que le dossier ~/.config existe bien avant de créer le fichier + if (home) { char config_dir[512]; - snprintf(config_dir, sizeof(config_dir), "%s/.config", home); - mkdir(config_dir, 0755); // Crée le dossier (s'il existe déjà, ne fait rien) - - snprintf(config_path, sizeof(config_path), "%s/.config/optifetch.conf", home); + snprintf(config_dir, sizeof(config_dir), "%s/.config/optifetch", home); + mkdir(config_dir, 0755); // Crée le dossier ~/.config/optifetch + + snprintf(config_path, sizeof(config_path), "%s/.config/optifetch/optifetch.conf", home); generate_default_config(config_path); - } - else - { - // Si pas de HOME (ex: environnement très restreint), on crée dans le dossier courant + } else { + // Fallback si pas de HOME snprintf(config_path, sizeof(config_path), "optifetch.conf"); generate_default_config(config_path); } @@ -106,7 +92,7 @@ int main(int argc, char *argv[]) } render_config(config_path, &info); - + printf("\033[0m"); return 0; } \ No newline at end of file