Old 8th October 2021, 12:36   #1
cdevidal
Junior Member
 
Join Date: Oct 2021
Posts: 8
Question $EXEDIR is set to .nsi file, NOT directory

Newbie to NSIS, though I've used WinAmp since 1999 I expected $EXEDIR to be set to
C:\Users\CBdeV\Documents\SecureCoop_Windows_app\

But with !echo I found that it is set to
(C:\Users\CBdeV\Documents\SecureCoop_Windows_app\setup.nsi:12)

As a consequence, operations such as CopyFiles fail. What am I doing wrong? I've attached my .nsi script.
Attached Files
File Type: nsi setup.nsi (1.5 KB, 45 views)
cdevidal is offline   Reply With Quote
Old 8th October 2021, 13:53   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,418
!echo $EXEDIR makes no sense, you need to learn the difference between compile time and run time and variables vs defines.

You probably want "File", not "CopyFiles".

You can't mix "RequestExecutionLevel user" and $Programfiles.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 8th October 2021, 14:26   #3
cdevidal
Junior Member
 
Join Date: Oct 2021
Posts: 8
Quote:
Originally Posted by Anders View Post
!echo $EXEDIR makes no sense, you need to learn the difference between compile time and run time and variables vs defines.

You probably want "File", not "CopyFiles".

You can't mix "RequestExecutionLevel user" and $Programfiles.
Thank you for responding. I removed !echo and changed RequestExecutionLevel to admin, but now MakeNSISW throws an error about the missing Icon file, though that file is present in the directory. Seems the $EXEDIR variable is still incorrect. What am I doing wrong?

Updated script attached.

code:
C:\Users\CBdeV\Documents\SecureCoop_Windows_app>dir SecureCoop.ico
Volume in drive C has no label.
Volume Serial Number is 980D-C70C

Directory of C:\Users\CBdeV\Documents\SecureCoop_Windows_app

10/07/2021 10:39 PM 4,286 SecureCoop.ico
1 File(s) 4,286 bytes
0 Dir(s) 268,724,682,752 bytes free

C:\Users\CBdeV\Documents\SecureCoop_Windows_app>



Output from MakeNSISW:

code:
MakeNSIS v3.08 - Copyright 1999-2021 Contributors
See the file COPYING for license details.
Credits can be found in the Users Manual.

Processing config: C:\Program Files (x86)\NSIS\nsisconf.nsh
Processing default plugins: "C:\Program Files (x86)\NSIS\Plugins\x86-unicode\*.dll"
+ Banner::destroy
+ Banner::getWindow
+ Banner::show
+ BgImage::AddImage
+ BgImage::AddText
+ BgImage::Clear
+ BgImage:estroy
+ BgImage::Redraw
+ BgImage::SetBg
+ BgImage::SetReturn
+ BgImage::Sound
+ Dialer::AttemptConnect
+ Dialer::AutodialHangup
+ Dialer::AutodialOnline
+ Dialer::AutodialUnattended
+ Dialer::GetConnectedState
+ InstallOptions::dialog
+ InstallOptions::initDialog
+ InstallOptions::make_unicode
+ InstallOptions::show
+ KillProcWMI::KillProc
+ LangDLL::LangDialog
+ Math::Script
+ StartMenu::Init
+ StartMenu::Select
+ StartMenu::Show
+ System::Alloc
+ System::Call
+ System::Copy
+ System::Free
+ System::Get
+ System::Int64Op
+ System::Store
+ System::StrAlloc
+ TypeLib::GetLibVersion
+ TypeLib::Register
+ TypeLib::UnRegister
+ UserInfo::GetAccountType
+ UserInfo::GetName
+ UserInfo::GetOriginalAccountType
+ VPatch::GetFileCRC32
+ VPatch::GetFileMD5
+ VPatch::vpatchfile
+ advsplash::show
+ nsDialogs::Create
+ nsDialogs::CreateControl
+ nsDialogs::CreateItem
+ nsDialogs::CreateTimer
+ nsDialogs::GetUserData
+ nsDialogs::KillTimer
+ nsDialogs::OnBack
+ nsDialogs::OnChange
+ nsDialogs::OnClick
+ nsDialogs::OnNotify
+ nsDialogs::SelectFileDialog
+ nsDialogs::SelectFolderDialog
+ nsDialogs::SetRTL
+ nsDialogs::SetUserData
+ nsDialogs::Show
+ nsExec::Exec
+ nsExec::ExecToLog
+ nsExec::ExecToStack
+ nsisdl::download
+ nsisdl::download_quiet
+ splash::show

