Archive: hye guys, problom with installation, please take a look!


hye guys, problom with installation, please take a look!
  hey guys!
i'm new to NSIS and this is my first installation made, it's working quite ok, however i do have some issues that i've failed to over-come no matter how hard i've tried!!!
______-
- the main problem is situated in the uninstalling field:

  ReadRegStr $RestartInstaller HKCU "Software\SKs\USDownloader" "RestartInstaller"

${If} $RestartInstaller = "1"
ExecShell "open" "$EXEPATH\$EXEFILE"
${EndIf}
this code i've wrote in order to read a certain key which is written to the registry in here:
WriteRegStr HKCU "Software\SKs\USDownloader" "RestartInstaller" "1" 

and once read to check if it's value equals to '1' then to start the installer again!
- That doesn't do it!!!

- my second issue is that the function files copy seems to create files which arn't already existing and even if i try to skip the function using iffileexists function it just doesn't work!
 ${If} $SAVEDFILE = 1

CreateDirectory "$INSTDIR"
CopyFiles /SILENT /FILESONLY "$TEMP\USDownloader.ini" "$INSTDIR\USDownloader.ini" 10
Delete "$TEMP\USDownloader.ini"
IfFileExists "$TEMP\USDownloader.lst" 0 +3
CopyFiles/SILENT /FILESONLY "$TEMP\USDownloader.lst" "$INSTDIR\USDownloader.lst" 10
Delete "$TEMP\USDownloader.lst"
IfFileExists "$TEMP\DecryptionCheck.ini" 0 +3
CopyFiles/SILENT /FILESONLY "$TEMP\DecryptionCheck.ini" "$INSTDIR\DecryptionCheck.ini" 10
Delete "$TEMP\DecryptionCheck.ini"
IfFileExists "$TEMP\Reconnect.ini" 0 +3
CopyFiles/SILENT /FILESONLY "$TEMP\Reconnect.ini" "$INSTDIR\Reconnect.ini" 10
Delete "$TEMP\Reconnect.ini"
${EndIf}

if it might help here is my entire code for the installatoin: (Any suggestions will be happily heard!)

:

;make it start the installer after uninstallation!
;--------------------------------

!ifdef HAVE_UPX
>!packhdr tmp.dat "upx\upx -9 tmp.dat"
>!endif

!ifdef NOCOMPRESS
SetCompress off
>!endif

;--------------------------------
;Include Modern UI
!include "LogicLib.nsh"
!include "MUI.nsh"

>;--------------------------------
;General

;Name and file
Name "USDownloader"
Caption "SK's USDownloader (v27.5)"
OutFile "SK's USDownloader.exe"

;Style
!insertmacro MUI_DEFAULT MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install-nsis.ico"
!insertmacro MUI_DEFAULT MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall-nsis.ico"
XPStyle on

;Default installation folder
InstallDir "$PROGRAMFILES\SK's\USDownloader"

;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\SKs\USDownloader" ""

;Vista redirects $SMPROGRAMS to all users without this
RequestExecutionLevel admin

>;--------------------------------
;Variables

Var MUI_TEMP
Var STARTMENU_FOLDER
Var SAVEDFILE
Var RestartInstaller

>;--------------------------------
;Interface Configuration

!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-nsis.bmp" ; optional
!define MUI_ABORTWARNING

VIProductVersion "1.0.0.0"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "SK's USDownloader (v27.5)"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "USDownloader compliation made by SK, fully automates download from share sites!"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "For The Greater Good!"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "USDownloader is a freeware by Dimoniusis, Recompiled by Shlomi Kalfa"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "© Shlomi Kalfa"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "SK's USDownloader (v27.5)"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "27.5.2007"

>;--------------------------------
;Language Selection Dialog Settings

;Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
!define MUI_LANGDLL_REGISTRY_KEY "Software\SKs\USDownloader"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"

>;--------------------------------
;Pages

!insertmacro MUI_PAGE_LICENSE "C:\USDBCKUP\Installations\License.txt"
!insertmacro MUI_PAGE_DIRECTORY

!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\SKs\USDownloader"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
!insertmacro MUI_PAGE_STARTMENU Application "$STARTMENU_FOLDER"

!insertmacro MUI_PAGE_INSTFILES

!define MUI_FINISHPAGE_RUN "$INSTDIR\USDownloader.exe"
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
!define MUI_FINISHPAGE_SHOWREADME
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Setup auto-reconnector"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION StartReconnector
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

