wineboot: Rewrite wininit.ini processing to use GetPrivateProfileSectionW. Convert to Unicode.

oldstable
Alexandre Julliard 2007-12-20 15:53:53 +01:00
parent 8f6e1db3e0
commit e34244a3b9
1 changed files with 36 additions and 99 deletions

View File

@ -61,6 +61,7 @@
# include <getopt.h> # include <getopt.h>
#endif #endif
#include <windows.h> #include <windows.h>
#include <wine/unicode.h>
#include <wine/debug.h> #include <wine/debug.h>
#define COBJMACROS #define COBJMACROS
@ -76,123 +77,59 @@ WINE_DEFAULT_DEBUG_CHANNEL(wineboot);
extern BOOL shutdown_close_windows( BOOL force ); extern BOOL shutdown_close_windows( BOOL force );
extern void kill_processes( BOOL kill_desktop ); extern void kill_processes( BOOL kill_desktop );
static BOOL GetLine( HANDLE hFile, char *buf, size_t buflen )
{
unsigned int i=0;
DWORD r;
buf[0]='\0';
do
{
DWORD read;
if( !ReadFile( hFile, buf, 1, &read, NULL ) || read!=1 )
{
return FALSE;
}
} while( isspace( *buf ) );
while( buf[i]!='\n' && i<=buflen &&
ReadFile( hFile, buf+i+1, 1, &r, NULL ) )
{
++i;
}
if( buf[i]!='\n' )
{
return FALSE;
}
if( i>0 && buf[i-1]=='\r' )
--i;
buf[i]='\0';
return TRUE;
}
/* Performs the rename operations dictated in %SystemRoot%\Wininit.ini. /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
* Returns FALSE if there was an error, or otherwise if all is ok. * Returns FALSE if there was an error, or otherwise if all is ok.
*/ */
static BOOL wininit(void) static BOOL wininit(void)
{ {
const char * const RENAME_FILE="wininit.ini"; static const WCHAR nulW[] = {'N','U','L',0};
const char * const RENAME_FILE_TO="wininit.bak"; static const WCHAR renameW[] = {'r','e','n','a','m','e',0};
const char * const RENAME_FILE_SECTION="[rename]"; static const WCHAR wininitW[] = {'w','i','n','i','n','i','t','.','i','n','i',0};
char buffer[MAX_LINE_LENGTH]; static const WCHAR wininitbakW[] = {'w','i','n','i','n','i','t','.','b','a','k',0};
HANDLE hFile; WCHAR initial_buffer[1024];
WCHAR *str, *buffer = initial_buffer;
DWORD size = sizeof(initial_buffer)/sizeof(WCHAR);
DWORD res;
for (;;)
hFile=CreateFileA(RENAME_FILE, GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL );
if( hFile==INVALID_HANDLE_VALUE )
{ {
DWORD err=GetLastError(); if (!(res = GetPrivateProfileSectionW( renameW, buffer, size, wininitW ))) return TRUE;
if (res < size - 2) break;
if( err==ERROR_FILE_NOT_FOUND ) if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
{ size *= 2;
/* No file - nothing to do. Great! */ if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
WINE_TRACE("Wininit.ini not present - no renaming to do\n");
return TRUE;
}
WINE_ERR("There was an error in reading wininit.ini file - %d\n",
GetLastError() );
return FALSE;
} }
while( GetLine( hFile, buffer, sizeof(buffer) ) && for (str = buffer; *str; str += strlenW(str) + 1)
lstrcmpiA(buffer,RENAME_FILE_SECTION)!=0 )
; /* Read the lines until we match the rename section */
while( GetLine( hFile, buffer, sizeof(buffer) ) && buffer[0]!='[' )
{ {
/* First, make sure this is not a comment */ WCHAR *value;
if( buffer[0]!=';' && buffer[0]!='\0' )
{
char * value;
value=strchr(buffer, '='); if (*str == ';') continue; /* comment */
if (!(value = strchrW( str, '=' ))) continue;
if( value==NULL ) /* split the line into key and value */
{ *value++ = 0;
WINE_WARN("Line with no \"=\" in it in wininit.ini - %s\n",
buffer);
} else
{
/* split the line into key and value */
*(value++)='\0';
if( lstrcmpiA( "NUL", buffer )==0 ) if (!lstrcmpiW( nulW, str ))
{ {
WINE_TRACE("Deleting file \"%s\"\n", value ); WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value) );
/* A file to delete */ if( !DeleteFileW( value ) )
if( !DeleteFileA( value ) ) WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value) );
WINE_WARN("Error deleting file \"%s\"\n", value); }
} else else
{ {
WINE_TRACE("Renaming file \"%s\" to \"%s\"\n", value, WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
buffer );
if( !MoveFileExA(value, buffer, MOVEFILE_COPY_ALLOWED| if( !MoveFileExW(value, str, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
MOVEFILE_REPLACE_EXISTING) ) WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
{ }
WINE_WARN("Error renaming \"%s\" to \"%s\"\n", value, str = value;
buffer );
}
}
}
}
} }
CloseHandle( hFile ); if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
if( !MoveFileExA( RENAME_FILE, RENAME_FILE_TO, MOVEFILE_REPLACE_EXISTING) ) if( !MoveFileExW( wininitW, wininitbakW, MOVEFILE_REPLACE_EXISTING) )
{ {
WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() ); WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );