Lines 2-7
Link Here
|
2 |
#include "ttd.h" |
2 |
#include "ttd.h" |
3 |
#include "sound.h" |
3 |
#include "sound.h" |
4 |
|
4 |
|
|
|
5 |
#include <unistd.h> |
6 |
#if !defined(WIN32) |
7 |
#include <pwd.h> |
8 |
#endif |
9 |
|
10 |
#if defined(WIN32) |
11 |
#define PATHSEP "\\" |
12 |
#else |
13 |
#define PATHSEP "/" |
14 |
#endif |
15 |
|
5 |
enum SettingDescType { |
16 |
enum SettingDescType { |
6 |
SDT_INTX, // must be 0 |
17 |
SDT_INTX, // must be 0 |
7 |
SDT_ONEOFMANY, |
18 |
SDT_ONEOFMANY, |
Lines 856-872
Link Here
|
856 |
proc(ini, patch_settings, "patches", &_patches); |
867 |
proc(ini, patch_settings, "patches", &_patches); |
857 |
} |
868 |
} |
858 |
|
869 |
|
|
|
870 |
/* Returns the name of the configuration file. */ |
871 |
static char* GetConfigName() { |
872 |
#if defined(WIN32) |
873 |
return "openttd.cfg"; |
874 |
#else |
875 |
return ".openttd"; |
876 |
#endif |
877 |
} |
878 |
|
879 |
/* Returns the full path of the configuration file. */ |
880 |
static char* GetConfigPath(char* name) { |
881 |
char *home = getenv("HOME"); |
882 |
if (!home) { |
883 |
#if defined(WIN32) |
884 |
home = "C:\windows"; |
885 |
#else |
886 |
struct passwd *pw = getpwuid(getuid()); |
887 |
if (pw) home = pw->pw_dir; |
888 |
else return ""; |
889 |
#endif |
890 |
} |
891 |
char* path = malloc(strlen(home) + strlen(name) + strlen(PATHSEP) + 1); |
892 |
if (path) sprintf(path,"%s" PATHSEP "%s", home, name); |
893 |
return path; |
894 |
} |
895 |
|
859 |
void LoadFromConfig() |
896 |
void LoadFromConfig() |
860 |
{ |
897 |
{ |
861 |
IniFile *ini = ini_load("openttd.cfg"); |
898 |
IniFile *ini = ini_load(GetConfigPath(GetConfigName())); |
862 |
HandleSettingDescs(ini, load_setting_desc); |
899 |
HandleSettingDescs(ini, load_setting_desc); |
863 |
ini_free(ini); |
900 |
ini_free(ini); |
864 |
} |
901 |
} |
865 |
|
902 |
|
866 |
void SaveToConfig() |
903 |
void SaveToConfig() |
867 |
{ |
904 |
{ |
868 |
IniFile *ini = ini_load("openttd.cfg"); |
905 |
IniFile *ini = ini_load(GetConfigPath(GetConfigName())); |
869 |
HandleSettingDescs(ini, save_setting_desc); |
906 |
HandleSettingDescs(ini, save_setting_desc); |
870 |
ini_save("openttd.cfg", ini); |
907 |
ini_save(GetConfigPath(GetConfigName()), ini); |
871 |
ini_free(ini); |
908 |
ini_free(ini); |
872 |
} |
909 |
} |