>;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English" ;first language is the default language
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "TradChinese"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro MUI_LANGUAGE "Norwegian"
!insertmacro MUI_LANGUAGE "NorwegianNynorsk"
!insertmacro MUI_LANGUAGE "Finnish"
!insertmacro MUI_LANGUAGE "Greek"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_LANGUAGE "Polish"
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Slovak"
!insertmacro MUI_LANGUAGE "Croatian"
!insertmacro MUI_LANGUAGE "Bulgarian"
!insertmacro MUI_LANGUAGE "Hungarian"
!insertmacro MUI_LANGUAGE "Thai"
!insertmacro MUI_LANGUAGE "Romanian"
!insertmacro MUI_LANGUAGE "Latvian"
!insertmacro MUI_LANGUAGE "Macedonian"
!insertmacro MUI_LANGUAGE "Estonian"
!insertmacro MUI_LANGUAGE "Turkish"
!insertmacro MUI_LANGUAGE "Lithuanian"
!insertmacro MUI_LANGUAGE "Catalan"
!insertmacro MUI_LANGUAGE "Slovenian"
!insertmacro MUI_LANGUAGE "Serbian"
!insertmacro MUI_LANGUAGE "SerbianLatin"
!insertmacro MUI_LANGUAGE "Arabic"
!insertmacro MUI_LANGUAGE "Farsi"
!insertmacro MUI_LANGUAGE "Hebrew"
!insertmacro MUI_LANGUAGE "Indonesian"
!insertmacro MUI_LANGUAGE "Mongolian"
!insertmacro MUI_LANGUAGE "Luxembourgish"
!insertmacro MUI_LANGUAGE "Albanian"
!insertmacro MUI_LANGUAGE "Breton"
!insertmacro MUI_LANGUAGE "Belarusian"
!insertmacro MUI_LANGUAGE "Icelandic"
!insertmacro MUI_LANGUAGE "Malay"
!insertmacro MUI_LANGUAGE "Bosnian"
!insertmacro MUI_LANGUAGE "Kurdish"
!insertmacro MUI_LANGUAGE "Irish"
!insertmacro MUI_LANGUAGE "Uzbek"
!insertmacro MUI_LANGUAGE "Galician"
!insertmacro MUI_LANGUAGE "Afrikaans"

>;--------------------------------
;Reserve Files

;If you are using solid compression, files that are required before
;the actual installation should be stored first in the data block,
;
because this will make your installer start faster.

!insertmacro MUI_RESERVEFILE_LANGDLL
>;--------------------------------
;Installer Functions

>Function .onInit

!insertmacro MUI_LANGDLL_DISPLAY



System::Call 'kernel32::CreateMutexA(i 0, i 0, t "Sk643Sk") i .r1 ?e'
Pop $R0

StrCmp $R0 0+3
MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
Abort

IfFileExists"$INSTDIR\Uninstall.exe" 0 ContinueInstalling
MessageBox MB_YESNO|MB_ICONQUESTION "It is recommanded that you'll uninstall previously installed versions! Uninstall now?" IDNO ContinueInstalling
WriteRegStr HKCU "Software\SKs\USDownloader" "RestartInstaller" "1"
ExecShell "open" "$INSTDIR\Uninstall.exe"
Abort

ContinueInstalling:
>FunctionEnd
>Function StartReconnector
ExecShell "open" "$INSTDIR\Reconnect (1.0B).exe"
>FunctionEnd

>;--------------------------------
;Installer Sections

Section "USDownloader"
SetOverwrite on
SetOutPath "$INSTDIR"

;ADD YOUR OWN FILES HERE...
IfFileExists "$INSTDIR\USDownloader.ini" 0 +2
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to save the previous USD settings?" IDYES DontCopy
File "C:\USDBCKUP\Installations\USDownloader_SK\USDownloader.ini"
DontCopy:
File /r "C:\USDBCKUP\Installations\USDownloader_SK\USDownloader\*.*"

;Store installation folder
WriteRegStr HKCU "Software\SKs\USDownloader" "" "$INSTDIR"
;Store installation info for windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SKs USDownloader" "DisplayName" "SK's USDownloader"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SKs USDownloader" "UninstallString" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SKs USDownloader" "InstallLocation" "$INSTDIR\"
WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallSKs USDownloader" "Publisher" "SK. For The Greater Good!"
WriteRegDWORD HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallSKs USDownloader" "NoModify " 1
WriteRegDWORD HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallSKs USDownloader" "NoRepair " 1


