Old 21st March 2009, 18:45   #1
Lupo73
Junior Member
 
Join Date: Jul 2008
Location: Italy
Posts: 11
Check a control

I'm using nsDialogs.. I have created a custom page where the user can load a file (with SelectFileDialog) and now I need to make a check, when the user click Next, to verify if the file selected is valid or not. If is not valid (if the name of the file doesn't contain the string "Pack") I need to open a message that ask to the user to select a correct file. Thanks for help!
Lupo73 is offline   Reply With Quote
Old 21st March 2009, 21:16   #2
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
You will need a callback function.
I guess you'll find all the info you need into nsDialogs documentation.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 22nd March 2009, 08:00   #3
Lupo73
Junior Member
 
Join Date: Jul 2008
Location: Italy
Posts: 11
But how can I set to don't leave the custom page if a variable has particular values?
Lupo73 is offline   Reply With Quote
Old 22nd March 2009, 12:10   #4
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
If you're using nsDialogs, then it won't leave the page anyway (that was a behavior of InstallOptions(2/Ex)). If you want to enable/disable the 'Next' button, you can do so in code as well.

The following code simply checks folder name validity - should be simple enough to adjust to check whether the specified file has 'pack' in it;
code:

!include "winmessages.nsh"
!include "LogicLib.nsh"
!include "nsDialogs.nsh"

Outfile "test.exe"

var dialog
var hwnd
var null

!macro RedrawControl control
Push $0
StrCpy $0 ${control}
System::Call "user32::InvalidateRect(i,i,i)i (r0, 0, 1)"
Pop $0
!macroend
!define RedrawControl `!insertmacro RedrawControl`

var InstallDir ; Use a variable separate from $INSTDIR to by-pass automatic adjustments

Function .onInit
StrCpy $InstallDir "$PROGRAMFILES\SomeFolder"
FunctionEnd


Page custom page.settings
Page InstFiles

var NSD_InstallDir
var NSD_InstallDirStatus
Function page.settings
nsDialogs::Create 1018
Pop $dialog

${NSD_CreateText} 3% 3% 89% 8% "$InstallDir"
Pop $NSD_InstallDir
${NSD_OnChange} $NSD_InstallDir page.settings.installdir.onchange

${NSD_CreateButton} 92% 3% 5% 8% "..."
Pop $hwnd
${NSD_OnClick} $hwnd page.settings.installdir.onclick

${NSD_CreateLabel} 3% 12% 100% 8% "status: "
Pop $NSD_InstallDirStatus

; Initialization
Push $NSD_InstallDir
Call page.settings.installdir.onchange

nsDialogs::Show
Abort
FunctionEnd

Function page.settings.installdir.onchange
Pop $hwnd
${NSD_GetText} $hwnd $InstallDir

; Kill trailing backslash
StrCpy $0 $InstallDir 1 -1
${If} $0 == "\"
StrLen $0 $InstallDir
IntOp $0 $0 - 1
StrCpy $InstallDir $InstallDir $0
${EndIf}

StrCpy $0 $InstallDir

; Kill invalid characters
Push $InstallDir
Exch $EXEDIR
Exch $EXEDIR
Pop $InstallDir

GetDlgItem $1 $HWNDPARENT 1 ; Next button

${If} $InstallDir == ""
${NSD_SetText} $NSD_InstallDirStatus "status: No destination folder specified"
EnableWindow $1 0
${ElseIf} $InstallDir != $0
${NSD_SetText} $NSD_InstallDirStatus "status: Destination folder contains disallowed characters"
EnableWindow $1 0
${ElseIf} ${FileExists} "$InstallDir\*.*"
${NSD_SetText} $NSD_InstallDirStatus "status: OK - Destination folder exists"
EnableWindow $1 1
${Else}
${NSD_SetText} $NSD_InstallDirStatus "status: OK - Destination folder will be created"
EnableWindow $1 1
${EndIf}
FunctionEnd

Function page.settings.installdir.onclick
nsDialogs::SelectFolderDialog "Please select the destination folder"
Pop $0
${If} $0 != "error"
${NSD_SetText} $NSD_InstallDir $0 ; This will automatically trigger page.settings.installdir.onchange
${EndIf}
FunctionEnd

Section ""
SectionEnd

Animaether is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump