|
From: <xue...@us...> - 2003-10-09 11:52:24
|
Update of /cvsroot/popfile/windows
In directory sc8-pr-cvs1:/tmp/cvs-serv24551
Modified Files:
WriteEnvStr.nsh
Log Message:
Improved Win9x handling of the "create environment variable" case.
Index: WriteEnvStr.nsh
===================================================================
RCS file: /cvsroot/popfile/windows/WriteEnvStr.nsh,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** WriteEnvStr.nsh 30 Sep 2003 13:12:12 -0000 1.2
--- WriteEnvStr.nsh 9 Oct 2003 11:52:20 -0000 1.3
***************
*** 57,84 ****
Function WriteEnvStr
! Exch $1 ; $1 has environment variable value
Exch
! Exch $0 ; $0 has environment variable name
! Push $2
! Push $3
Call IsNT
! Pop $2
! StrCmp $2 1 WriteEnvStr_NT
! ; On Win9x system, so we append the new data to AUTOEXEC.BAT
! StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:)
! FileOpen $2 "$2\autoexec.bat" a
! FileSeek $2 -2 END
! FileRead $2 $3
! FileSeek $2 0 END
! StrCmp $3 "$\r$\n" eof_ok
! FileWrite $2 "$\r$\n" ; file did not end with CRLF so we append CRLF
! eof_ok:
! FileWrite $2 "SET $0=$1$\r$\n"
! FileClose $2
SetRebootFlag true
Goto WriteEnvStr_done
--- 57,155 ----
Function WriteEnvStr
!
! ; Registers common to Win9x and non-Win9x processing
!
! !define ENV_NAME $R9 ; name of the environment variable
! !define ENV_VALUE $R8 ; value of the environment variable
! !define TEMP $R7
!
! ; Registers used only for Win9x processing
!
! !define DESTN $R6 ; used to access the revised AUTOEXEC.BAT file
! !define ENV_FOUND $R5 ; 0 = variable not found, 1 = variable found in AUTOEXEC.BAT
! !define ENV_SETLEN $R4 ; length of the left-hand side of the SET command (ENV_SETNAME)
! !define ENV_SETNAME $R3 ; left-hand side of the SET command for the variable, incl '='
! !define LINE $R2 ; a line from AUTOEXEC.BAT
! !define SOURCE $R1 ; used to access original AUTOEXEC.BAT file
! !define TEMPFILE $R0 ; name of file used to build the revised AUTOEXEC.BAT file
!
! Exch ${ENV_VALUE}
Exch
! Exch ${ENV_NAME}
! Push ${TEMP}
Call IsNT
! Pop ${TEMP}
! StrCmp ${TEMP} 1 WriteEnvStr_NT
! ; On Win9x system, so we add the new data to AUTOEXEC.BAT if it is not already there
!
! Push ${DESTN}
! Push ${ENV_FOUND}
! Push ${ENV_SETLEN}
! Push ${ENV_SETNAME}
! Push ${LINE}
! Push ${SOURCE}
! Push ${TEMPFILE}
!
! StrCpy ${ENV_SETNAME} "SET ${ENV_NAME}="
! StrLen ${ENV_SETLEN} ${ENV_SETNAME}
!
! StrCpy ${SOURCE} $WINDIR 2 ; Get the drive used for Windows (usually 'C:')
! FileOpen ${SOURCE} "${SOURCE}\autoexec.bat" r
! GetTempFileName ${TEMPFILE}
! FileOpen ${DESTN} ${TEMPFILE} w
!
! StrCpy ${ENV_FOUND} 0
! loop:
! FileRead ${SOURCE} ${LINE} ; Read line from AUTOEXEC.BAT
! StrCmp ${LINE} "" eof_found
! Push ${LINE}
! Call TrimNewlines
! Pop ${LINE}
! StrCmp ${LINE} "" copy_line ; Blank lines are preserved in the copy we make
! StrCpy ${TEMP} ${LINE} ${ENV_SETLEN}
! StrCmp ${TEMP} ${ENV_SETNAME} 0 copy_line
! StrCpy ${ENV_FOUND} 1 ; Have found a match. Now check the value it defines.
! StrCpy ${TEMP} ${LINE} "" ${ENV_SETLEN}
! StrCmp ${TEMP} ${ENV_VALUE} 0 different_value
! ReadEnvStr ${TEMP} ${ENV_NAME} ; Identical value found. Now see if it currently exists.
! StrCmp ${TEMP} ${ENV_VALUE} copy_line
! SetRebootFlag true ; Value does not exist, so we need to reboot
! copy_line:
! FileWrite ${DESTN} "${LINE}$\r$\n"
! Goto loop
!
! different_value:
! FileWrite ${DESTN} "REM ${LINE}$\r$\n" ; 'Comment out' the incorrect value
! FileWrite ${DESTN} "${ENV_SETNAME}${ENV_VALUE}$\r$\n"
SetRebootFlag true
+ Goto loop
+
+ eof_found:
+ StrCmp ${ENV_FOUND} 1 autoexec_done
+ FileWrite ${DESTN} "${ENV_SETNAME}${ENV_VALUE}$\r$\n" ; Append line for the new variable
+ SetRebootFlag true
+
+ autoexec_done:
+ FileClose ${SOURCE}
+ FileClose ${DESTN}
+
+ IfRebootFlag 0 win9x_done
+ StrCpy ${SOURCE} $WINDIR 2
+ Delete "${SOURCE}\autoexec.bat"
+ CopyFiles /SILENT ${TEMPFILE} "${SOURCE}\autoexec.bat"
+ Delete ${TEMPFILE}
+
+ win9x_done:
+ Pop ${TEMPFILE}
+ Pop ${SOURCE}
+ Pop ${LINE}
+ Pop ${ENV_SETNAME}
+ Pop ${ENV_SETLEN}
+ Pop ${ENV_FOUND}
+ Pop ${DESTN}
Goto WriteEnvStr_done
***************
*** 86,98 ****
WriteEnvStr_NT:
! WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
0 "STR:Environment" /TIMEOUT=5000
WriteEnvStr_done:
! Pop $3
! Pop $2
! Pop $1
! Pop $0
FunctionEnd
--- 157,181 ----
WriteEnvStr_NT:
! WriteRegExpandStr ${WriteEnvStr_RegKey} ${ENV_NAME} ${ENV_VALUE}
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
0 "STR:Environment" /TIMEOUT=5000
WriteEnvStr_done:
! Pop ${TEMP}
! Pop ${ENV_NAME}
! Pop ${ENV_VALUE}
!
! !undef ENV_NAME
! !undef ENV_VALUE
! !undef TEMP
!
! !undef DESTN
! !undef ENV_FOUND
! !undef ENV_SETLEN
! !undef ENV_SETNAME
! !undef LINE
! !undef SOURCE
! !undef TEMPFILE
!
FunctionEnd
|