then.js is cool

news/2024/11/30 15:42:43/
var CON_SERVER_ADDRESS = "";//服务器地址
//声明nodejs功能对象
var path = require('path');
var http = require('http');
var fs = require('fs');
var exec = require('child_process').execFile;
//var then = require('/thenjs/thenjs.js');
//初始化当前exe运行的路径,后面很多地方要用
var execPath = path.dirname(process.execPath);//读取本地配置文件,查看是否设置了服务器地址
function ReadServerAddress_Async(next)
{appconfig.read("_CON_SERVER_ADDRESS", function (addr){//console.info(addr);if (addr == ""){window.location.replace("choose-server.html");}else{CON_SERVER_ADDRESS = addr; //赋值console.info("$$ 读取服务器地址:", addr);next(null, CON_SERVER_ADDRESS);}});
}
//读取本地的最大版本文件,不含路径,应该返回 sonicc-9.05.zip
function GetClientMaxAppName_Async(next)
{fs.readdir(execPath + "\\app", function (err, files){try{var clientVersion = 0;var maxVersionFileName = "";for (var i = 0; i < files.length; i++){var ffn = path.basename(files[i], ".zip");var tVersion = parseFloat(ffn.split('-')[1]);//console.info("tVersion = " + tVersion);if (tVersion > clientVersion)maxVersionFileName = ffn;}console.info("$$ 读取客户机最大版本:", maxVersionFileName);next(null, maxVersionFileName);}catch (ex){_WriteError(ex);//出错后不回调是对的,因为退出按钮已经显示}});
}
//启动本地最新程序
function RunMaxVersionClientFileName()
{var then = require('./node_modules/thenjs');then(function (next){GetClientMaxAppName_Async(next);          //读取客户端最大版本的文件}).then(function (next, res){console.info("$$ 准备启动读取读取最大版本文件", res);var nwjsPath = execPath + "\\nw.exe ";var maxVerFl = execPath + "\\app\\" + res + ".zip ";const spawn = require('child_process').spawn;const child = spawn(nwjsPath, [maxVerFl], {detached: true, //表示启动的进程是独立的});})
}
//检查服务器版本,是不是需要下载
function CheckServerFile_Async(ClientMaxFileName, next)
{$.GetOnlyAsync(CON_SERVER_ADDRESS + "/w8/home/CheckNeedUpdateClient?clientFileName=" + ClientMaxFileName, true,function (res){if (res.xException != null && res.xException != ''){_WriteError("连接服务器成功,但服务器内部异常:", ex);}else{next(null, res);}},function (res){_WriteError("连接服务器异常:", ex);});
}
//下载最新文件
function DownloadFileFromServer (url, dest, next)
{var file = fs.createWriteStream(dest);var request = http.get(url, function (res){var fsize = res.headers['content-length'];res.on('data', function (data){file.write(data);var progressCounter = Math.round(100 - (((fsize - file.bytesWritten) / fsize) * 100), 2);$("#xProgressInfo").html(progressCounter + "%");});res.on('end', function (){file.end();next(null, null);});}).on('error', function (err){fs.unlink(dest);next(null, err.message);});
};$(document).ready(function ()
{var then = require('./node_modules/thenjs');then(function (next){ReadServerAddress_Async(next);          //读取服务器地址,如果没有则转向}).then(function (next, res){GetClientMaxAppName_Async(next);        //读取客户端最大版本的文件}).then(function (next, res){console.info("$$ 客户机最大版本号", res);CheckServerFile_Async(res, next)}).then(function (next, res){console.info("$$ 看看是否需要下载 = " , res);if (res.xNeed){_WriteMsg("下载文件:" + res.xFileName);DownloadFileFromServer(CON_SERVER_ADDRESS + "/w8/zo-content/client-down-package/" + res.xFileName,execPath + "\\app\\" + res.xFileName,next);}else{_WriteMsg("无需更新,准备启动...");next(null, null);}}).then(function (next, res){console.info("$$ 准备启动");RunMaxVersionClientFileName();})
});//辅助性函数//
function _WriteMsg(msg)
{$("#xsubMsg").html(msg);}
function _WriteError(msg, ex)
{$("#xsubMsg").html(msg + "<br>" + ex);$("#btnQuitAndClear,#btnQuit").show();
}
//

http://www.ppmy.cn/news/455183.html

相关文章

english site,cool!

非常棒的英语学习网站&#xff0c;绝对满足你&#xff01; 毫无疑问计算机网络 —— 因特网是外语学习的有用工具&#xff0c;通过环球网和电子邮件我们能获得 大量英语学习和教学的新信息和许多网上交流机会&#xff0c;为了帮助英语爱好者通过因特网学习英语&#xff0c;笔者…

Cool Flash Site: vitorvilela

[ 訪問 vitorvilela] 充滿活力,洋溢著一股童話氣息, 作者3D功底也是相當深厚

Cool stuff

Open trading system http://www.opentradingsystem.com/quantNotes/Basic_math_.html quant Notes

Cool JavaScript Tricks

参考&#xff1a;http://www.blogohblog.com/cool-javascript-tricks/ 网页图片rotate效果: <script type"text/javascript">document.body.contentEditabletrue; document.designModeon; var radius 0;var imgs document.getElementsByTagName("img&q…

This is cool...

Microsoft Windows XP [版本 5.1.2600] (C) 版权所有 1985-2001 Microsoft Corp. C:\Documents and Settings\Administrator>python G:\get-pip.py Collecting pip Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB) 35% |███████████▏ |…

10 cool things about Kotlin

10 cool things about Kotlin https://easykotlin.quora.com/10-cool-things-about-Kotlin

十一、docker学习-docker核心之docker网络(1)

docker网络 当开始大规模使用docker时&#xff0c;你会发现需要了解很多关于网络的知识。docker作为目前最火的轻量级容器技术&#xff0c;有很多令人称道的功能&#xff0c;如docker的镜像管理。然而&#xff0c;docker同样有着很多不完善的地方&#xff0c;网络方面就是Dock…

物联网卡是做什么用的

根据调查显示物联网卡的使用及数量得到了直线上升的趋势&#xff0c;随着物联网卡不断地向各个领域延伸&#xff0c;已经成为现代化智能设备中不可或缺的重要网络通信支撑。那么今天来探讨下物联网卡有哪些作用呢?   首先来说说物联网卡发挥的作用&#xff1a;   物联网卡…