From 66126249063c1a47b3e48e76e7178e05f838f9ea Mon Sep 17 00:00:00 2001 From: ARembo Date: Sun, 24 Jul 2011 21:49:18 -0400 Subject: [PATCH] =?utf8?q?=D0=9F=D1=83=D1=82=D0=B8=20=D0=BA=20=D1=84=D0=B0?= =?utf8?q?=D0=B9=D0=BB=D0=B0=D0=BC=20=D1=80=D0=B5=D1=81=D1=83=D1=80=D1=81?= =?utf8?q?=D0=BE=D0=B2=20=D0=BA=D0=B0=D0=BA=20=D0=B2=20UNIX?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/config.c | 19 +++++++++++++++++-- src/main.c | 11 ++++++++++- src/music.c | 27 ++++++++++++++++++--------- src/my.c | 11 +++++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/config.c b/src/config.c index bc498c6..2985a4f 100644 --- a/src/config.c +++ b/src/config.c @@ -184,8 +184,23 @@ void CFG_load(void) { char s[128]; char *p1,*p2; - logo("CFG_load: загрузка конфигурации из %s\n",cfg_file); - if((h=fopen(cfg_file,"rb"))==NULL) { + char pc[50]; + char *e = getenv("HOME"); + strncpy(pc, e, 30); + strcpy(&pc[strlen(pc)], "/default.cfg"); + if (!fexists(pc)) { + strcpy(pc, "default.cfg"); + if (!fexists(pc)) { + strcpy(pc, "/usr/share/doom2d-rembo/default.cfg"); + if (!fexists(pc)) { + logo("default.cfg not found\n"); + return; + } + } + } + + logo("CFG_load: загрузка конфигурации из %s\n",pc); + if((h=fopen(pc,"rb"))==NULL) { perror("Cannot open file");return; } while(!feof(h)) { diff --git a/src/main.c b/src/main.c index b12d7ec..5f0fe23 100644 --- a/src/main.c +++ b/src/main.c @@ -112,7 +112,16 @@ int main(int argc, char *argv[]) { pl2.id=-2; myrandomize(); F_startup(); - F_addwad("doom2d.wad"); + char *pw; +#ifndef WIN32 + pw = "/usr/share/doom2d-rembo/doom2d.wad"; +#else + pw = "doom2d.wad"; +#endif + if (fexists(pw)) + F_addwad(pw); + else + F_addwad("doom2d.wad"); CFG_args(argc, argv); CFG_load(); F_initwads(); diff --git a/src/music.c b/src/music.c index 1f08815..5e7308f 100644 --- a/src/music.c +++ b/src/music.c @@ -175,22 +175,31 @@ void trans_ascii_str (char *dest, char *src) void F_loadmus(char n[8]) { if (musdisabled) return; char f[50]; + char name[50]; #ifndef WIN32 - strcpy(f,"music/"); + strcpy(f, "/usr/share/doom2d-rembo/music/"); #else - strcpy(f,"music\\"); + strcpy(f, "music\\"); #endif - strncpy(&f[6], n, 8); - f[6+8]='\0'; - muslo = Mix_LoadMUS(f); - if (muslo == NULL) { - char name[50]; + int l = strlen(f); + strncpy(&f[l], n, 8); + f[l+8]='\0'; + trans_ascii_str(name, f); + muslo = Mix_LoadMUS(name); + if (muslo == NULL) + { +#ifndef WIN32 + strcpy(f, "music/"); + int l = strlen(f); + strncpy(&f[l], n, 8); + f[l+8]='\0'; trans_ascii_str(name, f); muslo = Mix_LoadMUS(name); - if (!muslo) logo("Music not found '%s'\n", name); +#endif } -} + if (!muslo) logo("Music not found '%s'\n", name); +} void F_freemus(void) { if (musdisabled) return; diff --git a/src/my.c b/src/my.c index 72f444d..701dd1d 100644 --- a/src/my.c +++ b/src/my.c @@ -95,3 +95,14 @@ void myrandomize(void) { srand(SDL_GetTicks()); } + +int fexists(char * filename) +{ + FILE *f; + if (f = fopen(filename, "r")) + { + fclose(f); + return 1; + } + return 0; +} \ No newline at end of file -- 2.29.2