Update version 9 & Fix

This commit is contained in:
StageGuard
2020-07-30 10:18:13 +08:00
parent 7e38f980d5
commit b8674f1f0d
4 changed files with 97 additions and 40 deletions

View File

@@ -10,7 +10,19 @@ A script to play Sheets generated by SkyStudio automatically in game Sky with ac
"use strict"; "use strict";
var emitter = events.emitter(threads.currentThread()); var emitter = events.emitter(threads.currentThread());
threads.start(function() { threads.start(function() {
emitter.emit("evaluate", http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/gitVersion").body.string() + "/source/SkyAutoplayer.js").body.string()); emitter.emit("evaluate", (function(){
var resp = http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/source/SkyAutoplayer.js");
if(resp.statusCode >= 200 && resp.statusCode < 300) {
return resp.body.string();
} else {
resp = http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/gitVersion").body.string() + "/source/SkyAutoplayer.js");
if(resp.statusCode >= 200 && resp.statusCode < 300) {
return resp.body.string();
} else {
return "console.show();console.log(\"Failed to load script\")";
}
}
}()));
}); });
emitter.on('evaluate', function(s){ emitter.on('evaluate', function(s){
eval(s); eval(s);

View File

@@ -82,10 +82,8 @@ sheetmgr = {
downloadAndLoad: function(file, author, listener) { downloadAndLoad: function(file, author, listener) {
listener({status:1}); listener({status:1});
var remoteHost = "https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/shared_sheets/" + file; config.fetchRepoFile("shared_sheets/" + file, null, function(body) {
var resp = http.get(encodeURI(remoteHost)); var sheet = files.join(sheetmgr.rootDir, files.getNameWithoutExtension(file) + (function(length) {
if(resp.statusCode >= 200 && resp.statusCode < 300) {
var sheet = files.join(this.rootDir, files.getNameWithoutExtension(file) + (function(length) {
var string = "0123456789abcde"; var string = "0123456789abcde";
var stringBuffer = new java.lang.StringBuffer(); var stringBuffer = new java.lang.StringBuffer();
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
@@ -93,23 +91,23 @@ sheetmgr = {
} }
return stringBuffer.toString(); return stringBuffer.toString();
} (7)) + ".txt"); } (7)) + ".txt");
var writable = files.open(sheet, "w", this.encoding); var writable = files.open(sheet, "w", sheetmgr.encoding);
var parsed; var parsed;
writable.write(parsed = (function() { writable.write(parsed = (function() {
var data = eval(resp.body.string())[0]; var data = eval(body.string())[0];
listener({status:2}); listener({status:2});
data.author = author; data.author = author;
return "[" + JSON.stringify(data) + "]"; return "[" + JSON.stringify(data) + "]";
}())); }()));
writable.close(); writable.close();
parsed = eval(parsed)[0]; parsed = eval(parsed)[0];
parsed.songNotes = this.parseSongNote(parsed.songNotes); parsed.songNotes = sheetmgr.parseSongNote(parsed.songNotes);
parsed.fileName = sheet; parsed.fileName = sheet;
this.cachedLocalSheetList.push(parsed); sheetmgr.cachedLocalSheetList.push(parsed);
listener({status:3}); listener({status:3});
} else { }, function (msg) {
listener({status:-1, msg: "获取 " + remoteHost + " 失败,原因:" + resp.statusMessage}); listener({status:-1, msg: "获取 " + remoteHost + " 失败,原因:" + resp.statusMessage});
} });
}, },
__internal_fetchLocalSheets: function(listener) { __internal_fetchLocalSheets: function(listener) {
@@ -126,9 +124,9 @@ sheetmgr = {
} }
}, },
__internal_fetchOnlineSharedSheets: function() { __internal_fetchOnlineSharedSheets: function() {
var remoteHost = "https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/shared_sheets.json"; config.fetchRepoFile("shared_sheets.json", config.values.gitVersion, function(body) {
var data = http.get(remoteHost).body.json(); sheetmgr.cachedOnlineSharedSheetInfoList = body.json().sheets;
this.cachedOnlineSharedSheetInfoList = data.sheets; })
}, },
parseSongNote: function(raw) { parseSongNote: function(raw) {
@@ -287,7 +285,7 @@ config = {
skipOpenPlayerPanelWindowTip: false, skipOpenPlayerPanelWindowTip: false,
skipOnlineUploadTip: false, skipOnlineUploadTip: false,
skipOnlineSharedSheetCTip: false, skipOnlineSharedSheetCTip: false,
currentVersion: 8, currentVersion: 9,
gitVersion: "", gitVersion: "",
}, },
@@ -313,21 +311,19 @@ config = {
checkVersion: function() { checkVersion: function() {
this.values.gitVersion = http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/gitVersion").body.string(); this.values.gitVersion = http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/gitVersion").body.string();
//this.values.gitVersion = "b8b694aa74de3bccfb2e0f432b49a16e9c8846bc";
var periodVersion = this._global_storage.get("version", this.values.currentVersion); var periodVersion = this._global_storage.get("version", this.values.currentVersion);
var currentVersion = this.values.currentVersion; var currentVersion = this.values.currentVersion;
if(periodVersion < currentVersion) { if(periodVersion < currentVersion) {
try { config.fetchRepoFile("update_log.txt", this.values.gitVersion, function(body) {
var updateInfo = http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + this.values.gitVersion + "/update_log.txt");
gui.dialogs.showConfirmDialog({ gui.dialogs.showConfirmDialog({
title: "SkyAutoPlayer已更新", title: "SkyAutoPlayer已更新",
text: "当前版本: " + currentVersion + " ← " + periodVersion + "\n\n更新日志: \n" + updateInfo.body.string(), text: "当前版本: " + currentVersion + " ← " + periodVersion + "\n\n更新日志: \n" + body.string(),
canExit: false, canExit: false,
buttons: ["确认"] buttons: ["确认"]
}); });
} catch(e) { }, function(msg) {
error("获取版本信息失败!详细信息:" + e); toast("版本检查失败,无法获取更新信息");
} });
} }
this.save("version", currentVersion); this.save("version", currentVersion);
}, },
@@ -358,30 +354,29 @@ config = {
}); });
if(downloadQueue.length == 0) { if(downloadQueue.length == 0) {
listener("资源加载完成"); listener("资源加载完成");
java.lang.Thread.sleep(1000); //为了方便看清 java.lang.Thread.sleep(500); //为了方便看清
return; return;
} }
while (downloadQueue.length != 0 && tryCount <= 5) { while (downloadQueue.length != 0 && tryCount <= 5) {
listener("第" + tryCount + "次尝试下载资源,共需下载" + downloadQueue.length + "项资源"); listener("第" + tryCount + "次尝试下载资源,共需下载" + downloadQueue.length + "项资源");
java.lang.Thread.sleep(1500); //为了方便看清 java.lang.Thread.sleep(750); //为了方便看清
var tmpQueue = []; var tmpQueue = [];
for(var i in downloadQueue) tmpQueue.push(downloadQueue[i]); for(var i in downloadQueue) tmpQueue.push(downloadQueue[i]);
var iterator = 0; var iterator = 0;
tmpQueue.map(function(element, i) { tmpQueue.map(function(element, i) {
try {
listener("下载资源中: " + element); listener("下载资源中: " + element);
config.fetchRepoFile("resources/" + element, config.values.gitVersion, function(body) {
var absolutePath = files.join(localRootDir, element); var absolutePath = files.join(localRootDir, element);
var resp = http.get(remoteHost + element);
files.create(absolutePath); files.create(absolutePath);
files.writeBytes(absolutePath, resp.body.bytes()); files.writeBytes(absolutePath, body.bytes());
config.bitmaps[files.getNameWithoutExtension(absolutePath)] = android.graphics.Bitmap.createBitmap(android.graphics.BitmapFactory.decodeFile(absolutePath)); config.bitmaps[files.getNameWithoutExtension(absolutePath)] = android.graphics.Bitmap.createBitmap(android.graphics.BitmapFactory.decodeFile(absolutePath));
downloadQueue.splice(iterator, 1); downloadQueue.splice(iterator, 1);
} catch(e) { }, function(msg) {
iterator++; iterator++;
listener("资源" + element + "下载/加载失败: " + e); listener("资源" + element + "下载/加载失败: " + e);
java.lang.Thread.sleep(1000); //为了方便看清 java.lang.Thread.sleep(500); //为了方便看清
} });
}); });
tryCount ++; tryCount ++;
} }
@@ -397,6 +392,33 @@ config = {
} }
}, },
//jsdelivr cdn需要指定repo版本, gitee和github则不用
//fetch顺序为 gitee raw content → jsdelivr cdn → github raw content
fetchRepoFile: function(path, gitVersion, successCbk, failCbk) {
//就用最蠢的if来判断吧
var resp = http.get(encodeURI("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/" + path));
if(resp.statusCode >= 200 && resp.statusCode < 300) {
successCbk(resp.body);
return;
} else {
var errorCollector = resp.statusCode + ": " + resp.statusMessage + "\n";
resp = http.get(encodeURI("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript" + (version == null ? "" : ("@" + gitVersion)) + "/" + path));
if(resp.statusCode >= 200 && resp.statusCode < 300) {
successCbk(resp.body);
return;
} else {
errorCollector += resp.statusCode + ": " + resp.statusMessage + "\n";
resp = http.get(encodeURI("https://raw.githubusercontent.com/StageGuard/SkyAutoPlayerScript/master/" + path));
if(resp.statusCode >= 200 && resp.statusCode < 300) {
successCbk(resp.body);
return;
} else {
errorCollector += resp.statusCode + ": " + resp.statusMessage + "\n";
if(failCbk != null) failCbk(errorCollector);
}
}
}
},
} }
@@ -1350,10 +1372,14 @@ gui = {
})); }));
gui.suspension._global_base.setOnClickListener(new android.view.View.OnClickListener({ gui.suspension._global_base.setOnClickListener(new android.view.View.OnClickListener({
onClick: function() { onClick: function() {
gui.suspension._global_base.setEnabled(false);
gui.suspension._global_base.setClickable(false);
gui.suspension.dismiss(); gui.suspension.dismiss();
gui.main.show(gui.main.current); gui.main.show(gui.main.current);
} }
})); }));
gui.suspension._global_base.setEnabled(true);
gui.suspension._global_base.setClickable(true);
s._winParams = new android.view.WindowManager.LayoutParams(); s._winParams = new android.view.WindowManager.LayoutParams();
s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
@@ -2375,14 +2401,15 @@ gui.dialogs.showProgressDialog(function(o) {
name: "查看LICENSE", name: "查看LICENSE",
onClick: function(v) { onClick: function(v) {
threads.start(function() { threads.start(function() {
var license = http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript/LICENSE").body.string(); config.fetchRepoFile("LICENSE", null, function(body) {
gui.dialogs.showConfirmDialog({ gui.dialogs.showConfirmDialog({
title: "GNU GENERAL PUBLIC LICENSE", title: "GNU GENERAL PUBLIC LICENSE",
text: license, text: body.string(),
canExit: true, canExit: true,
buttons: ["确认"], buttons: ["确认"],
}); });
}); });
});
}, },
}, { }, {
type: "default", type: "default",

View File

@@ -2,8 +2,20 @@
"use strict"; "use strict";
var emitter = events.emitter(threads.currentThread()); var emitter = events.emitter(threads.currentThread());
threads.start(function() { threads.start(function() {
emitter.emit("evaluate", http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@master/gitVersion").body.string() + "/source/SkyAutoplayer.js").body.string()); emitter.emit("evaluate", (function(){
var resp = http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/source/SkyAutoplayer.js");
if(resp.statusCode >= 200 && resp.statusCode < 300) {
return resp.body.string();
} else {
resp = http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/gitVersion").body.string() + "/source/SkyAutoplayer.js");
if(resp.statusCode >= 200 && resp.statusCode < 300) {
return resp.body.string();
} else {
return "console.show();console.log(\"Failed to load script\")";
}
}
}()));
}); });
emitter.on('evaluate', function(s){ emitter.on('evaluate', function(s){
eval(s); eval(s);
});; });

View File

@@ -1,3 +1,9 @@
版本: 9
更新时间: 2020.07.30 10:21
更新内容:
* 修复了连按两次悬浮窗按钮导致进入主界面时不会加载曲谱的问题
* 更改文件下载逻辑
版本: 8 版本: 8
更新时间: 2020.07.29 23:20 更新时间: 2020.07.29 23:20
更新内容: 更新内容: