Skip to content

Commit

Permalink
Fixed binary file writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Nov 4, 2024
1 parent 35a2814 commit 1bd8ada
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions File.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class File {
static bool SaveFile(string path, string data, bool binary = false) {
ResetLastError();

int handle = FileOpen(path, FILE_WRITE | (binary ? FILE_BIN : FILE_ANSI));
int handle = FileOpen(path, FILE_WRITE | (binary ? FILE_BIN : FILE_TXT), "", CP_UTF8);

if (handle == INVALID_HANDLE) {
string terminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH);
Expand All @@ -154,8 +154,15 @@ class File {
"\\Files\\\" as absolute paths may not work.");
return false;
}

FileWriteString(handle, data);

if (binary) {
uchar buffer[];
StringToCharArray(data, buffer, 0, WHOLE_ARRAY, CP_UTF8);
FileWriteArray(handle, buffer, 0, ArraySize(buffer));
}
else {
FileWriteString(handle, data);
}

FileClose(handle);

Expand Down

0 comments on commit 1bd8ada

Please sign in to comment.