!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS$STARTMENU_FOLDER"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERUSDownloader.lnk" "$INSTDIRUSDownloader.exe"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERRS_ServerSwitch.lnk" "$INSTDIRRS_ServerSwitch.exe"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERUninstall.lnk" "$INSTDIRUninstall.exe"
CreateDirectory "$SMPROGRAMS$STARTMENU_FOLDERDownload Sites"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERDownload SitesFXP.co.il.lnk" "$INSTDIRDownloadSites!!!FXP.co.il - קהילות מפולחות תוכן.URL"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERDownload SitesPhazeDDL.com.lnk" "$INSTDIRDownloadSites!!!PhazeDDL.com - Full Downloads, Games, Movies & Warez.URL"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERDownload SitesDirectDl.lnk" "$INSTDIRDownloadSites!!!DirectDl.URL"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERDownload SitesDDLSpot.lnk" "$INSTDIRDownloadSites!!!ddlSpot.URL"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERDownload SitesForumW.org.lnk" "$INSTDIRDownloadSites!!!ForumW.org.URL"
CreateShortCut "$SMPROGRAMS$STARTMENU_FOLDERDownload SitesWarezforum.lnk" "$INSTDIRDownloadSites!!!Warezforum - Powered by vBulletin.URL"
!insertmacro MUI_STARTMENU_WRITE_END

;Create uninstaller
WriteUninstaller "$INSTDIRUninstall.exe"
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to create a desktop shortcut?" IDNO DontCreate
CreateShortCut "$DESKTOPUSDownloader (by SK).lnk" "$INSTDIRUSDownloader.exe" "" "" "" "" "" ""
DontCreate:

SectionEnd

;--------------------------------
;Uninstaller Section

Section "Uninstall"

;ADD YOUR OWN FILES HERE...
MessageBox MB_YESNO|MB_ICONQUESTION "You are about to DELETE the folder: '$INSTDIR', Are You Sure ?!" IDNO ABORTOP
Delete "$INSTDIRUninstall.exe"
Delete "$DESKTOPUSDownloader (by SK).lnk"

IfFileExists "$INSTDIRUSDownloader.ini" 0 +4
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to save the previous USD settings?" IDNO DontSave
StrCpy $SAVEDFILE 1
CopyFiles /SILENT /FILESONLY "$INSTDIRUSDownloader.ini" "$TEMPUSDownloader.ini" 10
IfFileExists "$INSTDIRUSDownloader.lst" 0 +2
CopyFiles /SILENT /FILESONLY "$INSTDIRUSDownloader.lst" "$TEMPUSDownloader.lst" 10
IfFileExists "$INSTDIRDecryptionCheck.ini" 0 +2
CopyFiles /SILENT /FILESONLY "$INSTDIRDecryptionCheck.ini" "$TEMPDecryptionCheck.ini" 10
IfFileExists "$INSTDIRReconnect.ini" 0 +2
CopyFiles /SILENT /FILESONLY "$INSTDIRReconnect.ini" "$TEMPReconnect.ini" 10
Goto ContinueOperation
DontSave:
StrCpy $SAVEDFILE 0
ContinueOperation:

RMDir /r "$INSTDIR"

!insertmacro MUI_STARTMENU_GETFOLDER Application "$MUI_TEMP"
Delete "$SMPROGRAMS$MUI_TEMPUninstall.lnk"
RMDir /r "$SMPROGRAMS$MUI_TEMP"
;Delete empty start menu parent diretories
StrCpy $MUI_TEMP "$SMPROGRAMS$MUI_TEMP"
startMenuDeleteLoop:
ClearErrors
RMDir /r "$MUI_TEMP"
GetFullPathName "$MUI_TEMP" "$MUI_TEMP.."
IfErrors startMenuDeleteLoopDone
StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
startMenuDeleteLoopDone:

${If} $SAVEDFILE = 1
CreateDirectory "$INSTDIR"
CopyFiles /SILENT /FILESONLY "$TEMPUSDownloader.ini" "$INSTDIRUSDownloader.ini" 10
Delete "$TEMPUSDownloader.ini"
IfFileExists "$TEMPUSDownloader.lst" 0 +3
CopyFiles /SILENT /FILESONLY "$TEMPUSDownloader.lst" "$INSTDIRUSDownloader.lst" 10
Delete "$TEMPUSDownloader.lst"
IfFileExists "$TEMPDecryptionCheck.ini" 0 +3
CopyFiles /SILENT /FILESONLY "$TEMPDecryptionCheck.ini" "$INSTDIRDecryptionCheck.ini" 10
Delete "$TEMPDecryptionCheck.ini"
IfFileExists "$TEMPReconnect.ini" 0 +3
CopyFiles /SILENT /FILESONLY "$TEMPReconnect.ini" "$INSTDIRReconnect.ini" 10
Delete "$TEMPReconnect.ini"
${EndIf}
ABORTOP:
ReadRegStr $RestartInstaller HKCU "SoftwareSKsUSDownloader" "RestartInstaller"
${If} $RestartInstaller = "1"
ExecShell "open" "$EXEPATH$EXEFILE"
${EndIf}

DeleteRegKey /ifempty HKCU "SoftwareSKsUSDownloader"
DeleteRegKey /ifempty HKCU "SoftwareSKsUSDownloader"

SectionEnd
>

You should use StrCmp or IntCmp, instead of {If}. Something to do with run-time and compile-time.