!define: "MUI_INSERT_NSISCONF"=""

Changing directory to: "C:\Users\CBdeV\Documents\SecureCoop_Windows_app"

Processing script file: "C:\Users\CBdeV\Documents\SecureCoop_Windows_app\setup.nsi" (ACP)
OutFile: "SecureCoop setup.exe"
Name: "SecureCoop"
Caption: "SecureCoop"
BrandingText: " "
InstallDir: "$PROGRAMFILES64\SecureCoop"
Icon: "$EXEDIR/SecureCoop.ico"
Error while loading icon from "$EXEDIR/SecureCoop.ico": can't open file
Error in script "C:\Users\CBdeV\Documents\SecureCoop_Windows_app\setup.nsi" on line 7 -- aborting creation process

Attached Files
File Type: nsi setup.nsi (1.5 KB, 49 views)
cdevidal is offline   Reply With Quote
Old 9th October 2021, 10:45   #4
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
It fails when you compile the script because $EXEDIR is only available when you run the installer ie after it's compiled.

Basically, anything with only a '$' in front of it is a runtime variable and cannot be used at compile time.
A '${}' (dollar sign with curly braces) is a define which can be set and changed at compile time, can also be used at runtime but is not editable ie readonly.

The 'Icon' command is only used during compile time, and because the icon is in the same directory as the script, all you have to do is this:

Icon SecureCoop.ico

Same with 'UninstallIcon'.

The 'File' command refers to the file to include ie where on your machine it is. Whereas 'SetOutPath' controls what directory that file goes into when the installer is run.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 9th October 2021, 11:36   #5
cdevidal
Junior Member
 
Join Date: Oct 2021
Posts: 8
Thank you. So would I copy a large number of files using SetOutPath and File? Tried "${EXEDIR}" and that didn't work, but when I set the path absolutely and explicitly e.g. C:\Users.. that does work. It's a workaround for now.
cdevidal is offline   Reply With Quote
Old 12th October 2021, 11:58   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
${EXEDIR} doesn't exist because it's not a compile time variable. If you really want to set it (I would not recommend it though because it makes things more ambiguous), use: !define EXEDIR "."

You can use the path relative to the script file, like this:

File /r "dist/SecureCoop/*.*"

The '/r' flag means recurse into subdirectories too (the default is to stay in the specified directory). Just be aware that any files that don't have a dot in them will be skipped (basically, files with no extension will be skipped). To include all files, use a single wildcard.

SetOutPath just changes which directory the files go into, if you need it.

PHP Code:
'script.nsi, somefile.txt, and anotherfile.txt are all in the same directory.'

relative to script path    installer output path

SetOutPath 
"$INSTDIR"      C:\yourprogram
File 
"somefile.txt"        C:\yourprogram\somefile.txt
SetOutPath 
"$INSTDIR\bin"  C:\yourprogram\bin
File 
"anotherfile.txt"     C:\yourprogram\bin\anotherfile.txt 

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 12th October 2021, 12:28   #7
cdevidal
Junior Member
 
Join Date: Oct 2021
Posts: 8
Thank you, this did work.

SetOutPath "$INSTDIR"
File /r "dist\SecureCoop\*.*"
cdevidal 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