- NSIS Discussion
- Help with copying backup files
Archive: Help with copying backup files
Rovastar
6th February 2003 01:59 UTC
Help with copying backup files
Hi all,
I am not going to kid anyone my knowledge of NSIS is limited. :)
DOne a few basic installers for my website (with NSIS v1.98 and NSISplus GUI) but now for a new app my friend is writing I need to up a gear. :)
Playing with teh latest version v2.0a0 or something. :) and using the Venis GUI.
Ok getting the basic done no problem but what I need to know is how too machine the installer know that if the machine already has the app installed (i.e you are doing an upgrade rather than a fresh install) to give the option of having the saving the users setting (by not installing over the top of the profile.ini file)
I worked out how to get (i think) the installed path from teh registry which I put in myself via NSIS after that I am getting lost.......
Can some please help me. :)
ALso I need to make a backup of all the files and save them to the orginal directory under \backup (again maybe a check to see if the app is installed my be needed,
ReadRegStr $0 HKLM "SOFTWARE\HydraProductions\HydraIRC" "InstallPath"
CopyFiles $0\*.* $0\Backup\*.*
but on compile getting
Nothing
(edit -
CopyFiles $0 c:\backup
works ok but
CopyFiles $0 $0\backup
does not although in the installer it says
COpy to the corretc path in this case
C:\program Files\HydraIRC\Backup
But it does not create the directory and therefore nothing in it. WHat is happening?
Cna anyone help on this too?
Thanks in advance you good folks.:)
Joel
6th February 2003 02:12 UTC
About your app already installed:
when you scripting your app (the first one), use this:
WriteRegStr HKLM SOFTWARE\Lobo_Lunar "${MUI_PRODUCT}" $INSTDIR
where is the name of your app. Then add this:
InstallDir $PROGRAMFILES\${MUI_PRODUCT}
InstallDirRegKey HKLM SOFTWARE\Lobo_Lunar "${MUI_PRODUCT}"
We got our default install folder, BUT if our app is in the machine,
the installer change the default install folder with the old one.
hope, this help :D
Rovastar
6th February 2003 02:33 UTC
I think I understood all that already.
That is like an installer for plug-ins for Winamp where it detects the login path etc.
I understand that part (i hope I have understood correctly anyway :) )but it is the 'next' step that I am having problems with.
Joel
6th February 2003 02:59 UTC
mmm, check this Doc from Nsis:
http://nsis.sourceforge.net/Docs/Chapter3.html#3.7.3
is about copy files, then you can move old files to another folder
Rovastar
6th February 2003 10:11 UTC
:(
That is what I have been looking at before the CopyFile command.
Sadly, for me at least, it is not very useful as the info is vague IMHO.
CopyFiles $0 c:\backup
works ok but
CopyFiles $0 $0\backup
does not........
Maybe I am just getting the syntax all wrong. Dunno.
kichik
6th February 2003 11:22 UTC
The directory have to be there for the file copying to succeed. Therefore, use CreateDiretory to create it. To make sure the product is installed, the directory from the registry is not enough. One might just delete the folder without using the uninstaller. Therefore you should use IfFileExists to make sure the directory is there.
Rovastar
6th February 2003 14:06 UTC
"The directory have to be there for the file copying to succeed. "
not true kichik the c:\backup dir does not exist (in the other example) but it creates that.
Also if I create a directory called backup before the copyfiles than I will copy again that backup dir I do not want to do this.
I am making sense with this request.....
Or has anyone got a sample nsi script that I can look at doing something similiar.
Not my PC at the moment so I will try some things out later
kichik
6th February 2003 16:31 UTC
not true kichik the c:\backup dir does not exist (in the other example) but it creates that.
Are you sure? Are you sure it doesn't create a file named backup? Windows doesn't ever create the folder for you, it shouldn't. Can you please attach the script so I can see how does this happen?
If you don't want to override the old backup directory check if it's there first using IfFileExists.
Rovastar
6th February 2003 17:31 UTC
Yes mate I am sure after playing around with the syntax I got it to do it.
I am pretty sure it was
ReadRegStr $0 HKLM "SOFTWARE\HydraProductions\HydraIRC" "InstallPath"
CopyFiles $0 c:\backup
but it could have been c:\backup or C:\backup\ or c:\backup\*.* or something.
I will be back at my machine hopefully later on tonight so I post up the scripts that I have got.
Maybe then it will shed some light on it. :) as I said the NSIS documentation didn't tell me much. (*.* allowed etc, etc.) so I played around.
I also got it to make a file called backup?!? (my initial try) what is the point of that.....
Rovastar
6th February 2003 20:07 UTC
Yeah definatly makes a new directory
and it is
ReadRegStr $0 HKLM "SOFTWARE\HydraProductions\HydraIRC" "InstallPath"
CopyFiles $0 c:\backup
here si the stuff
http://www.rovastar.com/nsis stuff.zip
Joel
6th February 2003 21:02 UTC
Ok, this may help you
try this, must work...:
Section "${MUI_PRODUCT}"
;At this point the installer got our path
SetOutPath $INSTDIR
;Create the extra directory: Backup
CreateDirectory "$INSTDIR\Backup"
;We check if there is a installed file in the Directory
IfFileExists $INSTDIR\FileDude.txt yay
;If not, start your move: copy the file to the Backup
CopyFiles $INSTDIR\FileDude.txt $INSTDIR\Backup
;then installed the new one, It'll overwrite it (I think :))
SetOutPath $INSTDIR
File "NewFileDude.txt"
;If the there's no file, then proceed as normal
yay:
SetOutPath $INSTDIR
File "NewFileDude.txt"
SectionEnd
Hope this help :igor:
kichik
6th February 2003 21:06 UTC
OK. It's all a bit clearer now. You were copying the whole directory ($0) and not all of the files in it ($0\*.*) like I thought you were trying to do. It appears I got it all mixed up, and stuck to the first post where indeed you wrote \*.*. I am very sorry for the confusion.
I think CopyFiles $0 $0\backup didn't work because Windows doesn't allow copying a directory into a sub-directory of itself (NSIS just calls a Windows function SHFileOperation for CopyFiles). However, it does accept CopyFiles $0\*.* $0\backup and so far, according to my tests, it didn't copy backup itself into backup. For this you will have to create the backup directory ahead.
Again, I am sorry for the confusion.
Rovastar
7th February 2003 01:18 UTC
CHeers folks drunk now but I will try it.
I didn't think the copyfiles command could be so confusing. :)
Rovastar
7th February 2003 01:40 UTC
Just read it again and
" However, it does accept CopyFiles $0\*.* $0\backup and so far, according to my tests, it didn't copy backup itself into backup."
does that mean that NSIS should/wishlist do this (i.e. create a dir before copying itself to it automatically)or is it WIndows domain??
Rovastar
7th February 2003 01:50 UTC
hmm
yeah, because a recursive copy would copy itself.
e.g.
find first file
file 1
copy to new directory called backup\file 1
file 2
copy to new directory called backup\file 2
dir 1
copy to new directory called backup\dir 1
...
then it gets to the "backup" directory
and it eould try top copy all the contents of backup into backup\backup
and so on until you run out of disk space....
what you need to do is a
for each file in $0
if name NOT backup
copy to backup folder
end if
next
how i've no idea, but that's what you need to do..
Rovastar
7th February 2003 01:51 UTC
hahahaha, btw, rovastar didn't post that, I Hydra did.. just that he used my machine last in this forum.. lol...
kichik
7th February 2003 11:18 UTC
I have tested this on Windows 98 and it doesn't work. Seems like only NT is smart enough not to copy the backup directory too. Windows 98 just does nothing.
Here is how you should do what Hydra said (yes, we believe you... You don't have multiple personalities :p):
FindFirst $0 $1 "$INSTDIR\*.*"
again: StrCmp $1 "" done
StrCmp $1 "backup" +2
CopyFiles $INSTDIR\$1 $INSTDIR\backup
FindNext $0 $1
Goto again
done:
FindClose $0
Rovastar
7th February 2003 14:33 UTC
:confused: :) I was thinking I didn't post that thought I was going mad and talking to myself.
Yeah Hydra good point. I just wanted to get something working for you. Cannot *.* it.
I could say if the backup directory exists then delete it and THEn *.* to the $0 backup directory. Ummh but the CopyFiles command doe snot do what I wanted/thought it would do.
kichik,
Thanks for the code. I will try it out later on tonight.
CopyFiles command is strange indeed. Is it a bug with the NSIS code?
kichik
7th February 2003 14:35 UTC
No, it's just how Windows works. NSIS just calls a Windows function. The code I have sent above should work fine.
Joel
7th February 2003 19:22 UTC
Oops. I think a I need to simplify the things :p
I'll keep the hard work