|
From: <xue...@us...> - 2003-09-18 13:30:42
|
Update of /cvsroot/popfile/windows
In directory sc8-pr-cvs1:/tmp/cvs-serv22470
Modified Files:
stop_popfile.nsi
Log Message:
Improved error reporting, controlled by new optional parameter.
Index: stop_popfile.nsi
===================================================================
RCS file: /cvsroot/popfile/windows/stop_popfile.nsi,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stop_popfile.nsi 16 Sep 2003 17:39:00 -0000 1.1
--- stop_popfile.nsi 18 Sep 2003 13:27:50 -0000 1.2
***************
*** 3,14 ****
# stop_popfile.nsi --- A simple 'command-line' utility to shutdown POPFile silently.
#
- # One parameter is required: the port number used to access the
- # POPFile User Interface (the UI port number, in range 1 to 65535).
- #
- # Returns error code 0 if shutdown was successful (otherwise returns 1)
- #
- # If an invalid parameter is given (eg 131072), an error is returned.
- # If no parameter is supplied, the usage information is displayed.
- #
# Copyright (c) 2001-2003 John Graham-Cumming
#
--- 3,6 ----
***************
*** 28,37 ****
# along with POPFile; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#-------------------------------------------------------------------------------------------
#
! # An example of a simple batch file to shut down POPFile using the default port:
#
! # STOP_PF.EXE 8080
#
# A batch file which checks the error code after trying to shutdown POPFile using port 9090:
--- 20,54 ----
# along with POPFile; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #-------------------------------------------------------------------------------------------
+ # Notes:
+ #
+ # One parameter is required: the port number used to access the POPFile User Interface
+ # (the UI port number, in range 1 to 65535).
+ #
+ # Returns error code 0 if shutdown was successful (otherwise returns 1)
+ #
+ # There is also an optional parameter which selects the reporting mode:
+ # /SHOWERRORS, /SHOWALL or /NONE. (/NONE is used as the default if no mode is supplied)
#
+ # If '/SHOWERRORS' is specified then a message will be shown if any errors were detected
+ # (nothing is displayed if the shutdown was successful).
+ #
+ # If '/SHOWALL' is specified then a success/fail message will always be shown.
+ #
+ # If '/NONE' is specified then no messages are displayed.
+ #
+ # Uppercase or lowercase can be used for this optional parameter.
+ # If the optional parameter is used, it must be the first parameter.
+ #
+ # If an invalid parameter is given (eg 131072), an error is returned.
+ #
+ # If no parameters are supplied, or if only '/?' or '/HELP' is supplied, the copyright and
+ # usage information is displayed.
#-------------------------------------------------------------------------------------------
#
! # An example of a simple batch file to shut down POPFile using the default port (if any errors
! # are detected, a message box will be displayed):
#
! # STOP_PF.EXE /SHOWERRORS 8080
#
# A batch file which checks the error code after trying to shutdown POPFile using port 9090:
***************
*** 56,60 ****
Caption "POPFile Silent Shutdown Utility"
! !define VERSION "0.3.0" ; see 'VIProductVersion' comment below for format details
; Specify EXE filename and icon for the 'installer'
--- 73,77 ----
Caption "POPFile Silent Shutdown Utility"
! !define VERSION "0.4.0" ; see 'VIProductVersion' comment below for format details
; Specify EXE filename and icon for the 'installer'
***************
*** 93,154 ****
Section Shutdown
! !define L_GUI $R9
!
! ; Create the plugins directory (it will be deleted automatically when we exit)
! InitPluginsDir
! ; Check if any command-line parameter was supplied
Call GetParameters
! Pop ${L_GUI}
! StrCmp ${L_GUI} "" 0 check_port
MessageBox MB_OK "POPFile Silent Shutdown Utility v${VERSION} \
! Copyright (c) 2001-2003 John Graham-Cumming\
! $\r$\n$\r$\n\
! This utility shuts POPFile down silently, without opening a browser window.\
! $\r$\n$\r$\n\
! Usage: STOP_PF <PORT>\
! $\r$\n$\r$\n\
! where <PORT> is the port number used to access the POPFile User Interface (normally 8080)\
! $\r$\n$\r$\n\
! A success/fail error code is returned which can be checked in a batch file:\
! $\r$\n\
! $\r$\n @ECHO OFF\
! $\r$\n START /W STOP_PF 8080\
! $\r$\n IF ERRORLEVEL 1 GOTO FAILED\
! $\r$\n ECHO Shutdown succeeded\
! $\r$\n GOTO DONE\
! $\r$\n :FAILED\
! $\r$\n ECHO **** Shutdown failed ****\
! $\r$\n :DONE\
! $\r$\n$\r$\n\
! Distributed under the terms of the GNU General Public License (GPL).\
! "
! Goto ok
! check_port:
! ; Valid port numbers are in the range 1 to 65535 inclusive
! Push ${L_GUI}
! Call StrCheckDecimal
Pop ${L_GUI}
! StrCmp ${L_GUI} "" port_error
IntCmp ${L_GUI} 0 port_error port_error
IntCmp ${L_GUI} 65535 0 0 port_error
; Attempt to shutdown POPFile silently (nothing is displayed, no browser window is opened)
NSISdl::download_quiet http://127.0.0.1:${L_GUI}/shutdown "$PLUGINSDIR\shutdown.htm"
! Pop ${L_GUI}
! StrCmp ${L_GUI} "success" ok
port_error:
Abort ; Return error code 1 (failure)
ok: ; Return error code 0 (success)
SectionEnd
#--------------------------------------------------------------------------
# General Purpose Library Function: GetParameters
--- 110,248 ----
Section Shutdown
! !define L_GUI $R9 ; holds POPFile User Interface (UI) port number
! !define L_PARAMS $R8 ; parameter(s) extracted from the command-line
! !define L_REPORT $R7 ; 'none' = no msgs, 'errors' = only errors, 'all' = errors & success
! !define L_RESULT $R6 ; the status returned from the shutdown request
! !define L_TEMP $R5
! StrCpy ${L_REPORT} "none" ; default is to display no success or failure messages
! ; It does not matter if the command-line parameters are uppercase or lowercase
Call GetParameters
! Pop ${L_PARAMS}
! StrCmp ${L_PARAMS} "" usage
! StrCmp ${L_PARAMS} "/?" usage
! StrCmp ${L_PARAMS} "/help" usage
!
! Push ${L_PARAMS} ; Command-line may have more than one parameter
! Call GetNextParam
! Pop ${L_PARAMS} ; rest of the command-line
! Pop ${L_RESULT} ; first parameter from command-line
! StrCmp ${L_RESULT} "" usage
!
! ; If the first parameter starts with a digit, assume it is the PORT parameter
! ; and use the default REPORT mode (no messages displayed)
!
! StrCpy ${L_TEMP} ${L_RESULT} 1
! Push ${L_TEMP}
! Call StrCheckInteger
! Pop ${L_TEMP}
! StrCmp ${L_TEMP} "" 0 port_checks
! StrCmp ${L_RESULT} "/showerrors" only_errors
! StrCmp ${L_RESULT} "/showall" all_cases
! StrCmp ${L_RESULT} "/none" other_param
! Goto option_error
!
! usage:
MessageBox MB_OK "POPFile Silent Shutdown Utility v${VERSION} \
! Copyright (c) 2001-2003 John Graham-Cumming\
! $\r$\n$\r$\n\
! This command-line utility shuts POPFile down silently, without opening a browser window.\
! $\r$\n$\r$\n\
! Usage: STOP_PF [ <REPORT> ] <PORT>\
! $\r$\n$\r$\n\
! where <PORT> is the port number used to access the POPFile User Interface (normally 8080)\
! $\r$\n$\r$\n\
! and the optional <REPORT> is /SHOWERRORS (only error messages shown), /SHOWALL\
! $\r$\n\
! (success or error messages always shown), or /NONE (no messages - this is the default).\
! $\r$\n$\r$\n\
! A success/fail error code is always returned which can be checked in a batch file:\
! $\r$\n\
! $\r$\n @ECHO OFF\
! $\r$\n START /W STOP_PF 8080\
! $\r$\n IF ERRORLEVEL 1 GOTO FAILED\
! $\r$\n ECHO Shutdown succeeded\
! $\r$\n GOTO DONE\
! $\r$\n :FAILED\
! $\r$\n ECHO **** Shutdown failed ****\
! $\r$\n :DONE\
! $\r$\n$\r$\n\
! Distributed under the terms of the GNU General Public License (GPL)."
! Goto error_exit
! only_errors:
! StrCpy ${L_REPORT} "errors"
! Goto other_param
! all_cases:
! StrCpy ${L_REPORT} "all"
! other_param:
! Push ${L_PARAMS}
! Call GetNextParam
! Pop ${L_PARAMS}
! Pop ${L_RESULT} ; the second parameter from the command-line
!
! port_checks:
! StrCmp ${L_RESULT} "" no_port_supplied
! Push ${L_RESULT}
! Call StrCheckInteger
Pop ${L_GUI}
! StrCmp ${L_GUI} "" integer_error
IntCmp ${L_GUI} 0 port_error port_error
IntCmp ${L_GUI} 65535 0 0 port_error
+ ; Create the plugins directory (it will be deleted automatically when we exit)
+
+ InitPluginsDir
+
; Attempt to shutdown POPFile silently (nothing is displayed, no browser window is opened)
NSISdl::download_quiet http://127.0.0.1:${L_GUI}/shutdown "$PLUGINSDIR\shutdown.htm"
! Pop ${L_RESULT}
! StrCmp ${L_RESULT} "success" ok
! StrCmp ${L_REPORT} "none" exit
! MessageBox MB_OK|MB_ICONEXCLAMATION \
! "Silent shutdown using port '${L_GUI}' failed\
! $\r$\n\
! (error: ${L_RESULT})"
! Goto error_exit
!
! no_port_supplied:
! StrCmp ${L_REPORT} "none" exit
! MessageBox MB_OK|MB_ICONEXCLAMATION "No UI port was supplied"
! Goto error_exit
!
! integer_error:
! StrCmp ${L_REPORT} "none" exit
! MessageBox MB_OK|MB_ICONEXCLAMATION "Port number '${L_RESULT}' should only contain the \
! digits 0 to 9"
! Goto error_exit
port_error:
+ StrCmp ${L_REPORT} "none" exit
+ MessageBox MB_OK|MB_ICONEXCLAMATION "Port number '${L_GUI}' is not in range 1 to 65535"
+ Goto error_exit
+
+ option_error:
+ MessageBox MB_OK|MB_ICONEXCLAMATION "Unknown option supplied$\r$\n(${L_RESULT})"
+
+ error_exit:
Abort ; Return error code 1 (failure)
ok: ; Return error code 0 (success)
+ StrCmp ${L_REPORT} "none" exit
+ StrCmp ${L_REPORT} "errors" exit
+ MessageBox MB_OK|MB_ICONINFORMATION \
+ "Silent shutdown OK\
+ $\r$\n\
+ (port '${L_GUI}' used)"
+
+ exit:
SectionEnd
+
#--------------------------------------------------------------------------
# General Purpose Library Function: GetParameters
***************
*** 176,180 ****
Push $R2
Push $R3
!
StrCpy $R0 $CMDLINE 1
StrCpy $R1 '"'
--- 270,274 ----
Push $R2
Push $R3
!
StrCpy $R0 $CMDLINE 1
StrCpy $R1 '"'
***************
*** 183,187 ****
StrCmp $R0 '"' loop
StrCpy $R1 ' ' ; we're scanning for a space instead of a quote
!
loop:
StrCpy $R0 $CMDLINE 1 $R2
--- 277,281 ----
StrCmp $R0 '"' loop
StrCpy $R1 ' ' ; we're scanning for a space instead of a quote
!
loop:
StrCpy $R0 $CMDLINE 1 $R2
***************
*** 190,194 ****
IntOp $R2 $R2 + 1
Goto loop
!
loop2:
IntOp $R2 $R2 + 1
--- 284,288 ----
IntOp $R2 $R2 + 1
Goto loop
!
loop2:
IntOp $R2 $R2 + 1
***************
*** 196,200 ****
StrCmp $R0 " " loop2
StrCpy $R0 $CMDLINE "" $R2
!
Pop $R3
Pop $R2
--- 290,294 ----
StrCmp $R0 " " loop2
StrCpy $R0 $CMDLINE "" $R2
!
Pop $R3
Pop $R2
***************
*** 205,209 ****
#--------------------------------------------------------------------------
! # General Purpose Library Function: StrCheckDecimal
#--------------------------------------------------------------------------
#
--- 299,372 ----
#--------------------------------------------------------------------------
! # General Purpose Library Function: GetNextParam
! #--------------------------------------------------------------------------
! #
! # Extracts the next parameter (if any) from a list of space-separated parameters
! #
! # Inputs:
! # (top of stack) - a list of parameters separated by spaces (list may be empty)
! #
! # Outputs:
! # (top of stack) - the remaining parameters (if any)
! # (top of stack - 1) - the first parameter found in the list
! #
! # Usage:
! # Push "ABC 123 XYZ"
! # Call GetNextParam
! # Pop $R0
! # Pop $R1
! #
! # ($R0 at this point is "123 XYZ")
! # ($R1 at this point is "ABC")
! #
! #--------------------------------------------------------------------------
!
! Function GetNextParam
!
! !define L_CHAR $R9 ; a character from the input list
! !define L_LIST $R8 ; input list of parameters (may be empty)
! !define L_PARAM $R7 ; the first parameter found
!
! Exch ${L_LIST}
! Push ${L_PARAM}
! Push ${L_CHAR}
!
! StrCpy ${L_PARAM} ""
!
! loop_L:
! StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list
! StrCmp ${L_CHAR} "" done
! StrCpy ${L_LIST} ${L_LIST} "" 1 ; remove char from input list
! StrCmp ${L_CHAR} " " loop_L
!
! loop_P:
! StrCpy ${L_PARAM} ${L_PARAM}${L_CHAR}
! StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list
! StrCmp ${L_CHAR} "" done
! StrCpy ${L_LIST} ${L_LIST} "" 1
! StrCmp ${L_CHAR} " " 0 loop_P ; loop until a space is found
!
! loop_T:
! StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list
! StrCmp ${L_CHAR} "" done
! StrCmp ${L_CHAR} " " 0 done
! StrCpy ${L_LIST} ${L_LIST} "" 1 ; remove trailing spaces
! Goto loop_T
!
! done:
! Pop ${L_CHAR}
! Exch ${L_PARAM} ; put parameter on stack (may be "")
! Exch
! Exch ${L_LIST} ; put revised list on stack (may be "")
!
! !undef L_CHAR
! !undef L_LIST
! !undef L_PARAM
!
! FunctionEnd
!
!
! #--------------------------------------------------------------------------
! # General Purpose Library Function: StrCheckInteger
#--------------------------------------------------------------------------
#
***************
*** 212,216 ****
#
# Inputs:
! # (top of stack) - string which may contain a decimal number
#
# Outputs:
--- 375,379 ----
#
# Inputs:
! # (top of stack) - string which may contain an integer number
#
# Outputs:
***************
*** 219,223 ****
# Usage:
# Push "12345"
! # Call StrCheckDecimal
# Pop $R0
#
--- 382,386 ----
# Usage:
# Push "12345"
! # Call StrCheckInteger
# Pop $R0
#
***************
*** 226,230 ****
#--------------------------------------------------------------------------
! Function StrCheckDecimal
!define DECIMAL_DIGIT "0123456789"
--- 389,393 ----
#--------------------------------------------------------------------------
! Function StrCheckInteger
!define DECIMAL_DIGIT "0123456789"
|