Nsis temp folder - nsis

Function .onInit
DetailPrint "Temp folder - $TEMP"
System::Call 'Kernel32::GetTempFileName(t $TEMP, t "tmp", i 0, t.r0) i.r1
DetailPrint "Temp folder name - $0" //$0 gives empty string
FunctionEnd
When I call Kernel32::GetTempFileName in .onInit function i retrieves an empty file name. But when i call it from section everything is ok!
Can you explain me why?

I recommend you just call InitPluginsDir in .onInit and use $PLUGINSDIR as temp folder. It will be deleted automatically on exit.
$PLUGINSDIR
The path to a temporary folder created upon the first usage of a
plug-in or a call to InitPluginsDir. This folder is automatically
deleted when the installer exits.

It is important to quote all string parameters when using System::Call:
Section
System::Call 'Kernel32::GetTempFileName(t "$TEMP", t "tmp", i 0, t.r0) i.r1'
DetailPrint |$0|
SectionEnd
Please consider using $pluginsdir like the other answer suggests, it is a much better solution because it will not leave behind junk on the end-users machine...

Related

Space required on MUI_PAGE_DIRECTORY is 0.0KB

I'm writing an installer for Windows application. I'm using MUI for NSIS. One of the pages of the installer is Directory Page, where I have the "Space required" field. The problem is that the space required is always 0.0KB.
I was looking for some answers, but all I found was that space is calculated automatically. I wonder if there is some way to check which folder size this macro gets? Or any other ideas?
;Pages
; Installation
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "#CPACK_RESOURCE_FILE_LICENSE#"
!insertmacro MUI_PAGE_DIRECTORY
Page custom pgAppLanguageCreate
The size is automatically calculated by the File instructions in Sections plus any extra you add with AddSize.
If you are not happy with this calculation you can force a specific size in .onInit with SectionSetSize.
I found what causes the problem.
In the "Installer Section" I used a function that copies all files.
Instead of calling it here, I just paste the entire function and now that works. It looks like you cant use "File" instruction in function because it doesn't add size to the required space this way.
If you use it in section, it works perfectly.
; Installer Sections
Section "install" Install
${If} $instState != "1"
Call deleteAllFiles
Call deleteInfoFromRegistry
Call deleteShortcut
${EndIf}
SetOutPath "$INSTDIR"
; copy files
File ${ICON}
File "slicer_license"
File /r "${INSTALL_FILE}\package\"
;File "README.txt" ;Readme file.
Call createShortcut
Call addInfoToRegistry
Call setAppLanguageShortcut
Call createLanguageFile
SectionEnd

How to move a subdirectory with its contents to another directory with NSIS

this is the first time I work with NSIS, I want to edit an script NSIS to allow me:
If first instalation -> create the directory "Affaires" in the location "C:\Users\ali.ait-mouhoub.ext\AppData".
If it is an update (So the directory "Affaires" it already exists in "C:\N.O.E") -> move the directory "Affaires" with its contents to "C:\Users\ali.ait-mouhoub.ext\AppData".
The current script creates the directory "Affaires" in "C:\N.O.E".
Can you please help me modify my script to meet my needs?
If the both the new and old locations are on the same volume then you can use Rename:
Section
Rename "$InstDir\Stuff" "$InstDir\OldStuff"
SectionEnd
If the new location might be on a different volume then you have to copy+delete:
!include LogicLib.nsh
Section
ClearErrors
CopyFiles /Silent "$InstDir\Stuff" "x:\Backup"
${If} ${Errors}
MessageBox MB_ICONSTOP "Unable to move!"
${Else}
RMDir /R "$InstDir\Stuff"
${EndIf}
SectionEnd

DLL Function is not calling from the NSIS installer when uninstalling

