Jump to content

FileInstall not working expectly


Recommended Posts

I got the following code:

If Not (FileInstall("a.txt", "a2.txt") And FileInstall("b.txt", "b2.txt")) Then MsgBox(0, "", "Error")

 

Not compiled this works fine. But the compiled version wont work. Only the first file will be installed (There is no problem to install the file.. no old files to overwrite or something like that).
The crazy thing:

If Not (FileInstall("a.txt", "a2.txt") And FileInstall("b.txt", "b2.txt")) Then MsgBox(0, "", "error")
Exit
FileInstall("b.txt", "b2.txt")

 

This code works as expected. The third line will not be executed but maybe the Aut2Exe recognize the second file in this case (I think the compiler do not see the second FileInstall) and the installation works! Try it your self. Maybe someone has an explanation?

Link to comment
Share on other sites

First question, why would you want to code it this way?

There's better ways of determining if the files exist than trying to see if the fileinstall failed. After all, the way you wrote it if the out file already exists it will give you an error message which is probably not what you're looking for in the script in the first place. One liner coding just makes things easier for the coder, not for the poor people that have to read this dreck later.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers

@stamplin

Does any of these ring any ring any bells for you?:

this demonstrates why you shouldn't be doing it that way:

If Not (test("a") And test("b")) Then MsgBox(0, "", "End")

func test($A)
    Msgbox(0,$a,$a)
    return 0
EndFunc

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 hour ago, BrewManNH said:

First question, why would you want to code it this way?

There's better ways of determining if the files exist than trying to see if the fileinstall failed. After all, the way you wrote it if the out file already exists it will give you an error message which is probably not what you're looking for in the script in the first place. One liner coding just makes things easier for the coder, not for the poor people that have to read this dreck later.

No I just want to install two files and if one fails I want to return a error code. But why it is important how to write it? I like to code like this, short and easy for me. But it should work anyway,  or not? Why is this code not working?

Link to comment
Share on other sites

1 hour ago, Jos said:

@stamplin

Does any of these ring any ring any bells for you?:

this demonstrates why you shouldn't be doing it that way:

If Not (test("a") And test("b")) Then MsgBox(0, "", "End")

func test($A)
    Msgbox(0,$a,$a)
    return 0
EndFunc

Jos

You have to know the first file installs correctly. Id understand what you mean. But the first function doesnt fail.

Link to comment
Share on other sites

 

6 minutes ago, stamplin said:

Why is this code not working?

Because it doesn't, use another way.

If FileInstall("a.txt", "a2.txt") Then
    If Not FileInstall("b.txt", "b2.txt") Then
        MsgBox(0, "b2", "error")
    EndIf
Else
    MsgBox(0, "a2", "error")
EndIf

 

Edited by BrewManNH
Forgot a boolean

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

2 minutes ago, BrewManNH said:

 

Because it doesn't, use another way.

If FileInstall("a.txt", "a2.txt") Then
    If Not FileInstall("b.txt", "b2.txt") Then
        MsgBox(0, "b2", "error")
    EndIf
Else
    MsgBox(0, "a2", "error")
EndIf

 

Mh "Because it doesnt"... There should be information in the documention of FileInstall about that "issue".
We cannot easily say it doesnt work like that in my opinion. But who cares.. I know other ways to do it, but it is not that nice I think.

Link to comment
Share on other sites

We can easily say it doesn't work like that, it's been tested and it doesn't work. Whether or not you want it to work that way is immaterial because we both know it won't.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Another way I do it or maybe the same way I do it is like this:

If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf

If something can't be done in the way it should or better in the way you think it should, does not mean it can't be done or does not mean in the way it works is a bad way.

