NSIS license page prechecked - licensing

I have the following code in an NSIS script...
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_PAGE_LICENSE "eula.txt"
... and it works fine. As expected, the user needs to check the "I accept..." checkbox and then the install button is enabled.
I would like to simplify the process so that the checkbox is checked and the install button enabled by default and all the user needs to do is install or cancel.
Thank you all.

!define MUI_LICENSEPAGE_CHECKBOX ; Tell MUI you want the checkbox version of the license page
!define MUI_PAGE_CUSTOMFUNCTION_SHOW licshow ; Tell MUI to call a function before the page is displayed
!insertmacro MUI_PAGE_LICENSE "eula.txt" ; Adds the page
Function licshow ; Function to be called before the page is displayed
; Check it
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog (See attached picture)
GetDlgItem $0 $0 0x40A ; Find the checkbox control
SendMessage $0 ${BM_SETCHECK} 1 0 ; Check the checkbox
; Enable button
GetDlgItem $0 $hwndparent 1 ; Find the Install/Next button
EnableWindow $0 1 ; Enable the button
FunctionEnd
The last GetDlgItem+EnableWindow commands can be replaced by SendMessage $HWNDPARENT ${WM_COMMAND} 0x40A 0 to simulate the user clicking and would cause NSIS internal processing to enable the button.

I got lucky and was able to throw code together from several places.
The following works but I don't really know why NSIS-wise, which I don't like at all. If someone can break it down, I would really, really, appreciate it.
!define MUI_LICENSEPAGE_CHECKBOX
!define MUI_PAGE_CUSTOMFUNCTION_SHOW licshow
!insertmacro MUI_PAGE_LICENSE "eula.txt"
Function licshow
; Check it
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 0x40A
SendMessage $0 ${BM_SETCHECK} 1 0
; Enable button
GetDlgItem $0 $hwndparent 1
EnableWindow $0 1
FunctionEnd

Related

How to show and hide the on-screen keyboard "onboard" in mate-screensaver?

I'm trying to add a mate-screensaver, so that there would be a switch on and off the on-screen keyboard (onboard) right on the window. All the functionality is ready, I use 2 settings of the org.mate.screensaver schemas:
embedded-keyboard-enabled
embedded-keyboard-command "onboard --xid"
When switching the switch, I change the value of embedded-keyboard-enabled to true or false, respectively, but the keyboard appears or disappears only after restarting the mate-sreensaver window. As I understand it, the keyboard is created by an asynchronous process, but how do I hide or show it when I need it?
Of the functions, I use g_settings_set_boolean() to set the key parameter and g_settings_apply() to apply the changes.
I wrote a little script that I load at login which toggles hide and show using my middle mouse button. This works very when I want to hide/show it quickly.
You could copy and past the below script, give it execution permission, and run it at startup. (You may need to install xprintidle.)
Copy and paste below text in your favourite text editor.
#!/usr/bin/bash
if [[ "$(pidof -x $(basename $0))" != $$ ]] ; then exit;fi
rest=0
sleep 35;# (i need to wait 30-35 seconds at login for the physical mouse id to be assigned instead of the virtual mouse. It might go quicker for you.)
MOUSE=$(xinput --list --long | grep XIButtonClass | head -n 1 | egrep -o '[0-9]+');
toggle() { dbus-send --type=method_call --dest=org.onboard.Onboard /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.ToggleVisible;
}
while :;do
idle3=$(xprintidle)
STATE=$(xinput --query-state $MOUSE);
if [[ $STATE == *"button[2]=down"* ]];then toggle;sleep .5;elif [ $idle3 -gt 3000 ] && [ $rest = '.14' ];then rest=3;else rest=.14;fi;
sleep $rest;
done

How do I use the -exists flag from "window" command?

