fix pc install

This commit is contained in:
Puechberty Arthur
2026-06-26 22:20:46 +02:00
parent db3e904b89
commit 64eb0b165d
2 changed files with 25 additions and 41 deletions
+25 -39
View File
@@ -1,8 +1,7 @@
#include "optifetch.h"
#include <sys/stat.h> // Nécessaire pour mkdir()
#include <sys/stat.h> // 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;
}