Why Python is different from Perl, why C is Different from C++, why CSharp(C#) is different from C and C++, Why Ruby is different from? WHY? because every language do things in the way they feel or believe is better.
So what is the point here?

Regards
Alien.
 

Link to comment
Share on other sites

2 hours ago, alien4u said:

Why Python is different from Perl, why C is Different from C++, why CSharp(C#) is different from C and C++, Why Ruby is different from? WHY? because every language do things in the way they feel or believe is better.

You are totally right, but why I cannot use the function like this:

If Not FileInstall("a.txt", "a2.txt") Then FileInstall("b.txt", "b2.txt")

The second file will never be installed. But the first. And like this both file will be installed:

If FileInstall("a.txt", "a2.txt") Then FileInstall("b.txt", "b2.txt")
Exit
FileInstall("b.txt", "b2.txt")

No change in the executed code. But working. Something is not working right.

Link to comment
Share on other sites

7 hours ago, stamplin said:

You are totally right, but why I cannot use the function like this:

If Not FileInstall("a.txt", "a2.txt") Then FileInstall("b.txt", "b2.txt")

 

Maybe because FileInstall() function does not check if the file exists? and this is why we use it like this:

If Not FileExists(@TempDir & "\a2.txt") Then
    FileInstall("a.txt", @TempDir & "\a2.txt", 1)
EndIf


I still missing your point sorry...

Regards
Alien

Link to comment
Share on other sites

20 minutes ago, alien4u said:

I still missing your point sorry...

Ok, try the following yourself:

Create two empty textfiles called a.txt and b.txt and create a new AutoIt file with that content:

If FileInstall("a.txt", "a2.txt") Then FileInstall("b.txt", "b2.txt")

Just run it, do not compile it. a2.txt and b2.txt will be installed. As expected. The first FileInstall success and causes the second file to install, you will see.

Now compile it and try it again (delete the old a2.txt and b2.txt). b2.txt will not be installed. But a2.txt will be.. So the first succes and the second FileInstall fails. Why??

Its not that I want to check something.. my point is that it is not possible to use the function FileInstall twice in one and the same code line.

 

Link to comment
Share on other sites

7 hours ago, stamplin said:

You are totally right, but why I cannot use the function like this:

If Not FileInstall("a.txt", "a2.txt") Then FileInstall("b.txt", "b2.txt")

The second file will never be installed. But the first. And like this both file will be installed:

If FileInstall("a.txt", "a2.txt") Then FileInstall("b.txt", "b2.txt")
Exit
FileInstall("b.txt", "b2.txt")

No change in the executed code. But working. Something is not working right.

In 1. snipet the the 2. FileInstall will only executed when installing of 1. file failed. FileInstall returns 1 on success. The logic you try is:  if not 1 then ..

the 2. snippet installs the 2. FileInstallwill only executed when installing of 1. file is successfully. When first fileinstalls failed the second FileInstall wouldn't be executed. And it will be tried to install in line 1, after a exit no more line is executed.

 

Link to comment
Share on other sites

7 minutes ago, AutoBert said:

In 1. snipet the the 2. FileInstall will only executed when installing of 1. file failed. FileInstall returns 1 on success. The logic you try is:  if not 1 then ..

the 2. snippet installs the 2. FileInstallwill only executed when installing of 1. file is successfully. When first fileinstalls failed the second FileInstall wouldn't be executed. And it will be tried to install in line 1, after a exit no more line is executed.

 

 

 

7 hours ago, stamplin said:

Sorry i have no idea how to edit my post. But: The first code without the NOT inside the If.

 

Link to comment
Share on other sites

I think it's time to admit that you're not going to convince stamplin. He's going to sit here and stomp his feet like a petulant 2 year old determined to get his way, no matter what.

He's gotten his answer, he just refuses to accept it because he's so much smarter than the rest of us. /sarcasm

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

One more I have to say:

$res = FileInstall("a.txt", "a2.txt") + FileInstall("b.txt", "b2.txt")

 

executed as not compiled version:   value of $res = 2

executed as compiled version:           value of $res = 1

 

Just try it, please try it. This is not normal, but nobody believe me.
Now you can close it I said my part.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...