Sign in to follow this  
Followers 0
Angel

FileInstall - error in help file?

20 posts in this topic

Hi,

I am trying to use FileInstall to add some files to an executable. The problem is that it seems to be an error in the documentation.

The FileInstall function is supposed to have up to 3 arguments. The help file says that the 2nd argument must be a PATH finished with a backslash. BUT the example on the bottom of the help is the following:

FileInstall("C:\test.au3", "D:\mydir\test.au3")

So the 2nd is not a PATH! What must be done?

Also, the help file says that the "source" argument must not be a variable, but a string, in order to let the compiler find the file, which makes sense to me.

However, is it possible to use one of the folder macros like @ScriptDir or @ProgramsDir for instance? This would be very handy as who wants to hard code the "Program Files" folder into the script?

Otherwise, if it does not work, it would be great if at least we could use a "relative" path (or no path at all) and then the compiler would simply look for the file in the script folder (or some other folder relative to it). I think that this would make this function much more useful and easy to use.

Cheers,

Angel

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

FileInstall("dir of file you wish to combine to ur script", "dir u want this combined file to be installed to when ur compiled script is run)

So if u wanted a file A.exe from ur C:/ to be combined to ur script and when ur script is run make that file install to the dir D:/newfolder u would type this

FileInstall("C:/A.exe", "D:/newfolder)

The file A.exe is combined to ur script when you compile it

Is that what u wanted ?

Edited by nova

Share this post


Link to post
Share on other sites

Thanks Nova,

that is what I want. But that means that the documentation is wrong, right?

Also, is it possible to use the AutoIt macros or relative paths in the source file name? I could not check it for myself as the FileInstall gave an error when compiling :-(

Angel

Share this post


Link to post
Share on other sites

Yep u can use macros with FileInstall

Hope these examples help you out

FileInstall("C:\A.exe", @ScriptDir & '\A.exe')

FileInstall(@ScriptDir & '\A.exe', @WindowsDir & '\A.exe')

Share this post


Link to post
Share on other sites

Nova,

when I try:

FileInstall(@ScriptDir & "\encryp.ctf",@ScriptDir & "\encryp.ctf",0)

I get the following error from the compiler:

"Invalid FileInstall Function"

What am I doing wrong??

Angel

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

From help's docs: FileInstall

Remarks

The FileInstall function is designed to ....

The source file must be a string and not a variable so that the compiler can extract the filename to include. The source cannot contain wildcards.

When this function is used from a non-compiled script, a copy operation is performed instead (to allow for easy testing pre-compilation).

Files maintain their original creation/modification timestamps when installed.

Remember: The source path of the file to compile, this must be a literal string; it cannot be a variable. Edited by josbe

Share this post


Link to post
Share on other sites

Josbe,

Nova told me that it was alright to use macros, so I am using a macro, not a variable.

If this is not possible, then I think that it would be a great idea to allow this in the future, as it is so much convenient to include files by using macros like @ProgramsDir, for instance.

At least I've verified that it is possible to use relative paths to include files which are in the same folder as the script. I think that that should be explained in the documentation, as it is not clear enough.

Also, it seems that there is an error in the documentation, as in one part it says that the target is a folder and in another it says that the target is a filename.

Cheers,

Angel

Share this post


Link to post
Share on other sites

Angel,

Nova told me that it was alright to use macros, so I am using a macro, not a variable.

If this is not possible, then I think that it would be a great idea to allow this in the future, as it is so much convenient to include files by using macros like @ProgramsDir, for instance.

This is not a good idea. The limitation is there so you KNOW the file is going to be in the specified location. It would be messy if it was done any other way.

BTW, macros are just language wide variables... they are NOT literals. Literals are only defined by use of quotes.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

Angel,

This is not a good idea. The limitation is there so you KNOW the file is going to be in the specified location. It would be messy if it was done any other way.

BTW, macros are just language wide variables... they are NOT literals. Literals are only defined by use of quotes.

*** Matt @ MPCS

Forgive me for reviving a dead thread, but this _is_ a good idea. I was just bitten by this, and It means I had to go from this:

Global Const $DATA_DIR = @AppDataDir & "\Phosphor Media\YouHaveOrders\"
  Global Const $SOURCE_DIR =  "c:\work\active\apps\connector\trunk\src\"
  Global Const $FILESET[4]=["connect.ini","folder1.ico","folder2.ico","folder3.ico"]
  For $file In $FILESET
    If not FileInstall($SOURCE_DIR & $file, $DATA_DIR & $file, 1) Then
      return FatalError("Unable to install file:" & $DATA_DIR & $file)
    EndIf
  Next

To this:

Global Const $DATA_DIR = @AppDataDir & "\Phosphor Media\YouHaveOrders\"
  local $ok=true
  $ok = $ok And FileInstall("c:\work\active\apps\connector\trunk\src\connect.ini", $DATA_DIR & $file, 1)
  If not $ok Then return FatalError("Unable to install file:" & $DATA_DIR & $file)
  $ok = $ok And FileInstall("c:\work\active\apps\connector\trunk\src\folder1.ico", $DATA_DIR & $file, 1)
  If not $ok Then return FatalError("Unable to install file:" & $DATA_DIR & $file)
  $ok = $ok And FileInstall("c:\work\active\apps\connector\trunk\src\folder2.ico", $DATA_DIR & $file, 1)
  If not $ok Then return FatalError("Unable to install file:" & $DATA_DIR & $file)
  $ok = $ok And FileInstall("c:\work\active\apps\connector\trunk\src\folder3.ico", $DATA_DIR & $file, 1)
  If not $ok Then return FatalError("Unable to install file:" & $DATA_DIR & $file)

Somebody please tell me I'm doing this wrong, and there's a way that I can do this that is much closer to my first version.

Share this post


Link to post
Share on other sites

Variables and other interpreted values cannot be used in FileInstall because they are not evaluated at compile time. The compiler is not the interpreter, if it sees FileInstall($variable, ...) it doesn't know where to look. And no, it will not be changed, many people have asked and it's not feasible.

Share this post


Link to post
Share on other sites

Variables and other interpreted values cannot be used in FileInstall because they are not evaluated at compile time. The compiler is not the interpreter, if it sees FileInstall($variable, ...) it doesn't know where to look. And no, it will not be changed, many people have asked and it's not feasible.

Beat me to it :D

Share this post


Link to post
Share on other sites

Somebody please tell me I'm doing this wrong, and there's a way that I can do this that is much closer to my first version.

Unfortunately, as the others have mentioned about the limitations of FileInstall, you are unable to use the array concept to change the first literal parameter. I would do something closer to the below example as your last attempt looks confusing to me.

Global Const $DATA_DIR = @AppDataDir & "\Phosphor Media\YouHaveOrders\"

Func _Install()
    If DirCreate($DATA_DIR) Then
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\connect.ini", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\connect.ini")
        EndIf
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\folder1.ico", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\folder1.ico")
        EndIf
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\folder2.ico", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\folder2.ico")
        EndIf
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\folder3.ico", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\folder3.ico")
        EndIf
        Return True
    EndIf
    Return ''
