Check for spaces in a directory path: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.)
Line 17: Line 17:
!insertmacro MUI_PAGE_DIRECTORY </highlight-nsis>
!insertmacro MUI_PAGE_DIRECTORY </highlight-nsis>


== The Function == <highlight-nsis>
== The Function ==
<highlight-nsis>
Function CheckForSpaces
Function CheckForSpaces
Exch $R0
  Push $R1
  Push $R1
  Push $R2
  Push $R2
Line 24: Line 26:
  Push $R4
  Push $R4
  StrCpy $R1 -1
  StrCpy $R1 -1
  StrCpy $R3 0
  StrCpy $R3 $R0
StrCpy $R0 0
  loop:
  loop:
   StrCpy $R2 $INSTDIR 1 $R1
   StrCpy $R2 $R3 1 $R1
   IntOp $R1 $R1 - 1
   IntOp $R1 $R1 - 1
   StrCmp $R2 "" done
   StrCmp $R2 "" done
Line 33: Line 36:
  Goto loop
  Goto loop
  found:
  found:
   IntOp $R3 $R3 + 1
   IntOp $R0 $R0 + 1
  Goto loop
  Goto loop
  done:
  done:
  StrCmp $R3 0 +3
  MessageBox MB_OK|MB_ICONEXCLAMATION "Error: The Installaton directory \
has $R3 spaces.$\nPlease remove the spaces."
  Abort
  Pop $R4
  Pop $R4
  Pop $R3
  Pop $R3
  Pop $R2
  Pop $R2
  Pop $R1
  Pop $R1
Exch $R0
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>

Revision as of 18:55, 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 "" "" "CheckForSpaces"

MUI

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "CheckForSpaces"
!insertmacro MUI_PAGE_DIRECTORY

The Function

Function CheckForSpaces
 Exch $R0
 Push $R1
 Push $R2
 Push $R3
 Push $R4
 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
   StrCpy $R4 "$R2$R4"
 Goto loop
 found:
   IntOp $R0 $R0 + 1
 Goto loop
 done:
 Pop $R4
 Pop $R3
 Pop $R2
 Pop $R1
 Exch $R0
FunctionEnd

-Stu