Archive: File /oname usage


File /oname usage
I am having trouble using File to write one file to $SYSDIR. When I hard code a file name, no problem; the errors occur when I use variables.

A usage that I found in the NSIS directory is:
/Contrib/AdvSplash/Example.nsi:10: File /oname=$PLUGINSDIR\splash.bmp "${NSISDIR}\Contrib\Makensisw\logo.bmp".

The manual states "...When using the /oname= switch, only one file can be specified, and the file name can contain variables..."

So my usage is:
1. File /oname=$0 "SysDLLs\$0"
OR
2. StrCpy ${MISSING_DLL} $0
File /oname=$0 "SysDLLs\${MISSING_DLL}"

and on both compiler error is:
"File: "SysDLLs\$R5" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] filespec [...]|/oname=outfile one_file_only)"
($R5 for MISSING_DLL; usage #2 or substitute $0 in message for usage #1)

mdm


your fault is, that the /oname switch must be set on compile-time. but $0 isnt set on compile-time. therefore the error occurs. the filename can only contain constant variables, set by !define or by nsis on compile-time.


That seems kind of silly...let me understand you:
I can use a variable, but only one that is set at compile time and not
!define VAR_NAME $R5
so I can set it later...hmmm:(

I am verifying 18 different systemdll files in $SYSDIR. Any suggestions on alternatives to:
IfFileExists $SYSDIR\$0 present absent
present:
DetailPrint "$0 present in $SYSDIR$\n"
goto exit
absent: #start comparing with all 18 file names:
StrCmp $0 "file_1.dll" 0 file1
....
StrCmp $0 "file_18.dll" 0 file18
goto exit
file1:
File /oname="file_1.dll" "file_1.dll"
goto exit
....
file18:
File /oname="file_18.dll" "file_18.dll"
goto exit
....
exit:


That is incorrect Comm@nder21. Of cource /oname is a run-time setting, otherwise it would be quite useless.

The fault you are making is that the file location is a compile-time setting.

The compiler has to know the location of the file on the compiler system, otherwise it can't include anything.

Example of correct usage:

File /oname=$0 "file.dll"


Yes, that is the usage. It is unfortunate that I can't use variables for both arguments. Any further suggestions would be welcome also!

thanks,
mdm


You don't seem to get the difference between compile-time and run-time.

How could it allow you to use run-time variables when it has to include a file on the compiler system? You can use compile-time defined symbols.

If you have 18 different compile-time files you will have to include 18 file commands. However you can crete a macro that does all the checks.


oh, i'm sorry.
i've confounded the two parameters '/oname=targetfilename' and 'originalfilename'

i ment just, what u said.


got it, thanks for your help
mdm


one more time...

Originally posted by Joost Verburg

If you have 18 different compile-time files you will have to include 18 file commands. However you can crete a macro that does all the checks.
this post mentions using !defines instead of variables, which I finally get (I think..) and I just wanted to clarify the last part.
So, if I'm using !defines like so:

!define FILE1 "D:\stuff\myfile.txt"
!define FILE2 "D:\stuff\nxtOne.txt"

The only way I've been able to use these defines with the File command is like this:

File ${FILE1}
File ${FILE2}

So what would the macro Joost is talking about do? Check to see if a file needs to be backed up or whatever else you wanted to do before installing the file?

Or is there some way you could call the File command using defines inside a macro? So you could have a loop to go through all 18 of your defines?

I tried to do some nested stuff where I was creating the string "${FILE1}" but that's failing because I'm still storing that string in a variable, which the File command can't see...

So, if you've got 18 Files to install - you need to use 18 File commands, even if you are using defines? End of Story right?

thanks for the clarification, I've been going around and around on this trying to get some sort of trickery that I thought I'd seen somewhere on these boards, but I've just ended up confusing myself..

-marc

You cannot loop through defines unfortunately as they are around on compile-time not run-time.
So yes you have to insert X File commands.

-Stu


thanks much.

-marc