- NSIS Discussion
- NSIS CopyFiles
Archive: NSIS CopyFiles
Russell81
12th November 2008 11:14 UTC
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
Red Wine
12th November 2008 12:20 UTC
Yea it's possible, you'd need to build and add a custom dialog (page), before the InstFiles page.
Russell81
12th November 2008 13:10 UTC
Hello there,
Anybody has time to say more details!! Thanks for the reply.
Russell81
12th November 2008 13:35 UTC
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.
LoRd_MuldeR
13th November 2008 17:10 UTC
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 ;)
Russell81
17th November 2008 12:12 UTC
Thanks for reply. But seems to be so difficult to do.
LoRd_MuldeR
17th November 2008 15:10 UTC
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...
nsnb
17th November 2008 15:53 UTC
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?
LoRd_MuldeR
17th November 2008 16:29 UTC
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)
nsnb
17th November 2008 18:32 UTC
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.
LoRd_MuldeR
18th November 2008 02:16 UTC
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
Russell81
18th November 2008 06:29 UTC
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......
LoRd_MuldeR
18th November 2008 16:16 UTC
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
Russell81
19th November 2008 09:55 UTC
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.
LoRd_MuldeR
19th November 2008 20:49 UTC
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 ^^).
Russell81
20th November 2008 11:44 UTC
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.
LoRd_MuldeR
20th November 2008 13:29 UTC
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:
Russell81
20th November 2008 20:23 UTC
So what i will right on the desttination?
CopyFiles "$Source" "$?????" if i like to choose memory stick?
Sorry for bothering you.
LoRd_MuldeR
20th November 2008 20:30 UTC
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)
Russell81
21st November 2008 06:30 UTC
Thanks for the guide. I am so glad. I am quite new in this field that's why i am always bothering you.
Russell81
5th December 2008 09:55 UTC
Is there any way to check how many processor in pc by NSIS script?
Anders
5th December 2008 16:35 UTC
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
Russell81
8th December 2008 12:08 UTC
Really?