From b4a7c4b1f4145c2980c6ee56fe1f2049284b96e1 Mon Sep 17 00:00:00 2001 From: Plata Date: Sat, 7 Apr 2018 20:06:08 +0200 Subject: [PATCH 1/5] Make Checksum etc. a class --- Engines/Wine/Shortcuts/Reader/script.js | 76 +++--- Engines/Wine/Shortcuts/Wine/script.js | 234 +++++++++++-------- Utils/Functions/Apps/Resources/script.js | 53 +++-- Utils/Functions/Filesystem/Extract/script.js | 215 ++++++++++------- Utils/Functions/Filesystem/Files/script.js | 79 ++++--- Utils/Functions/Net/Download/script.js | 200 ++++++++++------ Utils/Functions/Net/Resource/script.js | 149 +++++++----- 7 files changed, 620 insertions(+), 386 deletions(-) diff --git a/Engines/Wine/Shortcuts/Reader/script.js b/Engines/Wine/Shortcuts/Reader/script.js index 579f31fda1..30bb2ea857 100644 --- a/Engines/Wine/Shortcuts/Reader/script.js +++ b/Engines/Wine/Shortcuts/Reader/script.js @@ -67,32 +67,52 @@ var _WineShortcutReader = function(shortcut) { } }; -/* exported ShortcutReader */ -var ShortcutReader = function() { - var that = this; - - this.of = function(shortcut) { - this.shortcut = shortcut; - var shortcutContentParsed = JSON.parse(this.shortcut.script); - - if(shortcutContentParsed.type == "WINE") { - that._runner = new _WineShortcutReader(this.shortcut); - } - }; - - this.run = function(userArguments) { - that._runner.run(userArguments); - }; - - this.stop = function() { - that._runner.stop(); - }; - - this.uninstall = function() { - that._runner.uninstall(); - }; +/** +* ShortcutReader prototype +* @constructor +*/ +function ShortcutReader() { +} + +/** +* sets shortcut +* @param {string} shortcut shortcut +*/ +ShortcutReader.prototype.of = function (shortcut) { + this.shortcut = shortcut; + var shortcutContentParsed = JSON.parse(this.shortcut.script); - this.container = function() { - return that._runner.container(); - }; -}; + if(shortcutContentParsed.type == "WINE") { + that._runner = new _WineShortcutReader(this.shortcut); + } +} + +/** +* runs shortcut +* @param {array} userArguments arguments +*/ +ShortcutReader.prototype.run = function (userArguments) { + this._runner.run(userArguments); +} + +/** +* stops running shortcut +*/ +ShortcutReader.prototype.stop = function () { + this._runner.stop(); +} + +/** +* uninstalls shortcut +*/ +ShortcutReader.prototype.uninstall = function () { + this._runner.uninstall(); +} + +/** +* returns container of shortcut +* @returns {string} container +*/ +ShortcutReader.prototype.container = function () { + return this._runner.container(); +} \ No newline at end of file diff --git a/Engines/Wine/Shortcuts/Wine/script.js b/Engines/Wine/Shortcuts/Wine/script.js index aedde30c79..f38598645d 100644 --- a/Engines/Wine/Shortcuts/Wine/script.js +++ b/Engines/Wine/Shortcuts/Wine/script.js @@ -1,107 +1,145 @@ include(["engines", "wine", "engine", "object"]); -/* exported WineShortcut */ -var WineShortcut = function () { - var that = this; - that._shortcutManager = Bean("shortcutManager"); - that._appsManager = Bean("repositoryManager"); - that._fileSearcher = Bean("fileSearcher"); - that._winePrefixesDirectory = Bean("propertyReader").getProperty("application.user.containers") + "/" + WINE_PREFIX_DIR + "/"; - - that._category = "Other"; - that._description = ""; - - that.name = function (name) { - that._name = name; - return that; - }; - - that.type = function (type) { - that._type = type; - return that; - }; - - that.category = function (category) { - that._category = category; - return that; - }; - - that.description = function (description) { - that._description = description; - return that; - }; - - that.arguments = function(args) { - that._arguments = args; - return that; - }; - - that.search = function(search) { - that._search = search; - return that; - }; - - that.prefix = function(prefix) { - that._prefix = prefix; - return that; - }; - - /** - * sets the miniature for the shortcut - * @param {string[]|URI} miniature - * array which specifies the application of which the miniature shall be used - * or - * URI of the miniature - * @returns {WineShortcut} - */ - that.miniature = function(miniature) { - if(isArray(miniature)) { - // application of miniature given - var application = that._appsManager.getApplication(miniature); - if(application != null && application.getMainMiniature().isPresent()) { - that._miniature = application.getMainMiniature().get(); - } - } else { - // miniature URI given - that._miniature = miniature; +/** +* WineShortcut prototype +* @constructor +*/ +function WineShortcut() { + this._shortcutManager = Bean("shortcutManager"); + this._appsManager = Bean("repositoryManager"); + this._fileSearcher = Bean("fileSearcher"); + this._winePrefixesDirectory = Bean("propertyReader").getProperty("application.user.containers") + "/" + WINE_PREFIX_DIR + "/"; + + this._category = "Other"; + this._description = ""; +} + +/** +* sets shortcut name +* @param {string} name shortcut name +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.name = function (name) { + this._name = name; + return this; +} + +/** +* sets shortcut type +* @param {string} type shortcut type +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.type = function (type) { + this._type = type; + return this; +} + +/** +* sets shortcut category +* @param {string} category shortcut category +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.category = function (category) { + this._category = category; + return this; +} + +/** +* sets shortcut description +* @param {string} description shortcut description +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.description = function (description) { + this._description = description; + return this; +} + +/** +* sets shortcut arguments +* @param {array} args shortcut arguments +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.arguments = function (args) { + this._arguments = args; + return this; +} + +/** +* sets executable which shall be used +* @param {string} search executable name +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.search = function (search) { + this._search = search; + return this; +} + +/** +* sets shortcut prefix +* @param {string} prefix shortcut prefix +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.prefix = function (prefix) { + this._prefix = prefix; + return this; +} + +/** +* sets the miniature for the shortcut +* @param {string[]|URI} miniature +* array which specifies the application of which the miniature shall be used +* or +* URI of the miniature +* @returns {WineShortcut} WineShortcut object +*/ +WineShortcut.prototype.miniature = function (miniature) { + if(isArray(miniature)) { + // application of miniature given + var application = this._appsManager.getApplication(miniature); + if(application != null && application.getMainMiniature().isPresent()) { + this._miniature = application.getMainMiniature().get(); } + } else { + // miniature URI given + this._miniature = miniature; + } - return that; - }; - - that.create = function () { - var _shortcutPrefixDirectory = that._winePrefixesDirectory + "/" + that._prefix; + return this; +} - var executables = that._fileSearcher.search(_shortcutPrefixDirectory, that._search); +/** +* creates shortcut +*/ +WineShortcut.prototype.create = function () { + var _shortcutPrefixDirectory = this._winePrefixesDirectory + "/" + this._prefix; - if (executables.length == 0) { - throw tr("Executable {0} not found!", that._search) - } + var executables = this._fileSearcher.search(_shortcutPrefixDirectory, this._search); - var info = new org.phoenicis.library.dto.ShortcutInfoDTO.Builder() - .withCategory(that._category) - .withName(that._name) - .withDescription(that._description) - .build(); - - var builder = new org.phoenicis.library.dto.ShortcutDTO.Builder() - .withId(that._name) - .withInfo(info) - .withScript(JSON.stringify({ - type: "WINE", - wineDebug: "-all", - winePrefix: that._prefix, - arguments: that._arguments, - workingDirectory:executables[0].getParentFile().getAbsolutePath(), - executable: executables[0].getAbsolutePath() - })); - - if(that._miniature) { - builder.withMiniature(that._miniature); - } + if (executables.length == 0) { + throw tr("Executable {0} not found!", this._search) + } - that._shortcutManager.createShortcut( - builder.build() - ); + var info = new org.phoenicis.library.dto.ShortcutInfoDTO.Builder() + .withCategory(this._category) + .withName(this._name) + .withDescription(this._description) + .build(); + + var builder = new org.phoenicis.library.dto.ShortcutDTO.Builder() + .withId(this._name) + .withInfo(info) + .withScript(JSON.stringify({ + type: "WINE", + wineDebug: "-all", + winePrefix: this._prefix, + arguments: this._arguments, + workingDirectory:executables[0].getParentFile().getAbsolutePath(), + executable: executables[0].getAbsolutePath() + })); + + if(this._miniature) { + builder.withMiniature(this._miniature); } -}; + + this._shortcutManager.createShortcut(builder.build()); +} \ No newline at end of file diff --git a/Utils/Functions/Apps/Resources/script.js b/Utils/Functions/Apps/Resources/script.js index b12cc09f55..6694dc974b 100644 --- a/Utils/Functions/Apps/Resources/script.js +++ b/Utils/Functions/Apps/Resources/script.js @@ -1,25 +1,36 @@ -/* exported AppResource */ -var AppResource = function() { - var that = this; - that._appsManager = Bean("repositoryManager"); +/** +* AppResource prototype +* @constructor +*/ +function AppResource() { + this._appsManager = Bean("repositoryManager"); +} - this.application = function(application) { - that._application = application; - return that; - }; +/** +* sets application +* @param {string} application application of the resource +* @returns {AppResource} AppResource object +*/ +AppResource.prototype.application = function (application) { + this._application = application; + return this; +} - this.get = function(resourceName) { - var application = that._appsManager.getApplication(that._application); - var foundResource = null; - if(application != null && application.resources != null) { - application.resources.forEach(function(resource) { - if(resource.name == resourceName) { - foundResource = resource.content; - } - }); - } - - return foundResource; +/** +* returns resource +* @param {string} resourceName name of the resource +* @returns found resource +*/ +AppResource.prototype.get = function (resourceName) { + var application = this._appsManager.getApplication(this._application); + var foundResource = null; + if (application != null && application.resources != null) { + application.resources.forEach(function(resource) { + if(resource.name == resourceName) { + foundResource = resource.content; + } + }); } -}; + return foundResource; +} \ No newline at end of file diff --git a/Utils/Functions/Filesystem/Extract/script.js b/Utils/Functions/Filesystem/Extract/script.js index 247b49cd72..f95c0488cf 100644 --- a/Utils/Functions/Filesystem/Extract/script.js +++ b/Utils/Functions/Filesystem/Extract/script.js @@ -1,85 +1,140 @@ include(["Utils", "Functions", "filesystem", "files"]); -/* exported CabExtract */ -var CabExtract = function() { - var that = this; - - that.wizard = function (wizard) { - that._wizard = wizard; - return that; - }; - - that.archive = function (archive) { - that._archive = archive; - return that; - }; - - that.message = function (progressMessage) { - that._progressMessage = progressMessage; - return that; - }; - - that.to = function (destination) { - that._destination = destination; - return that; - }; - - that.extract = function(args) { - if (!that._progressMessage) { - that._progressMessage = tr("Please wait while {0} is extracted ...", that._archive); - } - - if(that._wizard) { - var progressBar = that._wizard.progressBar(that._progressMessage); - } - - var processArguments; - if(args) { - processArguments = ["cabextract"].concat(args).concat([that._archive]); - } else { - processArguments = ["cabextract", that._archive]; - } - - print("Extracting to: " + that._destination); - mkdir(that._destination); - var processBuilder = new java.lang.ProcessBuilder(Java.to(processArguments, "java.lang.String[]")); - processBuilder.directory(new java.io.File(that._destination)); - processBuilder.inheritIO(); - processBuilder.start().waitFor(); +/** +* CabExtract prototype +* @constructor +*/ +function CabExtract() { +} + +/** +* sets wizard +* @param {SetupWizard} wizard setup wizard +* @returns {CabExtract} CabExtract object +*/ +CabExtract.prototype.wizard = function (wizard) { + this._wizard = wizard; + return this; +} + +/** +* sets archive +* @param {string} archive archive which shall be extracted +* @returns {CabExtract} CabExtract object +*/ +CabExtract.prototype.archive = function (archive) { + this._archive = archive; + return this; +} + +/** +* sets progress message text +* @param {string} progressMessage progress message +* @returns {CabExtract} CabExtract object +*/ +CabExtract.prototype.message = function (progressMessage) { + this._progressMessage = progressMessage; + return this; +} + +/** +* sets destination +* @param {string} destination place where the archive shall be extracted +* @returns {CabExtract} CabExtract object +*/ +CabExtract.prototype.to = function (destination) { + this._destination = destination; + return this; +} + +/** +* extracts archive +* @param {string} args arguments for the extraction +*/ +CabExtract.prototype.extract = function (args) { + if (!this._progressMessage) { + this._progressMessage = tr("Please wait while {0} is extracted ...", this._archive); } -}; - -/* exported Extractor */ -var Extractor = function () { - var that = this; - that._extractor = Bean("extractor"); - that.wizard = function (wizard) { - that._wizard = wizard; - return that; - }; - that.archive = function (archive) { - that._archive = archive; - return that; - }; - that.message = function (progressMessage) { - that._progressMessage = progressMessage; - return that; - }; - that.to = function (destination) { - that._destination = destination; - return that; - }; - that.extract = function () { - if (!that._progressMessage) { - that._progressMessage = tr("Please wait while {0} is extracted ...", that._archive); - } - - var progressBar = that._wizard.progressBar(that._progressMessage); - - mkdir(that._destination); - that._extractor.uncompress(that._archive, that._destination, function (progress) { - progressBar.accept(progress); - }); + if(this._wizard) { + var progressBar = this._wizard.progressBar(this._progressMessage); } -}; + + var processArguments; + if(args) { + processArguments = ["cabextract"].concat(args).concat([this._archive]); + } else { + processArguments = ["cabextract", this._archive]; + } + + print("Extracting to: " + this._destination); + mkdir(this._destination); + var processBuilder = new java.lang.ProcessBuilder(Java.to(processArguments, "java.lang.String[]")); + processBuilder.directory(new java.io.File(this._destination)); + processBuilder.inheritIO(); + processBuilder.start().waitFor(); +} + +/** +* Extractor prototype +* @constructor +*/ +function Extractor() { + this._extractor = Bean("extractor"); +} + +/** +* sets wizard +* @param {SetupWizard} wizard setup wizard +* @returns {Extractor} Extractor object +*/ +Extractor.prototype.wizard = function (wizard) { + this._wizard = wizard; + return this; +} + +/** +* sets archive +* @param {string} archive archive which shall be extracted +* @returns {Extractor} Extractor object +*/ +Extractor.prototype.archive = function (archive) { + this._archive = archive; + return this; +} + +/** +* sets progress message text +* @param {string} progressMessage progress message +* @returns {Extractor} Extractor object +*/ +Extractor.prototype.message = function (progressMessage) { + this._progressMessage = progressMessage; + return this; +} + +/** +* sets destination +* @param {string} destination place where the archive shall be extracted +* @returns {Extractor} Extractor object +*/ +Extractor.prototype.to = function (destination) { + this._destination = destination; + return this; +} + +/** +* extracts archive +*/ +Extractor.prototype.extract = function () { + if (!this._progressMessage) { + this._progressMessage = tr("Please wait while {0} is extracted ...", this._archive); + } + + var progressBar = this._wizard.progressBar(this._progressMessage); + + mkdir(this._destination); + this._extractor.uncompress(this._archive, this._destination, function (progress) { + progressBar.accept(progress); + }); +} diff --git a/Utils/Functions/Filesystem/Files/script.js b/Utils/Functions/Filesystem/Files/script.js index be6056b9ad..0d56cc29d5 100644 --- a/Utils/Functions/Filesystem/Files/script.js +++ b/Utils/Functions/Filesystem/Files/script.js @@ -59,32 +59,57 @@ var createTempFile = function (extension) { return tmpFile.getAbsolutePath(); }; -/* exported Checksum */ -var Checksum = function () { - var that = this; - that._method = "SHA"; - that._checksumCalculator = Bean("checksumCalculator"); - that.wizard = function (wizard) { - that._wizard = wizard; - return that; - }; - that.method = function (algorithm) { - that._method = algorithm; - return that; - }; - that.of = function (file) { - that._file = file; - return that; - }; - that.get = function () { - if(that._wizard) { - var progressBar = that._wizard.progressBar(tr("Checking file consistency ...")); - } +/** +* Checksum prototype +* @constructor +*/ +function Checksum() { + this._method = "SHA"; + this._checksumCalculator = Bean("checksumCalculator"); +} + +/** +* sets wizard +* @param {SetupWizard} wizard setup wizard +* @returns {Checksum} Checksum object +*/ +Checksum.prototype.wizard = function (wizard) { + this._wizard = wizard; + return this; +} + +/** +* sets checksum algorithm +* @param {string} algorithm algorithm (e.g. "SHA") +* @returns {Checksum} Checksum object +*/ +Checksum.prototype.method = function (algorithm) { + this._method = algorithm; + return this; +} + +/** +* sets file for which the checksum shall be computed +* @param {string} file file for which the checksum shall be computed +* @returns {Checksum} Checksum object +*/ +Checksum.prototype.of = function (file) { + this._file = file; + return this; +} - return that._checksumCalculator.calculate(that._file, that._method, function (progressEntity) { - if(progressBar) { - progressBar.accept(progressEntity); - } - }); +/** +* returns calculated checksum +* @returns {string} calculated checksum +*/ +Checksum.prototype.get = function () { + if(this._wizard) { + var progressBar = this._wizard.progressBar(tr("Checking file consistency ...")); } -}; + + return this._checksumCalculator.calculate(this._file, this._method, function (progressEntity) { + if(progressBar) { + progressBar.accept(progressEntity); + } + }); +} \ No newline at end of file diff --git a/Utils/Functions/Net/Download/script.js b/Utils/Functions/Net/Download/script.js index be70958e5a..ba86e82d10 100644 --- a/Utils/Functions/Net/Download/script.js +++ b/Utils/Functions/Net/Download/script.js @@ -1,87 +1,141 @@ include(["Utils", "Functions", "filesystem", "files"]); -/* exported Downloader */ -var Downloader = function () { - var that = this; - that._downloader = Bean("downloader"); - that._algorithm = "SHA"; - - that._fetchFileNameFromUrl = function (url) { - return url.substring(url.lastIndexOf('/') + 1); - }; - that.wizard = function (wizard) { - that._wizard = wizard; - return that; - }; - that.url = function (url) { - that._url = url; - return that; - }; - that.algorithm = function(algorithm) { - that._algorithm = algorithm; - return that; - }; - that.checksum = function (checksum) { - that._checksum = checksum; - return that; - }; - that.message = function (message) { - that._message = message; - return that; - }; - that.to = function (localFile) { - that._localFile = localFile; - return that; - }; - that.onlyIfUpdateAvailable = function (onlyIfUpdateAvailable) { - that._onlyIfUpdateAvailable = onlyIfUpdateAvailable; - return that; +/** +* Downloader prototype +* @constructor +*/ +function Downloader() { + this._downloader = Bean("downloader"); + this._algorithm = "SHA"; +} + +/** +* fetches the file name from an URL +* @param {string} url URL +* @returns {string} file name +*/ +Downloader.prototype._fetchFileNameFromUrl = function (url) { + return url.substring(url.lastIndexOf('/') + 1); +} + +/** +* sets wizard +* @param {SetupWizard} wizard setup wizard +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.wizard = function (wizard) { + this._wizard = wizard; + return this; +} + +/** +* sets URL which shall be used for the download +* @param {string} url URL +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.url = function (url) { + this._url = url; + return this; +} + +/** +* sets algorithm which shall be used to verify the checksum +* @param {string} algorithm checksum algorithm (e.g. "SHA") +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.algorithm = function (algorithm) { + this._algorithm = algorithm; + return this; +} + +/** +* sets checksum +* @param {string} checksum checksum which shall be used to verify the download +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.checksum = function (checksum) { + this._checksum = checksum; + return this; +} + +/** +* sets message text +* @param {string} message download message +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.message = function (message) { + this._message = message; + return this; +} + +/** +* sets destination +* @param {string} localFile destination of the download +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.to = function (localFile) { + this._localFile = localFile; + return this; +} + +/** +* specifies if the download shall be executed only if a newer version is available +* @param {boolean} onlyIfUpdateAvailable true the download shall be executed only if a newer version is available +* @returns {Downloader} Downloader object +*/ +Downloader.prototype.onlyIfUpdateAvailable = function (onlyIfUpdateAvailable) { + this._onlyIfUpdateAvailable = onlyIfUpdateAvailable; + return this; +} + +/** +* returns downloaded file +* @returns downloaded file +*/ +Downloader.prototype.get = function () { + if (!this._message) { + this._message = tr("Please wait while {0} is downloaded ...", this._fetchFileNameFromUrl(this._url)); } - that.get = function () { - if (!that._message) { - that._message = tr("Please wait while {0} is downloaded ...", that._fetchFileNameFromUrl(that._url)); - } - if(that._wizard) { - var progressBar = that._wizard.progressBar(that._message); - } + if(this._wizard) { + var progressBar = this._wizard.progressBar(this._message); + } - if (that._onlyIfUpdateAvailable) { - if (!that._downloader.isUpdateAvailable(that._localFile, that._url)) { - print(that._localFile + " already up-to-date."); - return; - } + if (this._onlyIfUpdateAvailable) { + if (!this._downloader.isUpdateAvailable(this._localFile, this._url)) { + print(this._localFile + " already up-to-date."); + return; } + } - if (that._localFile) { - that._downloader.get(that._url, that._localFile, function (progressEntity) { - if (progressBar) { - progressBar.accept(progressEntity); - } - }); + if (this._localFile) { + this._downloader.get(this._url, this._localFile, function (progressEntity) { + if (progressBar) { + progressBar.accept(progressEntity); + } + }); - if (that._checksum) { - var fileChecksum = new Checksum() - .wizard(that._wizard) - .of(that._localFile) - .method(that._algorithm) - .get(); + if (this._checksum) { + var fileChecksum = new Checksum() + .wizard(this._wizard) + .of(this._localFile) + .method(this._algorithm) + .get(); - if (fileChecksum != that._checksum) { - var checksumErrorMessage = tr("Error while calculating checksum. \n\nExpected = {0}\nActual = {1}", - that._checksum, fileChecksum); + if (fileChecksum != this._checksum) { + var checksumErrorMessage = tr("Error while calculating checksum. \n\nExpected = {0}\nActual = {1}", + this._checksum, fileChecksum); - that._wizard.message(checksumErrorMessage); + this._wizard.message(checksumErrorMessage); - throw checksumErrorMessage; - } + throw checksumErrorMessage; } - } else { - return that._downloader.get(that._url, function (progressEntity) { - if (progressBar) { - progressBar.accept(progressEntity); - } - }); } + } else { + return this._downloader.get(this._url, function (progressEntity) { + if (progressBar) { + progressBar.accept(progressEntity); + } + }); } -}; +} \ No newline at end of file diff --git a/Utils/Functions/Net/Resource/script.js b/Utils/Functions/Net/Resource/script.js index 4dfb40af5f..63d4e28a5d 100644 --- a/Utils/Functions/Net/Resource/script.js +++ b/Utils/Functions/Net/Resource/script.js @@ -1,79 +1,110 @@ include(["utils", "functions", "net", "download"]); include(["Utils", "Functions", "filesystem", "files"]); -/* exported Resource */ -var Resource = function () { - var that = this; +/** +* Resource prototype +* @constructor +*/ +function Resource() { this._algorithm = "SHA"; this._resourcesPath = Bean("propertyReader").getProperty("application.user.resources"); this._directory = ""; +} - that.wizard = function(wizard) { - that._wizard = wizard; - return that; - }; +/** +* sets wizard +* @param {SetupWizard} wizard setup wizard +* @returns {Resource} Resource object +*/ +Downloader.prototype.wizard = function (wizard) { + this._wizard = wizard; + return this; +} - that.algorithm = function(algorithm) { - that._algorithm = algorithm; - return that; - }; +/** +* sets algorithm +* @param {string} algorithm algorithm to verify the checksum (e.g. "SHA") +* @returns {Resource} Resource object +*/ +Downloader.prototype.algorithm = function (algorithm) { + this._algorithm = algorithm; + return this; +} - that.name = function (name) { - that._name = name; - return that; - }; +/** +* sets name +* @param {string} name name of the resource +* @returns {Resource} Resource object +*/ +Downloader.prototype.name = function (name) { + this._name = name; + return this; +} - that.checksum = function (checksum) { - that._checksum = checksum; - return that; - }; +/** +* sets checksum which shall be used to verify the resource +* @param {string} checksum checksum +* @returns {Resource} Resource object +*/ +Downloader.prototype.checksum = function (checksum) { + this._checksum = checksum; + return this; +} - that.url = function(url) { - that._url = url; - return that; - }; +/** +* sets URL +* @param {string} url URL +* @returns {Resource} Resource object +*/ +Downloader.prototype.url = function (url) { + this._url = url; + return this; +} - /** - * directory inside the resource directory where the Resource is stored - * @param {string} directory - * @returns {Resource} - */ - that.directory = function(directory) { - that._directory = directory; - return that; - }; +/** +* sets directory inside the resource directory where the Resource is stored +* @param {string} directory directory path +* @returns {Resource} Resource object +*/ +Downloader.prototype.directory = function (directory) { + this._directory = directory; + return this; +} - that.get = function () { - if (!that._message) { - that._message = tr("Please wait while {0} is downloaded ...", that._name); - } +/** +* returns the Resource +* @returns {Resource} downloaded Resource object +*/ +Downloader.prototype.get = function () { + if (!this._message) { + this._message = tr("Please wait while {0} is downloaded ...", this._name); + } - var resourcesPath = that._resourcesPath + "/" + that._directory; - mkdir(resourcesPath); + var resourcesPath = this._resourcesPath + "/" + this._directory; + mkdir(resourcesPath); - var resourcePath = resourcesPath + "/" + that._name; + var resourcePath = resourcesPath + "/" + this._name; - if (fileExists(resourcePath)) { - var fileChecksum = new Checksum() - .wizard(that._wizard) - .of(resourcePath) - .method(that._algorithm) - .get(); + if (fileExists(resourcePath)) { + var fileChecksum = new Checksum() + .wizard(this._wizard) + .of(resourcePath) + .method(this._algorithm) + .get(); - if(fileChecksum == that._checksum) { - return resourcePath; - } + if(fileChecksum == this._checksum) { + return resourcePath; } + } - new Downloader() - .url(that._url) - .wizard(that._wizard) - .message(that._message) - .checksum(that._checksum) - .algorithm(that._algorithm) - .to(resourcePath) - .get(); + new Downloader() + .url(this._url) + .wizard(this._wizard) + .message(this._message) + .checksum(this._checksum) + .algorithm(this._algorithm) + .to(resourcePath) + .get(); - return resourcePath; - } -}; + return resourcePath; +} From 9806bc4c1cb157f6ac9f56574beb34a5c4b1fd90 Mon Sep 17 00:00:00 2001 From: Plata Date: Sat, 7 Apr 2018 21:03:57 +0200 Subject: [PATCH 2/5] Add missing @returns --- Engines/Wine/Shortcuts/Reader/script.js | 4 ++++ Engines/Wine/Shortcuts/Wine/script.js | 1 + Utils/Functions/Filesystem/Extract/script.js | 2 ++ 3 files changed, 7 insertions(+) diff --git a/Engines/Wine/Shortcuts/Reader/script.js b/Engines/Wine/Shortcuts/Reader/script.js index 30bb2ea857..5c5dc84cb1 100644 --- a/Engines/Wine/Shortcuts/Reader/script.js +++ b/Engines/Wine/Shortcuts/Reader/script.js @@ -77,6 +77,7 @@ function ShortcutReader() { /** * sets shortcut * @param {string} shortcut shortcut +* @returns {void} */ ShortcutReader.prototype.of = function (shortcut) { this.shortcut = shortcut; @@ -90,6 +91,7 @@ ShortcutReader.prototype.of = function (shortcut) { /** * runs shortcut * @param {array} userArguments arguments +* @returns {void} */ ShortcutReader.prototype.run = function (userArguments) { this._runner.run(userArguments); @@ -97,6 +99,7 @@ ShortcutReader.prototype.run = function (userArguments) { /** * stops running shortcut +* @returns {void} */ ShortcutReader.prototype.stop = function () { this._runner.stop(); @@ -104,6 +107,7 @@ ShortcutReader.prototype.stop = function () { /** * uninstalls shortcut +* @returns {void} */ ShortcutReader.prototype.uninstall = function () { this._runner.uninstall(); diff --git a/Engines/Wine/Shortcuts/Wine/script.js b/Engines/Wine/Shortcuts/Wine/script.js index f38598645d..ff83b67d38 100644 --- a/Engines/Wine/Shortcuts/Wine/script.js +++ b/Engines/Wine/Shortcuts/Wine/script.js @@ -109,6 +109,7 @@ WineShortcut.prototype.miniature = function (miniature) { /** * creates shortcut +* @returns {void} */ WineShortcut.prototype.create = function () { var _shortcutPrefixDirectory = this._winePrefixesDirectory + "/" + this._prefix; diff --git a/Utils/Functions/Filesystem/Extract/script.js b/Utils/Functions/Filesystem/Extract/script.js index f95c0488cf..8a9a46b43f 100644 --- a/Utils/Functions/Filesystem/Extract/script.js +++ b/Utils/Functions/Filesystem/Extract/script.js @@ -50,6 +50,7 @@ CabExtract.prototype.to = function (destination) { /** * extracts archive * @param {string} args arguments for the extraction +* @returns {void} */ CabExtract.prototype.extract = function (args) { if (!this._progressMessage) { @@ -125,6 +126,7 @@ Extractor.prototype.to = function (destination) { /** * extracts archive +* @returns {void} */ Extractor.prototype.extract = function () { if (!this._progressMessage) { From 395e7dc926ab9f7d8e1019211234624631224b13 Mon Sep 17 00:00:00 2001 From: Plata Date: Sat, 7 Apr 2018 21:06:40 +0200 Subject: [PATCH 3/5] Fix no-undef --- Engines/Wine/Shortcuts/Reader/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engines/Wine/Shortcuts/Reader/script.js b/Engines/Wine/Shortcuts/Reader/script.js index 5c5dc84cb1..4f2c993bbe 100644 --- a/Engines/Wine/Shortcuts/Reader/script.js +++ b/Engines/Wine/Shortcuts/Reader/script.js @@ -84,7 +84,7 @@ ShortcutReader.prototype.of = function (shortcut) { var shortcutContentParsed = JSON.parse(this.shortcut.script); if(shortcutContentParsed.type == "WINE") { - that._runner = new _WineShortcutReader(this.shortcut); + this._runner = new _WineShortcutReader(this.shortcut); } } From 242015169616feead9d1327e92ce588697c1c7ba Mon Sep 17 00:00:00 2001 From: Plata Date: Sat, 7 Apr 2018 21:10:39 +0200 Subject: [PATCH 4/5] Fix Resource --- Utils/Functions/Net/Resource/script.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Utils/Functions/Net/Resource/script.js b/Utils/Functions/Net/Resource/script.js index 63d4e28a5d..979851c9ce 100644 --- a/Utils/Functions/Net/Resource/script.js +++ b/Utils/Functions/Net/Resource/script.js @@ -16,7 +16,7 @@ function Resource() { * @param {SetupWizard} wizard setup wizard * @returns {Resource} Resource object */ -Downloader.prototype.wizard = function (wizard) { +Resource.prototype.wizard = function (wizard) { this._wizard = wizard; return this; } @@ -26,7 +26,7 @@ Downloader.prototype.wizard = function (wizard) { * @param {string} algorithm algorithm to verify the checksum (e.g. "SHA") * @returns {Resource} Resource object */ -Downloader.prototype.algorithm = function (algorithm) { +Resource.prototype.algorithm = function (algorithm) { this._algorithm = algorithm; return this; } @@ -36,7 +36,7 @@ Downloader.prototype.algorithm = function (algorithm) { * @param {string} name name of the resource * @returns {Resource} Resource object */ -Downloader.prototype.name = function (name) { +Resource.prototype.name = function (name) { this._name = name; return this; } @@ -46,7 +46,7 @@ Downloader.prototype.name = function (name) { * @param {string} checksum checksum * @returns {Resource} Resource object */ -Downloader.prototype.checksum = function (checksum) { +Resource.prototype.checksum = function (checksum) { this._checksum = checksum; return this; } @@ -56,7 +56,7 @@ Downloader.prototype.checksum = function (checksum) { * @param {string} url URL * @returns {Resource} Resource object */ -Downloader.prototype.url = function (url) { +Resource.prototype.url = function (url) { this._url = url; return this; } @@ -66,7 +66,7 @@ Downloader.prototype.url = function (url) { * @param {string} directory directory path * @returns {Resource} Resource object */ -Downloader.prototype.directory = function (directory) { +Resource.prototype.directory = function (directory) { this._directory = directory; return this; } @@ -75,7 +75,7 @@ Downloader.prototype.directory = function (directory) { * returns the Resource * @returns {Resource} downloaded Resource object */ -Downloader.prototype.get = function () { +Resource.prototype.get = function () { if (!this._message) { this._message = tr("Please wait while {0} is downloaded ...", this._name); } From 28954882ae7390b6e733419e1c37cc6ae9bf46fe Mon Sep 17 00:00:00 2001 From: Plata Date: Sat, 7 Apr 2018 21:21:31 +0200 Subject: [PATCH 5/5] Add missing return types --- Utils/Functions/Apps/Resources/script.js | 2 +- Utils/Functions/Net/Download/script.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Utils/Functions/Apps/Resources/script.js b/Utils/Functions/Apps/Resources/script.js index 6694dc974b..9160411fed 100644 --- a/Utils/Functions/Apps/Resources/script.js +++ b/Utils/Functions/Apps/Resources/script.js @@ -19,7 +19,7 @@ AppResource.prototype.application = function (application) { /** * returns resource * @param {string} resourceName name of the resource -* @returns found resource +* @returns {Resource} found resource */ AppResource.prototype.get = function (resourceName) { var application = this._appsManager.getApplication(this._application); diff --git a/Utils/Functions/Net/Download/script.js b/Utils/Functions/Net/Download/script.js index ba86e82d10..fab55a161a 100644 --- a/Utils/Functions/Net/Download/script.js +++ b/Utils/Functions/Net/Download/script.js @@ -90,7 +90,7 @@ Downloader.prototype.onlyIfUpdateAvailable = function (onlyIfUpdateAvailable) { /** * returns downloaded file -* @returns downloaded file +* @returns {String} content of downloaded file */ Downloader.prototype.get = function () { if (!this._message) {