Archive: NSIS CopyFiles


NSIS CopyFiles
Hi,
I am doing one istaller with NSIS and i need to copy a file from previously installed program. I managed to do that and the file destination is desktop. But the question is that, is it possible that installer will ask where to paste that copyed file? Please help me if possible.

Russell


Yea it's possible, you'd need to build and add a custom dialog (page), before the InstFiles page.


Hello there,
Anybody has time to say more details!! Thanks for the reply.


Or it possible to send the copied file to usb memory stick?
CopyFiles "$Source" "$Destination"
So i did like this:
CopyFiles "$C:\...." "$DESKTOP"
But I want that it will promt that where to save the file. or go to usb memory stick.
Please help.


You must get the desired location into $Destination somehow before calling CopyFiles. I guess you'd better do this before proceeding to the "instfiles" page. You should use a "custom" page as suggested by Red Wine. First of all have a look at section "2.3.2 Pages" and "4.5.4 Page" in the NSIS manual! Then you must learn how to actually create a custom page, either via InstallOptions(Ex) or via nsDialogs. Have a look at "NSIS\Docs\InstallOptions\Readme.html", "NSIS\Docs\InstallOptionsEx\Readme.html" or "NSIS\Docs\nsDialogs\Readme.html". On your custom page you simply put a "DirRequest" control, which allows the user to choose the desired folder...

There are also examples in the "NSIS\Examples" folder ;)


Thanks for reply. But seems to be so difficult to do.


Originally posted by Russell81
Thanks for reply. But seems to be so difficult to do.
In fact it's not that hard ;)

Look at the docs or simply adapt one of the example files...

Originally posted by LoRd_MuldeR
On your custom page you simply put a "DirRequest" control, which allows the user to choose the desired folder...

There are also examples in the "NSIS\Examples" folder ;)
LoRd_MuldeR, I am also facing a similar challenge (ask the end user select a directory). I found the examples you were referring to for InstallOptions, but I prefer using the nsDialog approach.

Which means that, instead of a "DirRequest" control inside a custom dialog, I am using NSIS's pre-made nsDialogs::SelectFolderDialog.

However, I am having some weird problems, as described in this post. Apparently it's not that simple - or it is simple but I am missing something really fundamental.

Any suggestion as to how to proceed from here? Perhaps I should have taken the DirRequest approach?

What is the "nsDialogs::Show" at the end of your "PageDirSelect" function supposed to do?

Is it needed with nsDialogs::SelectFolderDialog ??? :confused:

(I'm not at home right now, so I cannot test it from here - no NSIS)


Originally posted by LoRd_MuldeR
What is the "nsDialogs::Show" at the end of your "PageDirSelect" function supposed to do?

Is it needed with nsDialogs::SelectFolderDialog ??? :confused:

(I'm not at home right now, so I cannot test it from here - no NSIS)
Wow! You were right on the money :up: - I just commented out that nsDialogs::Show line and all works now perfectly. :)

Thank you so much, LoRd_MuldeR! I will now post the solution in the other thread as well, so that it may help others in the future.

Originally posted by nsnb
I just commented out that nsDialogs::Show line and all works now perfectly. :)
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

I have a code that is making an installer with some normal pages such as:WELCOME,COMPONETNS,DIRECTORY,INSTFILES AND FINISH. So what i am trying to do is that after WELCOME page i need to copy a file from previous installed SW and save it somewhere. And wishing that installer will copy it and ask the user where to save. After saving that file in desired place the COMPONENTS page will appear and go forward. So do i need to do i need to make a totally separate page and call it somehow for saving file or i can make a custom page between WELCOME and COMPONENTS page? I am so out of my knowledge. Help......


Since you mention "Welcome" and "Finish" pages, I have to assume you user MUI or MUI2. So simply put an addtional "custom" page between the MUI_WELCOME_PAGE and MUI_COMPONENTS_PAGE macros, just like:

  !insertmacro MUI_PAGE_WELCOME
Page custom MyCustomPageFun
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH


Then let your custom page show the dialog box:

Var varSelectedFolder

Function MyCustomPageFun
!insertmacro MUI_HEADER_TEXT $(PAGE_TITLE) $(PAGE_SUBTITLE)

FolderForceSelection:
nsDialogs::SelectFolderDialog /NOUNLOAD "Select Folder" "$DOCUMENTS"
Pop $varSelectedFolder ;where selected folder string is returned

; Check A Folder Has Been Selected
StrCmp $varSelectedFolder "error" 0 FolderWasSelected
MessageBox MB_OK|MB_ICONWARNING "You must select a folder a folder!"
Goto FolderForceSelection

FolderWasSelected:
FunctionEnd

Thanks for the details and helpful reply. I am glad you loan me some knowledge from you.
So I make this custom page and need to use this custom page for saving a file which is copied by command "CopyFiles". So the idea is that i wish to use this custom page for saving that copied file to my desired destination.
CopyFiles "$Source" "$Destination". Do you suggest me that i can use this custom page as a destination somehow.


In fact you only use the "custom" page to display the SelectFolder dialog and let the user choose the desired destination folder. That folder will be stored in $varSelectedFolder and can be used at a later time. For example you can call CopyFiles in one of your install sections and use the target folder obtained before (it's still stored in $varSelectedFolder, unless you overwrote it ^^).


Do u think, it is possible to choose "USB Memory stick" as a destination folder? For example if i choose the memory stick from the custom window and use that as a destination when i call CopyFiles.


Originally posted by Russell81
Do u think, it is possible to choose "USB Memory stick" as a destination folder? For example if i choose the memory stick from the custom window and use that as a destination when i call CopyFiles.
Why not? :confused:

So what i will right on the desttination?
CopyFiles "$Source" "$?????" if i like to choose memory stick?
Sorry for bothering you.


If you use the code above, the folder selected by the user (via "Browse for Folder" dialog on the "custom" page) will be stored in $varSelectedFolder. That folder may or may not be located on an USB Memory Stick, depending on the user's choice. Anyways you can copy the files to the selected folder like this:

Section "Some Section"
CopyFiles "$Source" "$varSelectedFolder"
SectionEnd


(Given that the correct source folder is stored in $Source already)

Thanks for the guide. I am so glad. I am quite new in this field that's why i am always bothering you.


Is there any way to check how many processor in pc by NSIS script?


Originally posted by Russell81
Is there any way to check how many processor in pc by NSIS script?
How is this related to copyfiles? Take a look on the wiki, maybe you'll find something

Really?