Archive: Looking for a little help


Looking for a little help
  Hi,

I'm looking for a little help, :)

I put together a script using HM NIS Script Wizard

But I've made a few changes to it

What I'm looking for is a script which helps me, if the file exists it will be backed up, but I would like another option, if uninstalled the backedup files will will be placed back in the original directories.

Is this possible?

I know I could use copyfile, to backup the files

I have seen this script Backup

Plus I'm a total novice to NSIS, and I'm not sure what all the commands and so on mean, I have looked through your documentation, but just can't figure it out :igor:

I have attached the script I'm working with Text

It works fine so far, I still have to make a few changes so it will delete all the installed files, but I would like if possible to back them up first

Would it be possible for someone, to create that script and explain how to use.

Please

I would be so grateful

Thanks so much:D


## Place in installer
IfFileExists "$INSTDIR\filetobackup.exe" 0 nobackup
CreateDirectory "$INSTDIR\backup"
CopyFiles "$INSTDIR\filetobackup.exe" "$INSTDIR\backup\filetobackup.exe"
nobackup:

## Place in uninstaller
IfFileExists "$INSTDIR\backup\filetobackup.exe" 0 nobackup
CopyFiles "$INSTDIR\backup\filetobackup.exe" "$INSTDIR\filetobackup.exe"
RMDir /r "$INSTDIR\backup"
nobackup:

-Stu


Thanks alot, but the only problem was I kept getting a error with the

nobackup

at the end of the IfFileExists line

and a error with the

nobackup:

at the end

once I removed them it created the backup dir and placed the file in to it

but once I tried to restore the backup file nothing happened plus it didn't delete the backup dir

could you explain what the nobackup means

Thanks again so much


Um.
If you have the codes seperated into the Uninstall section and Install section, then it will work.
If you put the whole lot in the same section, then it defeats the purpose of the code.

1st part backs up the file if it is found.
2nd part returns the file on uninstall from the backup folder.

-Stu


Yeah I did that

Sorry to be a nuisance

But would it be possible to put it into my script

To show me how to do it

Or do you have it in a script with it in, which I could learn from

Again I know I’m a pain

Thanks

-Tony


Section "Backup old files"
IfFileExists "$INSTDIR\filetobackup.exe" 0 nobackup
CreateDirectory "$INSTDIR\backup"
CopyFiles "$INSTDIR\filetobackup.exe" "$INSTDIR\backup\filetobackup.exe"
nobackup:
SectionEnd

Section "Uninstall"
IfFileExists "$INSTDIR\backup\filetobackup.exe" 0 nobackup
CopyFiles "$INSTDIR\backup\filetobackup.exe" "$INSTDIR\filetobackup.exe"
RMDir /r "$INSTDIR\backup"
nobackup:
SectionEnd

The Uninstall section is what makes up your uninstaller.

-Stu


Thanks Stu

I finally got it to work :)

Now I just have to repeat the script for around 300 files :cry:

I've done it with two sets of files and it works fine

Hopefully I won't bug you again about this

Thanks so much

And to the guys who made or contribute to NSIS

Thanks also :up:

-Tony


To make the script shorter and easier to maintain you can use a macro just like the one in the link you posted in your first post.


Thanks, I would if I knew how to implement it in to my script

I know this might be asking a lot

I have uploaded my script again with the changes Afrow UK suggested Text script updated

If it's possible and if you have the time could you take a look at it and replace it with your script, please

Sorry but I learn better if I know where to put things :confused:

I would greatly appreciate it if you could :D

Please

Thanks so much


It's very simple.

!macro BackupFile FILE
IfFileExists "$INSTDIR\${FILE}" 0 +3
CreateDirectory "$INSTDIR\backup"
CopyFiles "$INSTDIR\${FILE}" "$INSTDIR\backup\${FILE}"
!macroend


Put this code on the top of your script and for every file you want to backup use:

!insertmacro BackupFile file_name


To restor them at uninstall time put this macro on top:

!macro RestoreFile FILE
IfFileExists "$INSTDIR\backup\${FILE}" 0 +3
CopyFiles "$INSTDIR\backup\${FILE}" "$INSTDIR\${FILE}"
!macroend


and for every file you want restored (in the uninstall section) use this code:

!insertmacro RestoreFile file_name

Ok thanks that works fine

In your other script you have subfolder

Would there be any chance of you showing me how to include them also

Please
Sorry again about this

Edit

No matter I figured it out, from your previous script, simple as you said :)

!macro BackupFile DIR FILE

IfFileExists"$INSTDIR\${DIR}\${FILE}" 0 +3
CreateDirectory "$INSTDIR\backup\${DIR}"
>CopyFiles "$INSTDIR\${FILE}" "$INSTDIR\backup\${DIR}\${FILE}"
>!macroend
>

"subfolder" "file_name"


>!insertmacro BackupFile "file_name"
!macro RestoreFile DIR FILE

IfFileExists"$INSTDIR\backup\${DIR}\${FILE}" 0 +3
CopyFiles "$INSTDIR\backup\${DIR}\${FILE}" "$INSTDIR\${DIR}\${FILE}"
>!macroend
>

"Subfolder" "file_name"


>!insertmacro RestoreFile "file_name"
Thanks so much both of you for your help :D

Yeah I made a mistake with the script above

should have been

!insertmacro BackupFile "subfolder" "file_name"


>!insertmacro BackupFile "" "file_name"
Anyhow

Thanks for the help :up: