Sign in to follow this  
Followers 0
Rackoon

download, compare and change script

3 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

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