ResultType Line::IniWrite(LPTSTR aValue, LPTSTR aFilespec, LPTSTR aSection, LPTSTR aKey) { TCHAR szFileTemp[_MAX_PATH+1]; TCHAR *szFilePart; BOOL result; // Get the fullpathname (INI functions need a full path) GetFullPathName(aFilespec, _MAX_PATH, szFileTemp, &szFilePart); #ifdef UNICODE // WritePrivateProfileStringW() always creates INIs using the system codepage. // IniEncodingFix() checks if the file exists and if it doesn't then it creates // an empty file with a UTF-16LE BOM. result = IniEncodingFix(szFileTemp); if(result){ #endif result = WritePrivateProfileString(aSection, aKey, aValue, szFileTemp); // Returns zero on failure. WritePrivateProfileString(NULL, NULL, NULL, szFileTemp); // Flush #ifdef UNICODE } #endif return g_script.mIsAutoIt2 ? OK : g_ErrorLevel->Assign(result ? ERRORLEVEL_NONE : ERRORLEVEL_ERROR); }
ResultType Line::IniWrite(LPTSTR aValue, LPTSTR aFilespec, LPTSTR aSection, LPTSTR aKey) { TCHAR szFileTemp[_MAX_PATH+1]; TCHAR *szFilePart; BOOL result; // Get the fullpathname (INI functions need a full path) GetFullPathName(aFilespec, _MAX_PATH, szFileTemp, &szFilePart); #ifdef UNICODE // WritePrivateProfileStringW() always creates INIs using the system codepage. // IniEncodingFix() checks if the file exists and if it doesn't then it creates // an empty file with a UTF-16LE BOM. result = IniEncodingFix(szFileTemp, aSection); if(result){ #endif if (*aKey) { result = WritePrivateProfileString(aSection, aKey, aValue, szFileTemp); // Returns zero on failure. } else { size_t value_len = ArgLength(1); TCHAR c, *cp, *szBuffer = talloca(value_len + 2); // +2 for double null-terminator. // Convert newline-delimited list to null-terminated array of null-terminated strings. for (cp = szBuffer; *aValue; ++cp, ++aValue) { c = *aValue; *cp = (c == '\n') ? '\0' : c; } *cp = '\0', cp[1] = '\0'; // Double null-terminator. result = WritePrivateProfileSection(aSection, szBuffer, szFileTemp); } WritePrivateProfileString(NULL, NULL, NULL, szFileTemp); // Flush #ifdef UNICODE } #endif return g_script.mIsAutoIt2 ? OK : SetErrorLevelOrThrowBool(!result); }