Problems on creating new page in NSIS with checkbox etc - checkbox

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

Related

Pause in the middle of a Clojure doseq function?

My program allows users to select files to import into a database. Before now, it only allowed them to import one file at a time. Letting them import more than one file at a time is easy. But the problem I have is that if the database already contains a page with the same title, I want to display a warning and get confirmation before overwriting the version in the database with the one being imported.
Here's what I have so far. It largely follows what I was doing to import single files.
;; Handler for the POST "/import" route.
(defn- post-import-page
"Import the file(s) specified in the upload dialog. Checks the page
title of the import file against existing pages in the database. If
a page of the same name already exists, asks for confirmation before
importing."
[{{file-info "file-info"
referer "referer"} :multipart-params :as req}]
(let [file-vec (if (map? file-info)
(conj [] file-info)
file-info)]
(doseq [fm file-vec]
(let [file-name (:filename fm)
import-map (files/load-markdown-from-file (:tempfile fm))
page-title (get-in import-map [:meta :title])
id-exists? (db/title->page-id page-title)]
(if id-exists?
(build-response
(layout/compose-import-existing-page-warning
import-map file-name referer) req)
(do-the-import import-map file-name req))))))
This function imports any files that don't already exist in the database, but doesn't import anything that would overwrite an existing database entry with the same title. It never shows the warning page asking for confirmation either.
The warning page is constructed like this:
(defn compose-import-existing-page-warning
"Return a page stating that a page with the same title already exists
in the wiki. Ask the user to proceed or cancel the import."
[import-map file-name referer]
(short-form-template
[:div {:class "cwiki-form"}
(form-to {:enctype "multipart/form-data"
:autocomplete "off"}
[:post "proceed-with-import"]
(hidden-field "import-map" import-map)
(hidden-field "file-name" file-name)
(hidden-field "referer" referer)
[:p {:class "form-title"} "Page Already Exists"]
[:div {:class "form-group"}
[:p (str "A page with the title \"" (get-in import-map [:meta :title])
"\" already exists in the wiki.")]
[:p (str "Click \"Proceed\" to delete the existing page and "
"replace it with the contents of the imported file.")]
[:div {:class "button-bar-container"}
(submit-button {:id "proceed-with-import-button"
:class "form-button button-bar-item"}
"Proceed")
[:input {:type "button" :name "cancel-button"
:value "Cancel"
:class "form-button button-bar-item"
:autofocus "autofocus"
:onclick "window.history.back();"}]]])]))
How would the program be paused in the middle of the doseq (or other looping function) to display the confirmation page and wait for the user to make a selection?
Just use read-line in the middle of your loop, and then an if to choose the branching you want. Here is a list of other documentation you may find useful, especially the Clojure CheatSheet.

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!

Show powershell message box when minimised

I have a PowerShell script which is monitoring my filesystem. I would like it to display a message box when a new file is detected in a certain folder.
However because I have my PowerShell script running minimized, the message box does not pop up as expected.
Is there a way to get just the message box to appear on top of all other windows, preferably selected, without un-minimising the PowerShell script?
I generate the message box with this code (although any kind of on screen notification would be good)
### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path= "C:\Users\[...]"
$watcher.Filter = "*.bin"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
Add-Type -AssemblyName PresentationFramework #reference for message box
### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = { [System.Windows.MessageBox]::Show('Binary received') #display msgbox
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 5}
To show a message box as an always on top dialog, you can use MessageBox.Show using ServiceNotification style for the dialog:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show("Message","Title",`
[System.Windows.Forms.MessageBoxButtons]::OK,`
[System.Windows.Forms.MessageBoxIcon]::Information,`
[System.Windows.Forms.MessageBoxDefaultButton]::Button1,`
[System.Windows.Forms.MessageBoxOptions]::ServiceNotification)

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

NSIS license page prechecked

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

Resources