The maya manual does not describe how -exists flag in window command is used. I tried many ways of using it and it does not budge.
I've been fiddling and googling for 2 days, it wasn't going anywhere. I was only trying to detect if one of my window is opened or not.
Here's the test code I've got so far:
string $something = `window -title "name of the window" -widthHeight 200 150`;
columnLayout -adjustableColumn false;
button -label "detect this window" -command "dothis_1";
showWindow $something;
proc dothis_1()
{
if (`window -ex $something` == true)
{
print "window detected!\n";
}
else
{
print "window detection failed!\n";
}
}
//--------
So...I assumed I did something wrong somewhere or I simply misunderstood what -exists does? What did I do wrong and how do I detect whether my window is opened or not?
Your procedure has a variable scope issue, where it doesn't know what $something is, because it's defined outside of it.
You could make your procedure accept an argument for a window name you want to check against, create your window, then pass its name to the button's command:
string $something = `window -title "name of the window" -widthHeight 200 150`;
columnLayout -adjustableColumn false;
button -label "detect this window" -command ("dothis_1 " + $something); // Pass window name to proc.
showWindow $something;
proc dothis_1(string $win) {
if (`window -ex $win` == true) {
print "window detected!\n";
} else {
print "window detection failed!\n";
}
}
Alternatively you should be able to create a global variable so that it's accessible within the procedure too.
Although your use case is a bit weird. You can only click the button if the window exists!

Remember check box state when click back during NSIS installer

I have a checkbox on one of my customer installer pages
${NSD_CreateCheckbox} 0 0 100% 15 "Check to run"
Pop $SvcCheckBox
CreateFont $0 "$(^Font)" "10"
SendMessage $SvcCheckBox ${WM_SETFONT} $0 1
GetFunctionAddress $0 OnCheckbox
nsDialogs::OnClick $SvcCheckBox $0
I want to remember this if the user comes back to this page.
I've used the code below to attempt this
${NSD_OnBack} "pageLeave"
FunctionEnd
Function pageLeave
${NSD_GetState} $SvcCheckBoxState $SvcCheckBox
FunctionEnd
However, if a user un-checks the box, goes to the next page, comes back to this page, the check box is checked again. I need it to remain unchecked.
How do I implement my pageLeave check box state on page load?
You need initialize the checkbox state when you create the page. You don't need a On* handler unless you want to update something else on the page when the checkbox changes.
!include nsDialogs.nsh
Var CheckboxState
Var hCheckbox
Function .onInit
StrCpy $CheckboxState ${BST_CHECKED} ; Set initial/default state
FunctionEnd
Page Components
Page Custom MyPageCreate MyPageLeave
Page Components
Page InstFiles
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckbox} 0 0 100% 15 "Check to run"
Pop $hCheckbox
${NSD_SetState} $hCheckbox $CheckboxState
nsDialogs::Show
FunctionEnd
Function MyPageLeave
${NSD_GetState} $hCheckbox $CheckboxState
FunctionEnd
Section
DetailPrint State=$CheckboxState
SectionEnd

In AutoIt, WinWait still waits after the window has opened

I used AU3info to make sure I am using the right windows title.
RunWait ("\\sv44\vol1\Install\LibreOffice\install /exenoui")
WinWait("Installation of LibreOffice")
Send("{ENTER}")
What I am trying to achieve: When I the confirmation box appears ("Installation of LibreOffice"), press OK.
WinWait loops forever. I tried WinWaitActive...same result.
How do I make it work?
When manipulating external application windows, always use #RequireAdmin in order to get a permission elevation. Also use Opt("WinSearchChildren", 1) in order to search child windows too. Play with "WinTitleMatchMode".
#RequireAdmin ; Will give your script a permission elevation (sometimes its needed)
Opt("WinTitleMatchMode", 2) ; 1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ; 0=no, 1=search children also
RunWait("\\sv44\vol1\Install\LibreOffice\install /exenoui")
WinWait("Installation of LibreOffic")
Send("{ENTER}")
Notice that I use "Installation of LibreOffic" (missing "e") because Opt is set to use substring and not the whole title (just in case).

Problems on creating new page in NSIS with checkbox etc

