Old 12th November 2008, 10:14   #1
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
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
Russell81 is offline   Reply With Quote
Old 12th November 2008, 11:20   #2
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
Yea it's possible, you'd need to build and add a custom dialog (page), before the InstFiles page.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 12th November 2008, 12:10   #3
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
Hello there,
Anybody has time to say more details!! Thanks for the reply.
Russell81 is offline   Reply With Quote
Old 12th November 2008, 12:35   #4
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
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.
Russell81 is offline   Reply With Quote
Old 13th November 2008, 16:10   #5
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 17th November 2008, 11:12   #6
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
Thanks for reply. But seems to be so difficult to do.
Russell81 is offline   Reply With Quote
Old 17th November 2008, 14:10   #7
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
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...

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 17th November 2008, 14:53   #8
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Quote:
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?
nsnb is offline   Reply With Quote
Old 17th November 2008, 15:29   #9
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
What is the "nsDialogs::Show" at the end of your "PageDirSelect" function supposed to do?

Is it needed with nsDialogs::SelectFolderDialog ???

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

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 17th November 2008, 17:32   #10
nsnb
Senior Member
 
Join Date: Jul 2008
Posts: 157
Quote:
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 ???

(I'm not at home right now, so I cannot test it from here - no NSIS)
Wow! You were right on the money - 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.
nsnb is offline   Reply With Quote
Old 18th November 2008, 01:16   #11
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
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

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 18th November 2008, 05:29   #12
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
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......
Russell81 is offline   Reply With Quote
Old 18th November 2008, 15:16   #13
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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:

code:
!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:

code:
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


My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 19th November 2008, 08:55   #14
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
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.
Russell81 is offline   Reply With Quote
Old 19th November 2008, 19:49   #15
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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 ^^).

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 20th November 2008, 10:44   #16
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
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.
Russell81 is offline   Reply With Quote
Old 20th November 2008, 12:29   #17
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
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?

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 20th November 2008, 19:23   #18
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
So what i will right on the desttination?
CopyFiles "$Source" "$?????" if i like to choose memory stick?
Sorry for bothering you.
Russell81 is offline   Reply With Quote
Old 20th November 2008, 19:30   #19
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
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:

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



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

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 21st November 2008, 05:30   #20
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
Thanks for the guide. I am so glad. I am quite new in this field that's why i am always bothering you.
Russell81 is offline   Reply With Quote
Old 5th December 2008, 08:55   #21
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
Is there any way to check how many processor in pc by NSIS script?
Russell81 is offline   Reply With Quote
Old 5th December 2008, 15:35   #22
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,590
Quote:
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 8th December 2008, 11:08   #23
Russell81
Junior Member
 
Join Date: Nov 2008
Posts: 30
Really?
Russell81 is offline   Reply With Quote
Old 29th March 2017, 16:57   #24
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 40
Another way to copy files or folders

#Copy Files

PHP Code:
Name "Copy File"
OutFile "Copy File.exe"
InstallDir "$TEMP\Copy File"

# INCLUDES

!include "MUI2.nsh"
!include "WinCore.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"

# Icon & Stye

BrandingText /TRIMRIGHT " "

# Page

Page instfiles "" ""

# LANGUAGES

!insertmacro MUI_LANGUAGE "English" # first language

!define NSIS_SourceFile '!insertmacro NSIS_SourceFile'
!macro NSIS_SourceFile VAR FILE
    Push 
"${FILE}"
     
${GetParent"${FILE}$0
    Pop 
${VAR}
!
macroend

!define NSIS_SourceFolder '!insertmacro NSIS_SourceFolder'
!macro NSIS_SourceFolder VAR FOLDER
    Push 
"${FOLDER}"
     
${GetParent"${FOLDER}$
    Pop 
${VAR}
!
macroend

Section 
"" SEC01

 
# Source File #

 
${NSIS_SourceFile} $"$DESKTOP\Text.txt"
  
DetailPrint "$1"

 
# Destination #

 
${NSIS_SourceFolder} $"$DOCUMENTS"
  
DetailPrint "$2"

 
# Copy #

 
${If} $== $
    CreateDirectory 
`$2
    
CopyFiles /SILENT `$1` `$2
 ${Else} 
    
CreateDirectory `$2
    
CopyFiles /SILENT `$1` `$2
 ${EndIf}  

 ;
SetAutoClose true 
SectionEnd 
#Copy Folders

PHP Code:
Name "Copy Folder"
OutFile "Copy Folder.exe"
InstallDir "$TEMP\Copy Folder"

# INCLUDES

!include "MUI2.nsh"
!include "WinCore.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"

# Icon & Stye

BrandingText /TRIMRIGHT " "

# Page

Page instfiles "" ""

# LANGUAGES

!insertmacro MUI_LANGUAGE "English" # first language

!define NSIS_SourceFolder '!insertmacro NSIS_SourceFolder'
!macro NSIS_SourceFolder VAR FOLDER
    Push 
"${FOLDER}"
     
${GetParent"${FOLDER}$
    Pop 
${VAR}
!
macroend

Section 
"" SEC01

 
${NSIS_SourceFolder} $"$DESKTOP\Test"
  
DetailPrint "$1"
 
${NSIS_SourceFolder} $"$DOCUMENTS\Test"
  
DetailPrint "$2"

  
CreateDirectory `$2
  
CopyFiles /SILENT `$1\*.*` `$2`  

 ;
SetAutoClose true 
SectionEnd 
Attached Files
File Type: nsi Copy File.nsi (1.1 KB, 22 views)
File Type: nsi Copy Folder.nsi (802 Bytes, 19 views)
Coby is offline   Reply With Quote
Old 29th March 2017, 20:01   #25
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 853
Quote:
Originally Posted by Coby View Post
#Copy Files

PHP Code:
 ${If} $== $
    CreateDirectory 
`$2
    
CopyFiles /SILENT `$1` `$2
 ${Else} 
    
CreateDirectory `$2
    
CopyFiles /SILENT `$1` `$2
 ${EndIf} 
This is pointless having an 'if' statement because both branches have the same code.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast 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