Sign in to follow this  
Followers 0
coles

Places for improvement

4 posts in this topic

Can Autoit gurus please have a look at this script and let me know what all changes or improvements i need to make it more effective or faster or shorter.

Any new ideas are welcomed also :)

What the script does is " from Main computer maps a drive(from a list of IP's provided in a text file) and it checks whether the file is newer in main computer. IF yes then it will copies the file.once it's done it opens a txt file and writes the IP address 

  

func latestIndexHTML($address, $name)
   Local $result
   Local $hFileIndexHTML
   DriveMapDel ( "G:" )
   ConsoleWrite('Trying: ' & $address & "/" & $name & @CRLF);
   $result = DriveMapAdd ( "G:", "\\" & $address & "\C$", 0, $name & "\admin","adminpswd")
   if Number(FileGetTime("C:\a\index.html", $FT_CREATED, 1)) > Number(FileGetTime("G:\Program Files\L\LC\", $FT_CREATED, 1)) And $result = 1 Then
      FileCopy( "C:\a\index.html", "G:\Program Files\L\LC\", 1);
      ConsoleWrite('Copying Index.html file: ' & $address & @CRLF);
      $hFileIndexHTML = FileOpen("C:\a\indexhtml.txt", 1)
      FileWrite($hFileIndexHTML, $address & @CRLF)
      FileClose($hFileIndexHTML)
   EndIf
EndFunc

Thank you 

Share this post


Link to post
Share on other sites



I'm not an AutoIt Guru and I'm not a programming Guru and this is not a code improvement but if you allow me I can give you some logic tips(I'm not a logic Guru).

If you are checking different destinations and you are the "Main" source because you are the one who is going to Update the rest. Then you probably should not take the update process on you, that will be resource consuming and time consuming for you and your machine, so if "THEY" need the update, "they" do the job.
For your example code I assume they are web servers, so you can probably make that Server(Linux or Windows) do the job for you, task scheduler(windows), cron job(linux) to check if there is a new version of your "index.html" file and get the new version.

Of course this is only useful if the amount of work needed is not insanely big and hard to scale and support.

You maybe be wonder, why this is useful?
Let say your computer(updater.example.com) update 20 mores computers, if you computer break or got a virus or anything, then 20 computers are going to be outdate and unable to have an update until that computer get fixed.
In the other hand if your 20 computers get the updates connecting to an update server(updater.example.com) and the update server is broken or malfunction you could change your dns record pointing to updater.example.com to another computer with the same "index.html" file and all is working again with only one minor change.

I hope you get my point and forgive me this little off topic. I'm just trying to help.

Regards
Alien.

Share this post


Link to post
Share on other sites

@alien4u Thanks for your input and comment.

Yes this will be run automatically with help of Task sheduler(actually i am thinking of putting a {1000 * 60 * 24} so that it does every 24 hours)

i do have multiple files for to check whether it needs update, so was thinking instead of putting it up as

func latestIndexHTML($address, $name)
   Local $result
   Local $hFileIndexHTML
   DriveMapDel ( "G:" )
   ConsoleWrite('Trying: ' & $address & "/" & $name & @CRLF);
   $result = DriveMapAdd ( "G:", "\\" & $address & "\C$", 0, $name & "\admin","adminpswd")
   if Number(FileGetTime("C:\a\index.html", $FT_CREATED, 1)) > Number(FileGetTime("G:\Program Files\L\LC\", $FT_CREATED, 1)) And $result = 1 Then
      FileCopy( "C:\a\index.html", "G:\Program Files\L\LC\", 1);
      ConsoleWrite('Copying Index.html file: ' & $address & @CRLF);
      $hFileIndexHTML = FileOpen("C:\a\indexhtml.txt", 1)
      FileWrite($hFileIndexHTML, $address & @CRLF)
      FileClose($hFileIndexHTML)
   EndIf
EndFunc

func latestIndexHTML2($address, $name)
   Local $result
   Local $hFileIndexHTML2
   DriveMapDel ( "G:" )
   ConsoleWrite('Trying: ' & $address & "/" & $name & @CRLF);
   $result = DriveMapAdd ( "G:", "\\" & $address & "\C$", 0, $name & "\admin","adminpswd")
   if Number(FileGetTime("C:\a\index2.html", $FT_CREATED, 1)) > Number(FileGetTime("G:\Program Files\L\LC\", $FT_CREATED, 1)) And $result = 1 Then
      FileCopy( "C:\a\index2.html", "G:\Program Files\L\LC\", 1);
      ConsoleWrite('Copying Index2.html file: ' & $address & @CRLF);
      $hFileIndexHTML = FileOpen("C:\a\indexhtml2.txt", 1)
      FileWrite($hFileIndexHTML2, $address & @CRLF)
      FileClose($hFileIndexHTML2)
   EndIf
EndFunc

will it be good to do multiple IFELSE

Share this post


Link to post
Share on other sites

If you have 20 files you wish to check maybe the best way would be to have all this files on an array and then check each one to see if there is a new version or anything you want.

Regards
Alien.

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