| 92 | |
| 93 | #ifdef UNICODE |
| 94 | static BOOL IniEncodingFix(LPWSTR aFilespec, LPWSTR aSection) |
| 95 | { |
| 96 | BOOL result = TRUE; |
| 97 | if (!DoesFilePatternExist(aFilespec)) |
| 98 | { |
| 99 | HANDLE hFile; |
| 100 | DWORD dwWritten; |
| 101 | |
| 102 | // Create a Unicode file. (UTF-16LE BOM) |
| 103 | hFile = CreateFile(aFilespec, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL); |
| 104 | if (hFile != INVALID_HANDLE_VALUE) |
| 105 | { |
| 106 | DWORD cc = (DWORD)wcslen(aSection); |
| 107 | DWORD cb = (cc + 1) * sizeof(WCHAR); |
| 108 | |
| 109 | aSection[cc] = ']'; // Temporarily replace the null-terminator. |
| 110 | |
| 111 | // Write a UTF-16LE BOM to identify this as a Unicode file. |
| 112 | // Write [%aSection%] to prevent WritePrivateProfileString from inserting an empty line (for consistency and style). |
| 113 | if ( !WriteFile(hFile, L"\xFEFF[", 4, &dwWritten, NULL) || dwWritten != 4 |
| 114 | || !WriteFile(hFile, aSection, cb, &dwWritten, NULL) || dwWritten != cb ) |
| 115 | result = FALSE; |
| 116 | |
| 117 | if (!CloseHandle(hFile)) |
| 118 | result = FALSE; |
| 119 | |
| 120 | aSection[cc] = '\0'; // Re-terminate. |
| 121 | } |
| 122 | } |
| 123 | return result; |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | ResultType Line::IniWrite(LPTSTR aValue, LPTSTR aFilespec, LPTSTR aSection, LPTSTR aKey) |
no test coverage detected