Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 19th July 2010, 17:30   #1
axysharma
Junior Member
 
Join Date: Aug 2009
Posts: 12
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.
axysharma is offline   Reply With Quote
Old 19th July 2010, 18:24   #2
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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'.
Animaether is offline   Reply With Quote
Old 19th July 2010, 18:44   #3
axysharma
Junior Member
 
Join Date: Aug 2009
Posts: 12
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?
axysharma is offline   Reply With Quote
Old 19th July 2010, 18:58   #4
axysharma
Junior Member
 
Join Date: Aug 2009
Posts: 12
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.
axysharma is offline   Reply With Quote
Old 19th July 2010, 19:03   #5
axysharma
Junior Member
 
Join Date: Aug 2009
Posts: 12
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.
axysharma is offline   Reply With Quote
Old 19th July 2010, 19:04   #6
axysharma
Junior Member
 
Join Date: Aug 2009
Posts: 12
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.
axysharma is offline   Reply With Quote
Old 19th July 2010, 19:06   #7
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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.

code:

!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

Animaether is offline   Reply With Quote
Old 19th July 2010, 19:09   #8
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
Quote:
Originally Posted by axysharma View Post
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:
code:

!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

Animaether is offline   Reply With Quote
Old 19th July 2010, 20:24   #9
axysharma
Junior Member
 
Join Date: Aug 2009
Posts: 12
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.
axysharma is offline   Reply With Quote
Old 19th July 2010, 21:12   #10
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
Quote:
Originally Posted by axysharma View Post
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:
code:

!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.
Animaether is offline   Reply With Quote
Reply
Go Back   Winamp 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