Check for spaces in a directory path: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(→MUI) |
(→Usage) |
||
Line 8: | Line 8: | ||
== Usage == | == Usage == | ||
=== Non-MUI === | === Non-MUI === | ||
<highlight-nsis> | <highlight-nsis> | ||
Page Directory "" "" " | Page Directory "" "" "DirectoryLeave" | ||
</highlight-nsis> | |||
=== MUI === | === MUI === | ||
Line 16: | Line 18: | ||
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "DirectoryLeave" | !define MUI_PAGE_CUSTOMFUNCTION_LEAVE "DirectoryLeave" | ||
!insertmacro MUI_PAGE_DIRECTORY | !insertmacro MUI_PAGE_DIRECTORY | ||
</highlight-nsis> | |||
=== DirectoryLeave Function === | |||
<highlight-nsis> | |||
Function DirectoryLeave | |||
# Call the CheckForSpaces function. | |||
Push $INSTDIR | |||
Call CheckForSpaces | |||
Pop $R0 | |||
# Check if any spaces exist in $INSTDIR. | |||
StrCmp $R0 0 NoSpaces | |||
# Plural if more than 1 space in $INSTDIR. | |||
StrCmp $R0 1 0 +3 | |||
StrCpy $R1 "" | |||
Goto +2 | |||
StrCpy $R1 "s" | |||
# Show message box then take the user back to the Directory page. | |||
MessageBox MB_OK|MB_ICONEXCLAMATION "Error: The Installaton directory \ | |||
has $R0 space$R1.$\nPlease remove the space$R1." | |||
Abort | |||
NoSpaces: | |||
FunctionEnd | |||
</highlight-nsis> | </highlight-nsis> | ||
Revision as of 18:59, 12 January 2006
Author: Afrow UK (talk, contrib) |
Description
This script will tell the user that he has entered spaces (" ") in the installation directory. This can be used if you don't want spaces in the directory path, and should be placed in the directory page's leave function (because if the directory page has spaces, then it will go back to the directory page).
Updated 10th October 2003
Usage
Non-MUI
Page Directory "" "" "DirectoryLeave"
MUI
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "DirectoryLeave" !insertmacro MUI_PAGE_DIRECTORY
DirectoryLeave Function
Function DirectoryLeave # Call the CheckForSpaces function. Push $INSTDIR Call CheckForSpaces Pop $R0 # Check if any spaces exist in $INSTDIR. StrCmp $R0 0 NoSpaces # Plural if more than 1 space in $INSTDIR. StrCmp $R0 1 0 +3 StrCpy $R1 "" Goto +2 StrCpy $R1 "s" # Show message box then take the user back to the Directory page. MessageBox MB_OK|MB_ICONEXCLAMATION "Error: The Installaton directory \ has $R0 space$R1.$\nPlease remove the space$R1." Abort NoSpaces: FunctionEnd
The Function
Function CheckForSpaces Exch $R0 Push $R1 Push $R2 Push $R3 StrCpy $R1 -1 StrCpy $R3 $R0 StrCpy $R0 0 loop: StrCpy $R2 $R3 1 $R1 IntOp $R1 $R1 - 1 StrCmp $R2 "" done StrCmp $R2 " " found Goto loop found: IntOp $R0 $R0 + 1 Goto loop done: Pop $R3 Pop $R2 Pop $R1 Exch $R0 FunctionEnd
-Stu