[client] Updater update

This commit is contained in:
2019-09-04 22:46:06 +03:00
parent 5f24e85deb
commit 4d7fcb4b4b
6 changed files with 48 additions and 20 deletions

View File

@@ -4,15 +4,15 @@
* tanks and bullets speed balancing * tanks and bullets speed balancing
* game series * game series
* network series * network series
* save human state in classic game
* map packs * map packs
* create in editor * create in editor
* import in game * import in game
* save imported in local storage * save imported in local storage
* database * database
* cache
* improve bots * improve bots
* A star * A star
* game config macro * game config validate
* additional weapon * additional weapon
* mine * mine
* display count * display count

View File

@@ -40,9 +40,7 @@ exports.levels = function levels() {
}; };
/** /**
* ToDo: * base config
* windows target
* window exe package (innosetup)
*/ */
const config = new Project.Config({ const config = new Project.Config({
meta: { meta: {

View File

@@ -1,6 +1,6 @@
{ {
"name": "tankz", "name": "tankz",
"version": "0.16.10", "version": "0.16.11",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"dateformat": "^3.0.3", "dateformat": "^3.0.3",

View File

@@ -1,7 +1,27 @@
package ru.m; package ru.m;
@:enum abstract Platform(String) from String to String {
var ANDROID = "android";
var LINUX = "linux";
var WINDOWS = "windows";
}
class Device { class Device {
public static var platform(get, null):Platform;
private static function get_platform():Platform {
#if android
return ANDROID;
#elseif linux
return LINUX;
#elseif windows
return WINDOWS;
#else
return null;
#end
}
private static var MOBILES(default, never):Array<String> = [ private static var MOBILES(default, never):Array<String> = [
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone", "Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
]; ];

View File

@@ -4,9 +4,18 @@ import haxework.net.JsonLoader;
import openfl.Lib; import openfl.Lib;
import openfl.net.URLRequest; import openfl.net.URLRequest;
import promhx.Promise; import promhx.Promise;
import ru.m.Device;
@:enum abstract PackageType(String) from String to String {
var APK = "apk";
var DEB = "deb";
var EXE = "exe";
var ARCHIVE = "archive";
}
typedef PackageInfo = { typedef PackageInfo = {
var type:String; var platform:Platform;
var type:PackageType;
var path:String; var path:String;
var filename:String; var filename:String;
var url:String; var url:String;
@@ -22,7 +31,7 @@ class Updater {
private static inline var TAG = "Update"; private static inline var TAG = "Update";
public var type(get, null):String; public var type(get, null):PackageType;
public var bundle(default, null):PackagesBundle; public var bundle(default, null):PackagesBundle;
private var url:String; private var url:String;
@@ -33,14 +42,13 @@ class Updater {
this.version = version; this.version = version;
} }
private function get_type():String { private function get_type():PackageType {
#if android return switch Device.platform {
return "android"; case ANDROID: APK;
#elseif linux case LINUX: DEB;
return "debian"; case WINDOWS: EXE;
#else case _: null;
return null; }
#end
} }
private function resolveBundle():Promise<PackagesBundle> { private function resolveBundle():Promise<PackagesBundle> {
@@ -53,14 +61,16 @@ class Updater {
public function check():Promise<Bool> { public function check():Promise<Bool> {
return resolveBundle().then(function(bundle:PackagesBundle):Bool { return resolveBundle().then(function(bundle:PackagesBundle):Bool {
this.bundle = bundle; this.bundle = bundle;
return bundle.version != version && Lambda.exists(bundle.packages, function(item) return item.type == type); return bundle.version != version && Lambda.exists(bundle.packages, function(item) {
return item.platform == Device.platform && item.type == type;
});
}); });
} }
public function download():Promise<Bool> { public function download():Promise<Bool> {
return resolveBundle().then(function(bundle:PackagesBundle) { return resolveBundle().then(function(bundle:PackagesBundle) {
for (item in bundle.packages) { for (item in bundle.packages) {
if (item.type == type) { if (item.platform == Device.platform && item.type == type) {
L.i(TAG, 'download: ${item.url}'); L.i(TAG, 'download: ${item.url}');
Lib.getURL(new URLRequest(item.url)); Lib.getURL(new URLRequest(item.url));
return true; return true;

View File

@@ -19,7 +19,7 @@ class Package {
static getPlatform(filename) { static getPlatform(filename) {
for (const [platform, r] of [ for (const [platform, r] of [
['android', /^.*?\.apk$/], ['android', /^.*?\.apk$/],
['debian', /^.*?\.deb$/], ['linux', /^.*?\.deb$/],
['linux', /^.*?linux\.tar\.gz$/], ['linux', /^.*?linux\.tar\.gz$/],
['windows', /^.*?win\.zip$/], ['windows', /^.*?win\.zip$/],
['windows', /^.*?\.exe$/], ['windows', /^.*?\.exe$/],
@@ -37,7 +37,7 @@ class Package {
['deb', /^.*?\.deb$/], ['deb', /^.*?\.deb$/],
['archive', /^.*?\.tar\.gz$/], ['archive', /^.*?\.tar\.gz$/],
['archive', /^.*?\.zip$/], ['archive', /^.*?\.zip$/],
['installer', /^.*?\.exe$/], ['exe', /^.*?\.exe$/],
]) { ]) {
if (r.test(filename)) { if (r.test(filename)) {
return type; return type;