From: ARembo Date: Mon, 25 Jul 2011 01:49:18 +0000 (-0400) Subject: Пути к файлам ресурсов как в UNIX X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=66126249063c1a47b3e48e76e7178e05f838f9ea;p=flatwaifu.git Пути к файлам ресурсов как в UNIX --- 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