2 * Copyright (C) 2002 Andreas Mohr
3 * Copyright (C) 2002 Shachar Shemesh
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(wineboot);
26 const char * const RENAME_FILE="wininit.ini";
27 const char * const RENAME_FILE_SECTION="[rename]";
28 #define MAX_LINE_LENGTH (2*MAX_PATH+2)
30 static BOOL GetLine( HANDLE hFile, char *buf, size_t buflen )
38 if( !ReadFile( hFile, buf, 1, &read, NULL ) || read!=1 )
43 } while( isspace( *buf ) );
45 while( buf[i]!='\n' && i<=buflen &&
46 ReadFile( hFile, buf+i+1, 1, NULL, NULL ) )
57 if( i>0 && buf[i-1]=='\r' )
65 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
66 * Returns FALSE if there was an error, or otherwise if all is ok.
70 char buffer[MAX_LINE_LENGTH];
71 char ini_path[MAX_PATH];
75 res=GetWindowsDirectoryA( ini_path, sizeof(ini_path) );
79 WINE_ERR("Couldn't get the windows directory - error %ld\n",
85 if( res>=sizeof(ini_path) )
87 WINE_ERR("Windows path too long (%ld)\n", res );
92 sprintf( ini_path+res, "\\%s", RENAME_FILE );
94 hFile=CreateFileA(ini_path, GENERIC_READ,
95 FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
98 if( hFile==INVALID_HANDLE_VALUE )
100 DWORD err=GetLastError();
102 if( err==ERROR_FILE_NOT_FOUND )
104 /* No file - nothing to do. Great! */
105 WINE_TRACE("Wininit.ini not present - no renaming to do\n");
110 WINE_ERR("There was an error in reading wininit.ini file - %ld\n",
116 printf("Wine is finalizing your software installation. This may take a few minutes,\n");
117 printf("though it never actually does.\n");
119 while( GetLine( hFile, buffer, sizeof(buffer) ) &&
120 lstrcmpiA(buffer,RENAME_FILE_SECTION)!=0 )
121 ; /* Read the lines until we match the rename section */
123 while( GetLine( hFile, buffer, sizeof(buffer) ) && buffer[0]!='[' )
125 /* First, make sure this is not a comment */
126 if( buffer[0]!=';' && buffer[0]!='\0' )
130 value=strchr(buffer, '=');
134 WINE_WARN("Line with no \"=\" in it in wininit.ini - %s\n",
138 /* split the line into key and value */
141 if( lstrcmpiA( "NUL", buffer )==0 )
143 WINE_TRACE("Deleting file \"%s\"\n", value );
144 /* A file to delete */
145 if( !DeleteFileA( value ) )
146 WINE_WARN("Error deleting file \"%s\"\n", value);
149 WINE_TRACE("Renaming file \"%s\" to \"%s\"\n", value,
152 if( !MoveFileExA(value, buffer, MOVEFILE_COPY_ALLOWED|
153 MOVEFILE_REPLACE_EXISTING) )
155 WINE_WARN("Error renaming \"%s\" to \"%s\"\n", value,
163 CloseHandle( hFile );
165 if( !DeleteFileA( ini_path ) )
167 WINE_ERR("Couldn't erase %s, error %ld\n", ini_path, GetLastError() );
175 int main( int argc, char *argv[] )