EndFunc

Ensure that $DATA_DIR has a trailing backspace with the declaration or the FileInstall above may fail.

:D

Share this post


Link to post
Share on other sites

I wish they could fix that problem, because then I could make a all-around installer. But, theres really no chance for it, because as i've been told, The FileInstall() Is read at compilation time, NOT when the script runs (Which is where the variables are).

Share this post


Link to post
Share on other sites

I wish they could fix that problem, because then I could make a all-around installer. But, theres really no chance for it, because as i've been told, The FileInstall() Is read at compilation time, NOT when the script runs (Which is where the variables are).

Very unlikely.

Share this post


Link to post
Share on other sites

Thanks much the replies, at least I'm not alone in wanting it. I understand that it would be quite tricky to pull off at compile time, but I'd love it if they could.

I'm not too worried about about errors and/or missing files, because that will happen to me, not to my users.

Share this post


Link to post
Share on other sites

I would do something closer to the below example as your last attempt looks confusing to me.

Global Const $DATA_DIR = @AppDataDir & "\Phosphor Media\YouHaveOrders\"

Func _Install()
    If DirCreate($DATA_DIR) Then
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\connect.ini", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\connect.ini")
        EndIf
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\folder1.ico", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\folder1.ico")
        EndIf
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\folder2.ico", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\folder2.ico")
        EndIf
        If Not FileInstall("c:\work\active\apps\connector\trunk\src\folder3.ico", $DATA_DIR, 1) Then
            Return FatalError("Unable to install file:" & $DATA_DIR & "\folder3.ico")
        EndIf
        Return True
    EndIf
    Return ''
EndFunc

Ensure that $DATA_DIR has a trailing backspace with the declaration or the FileInstall above may fail.

:D

Yeah, it should be confusing, that's what happens when you're a cobol programmer and you're writing java code. I'm carrying the style of another language into AutoIt code. This shall pass, it was only day 2 :D

Here's what I ended up with - added a couple of wrapper functions to reduce repetition.

