hooklee
16th May 2005 09:26 UTC
Problem with $INSTDIR: a bug?
When I click "Cancel" button of the Dir-Browsing dialog of DirPage, $INSTDIR becomes the last path I have clicked in the cancelled dialog, though the original value (maybe different from the real value of $INSTDIR) is displayed in the edit box. As a result, I cannot verify the correct $INSTDIR in my own LeaveDirPage function :-(
To make the above description clearer, see the following code segment and example.
PageEx directory
  DirVerify leave
  PageCallbacks "" "" LeaveDirPage
PageExEnd
Function LeaveDirPage
...
FunctionEnd
      
      -- The original value of $INSTDIR is "C:\temp"
      -- Click "Browse" button, click a different folder "C:\abc", then click "Cancel" button to close the dir-browsing dialog.
      -- Then, "C:\temp" remains in the edit box, however, now $INSTDIR = "C:\abc" if you check it in .onVerifyInstDir or LeaveDirPage function.
      -- After LeaveDirPage runs, $INSTDIR is assigned to the original value (i.e., the one displayed in the edit box) "C:\temp".
      -- Though NSIS will not install to a wrong dir, but LeaveDirPage cannot catch a correct one.
      
      Do you think it is a BUG? Or did I misuse antything?
    
      hooklee
      16th May 2005 09:56 UTC
      Two possible solutions to my problem:
      
      1) In LeaveDirPage function, read $INSTDIR from the edit box. Could anyone please tell me how to do so?
      
      2) In the pre function of the next page, verify $INSTDIR. If it is invalid, automatically back to DirPage. I failed to find a instruction to mimic the Back button. Please help me if you know. Thanks.
     
    
      Instructor
      16th May 2005 12:30 UTC
      I think there is two bugs:
      1. Problem you post
      2. SendMessage with WM_GETTEXT
          (crash: SendMessage $0 ${WM_GETTEXT} ${NSIS_MAX_STRLEN} $0)
      
      Try this:
      
Name "Output"
OutFile "Output.exe"
InstallDir "C:\temp"
!include "WinMessages.nsh"
PageEx directory
        DirVerify leave
        PageCallbacks "" "" LeaveDirPage
PageExEnd
Page instfiles
Function LeaveDirPage
        FindWindow $0 "#32770" "" $HWNDPARENT
        GetDlgItem $0 $0 1019
        System::Call "user32::SendMessage(i $0, i ${WM_GETTEXT}, i ${NSIS_MAX_STRLEN}, t .r0)"
        MessageBox MB_OK "$$INSTDIR={$INSTDIR}$\n$$0={$0}"
FunctionEnd
Section
SectionEnd
     
    
      hooklee
      16th May 2005 13:11 UTC
      Thanks for the code. Using GetWindowText may be simpler ;-)
      
      
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 1019 ; IDC_DIR
System::Call 'User32::GetWindowText(i $1, t .R0, i 256)'
     
    
      kichik
      17th May 2005 20:53 UTC
      The problem is indeed a bug. I have fix this in CVS. Thanks.
      
      The SendMessage is not a bug. When you use $0, you use its value, not a pointer to it.
     
    
      Instructor
      18th May 2005 08:40 UTC
      
      
        Originally posted by kichik
        The problem is indeed a bug. I have fix this in CVS. Thanks.
        
        The SendMessage is not a bug. When you use $0, you use its value, not a pointer to it.
      
Can you write an example using SendMessage $0 ${WM_GETTEXT} ...
    
 
    
      kichik
      19th May 2005 17:38 UTC
      I can't give you an example because it's impossible. You can't define pointers in the script without the System plug-in.