src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js
function downloadInstaller(requester, isInitialAttempt, updateParams) {
        updateParams = updateParams || _updateParams;
        var currentRequester = requester || "";
        try {
            var ext = path.extname(updateParams.installerName);
            var localInstallerPath = path.resolve(updateDir, Date.now().toString() + ext),
                localInstallerFile = fs.createWriteStream(localInstallerPath),
                requestCompleted = true,
                readTimeOut = 180000;
            progress(request(updateParams.downloadURL, {timeout: readTimeOut}), {})
                .on('progress', function (state) {
                    var target = "retry-download";
                    if (isInitialAttempt) {
                        target = "initial-download";
                    }
                    var info = Math.floor(parseFloat(state.percent) * 100).toString() + '%';
                    var status = {
                        target: target,
                        spans: [{
                            id: "percent",
                            val: info
                        }]
                    };
                    postMessageToBrackets(MessageIds.SHOW_STATUS_INFO, currentRequester, status);
                })
                .on('error', function (err) {
                    console.log("AutoUpdate : Download failed. Error occurred : " + err.toString());
                    requestCompleted = false;
                    localInstallerFile.end();
                    var error = err.code === 'ESOCKETTIMEDOUT' || err.code === 'ENOTFOUND' ?
                                nodeErrorMessages.NETWORK_SLOW_OR_DISCONNECTED :
                                nodeErrorMessages.DOWNLOAD_ERROR;
                    postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE, currentRequester, error);
                })
                .pipe(localInstallerFile)
                .on('close', function () {
                    if (requestCompleted) {
                        try {
                            fs.renameSync(localInstallerPath, installerPath);
                            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_SUCCESS, currentRequester);
                        } catch (e) {
                            console.log("AutoUpdate : Download failed. Exception occurred : " + e.toString());
                            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE,
                                                      currentRequester, nodeErrorMessages.DOWNLOAD_ERROR);
                        }
                    }
                });
        } catch (e) {
            console.log("AutoUpdate : Download failed. Exception occurred : " + e.toString());
            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE,
                                  currentRequester, nodeErrorMessages.DOWNLOAD_ERROR);
        }
    }
function downloadInstaller(requester, isInitialAttempt, updateParams) {
        updateParams = updateParams || _updateParams;
        var currentRequester = requester || "";
        try {
            var ext = path.extname(updateParams.installerName);
            var localInstallerPath = path.resolve(updateDir, Date.now().toString() + ext),
                localInstallerFile = fs.createWriteStream(localInstallerPath),
                requestCompleted = true,
                readTimeOut = 180000;
            progress(request(updateParams.downloadURL, {timeout: readTimeOut}), {})
                .on('progress', function (state) {
                    var target = "retry-download";
                    if (isInitialAttempt) {
                        target = "initial-download";
                    }
                    var info = Math.floor(parseFloat(state.percent) * 100).toString() + '%';
                    var status = {
                        target: target,
                        spans: [{
                            id: "percent",
                            val: info
                        }]
                    };
                    postMessageToBrackets(MessageIds.SHOW_STATUS_INFO, currentRequester, status);
                })
                .on('error', function (err) {
                    console.log("AutoUpdate : Download failed. Error occurred : " + err.toString());
                    requestCompleted = false;
                    localInstallerFile.end();
                    var error = err.code === 'ESOCKETTIMEDOUT' || err.code === 'ENOTFOUND' ?
                                nodeErrorMessages.NETWORK_SLOW_OR_DISCONNECTED :
                                nodeErrorMessages.DOWNLOAD_ERROR;
                    postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE, currentRequester, error);
                })
                .pipe(localInstallerFile)
                .on('close', function () {
                    if (requestCompleted) {
                        try {
                            fs.renameSync(localInstallerPath, installerPath);
                            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_SUCCESS, currentRequester);
                        } catch (e) {
                            console.log("AutoUpdate : Download failed. Exception occurred : " + e.toString());
                            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE,
                                                      currentRequester, nodeErrorMessages.DOWNLOAD_ERROR);
                        }
                    }
                });
        } catch (e) {
            console.log("AutoUpdate : Download failed. Exception occurred : " + e.toString());
            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE,
                                  currentRequester, nodeErrorMessages.DOWNLOAD_ERROR);
        }
    }
function downloadInstaller ( requester , isInitialAttempt , updateParams ) { updateParams = updateParams || _updateParams ; var currentRequester = requester || "" ; try { var ext = path . extname ( updateParams . installerName ) ; var localInstallerPath = path . resolve ( updateDir , Date . now ( ) . toString ( ) + ext ) , localInstallerFile = fs . createWriteStream ( localInstallerPath ) , requestCompleted = true , readTimeOut = 180000 ; progress ( request ( updateParams . downloadURL , { timeout : readTimeOut } ) , { } ) . on ( 'progress' , function ( state ) { var target = "retry-download" ; if ( isInitialAttempt ) { target = "initial-download" ; } var info = Math . floor ( parseFloat ( state . percent ) * 100 ) . toString ( ) + '%' ; var status = { target : target , spans : [ { id : "percent" , val : info } ] } ; postMessageToBrackets ( MessageIds . SHOW_STATUS_INFO , currentRequester , status ) ; } ) . on ( 'error' , function ( err ) { console . log ( "AutoUpdate : Download failed. Error occurred : " + err . toString ( ) ) ; requestCompleted = false ; localInstallerFile . end ( ) ; var error = err . code === 'ESOCKETTIMEDOUT' || err . code === 'ENOTFOUND' ? nodeErrorMessages . NETWORK_SLOW_OR_DISCONNECTED : nodeErrorMessages . DOWNLOAD_ERROR ; postMessageToBrackets ( MessageIds . NOTIFY_DOWNLOAD_FAILURE , currentRequester , error ) ; } ) . pipe ( localInstallerFile ) . on ( 'close' , function ( ) { if ( requestCompleted ) { try { fs . renameSync ( localInstallerPath , installerPath ) ; postMessageToBrackets ( MessageIds . NOTIFY_DOWNLOAD_SUCCESS , currentRequester ) ; } catch ( e ) { console . log ( "AutoUpdate : Download failed. Exception occurred : " + e . toString ( ) ) ; postMessageToBrackets ( MessageIds . NOTIFY_DOWNLOAD_FAILURE , currentRequester , nodeErrorMessages . DOWNLOAD_ERROR ) ; } } } ) ; } catch ( e ) { console . log ( "AutoUpdate : Download failed. Exception occurred : " + e . toString ( ) ) ; postMessageToBrackets ( MessageIds . NOTIFY_DOWNLOAD_FAILURE , currentRequester , nodeErrorMessages . DOWNLOAD_ERROR ) ; } }
Downloads the installer for latest Brackets release
@param {boolean} sendInfo   - true if download status info needs to be
sent back to Brackets, false otherwise
@param {object}   [updateParams=_updateParams] - json containing update parameters
Downloads the installer for latest Brackets release