Func Install()
  If not DirCreate( $DATA_DIR ) Then 
    return FatalError("Unable to create directory:" & $DATA_DIR)
  EndIf

  Select
    Case not PutFile("c:\work\active\apps\connector\trunk\src\connect.ini")
      return FileError("connect.ini")
    Case not PutFile("c:\work\active\apps\connector\trunk\src\folder1.ico")
      return FileError("folder1.ico")
    Case not PutFile("c:\work\active\apps\connector\trunk\src\folder2.ico")
      return FileError("folder2.ico")
    Case not PutFile("c:\work\active\apps\connector\trunk\src\folder3.ico")
      return FileError("folder3.ico")
  EndSelect
  return true
EndFunc

Func PutFile($file)
  local $path = StringSplit($file, "\")
  local $dest = $path[$path[0]]
  return FileInstall("c:\work\active\apps\connector\trunk\src\folder3.ico", $DATA_DIR & $dest, 1)
EndFunc

Func FileError($file)
  return FatalError("Unable to install file:" & $DATA_DIR & $file)
EndFunc

Func FatalError($msg)
  MsgBox(4096,"Error", $msg)
  sleep(2000)
  return false
EndFunc

Share this post


Link to post
Share on other sites

Here's what I ended up with - added a couple of wrapper functions to reduce repetition.

Looks better but notice that FileInstall is hardcoded with a literal string within the PutFile function so you are FileInstalling the same file to different filenames. If that is your original intention then looks good.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Looks better but notice that FileInstall is hardcoded with a literal string within the PutFile function so you are FileInstalling the same file to different filenames. If that is your original intention then looks good.

Shite! Nope, I done broke it again. Need more coffee...

edit: Ok, so I dropped 'PutFile', and reverted to individual FileInstalls. All that damned repetition still makes me want to cry. Such is life.

Select
    Case not FileInstall("c:\work\active\apps\connector\trunk\src\connect.ini", $DIR_APP & "connect.ini", 1)
      return FileError("connect.ini")
    Case not FileInstall("c:\work\active\apps\connector\trunk\src\folder1.ico", $DIR_APP & "folder1.ico", 1)
      return FileError("folder1.ico")
    Case not FileInstall("c:\work\active\apps\connector\trunk\src\folder2.ico", $DIR_APP & "folder2.ico", 1)
      return FileError("folder2.ico")
    Case not FileInstall("c:\work\active\apps\connector\trunk\src\folder3.ico", $DIR_APP & "folder3.ico", 1)
      return FileError("folder3.ico")
  EndSelect
Edited by aGorilla

Share this post


Link to post
Share on other sites

if you have a lot of files in one directory, this may help you a bit before you start doing the select case or not:

http://www.autoitscript.com/forum/index.ph...c=34805&hl=

If anything might give you a bit more insight.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Thanks for the pointer.

For the moment, I've switched to a 'DoOrDie' model. Wrap it around any action, and supply an error message just in case. If it dies, it shows the error on the way out the door.

Doesn't get rid of all the repetition, but I was able to lose the case statement, and it's much shorter (which is a good thing).

Global Const $DIR_DEV = @AppDataDir & "\Dev\"
Global Const $DIR_APP = $DIR_DEV & "App\"

Global Const $FILE_INI  = "connect.ini"
Global Const $FILE_ICO1 = "folder1.ico"
Global Const $FILE_ICO2 = "folder2.ico"
Global Const $FILE_ICO3 = "folder3.ico"
Global Const $FILESET[4]=[$FILE_INI, $FILE_ICO1, $FILE_ICO2, $FILE_ICO3]

Global Const $ERR_MKDIR = "Unable to create directory: " 
Global Const $ERR_INSTALL  = "Unable to install file: " & $DIR_APP
Global Const $ERR_NOTFOUND = "File not found: " 
Global Const $ERR_INISAVE  = "Unable to save setting: "  

Func DoOrDie($act, $err_msg)
  If $act Then return true
  MsgBox(4096,"Error", $err_msg)
  exit
EndFunc

Func Install()
  DoOrDie(DirCreate($DIR_APP), $ERR_MKDIR & $DIR_APP)

  DoOrDie(FileInstall("c:\work\active\apps\connector\trunk\src\connect.ini", $DIR_APP & $FILE_INI , 1), $ERR_INSTALL & $FILE_INI )
  DoOrDie(FileInstall("c:\work\active\apps\connector\trunk\src\folder1.ico", $DIR_APP & $FILE_ICO1, 1), $ERR_INSTALL & $FILE_ICO1)
  DoOrDie(FileInstall("c:\work\active\apps\connector\trunk\src\folder2.ico", $DIR_APP & $FILE_ICO2, 1), $ERR_INSTALL & $FILE_ICO2)
  DoOrDie(FileInstall("c:\work\active\apps\connector\trunk\src\folder3.ico", $DIR_APP & $FILE_ICO3, 1), $ERR_INSTALL & $FILE_ICO3)
  return true
EndFunc

edit: dropped the 'sleep' after the error msg - not needed.

Edited by aGorilla

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0