When uninstaling the software to do the complete cleanup calling the function in the C++ DLL .
To achieve this I am placing the DLL file in the temp directory. Then in the Uninstall section calling the DLL function. But it is not calling the function.
If I place that DLL file in the installed directory then it is calling the DLL function.
But I should not place it in the installed directory because I am calling this function when uninstalling.
Is it the correct way that I am doing? or is there any other way?
Below is my code snippet:
Section "MyApp"
InitPluginsDir
SetOutPath $PluginsDir
File "C:\Desktop\KillNofificationSoftly.dll"
SetOutPath $Temp
MessageBox MB_OK "Temp Path $Temp"
System::Call 'KERNEL32::AddDllDirectory(w "$PluginsDir")'
SetOutPath $INSTDIR
SectionEnd
Section "Uninstall"
System::Call "$PluginsDir\KillNofificationSoftly.dll::KillMeSoftly() i.r0 ?e"
Pop $1 ; LastError
${If} $0 = 0
MessageBox MB_OK "Success"
${EndIf}
SectionEnd
You are extracting the .DLL in the installer! $PluginsDir is deleted when the installer finishes. Move all the code to the uninstaller section.
If you are the author of this .DLL you should consider writing a NSIS plug-in, then it becomes just a single line of code, no need for System::Call.

IfFileExists command run 3 command lines

How do I the result of IfFileExists command run three lines and not only the first.
In the code below is the result of IfFileExists is TemWSConfig, must perform the 3 lines to the NaoTemWSConfig command.
Presently the line 2 and 3 after TemWSConfig, always run
IfFileExists "$INSTDIR\IntegradorWS.exe.Config" TemWSConfig NaoTemWSConfig
TemWSConfig:
File "..\IntegradorWS\bin\x86\Release\AppInstalado.config"
Rename "$INSTDIR\IntegradorWS.exe.Config" "$INSTDIR\Antigo_IntegradorWS.exe.Config"
Rename "$INSTDIR\AppInstalado.config" "$INSTDIR\IntegradorWS.exe.Config"
NaoTemWSConfig:
File "..\IntegradorWS\bin\x86\Release\IntegradorWS.exe.Config"
NSIS does not skip around like this, you can verify that by switching out the problematic instructions:
Section
; Fake the IntegradorWS.exe.Config file for this example:
StrCpy $INSTDIR $temp
File "/oname=$INSTDIR\IntegradorWS.exe.Config" "${__FILE__}"
IfFileExists "$INSTDIR\IntegradorWS.exe.Config" TemWSConfig NaoTemWSConfig
TemWSConfig:
DetailPrint "TemWSConfig:1"
DetailPrint "TemWSConfig:2"
DetailPrint "TemWSConfig:3"
NaoTemWSConfig:
DetailPrint "NaoTemWSConfig:1"
; Clean up
Delete "$temp\IntegradorWS.exe.Config"
SectionEnd
This means the problem must be with the File instruction. Make sure you have called SetOutPath so it knows where to extract. File extraction can be skipped if you have changed SetOverwrite etc.

NSISdl could not open file during download

I'm using NSIS to create an installer which will install files from a web server. I'm using the NSISdl plugin to download the files but they are not downloading, it just says Download Failed: failed to open file.
This is the section which is doing the download, could I be missed something here.
Section "Aquiva"
; Set output path to the installation directory.
SetOutPath $INSTDIR
;Include files from this location, and copy that to the current
;out path
NSISdl::download http://41.78.239.158/Aquiva.exe
Pop $R0 ;Get the return value
StrCmp $R0 "success" +3
MessageBox MB_OK "Download failed: $R0"
Quit
SectionEnd ; end the section
You should use inetc for this purpose:
inetc::get "http://41.78.239.158/Aquiva.exe" "$EXEDIR\Aquiva.exe"
pop $R0
DetailPrint "Result: $R0"
You can get it here
If you insist on using NSISdl, your problem is probably due to not specifying the destination file, try this:
NSISdl::download http://41.78.239.158/Aquiva.exe "$INSTDIR\Aquiva.exe"
pop $R0
...

Resources