Improvements to path handling. Patch from bit.
This commit is contained in:
parent
1d4c9ab4e8
commit
807b710a5d
55 changed files with 588 additions and 368 deletions
|
|
@ -14,7 +14,13 @@
|
|||
#include "plat-mouse.h"
|
||||
#include "sound.h"
|
||||
#include "video.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include "paths.h"
|
||||
|
||||
#undef printf
|
||||
|
||||
int has_been_inited = 0;
|
||||
|
|
@ -60,10 +66,41 @@ uint64_t timer_read()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dir_exists(char *path)
|
||||
{
|
||||
DIR *dir = opendir(path);
|
||||
if (dir)
|
||||
{
|
||||
closedir(dir);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int create_dir(char *path)
|
||||
{
|
||||
if (!mkdir(path, 0755))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_pcem_path(char *s, int size)
|
||||
{
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
|
||||
strncpy(s, pw->pw_dir, size-10);
|
||||
append_slash(s, size);
|
||||
strcat(s, ".pcem/");
|
||||
//get_executable_name(s, size);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char s[512];
|
||||
int frames = 0;
|
||||
int c;
|
||||
FILE *f;
|
||||
|
||||
allegro_init();
|
||||
allegro_video_init();
|
||||
install_timer();
|
||||
|
|
@ -71,12 +108,51 @@ int main(int argc, char *argv[])
|
|||
install_int_ex(onesec, BPS_TO_TIMER(1));
|
||||
midi_init();
|
||||
|
||||
getpath();
|
||||
paths_init();
|
||||
|
||||
/* create directories if they don't exist */
|
||||
if (!dir_exists(pcem_path)) {
|
||||
if (!create_dir(pcem_path))
|
||||
return 0;
|
||||
append_filename(s, pcem_path, "configs", 511);
|
||||
if (!dir_exists(s) && !create_dir(s))
|
||||
return 0;
|
||||
|
||||
append_filename(s, pcem_path, "roms", 511);
|
||||
if (!dir_exists(s) && !create_dir(s))
|
||||
return 0;
|
||||
|
||||
append_filename(s, pcem_path, "nvr", 511);
|
||||
if (!dir_exists(s) && !create_dir(s))
|
||||
return 0;
|
||||
|
||||
append_filename(s, pcem_path, "logs", 511);
|
||||
if (!dir_exists(s) && !create_dir(s))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set up default paths */
|
||||
sprintf(s, "%s%s%c%s", pcem_path, "roms/", get_path_separator(), "/usr/share/pcem/roms/");
|
||||
set_default_roms_paths(s);
|
||||
append_filename(s, pcem_path, "nvr/", 511);
|
||||
set_default_nvr_path(s);
|
||||
append_filename(s, pcem_path, "configs/", 511);
|
||||
set_default_configs_path(s);
|
||||
append_filename(s, pcem_path, "logs/", 511);
|
||||
set_default_logs_path(s);
|
||||
|
||||
sound_init();
|
||||
|
||||
initpc(argc, argv);
|
||||
|
||||
/* check if cfg exists, and if not create it */
|
||||
append_filename(s, pcem_path, "pcem.cfg", 511);
|
||||
f = fopen(s, "r");
|
||||
if (f)
|
||||
fclose(f);
|
||||
else
|
||||
saveconfig(NULL);
|
||||
|
||||
keyboard_init();
|
||||
mouse_init();
|
||||
joystick_init();
|
||||
|
|
|
|||
Loading…
Reference in a new issue