OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
17 # include <emscripten.h>
20 #if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500)
27 # include <shellapi.h>
53 std::string file_new{ filename };
54 file_new.append(
".new");
56 std::ofstream os(
OTTD2FS(file_new.c_str()));
57 if (os.fail())
return false;
65 if (item->name.find(
' ') != std::string::npos ||
66 item->name[0] ==
'[') {
67 os <<
"\"" << item->name <<
"\"";
72 os <<
" = " << item->value.value_or(
"") <<
"\n";
79 if (os.fail())
return false;
87 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
88 int f = open(file_new.c_str(), O_RDWR);
89 int ret = fdatasync(f);
91 if (ret != 0)
return false;
96 wchar_t tfilename[MAX_PATH + 1], tfile_new[MAX_PATH + 1];
97 wcsncpy(tfilename,
OTTD2FS(filename.c_str()), MAX_PATH);
98 wcsncpy(tfile_new,
OTTD2FS(file_new.c_str()), MAX_PATH);
100 tfilename[MAX_PATH - 1] =
'\0';
101 tfile_new[MAX_PATH - 1] =
'\0';
102 tfilename[wcslen(tfilename) + 1] =
'\0';
103 tfile_new[wcslen(tfile_new) + 1] =
'\0';
106 SHFILEOPSTRUCT shfopt;
108 shfopt.wFunc = FO_MOVE;
109 shfopt.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;
110 shfopt.pFrom = tfile_new;
111 shfopt.pTo = tfilename;
112 SHFileOperation(&shfopt);
114 if (rename(file_new.c_str(), filename.c_str()) < 0) {
115 DEBUG(misc, 0,
"Renaming %s to %s failed; configuration not saved", file_new.c_str(), filename.c_str());
119 #ifdef __EMSCRIPTEN__
120 EM_ASM(
if (window[
"openttd_syncfs"]) openttd_syncfs());
std::string comment
last comment in file
IniItem * next
The next item in this group.
A single "line" in an ini file.
A group within an ini file.
Ini file that only supports loading.
IniFile(const char *const *list_group_names=nullptr)
Create a new ini file with given group names.
#define DEBUG(name, level,...)
Output a line of debugging information.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
virtual void ReportFileError(const char *const pre, const char *const buffer, const char *const post)
Report an error about the file contents.
IniGroup * group
the first group in the ini
std::string comment
comment for group
std::string name
name of group
virtual FILE * OpenFile(const std::string &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.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
IniItem * item
the first item in the group
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
const wchar_t * OTTD2FS(const char *name, bool console_cp)
Convert from OpenTTD's encoding to wide characters.
IniGroup * next
the next group within this file