Skip to content

Commit ff46ea0

Browse files
committed
create default config file on first launch #373
create a hex dump of example config file with xxd in autogenerate.sh use this to create a default config file in home dir on first launch if no file is found. this only applies if the path to config file is not specified
1 parent ce28162 commit ff46ea0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ ltmain.sh
2323
m4/
2424
missing
2525
version
26+
config_file.h

autogen.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,4 @@ aclocal
1111
autoconf
1212
automake --add-missing
1313

14-
CONFIGDIR=$XDG_CONFIG_HOME/cava
15-
16-
if [ -z "$XDG_CONFIG_HOME" ]; then CONFIGDIR=$HOME/.config/cava; fi
17-
18-
mkdir -p "$CONFIGDIR"
19-
[ -f "$CONFIGDIR"/config ] || cp example_files/config "$CONFIGDIR"/config
14+
xxd -i example_files/config config_file.h # make a hex dump of default config file to be generated in home dir on first launch

config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "config.h"
2+
#include "config_file.h"
23
#include "util.h"
34

45
#include <ctype.h>
@@ -407,6 +408,11 @@ bool load_config(char configPath[PATH_MAX], struct config_params *p, bool colors
407408
// open file or create file if it does not exist
408409
fp = fopen(configPath, "ab+");
409410
if (fp) {
411+
fseek(fp, 0, SEEK_END);
412+
if (ftell(fp) == 0) {
413+
printf("config file is empty, creating default config file\n");
414+
fwrite(example_files_config, example_files_config_len, sizeof(unsigned char), fp);
415+
}
410416
fclose(fp);
411417
} else {
412418
// try to open file read only

0 commit comments

Comments
 (0)