Archive: Save File dialog


Save File dialog
Hi,

I have created a custom installer. On the installer main page, i have a save button. On click of this button. I want to open a Save File dialog, that will save the licence.rtf file.

how to do this.

Thanx.


if you are using nsDialogs, just add an ${NSD_OnClick} event to that button, and in the function called by that event, call the nsDialogs::SelectFileDialog function specifying the mode as 'save'.


Thanx for the reply. I have file $LICENCE. So when I am doing
nsDialogs::SelectFileDialog /NOUNLOAD save $LICENSE "*.txt"

it is not saving it. Am i doing something wrong?


What exactly i want is I have displayed License in the nsis installer screen. I have a save button on the installer, so when the user clicks on save button, it should save the license on the user system.


I tried this way

nsDialogs::SelectFileDialog /NOUNLOAD "save" $PLUGINSDIR\license.rtf "*.txt"

It is opening save file dialog with my file name and save as type "*.txt". But when I am clicking save, it is not actually saving it on the system.


I tried this way

nsDialogs::SelectFileDialog /NOUNLOAD "save" $PLUGINSDIR\license.rtf "*.txt"

It is opening save file dialog with my file name and save as type "*.txt". But when I am clicking save, it is not actually saving it on the system.


any recent version of nsDialogs doesn't require /NOUNLOAD - not sure if it ever did :)

You may also wish to put quotation marks around your $license if that is the variable being used for the default location on the user's computer to save the file to.


!include "nsDialogs.nsh"

outfile "$%temp%\test.exe"

Section
nsDialogs::SelectFileDialog save "$DOCUMENTS\hello_world.txt" "*.txt"
Pop $0
MessageBox MB_OK "Save location: [$0]"
SectionEnd

Originally posted by axysharma
It is opening save file dialog with my file name and save as type "*.txt". But when I am clicking save, it is not actually saving it on the system.
Yeah, it doesn't work that way - it simply returns the path\filename that the user chose in the dialog on the stack.

To actually save the file, you'd need to add a GetParent (from FileFunc.nsh) and File combination or maybe use CopyFiles - presuming your license text file is already in the PLUGINSDIR anyway:

!include "nsDialogs.nsh"

outfile "$%temp%\test.exe"

Section
nsDialogs::SelectFileDialog save "$DOCUMENTS\hello_world.txt" "*.txt"
Pop $0
MessageBox MB_OK "Save location: [$0]"
CopyFiles /SILENT "$PLUGINSDIR\hello_world.txt" "$0"
SectionENd

Thanx..it is working that way. But if the file is already at the location where I am trying to save, it overwrites it without prompting any message. is there any way we can handle it. i mean if file is already there, then it should prompt message to overwrite it.


Originally posted by axysharma
Thanx..it is working that way. But if the file is already at the location where I am trying to save, it overwrites it without prompting any message. is there any way we can handle it. i mean if file is already there, then it should prompt message to overwrite it.
sure - you'd use something like:

!include "nsDialogs.nsh"

outfile "$%temp%\test.exe"

Section
_getSavePath:
nsDialogs::SelectFileDialog save "$DOCUMENTS\hello_world.txt" "*.txt"
Pop $0
StrCmp "$0" "" _skip
MessageBox MB_OK "Save location: [$0]"
IfFileExists "$0" 0 _copyFile
MessageBox MB_YESNO "The file '$0' already exists. Do you wish to overwrite?" /SD IDNO IDNO _getSavePath
_copyFile:
CopyFiles /SILENT "$PLUGINSDIR\hello_world.txt" "$0"
_skip:
SectionEnd


This checks if the path was empty (user canceled), in which case all the code is skipped.
This checks if the path already exists, in which case the installers asks the user if they want to overwrite, first. If they do not want to overwrite (the default), the user is prompted for a new path by going back to the beginning of the code.
If the path does not already exist, or the user chooses to overwrite, it will continue with the CopyFiles code as before.