diff --git a/Engines/Wine/Engine/Object/script.js b/Engines/Wine/Engine/Object/script.js index 86cc1b3696..11d0ddf58f 100644 --- a/Engines/Wine/Engine/Object/script.js +++ b/Engines/Wine/Engine/Object/script.js @@ -301,13 +301,18 @@ Wine.prototype.kill = function () { /** * -* @returns {Downloader} +* @returns available Wine versions */ Wine.prototype.getAvailableVersions = function () { - return new Downloader() + var versionsFile = this._wineEnginesDirectory + "/availableVersions.json"; + touch(versionsFile); + new Downloader() .wizard(this._wizard) .url(this._wineWebServiceUrl) - .get() + .to(versionsFile) + .onlyIfUpdateAvailable(true) + .get(); + return cat(versionsFile); }; /** diff --git a/Utils/Functions/Filesystem/Files/script.js b/Utils/Functions/Filesystem/Files/script.js index b45cbe67fa..48bdece364 100644 --- a/Utils/Functions/Filesystem/Files/script.js +++ b/Utils/Functions/Filesystem/Files/script.js @@ -33,6 +33,12 @@ var remove = function(filePath) { return Bean("fileUtilities").remove(new java.io.File(filePath)); }; +var touch = function(filePath) { + if (!fileExists(filePath)) { + Bean("fileUtilities").writeToFile(new java.io.File(filePath), ""); + } +}; + var writeToFile = function(filePath, content) { Bean("fileUtilities").writeToFile(new java.io.File(filePath), content); }; diff --git a/Utils/Functions/Net/Download/script.js b/Utils/Functions/Net/Download/script.js index a63c5cff3f..e1770fdc64 100644 --- a/Utils/Functions/Net/Download/script.js +++ b/Utils/Functions/Net/Download/script.js @@ -32,6 +32,10 @@ var Downloader = function () { that._localFile = localFile; return that; }; + that.onlyIfUpdateAvailable = function (onlyIfUpdateAvailable) { + that._onlyIfUpdateAvailable = onlyIfUpdateAvailable; + return that; + } that.get = function () { if (!that._message) { that._message = tr("Please wait while {0} is downloaded ...", that._fetchFileNameFromUrl(that._url)); @@ -41,9 +45,18 @@ var Downloader = function () { var progressBar = that._wizard.progressBar(that._message); } + if (that._onlyIfUpdateAvailable) { + if (!that._downloader.isUpdateAvailable(that._localFile, that._url)) { + print(that._localFile + " already up-to-date."); + return; + } + } + if (that._localFile) { that._downloader.get(that._url, that._localFile, function (progressEntity) { - progressBar.accept(progressEntity); + if (progressBar) { + progressBar.accept(progressEntity); + } }); if (that._checksum) { @@ -64,10 +77,10 @@ var Downloader = function () { } } else { return that._downloader.get(that._url, function (progressEntity) { - if(progressBar) { + if (progressBar) { progressBar.accept(progressEntity); } }); } } -}; \ No newline at end of file +};