ReadRegStr $RestartInstaller HKCU "SoftwareSKsUSDownloader" "RestartInstaller"
IntCmp $RestartInstaller 1 execute dont_execute dont_execute

execute:
ExecShell "open" "$EXEPATH\$EXEFILE"

dont_execute:

No that is not the problem. Your ${If} is fine. It's because you are using ExecShell to execute a .exe file. You have to use Exec instead.

As for CopyFiles, what are you doing? Are you trying to only copy files across if they don't already exist in the source or the destination folder?
Also, rather than using CopyFiles followed by Delete, you should use Rename. CopyFiles makes a copy whereas Rename does not (so it is faster and will not cause disk fragmentation).

Edit: Also in future please attach large scripts (as a file attachment). For code snippets, use [code] and not [php] as [php] strips backstrokes.

Stu


for a matter i fact i do (:
- i want the files to be copied only if they exists in order to save the settings !!!

- about that 'exe' issue i'll try using what you mentioned !


What happens if you don't use /FILESONLY?

Also I wouldn't recommend using RMDir /r $INSTDIR in case the user uses a folder that contains other files for the installation or if $INSTDIR is empty (in which case everything on the root C:\ will be deleted including the operating system).

Stu


(in which case everything on the root C:\ will be deleted including the operating system).
WOW, and I've already spread it all around, with more then 300+ users... LOL !!!
- luckily there is a msg asking -> are you sure you want to delete.... let's hope they'll read it (:

- can you recommend me of any other way ?!
;=====================================================
- by now i've changed my script almost totally, i'll upload it now!

my issues with it:
1- can i maybe use that instead of deleting their C:\

RMDir /r "$INSTDIR\SomeDir\"

that will delete just the dir 'SomeDir' all also C:\ ?!

2- how do i make the groupsections be always opened ?! - solved ! used /e to set them expend them...

3- seems like the program always fails to discover if the program is already installed or not, why ?!

ANY HELP WILL BE APPRECIATED !!!

In the uninstaller you should do some checks on $INSTDIR using IfFileExists, StrCmp, StrCpy etc
If $INSTDIR is coming from the registry and that registry entry is gone, then all hell could break loose.

This should be adequate:


StrCmp $INSTDIR "" 0 +3
MessageBox MB_OK|MB_ICONSTOP "Install path missing!"
Abort

# Does path end with "\MyApp"?
StrCpy $R0 $INSTDIR "" -6
StrCmp $R0 "\MyApp" +3
MessageBox MB_YESNO|MB_ICONQUESTION "..." IDYES +2
Abort

IfFileExists "$INSTDIR\*.*" +3
MessageBox MB_OK|MB_ICONSTOP "Install path invalid!"
Abort


Fortunately, you do not have to check $INSTDIR for invalid characters as NSIS handles this itself internally for that variable specifically.

Shouldn't this:
IfFileExists "$INSTDIR\USDownloader.exe" no_remove_uninstaller
Be:
IfFileExists $R1 no_remove_uninstaller
?

For question #3, where is the code to check if it is already installed? There is no built in support for this.
The best way to check if the installer has already been completed is to clear the error flag (ClearErrors) then attempt to read from the same registry entry that InstallDirRegKey uses and then use IfErrors. This assumes that you WriteRegStr in one of your install sections to create this entry.

Stu

hey mate, the script is further developed and everything works smoothly by now beside that issue with the versions!!!
now i'm using that:


${VersionCompare} ${3} ${VERSION} $4
IntCmp ${4} 1 older_version new_version same_version

to differentiate between versions, and guess what, it's aint working !!!
even when i look in the registry i get the following data:
1.0.0.2
and in the program i wrote:
"1.0.0.1"
it's still telling me that i've got an older installation on of it!!!!

- i've added those things you've suggested for the uninstallation even though i think the problem is already solved by this kind of script:

RMDir /r "$INSTDIR\Icons"


reffering into directories only and deleting the main dir with the following loop:

FindFirst $0 $1 "$INSTDIR\*.*"
loop:
StrCmp $1 "" done
Delete "$INSTDIR\$1"
FindNext $0 $1
Goto loop
done:


- PLEASE HELP (:
(how do i fix the version issue ?!)

-

sorry for not edditing, i just didn't found the way to get to the uploading part without opening a new reply !


${VersionCompare} ${3} ${VERSION} $4
IntCmp ${4} 1 older_version new_version same_version

->

${VersionCompare} $3 ${VERSION} $4
IntCmp $4 1 older_version new_version same_version

Don't you check your compiler window for warnings?
${} is a compile time constant.

Stu


i always do !
- there where no warnings !!!

THANKS FOR THE HELP MATE !!!!
- EVERYTHING SEEMS TO BE IN ORDER, THANKS !!!!


No problem!
I'm surprised there were no warnings regarding that.

Stu