Jump to content

download, compare and change script


Rackoon
 Share

Go to solution Solved by FireFox,

Recommended Posts

Hi,

I try to create application what will:

1. download file after every 1 min. from http url (timer - not yet implemented)

2. compare downloaded and running file

3. if files are same, then delete downloaded (delete - not yet implemented)

4. if files are different then move downloaded over running
5. kill running windows application by process name (not yet implemented)

6. start windows application to reload new file (not yet implemented)

; Download configuration file.
InetGet("http://192.168.56.101/autoit/config.php?did=2", "c:\_config.ini")

; Compare configuration file.
IsFileSame("c:\_config.ini", "c:\config.ini")
Func _IsFileSame($sFilePath_1, $sFilePath_2)
    Return RunWait(@ComSpec & ' /c FC /B /W "' & $sFilePath_1 & '" "' & $sFilePath_2 & '"', @WorkingDir, @SW_HIDE) = 0
EndFunc

; Copy new configuration file.
If $_IsFileSame = False Then
FileMove("C:\_config.ini", "C:\config.ini", 1)
EndIf

I don't understand what is wrong but I cannot run/compile solutsion... can someone please help me?

Thanks.

Link to comment
Share on other sites

  • Solution

Hi,

Welcome to the autoit forum :)

Instead of downloading the file each time to compare it with your current one, it would be better to directly compare the file versions by a http request made either on a txt or on a php (which make a sql request) file.

For the rest it's quite easy.

  • Kill processes:

ProcessList with ProcessClose (and compare pid (@AutoItPID) to avoid closing the current process)

  • Compare files (versions will be enough):

FileGetVersion with _VersionCompare

  • And finally restart the application:

Run/ShellExecute followed by Exit.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi FireFox,

Thanks for warm welcome! :)

Also thanks for advice about version check before download, I will think about it and when there is point in my system, I will implement it - less data to transfer :P
---
For now I have solved my issues and application is doing what I need:
 

#include <File.au3>

; Open the logfile in write mode.
Local $hFile = FileOpen(@ScriptDir & "\application.log", 1) 

; Download configuration file.
InetGet("http://192.168.56.101/autoit/config.php?did=2", "c:\_config.ini")
Sleep(1000)

; Compare configuration files.
$version = _IsFileSame("c:\_config.ini", "c:\config.ini")
Sleep(1000)

; Configuration control function.
If $version = False Then 
FileMove("C:\_config.ini", "C:\config.ini", 1)
_FileWriteLog($hFile, "Configuration changed")
Run("stop.bat", "", @SW_MINIMIZE)
Sleep(3000)
_FileWriteLog($hFile, "Application closed")
Run("start.bat", "", @SW_MINIMIZE)
Sleep(3000)
_FileWriteLog($hFile, "Application started")
Else
FileDelete ( "C:\_config.ini" )
EndIf
Sleep(1000)

; Compare configuration function.
Func _IsFileSame($sFilePath_1, $sFilePath_2)
    Return RunWait(@ComSpec & ' /c FC /B /W "' & $sFilePath_1 & '" "' & $sFilePath_2 & '"', @WorkingDir, @SW_HIDE) = 0
    Sleep(1000)
EndFunc

I will test my solutsion for some days and let's see - when it's working, how it's working... :)

EDIT: sorry, loop is still missing, will implement it.

BR, Rackoon

Edited by Rackoon
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...