Generische automatisierte Aktualisierung von Desktop-Anwendungen

485
rationalboss

Gibt es eine Anwendung, die automatisch einen lokalen Ordner mit allen Dateien in einem Webverzeichnis aktualisiert? Oder noch besser: Wenn es eine ZIP-Datei gibt, werden die Dateien in den angegebenen Ordner extrahiert.

Ich habe eine einfache Desktop-Webanwendung (HTML / Javascript mit jQuery) in einem lokalen Ordner, und bei jeder Aktualisierung möchte ich, dass die Computer in unserem Büro das Update automatisch installieren, indem sie etwa "latest.zip" automatisch herunterladen (über HTTP-Download (kein FTP-Download) und lassen Sie die Dateien vom Updater in das Anwendungsverzeichnis kopieren.

Ich habe gesucht, aber alles, was ich sehe, ist die Dateisynchronisation, die bidirektional ist, und Programme, die zu kompliziert zu verwenden oder zu schwer sind. Mein Ziel ist es, das Anwendungsverzeichnis ohne großen Benutzereingriff im Hintergrund zu aktualisieren. Da JavaScript jedoch nicht auf Festplatten schreiben kann, muss es mit einer anderen Anwendung (Exe-Datei) ausgeführt werden, die regelmäßig ausgeführt wird.

Vielleicht gibt es so etwas wie eine generische Updater-Anwendung, in der Sie eine Webadresse der Dateien und das lokale Verzeichnis angeben können, in das die Dateien kopiert werden sollen?

0
Sie sind sich nicht sicher, nach welchen Programmen Sie suchen, aber haben Sie http://www.ninite.com ausgecheckt? Kruug vor 11 Jahren 0

2 Antworten auf die Frage

1
Indrek

Since the question mentions an .exe file, I assume you're on Windows. If so, you can do this with PowerShell.

The script

# Set some variables to hold the source, name and destination of the update file $UpdateUrl = "http://example.com/" $UpdateFile = "update.zip" $Destination = "C:\Path\to\application\" $TempDir = $Env:Temp + "\" # Download the update file to a temporary directory $Client = New-Object System.Net.WebClient $Client.DownloadFile($UpdateUrl + $UpdateFile, $TempDir + $UpdateFile) # Calculate MD5 hash of the downloaded update file $MD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider $Hash1 = [System.BitConverter]::ToString( $MD5.ComputeHash([System.IO.File]::ReadAllBytes($TempDir + $UpdateFile)) ) # If an old update file exists at the destination, calculate its MD5 hash as well If (Test-Path ($Destination + $UpdateFile)) { $Hash2 = [System.BitConverter]::ToString( $MD5.ComputeHash([System.IO.File]::ReadAllBytes($Destination + $UpdateFile)) ) } Else { $Hash2 = "" } # Compare the MD5 hashes # If they're not equal, then copy the new update file to the destination and extract its contents If ($Hash1 -ne $Hash2) { Copy-Item ($TempDir + $UpdateFile) $Destination $Shell = New-Object -ComObject Shell.Application $Shell.NameSpace($Destination).CopyHere( $Shell.NameSpace($Destination + $UpdateFile).Items(), 20 ) } # Delete the downloaded update file Remove-Item ($TempDir + $UpdateFile) 

Explanation

The first block declares some variables that contain the name, source and destination of the update file, as well as a temporary directory to hold the downloaded update file. Don't forget the trailing slashes when you change them to your own paths.

The next block uses the WebClient object to download the file to the temporary directory.

Next, the script calculates the MD5 hash of the downloaded file. If you want to calculate a different hash, like SHA-1, check out the available classes in the System.Security.Cryptography namespace.

Then, the script checks for the existence of an old update file at the destination folder, and calculates its MD5 hash.

Next, the two hashes are compared. If they're not equal, it means there has been an update. The script then uses the Windows Shell object to copy the update file to the destination folder and extract its contents. The number 20 is the sum of two options of the CopyHere() function - 4 (which supresses the progress dialog) and 16 (which answers "Yes to All" to any dialogs, thus automatically overwriting existing files).

Finally, the last line deletes the downloaded update file from the temp directory.


References

For more information on the classes, methods and cmdlets used, see the following links:

Extrahiert Ihr Code auch den Inhalt? Wäre es möglich, die vorhandene "update.zip" im Pfad auch mit der heruntergeladenen Datei zu vergleichen? rationalboss vor 11 Jahren 0
@rationalboss Ja, es extrahiert den Inhalt. Ich habe meinem Beitrag eine kurze Erläuterung des Skripts hinzugefügt. Wie genau möchten Sie die ZIP-Dateien vergleichen - Größe, Änderungsdatum, eine Art Hash / Prüfsumme oder etwas anderes? Indrek vor 11 Jahren 0
Hash / Prüfsumme :) rationalboss vor 11 Jahren 0
@rationalboss Angenommen, MD5 ist in Ordnung, ich habe das Skript in meinem Post aktualisiert, um die heruntergeladene Datei mit der vorhandenen Aktualisierungsdatei im Zielverzeichnis zu vergleichen und sie nur zu extrahieren, wenn sie sich unterscheidet. Indrek vor 11 Jahren 1
0
Patabugen

Das Problem, das ich sehe, ist, dass Ihre Client-Computer keinen Zugriff auf Ihren lokalen Ordner haben. Sie wissen also nicht, dass es Zeit ist. Wenn es klein ist, können Sie es sowieso schon öfters automatisch herunterladen, oder es wird ein Shell / Bash-Skript erstellt, mit dem sie gestartet werden, das bei jedem Öffnen nach einer neuen Version sucht und diese herunterlädt.

Wenn Sie sich unter Windows mit der mit FreeFileSync gelieferten RealtimeSync-Anwendung beschäftigen, können Sie festlegen, dass ein Ordner auf Änderungen überwacht wird. Anschließend kann er einen Befehl ausführen, wenn Änderungen entdeckt werden, beispielsweise ein Stapel Skript zum Hochladen für die anderen Maschinen zum Herunterladen.

http://sourceforge.net/projects/freefilesync/

Die Dateien sind jedoch nicht über NAS zugänglich. Es ist über http erreichbar. Ist das über FreeFileSync möglich? rationalboss vor 11 Jahren 0
Nein, das ist das Problem, das ich im ersten Absatz sehe. Sie müssen die Aktualisierungsdatei herunterladen, bevor Sie wissen, ob sie aktualisiert wurde. FFS konnte die Datei nur für Sie hochladen, wenn Sie eine Bearbeitung vorgenommen haben, und selbst dann nur in Verbindung mit einem anderen Skript, um den Upload durchzuführen. Patabugen vor 11 Jahren 0