- Sync profile functions with Wine 1.1.20

svn path=/trunk/; revision=40866
This commit is contained in:
Dmitry Chapyshev 2009-05-09 12:40:35 +00:00
parent 80b7580343
commit 619d40264f

View file

@ -130,7 +130,7 @@ static void PROFILE_CopyEntry( LPWSTR buffer, LPCWSTR value, int len,
static __inline void PROFILE_ByteSwapShortBuffer(WCHAR * buffer, int len) static __inline void PROFILE_ByteSwapShortBuffer(WCHAR * buffer, int len)
{ {
int i; int i;
USHORT * shortbuffer = (USHORT *)buffer; USHORT * shortbuffer = buffer;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
shortbuffer[i] = RtlUshortByteSwap(shortbuffer[i]); shortbuffer[i] = RtlUshortByteSwap(shortbuffer[i]);
} }
@ -293,7 +293,7 @@ static __inline ENCODING PROFILE_DetectTextEncoding(const void * buffer, int * l
INT flags = IS_TEXT_UNICODE_SIGNATURE | INT flags = IS_TEXT_UNICODE_SIGNATURE |
IS_TEXT_UNICODE_REVERSE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE |
IS_TEXT_UNICODE_ODD_LENGTH; IS_TEXT_UNICODE_ODD_LENGTH;
if (*len >= (int)sizeof(bom_utf8) && !memcmp(buffer, bom_utf8, sizeof(bom_utf8))) if (*len >= sizeof(bom_utf8) && !memcmp(buffer, bom_utf8, sizeof(bom_utf8)))
{ {
*len = sizeof(bom_utf8); *len = sizeof(bom_utf8);
return ENCODING_UTF8; return ENCODING_UTF8;
@ -334,7 +334,7 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
DPRINT("%p\n", hFile); DPRINT("%p\n", hFile);
dwFileSize = GetFileSize(hFile, NULL); dwFileSize = GetFileSize(hFile, NULL);
if (dwFileSize == INVALID_FILE_SIZE) if (dwFileSize == INVALID_FILE_SIZE || dwFileSize == 0)
return NULL; return NULL;
buffer_base = HeapAlloc(GetProcessHeap(), 0 , dwFileSize); buffer_base = HeapAlloc(GetProcessHeap(), 0 , dwFileSize);
@ -359,40 +359,40 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
case ENCODING_ANSI: case ENCODING_ANSI:
DPRINT("ANSI encoding\n"); DPRINT("ANSI encoding\n");
len = MultiByteToWideChar(CP_ACP, 0, (char *)pBuffer, dwFileSize, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, NULL, 0);
szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!szFile) if (!szFile)
{ {
HeapFree(GetProcessHeap(), 0, buffer_base); HeapFree(GetProcessHeap(), 0, buffer_base);
return NULL; return NULL;
} }
MultiByteToWideChar(CP_ACP, 0, (char *)pBuffer, dwFileSize, szFile, len); MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len; szEnd = szFile + len;
break; break;
case ENCODING_UTF8: case ENCODING_UTF8:
DPRINT("UTF8 encoding\n"); DPRINT("UTF8 encoding\n");
len = MultiByteToWideChar(CP_UTF8, 0, (char *)pBuffer, dwFileSize, NULL, 0); len = MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, NULL, 0);
szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!szFile) if (!szFile)
{ {
HeapFree(GetProcessHeap(), 0, buffer_base); HeapFree(GetProcessHeap(), 0, buffer_base);
return NULL; return NULL;
} }
MultiByteToWideChar(CP_UTF8, 0, (char *)pBuffer, dwFileSize, szFile, len); MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len; szEnd = szFile + len;
break; break;
case ENCODING_UTF16LE: case ENCODING_UTF16LE:
DPRINT("UTF16 Little Endian encoding\n"); DPRINT("UTF16 Little Endian encoding\n");
szFile = (WCHAR *)pBuffer;// + 1; szFile = pBuffer;// + 1;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize); szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
break; break;
case ENCODING_UTF16BE: case ENCODING_UTF16BE:
DPRINT("UTF16 Big Endian encoding\n"); DPRINT("UTF16 Big Endian encoding\n");
szFile = (WCHAR *)pBuffer;// + 1; szFile = pBuffer;// + 1;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize); szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR)); PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR));
break; break;
@ -834,6 +834,7 @@ static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access )
else else
{ {
DPRINT("(%S): already opened, needs refreshing (mru=%d)\n", buffer, i); DPRINT("(%S): already opened, needs refreshing (mru=%d)\n", buffer, i);
PROFILE_Free(CurProfile->section);
CurProfile->section = PROFILE_Load(hFile, &CurProfile->encoding); CurProfile->section = PROFILE_Load(hFile, &CurProfile->encoding);
CurProfile->LastWriteTime = LastWriteTime; CurProfile->LastWriteTime = LastWriteTime;
} }
@ -1459,8 +1460,7 @@ BOOL WINAPI WritePrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
else if (PROFILE_Open( filename, TRUE )) else if (PROFILE_Open( filename, TRUE ))
{ {
if (!section) { if (!section) {
DPRINT1("(NULL?, %S, %S, %S)?\n", SetLastError(ERROR_FILE_NOT_FOUND);
entry, string, filename);
} else { } else {
ret = PROFILE_SetString( section, entry, string, FALSE); ret = PROFILE_SetString( section, entry, string, FALSE);
PROFILE_FlushFile(); PROFILE_FlushFile();
@ -1733,7 +1733,7 @@ BOOL WINAPI GetPrivateProfileStructW (LPCWSTR section, LPCWSTR key,
{ {
BOOL highnibble = TRUE; BOOL highnibble = TRUE;
BYTE b = 0, val; BYTE b = 0, val;
LPBYTE binbuf = (LPBYTE)buf; LPBYTE binbuf = buf;
end -= 2; /* don't include checksum in output data */ end -= 2; /* don't include checksum in output data */
/* translate ASCII hex format into binary data */ /* translate ASCII hex format into binary data */