18 #if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) 24 # include <shellapi.h> 50 char file_new[MAX_PATH];
54 FILE *f = fopen(file_new,
"w");
55 if (f == NULL)
return false;
61 if (item->comment != NULL) fputs(item->comment, f);
64 if (strchr(item->name,
' ') != NULL ||
65 item->name[0] ==
'[') {
66 fprintf(f,
"\"%s\"", item->name);
68 fprintf(f,
"%s", item->name);
71 fprintf(f,
" = %s\n", item->value == NULL ?
"" : item->value);
82 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 83 int ret = fdatasync(fileno(f));
85 if (ret != 0)
return false;
90 #if defined(WIN32) || defined(WIN64) 94 TCHAR tfilename[MAX_PATH + 1], tfile_new[MAX_PATH + 1];
95 _tcsncpy(tfilename,
OTTD2FS(filename), MAX_PATH);
96 _tcsncpy(tfile_new,
OTTD2FS(file_new), MAX_PATH);
98 tfilename[MAX_PATH - 1] =
'\0';
99 tfile_new[MAX_PATH - 1] =
'\0';
100 tfilename[_tcslen(tfilename) + 1] =
'\0';
101 tfile_new[_tcslen(tfile_new) + 1] =
'\0';
104 SHFILEOPSTRUCT shfopt;
106 shfopt.wFunc = FO_MOVE;
107 shfopt.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;
108 shfopt.pFrom = tfile_new;
109 shfopt.pTo = tfilename;
110 SHFileOperation(&shfopt);
112 if (rename(file_new, filename) < 0) {
113 DEBUG(misc, 0,
"Renaming %s to %s failed; configuration not saved", file_new, filename);
A group within an ini file.
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
char * comment
comment for group
Functions related to debugging.
IniItem * item
the first item in the group
Functions for Standard In/Out file operations.
#define lastof(x)
Get the last element of an fixed size array.
IniItem * next
The next item in this group.
char * comment
last comment in file
A single "line" in an ini file.
virtual FILE * OpenFile(const char *filename, Subdirectory subdir, size_t *size)
Open the INI file.
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Functions related to low-level strings.
IniGroup * group
the first group in the ini
IniFile(const char *const *list_group_names=NULL)
Create a new ini file with given group names.
bool SaveToDisk(const char *filename)
Save the Ini file's data to the disk.
FILE * FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
virtual void ReportFileError(const char *const pre, const char *const buffer, const char *const post)
Report an error about the file contents.
Types related to reading/writing '*.ini' files.
const TCHAR * OTTD2FS(const char *name, bool console_cp)
Convert from OpenTTD's encoding to that of the local environment.
#define DEBUG(name, level,...)
Output a line of debugging information.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
IniGroup * next
the next group within this file
Ini file that only supports loading.
Functions related to memory operations.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().