--- njam.cpp.orig 2003-11-06 23:59:22.000000000 -0800 +++ njam.cpp 2003-11-06 23:59:50.000000000 -0800 @@ -33,6 +33,8 @@ // needed for chdir #ifdef __linux__ #include +#include +#include #endif #include @@ -213,16 +215,30 @@ if (m_NetworkAvailable) SDLNet_Quit(); + FILE *fp; // write configuration options - char filename[] = "njam.conf"; - FILE *fp = fopen(filename, "w+"); - if (fp) + if (getenv("HOME") && !chdir(getenv("HOME"))) { - fprintf(fp, "M=%d\n", (m_GameOptions.PlayMusic ? 1 : 0)); - fprintf(fp, "S=%d\n", (m_GameOptions.PlaySound ? 1 : 0)); - fprintf(fp, "A=%d\n", (m_GameOptions.UseAllSkins ? 1 : 0)); - fprintf(fp, "I=%s\n", m_GameOptions.ServerIP); - fclose(fp); + mkdir(".njam", 0774); + if (!chdir(".njam")) + { + char filename[] = "njam.conf"; + fp = fopen(filename, "w+"); + + if (fp) + { + fprintf(fp, + "M=%d\n" + "S=%d\n" + "A=%d\n" + "I=%s\n", + (m_GameOptions.PlayMusic ? 1 : 0), + (m_GameOptions.PlaySound ? 1 : 0), + (m_GameOptions.UseAllSkins ? 1 : 0), + m_GameOptions.ServerIP); + fclose(fp); + } + } } // format: NAME#POINTS#LEVEL# @@ -597,35 +613,39 @@ m_FontBlue = new NjamFont("data/font-blue.bmp", 6, 9); m_FontYellow = new NjamFont("data/font-yellow.bmp", 10, 15); + FILE *fp; // Load user settings from .conf file - char filename[] = "njam.conf"; - FILE *fp = fopen(filename, "r"); - if (fp) + if (getenv("HOME") && !chdir(getenv("HOME")) && !chdir(".njam")) { - LogFile("Reading njam.conf file.\n"); - char buff[20]; - while (!feof(fp)) - { - fgets(buff, 20, fp); - if (buff[1] == '=') + char filename[] = "njam.conf"; + fp = fopen(filename, "r"); + if (fp) + { + LogFile("Reading njam.conf file.\n"); + char buff[20]; + while (!feof(fp)) { - int i; - switch (buff[0]) + fgets(buff, 20, fp); + if (buff[1] == '=') { - case 'M': m_GameOptions.PlayMusic = (buff[2] == '1'); break; - case 'S': m_GameOptions.PlaySound = (buff[2] == '1'); break; - case 'A': m_GameOptions.UseAllSkins = (buff[2] == '1'); break; - case 'I': // serverIP - for (i=2; buff[i] != '\n' && buff[i] && i<17; i++) - m_GameOptions.ServerIP[i-2] = buff[i]; - m_GameOptions.ServerIP[i] = '\0'; - break; - default: - printf("Unknown configuration file option: %c\n", buff[0]); + int i; + switch (buff[0]) + { + case 'M': m_GameOptions.PlayMusic = (buff[2] == '1'); break; + case 'S': m_GameOptions.PlaySound = (buff[2] == '1'); break; + case 'A': m_GameOptions.UseAllSkins = (buff[2] == '1'); break; + case 'I': // serverIP + for (i=2; buff[i] != '\n' && buff[i] && i<17; i++) + m_GameOptions.ServerIP[i-2] = buff[i]; + m_GameOptions.ServerIP[i] = '\0'; + break; + default: + printf("Unknown configuration file option: %c\n", buff[0]); + } } } + fclose(fp); } - fclose(fp); } // create default hiscore