I want to insert a new page in the installation which contains two checkboxes named Client version and Server version. On clicking client version nothing special happens as of now. But if server version is selected then a browse option should come to select a folder (This is not a installation folder). I am finding some difficulties to do this. I have added two checkboxes, a text box and browse button. In the onchange of checkbox I make browse and textbox.
But now the problem is
I want only one checkbox to be checked at a time.
When server version checked browse option should appear (which works now), but if it is unchecked again then that browse option should disappear (which does not work because I was not able to write code for that).
If I click Next on this page and then come back to same page using Back then all controls or checkbox I checked should be as it is. But now those browse options will disappear even if server version checkbox is selected (as I have not done proper coding for this also).
So please help me to do all these things. Also help me if there any other method to do the same
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
Var Dialog
Var Text
Var Text_State
Var Checkbox
Var Checkbox1
Var Checkbox_State
Var Checkbox1_State
var /GLOBAL SOURCETEXT
var /global SOURCE
var /global BROWSESOURCE
!include "MUI.nsh"
!include nsDialogs.nsh
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Page custom InstallPageCreate checkinstdir
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show
Var InstallPageDialog
Var InstallPage.DirRequest
Var InstallPage.BrowseButton
Var mui.WelcomePage
Var mui.WelcomePage1
Var mui.WelcomePage.Image1
Var mui.WelcomePage.Title
Var mui.WelcomePage.Text
Var ImageHandle
Var mui.WelcomePage.Title.Font
Var LINK
Var LINK.Font
Var clickinstall
Var mui.WelcomePage.Image.Bitmap
var checked
var checked1
Var CheckBox.Font
var mui.WelcomePage1.Title1
var mui.WelcomePage.Title.Font1
Function InstallPageCreate
nsDialogs::Create 1044
Pop $mui.WelcomePage
nsDialogs::SetRTL $(^RTL)
SetCtlColors $mui.WelcomePage 0xffffff 0xffffff
${NSD_CreateLabel} 120u 70u 140u 14u "Choose the intallation method"
Pop $clickinstall
SetCtlColors $clickinstall "" "ffffff"
${NSD_CreateCheckbox} 120u 90u 100% 10u "&Client version"
Pop $CheckBox
CreateFont $CheckBox.Font "$(^Font)" "08" "500"
SetCtlColors $CheckBox "" "FFFFFF"
SendMessage $CheckBox ${WM_SETFONT} $CheckBox.Font 0
GetFunctionAddress $0 OnCheckbox1
nsDialogs::OnClick $CheckBox $0
${NSD_CreateCheckbox} 120u 100u 100% 10u "&Server version"
Pop $CheckBox1
CreateFont $CheckBox.Font "$(^Font)" "08" "500"
SetCtlColors $CheckBox1 "" "FFFFFF"
SendMessage $CheckBox1 ${WM_SETFONT} $CheckBox.Font 0
GetFunctionAddress $0 OnCheckbox2
nsDialogs::OnClick $CheckBox1 $0
${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox
${EndIf}
${If} $Checkbox1_State == ${BST_CHECKED}
${NSD_Check} $Checkbox1
${EndIf}
nsDialogs::Show
${NSD_FreeImage} $mui.WelcomePage.Image.Bitmap
FunctionEnd
Function OnCheckbox2
StrCpy $SOURCE "C:\"
${NSD_CreateText} 120u 120u 80u 12u "$SOURCE"
pop $SOURCETEXT
${NSD_CreateBrowseButton} 280u 120u 35u 14u "Browse"
Pop $InstallPage.BrowseButton
${NSD_OnClick} $InstallPage.BrowseButton Browsesource
FunctionEnd
Function OnCheckbox1
FunctionEnd
Function checkinstdir
${NSD_GetText} $Text $Text_State
${NSD_GetState} $Checkbox $Checkbox_State
${If} $Checkbox_State == ${BST_CHECKED}
strcpy $checked 1
${else}
strcpy $checked 0
${Endif}
${NSD_GetState} $Checkbox1 $Checkbox1_State
${If} $Checkbox1_State == ${BST_CHECKED}
strcpy $checked1 1
${else}
strcpy $checked1 0
${Endif}
FunctionEnd
Function Browsesource
nsDialogs::SelectFolderDialog "Select Source Folder" "c:\"
pop $SOURCE
${NSD_SetText} $SOURCETEXT $SOURCE
FunctionEnd
Section "MainSection" SEC01
SectionEnd
Section -Post
SectionEnd

Resources