Old 3rd March 2016, 10:56   #1
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
nsDialogs - NSD_SetText "timing" issue

Hi,

I have the following function:

code:
Function generate
Call getOptions
StrCpy $license "$hwsn-$build"
blowfish::encrypt $license ${BF_PASSWORD}
${NSD_SetText} $hCtl_license_gen_TextBox1 $8
${If} $autoApply == 1
nsExec::Exec "taskkill /F /T /IM MyApp.exe"
WriteINIStr "$PROGRAMFILES\MyApp\Config.ini" License LicenseKey $8
nsExec::ExecToStack "net stop MyAppApache /Y"
${EndIf}
FunctionEnd



Basically what I do is generate an encrypted "license" which will be displayed to the user in a text field. If the checkbox "Auto Apply" is checked, the license will also be added to the config file.

My problem is the following: I would like the text field to be updated with the value of the license before the other operations (kill my process, write to ini, kill my service) but it doesn't. The value is added only when all the other things are done.

Any idea why?

Thanks,
Mircea
Mircea M is offline   Reply With Quote
Old 3rd March 2016, 11:44   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,316
You are performing operations on the UI thread that prevents it from processing messages. A quick solution might be to call RedrawWindow with the system plugin but it is better to use the BgWorker plugin...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd March 2016, 12:40   #3
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
Hi Anders,

thanks for the suggestion(s). I tried the BgWorker plugin. I have the following code now:

code:
Function generate
Call getOptions
StrCpy $license "$hwsn-$build"
blowfish::encrypt $license ${BF_PASSWORD}
${NSD_SetText} $hCtl_license_gen_TextBox1 $8
${If} $autoApply == 1
GetFunctionAddress $0 aaply
BgWorker::CallAndWait
${EndIf}
FunctionEnd

Function aaply
nsExec::Exec "taskkill /F /T /IM MyApp.exe"
WriteINIStr "$PROGRAMFILES\Config.ini" License LicenseKey $8
nsExec::ExecToStack "net stop MyAppApache /Y"
FunctionEnd



Problem is, the installer crashes whenever I enable my CheckBox and call the generate function...
Mircea M is offline   Reply With Quote
Old 3rd March 2016, 13:10   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,316
Why did you not comment things out until you found the line with the actual problem? Not everything works when called on a background thread because NSIS and plugins were never designed to do this. You are also missing a lot of Pop's in your code.

I can't get it to crash:
PHP Code:
Page Custom MyPage 
Page InstFiles 

!include nsDialogs.nsh 
!include LogicLib.nsh 



Function aaply
    nsExec
::Exec "taskkill /F /T /IM MyApp.exe"
    
#Pop ??
    
WriteINIStr "$pluginsdir\Config.ini" License LicenseKey $8
    nsExec
::ExecToStack "net stop MyAppApache /Y"
    
#Pop $0
    #Pop ??
    #MessageBox mb_ok |$0|
FunctionEnd

Function Crash 
Pop 
$7
EnableWindow 
$7 0
System
::Call KERNEL32::GetTickCount()i.r0
${NSD_SetText} $$0
GetFunctionAddress 
$0 aaply
BgWorker
::CallAndWait
EnableWindow 
$7 1
FunctionEnd 

Function Generate 
Pop 
$0
EnableWindow 
$8 0
System
::Call KERNEL32::GetTickCount()i.r0
${NSD_SetText} $$0
System
::Call USER32::UpdateWindow(i$9) ; Comment out this for slow updates
Sleep 3333
EnableWindow 
$8 1
FunctionEnd 


Function MyPage 
nsDialogs
::Create 1018 
Pop 
$
${NSD_CreateText0 10u 10012u "" 
Pop $9
${NSD_CreateBrowseButton0 30u 10012u "Works"
Pop $8
${NSD_OnClick} $8 Generate 
${NSD_CreateBrowseButton0 50u 10012u "Crash?"
Pop $0
${NSD_OnClick} $0 Crash 
nsDialogs
::Show 
FunctionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd March 2016, 14:27   #5
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
Hi again,

I used the system messages instead of BgWorker and it works (also added the Pops). Thanks for all your help!

Mircea
Mircea M is offline   Reply With Quote
Old 3rd March 2016, 14:36   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,316
Quote:
Originally Posted by Mircea M View Post

I used the system messages instead of BgWorker and it works (also added the Pops).
Not sure why you call it a message. UpdateWindow paints the window once but your UI is still technically not responding and long running actions are not recommended.

IntOp $PostCount $PostCount + 1
Anders 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