[client] Updater update
This commit is contained in:
4
WORK.md
4
WORK.md
@@ -4,15 +4,15 @@
|
||||
* tanks and bullets speed balancing
|
||||
* game series
|
||||
* network series
|
||||
* save human state in classic game
|
||||
* map packs
|
||||
* create in editor
|
||||
* import in game
|
||||
* save imported in local storage
|
||||
* database
|
||||
* cache
|
||||
* improve bots
|
||||
* A star
|
||||
* game config macro
|
||||
* game config validate
|
||||
* additional weapon
|
||||
* mine
|
||||
* display count
|
||||
|
||||
@@ -40,9 +40,7 @@ exports.levels = function levels() {
|
||||
};
|
||||
|
||||
/**
|
||||
* ToDo:
|
||||
* windows target
|
||||
* window exe package (innosetup)
|
||||
* base config
|
||||
*/
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.16.10",
|
||||
"version": "0.16.11",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
package ru.m;
|
||||
|
||||
@:enum abstract Platform(String) from String to String {
|
||||
var ANDROID = "android";
|
||||
var LINUX = "linux";
|
||||
var WINDOWS = "windows";
|
||||
}
|
||||
|
||||
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> = [
|
||||
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
|
||||
];
|
||||
|
||||
@@ -4,9 +4,18 @@ import haxework.net.JsonLoader;
|
||||
import openfl.Lib;
|
||||
import openfl.net.URLRequest;
|
||||
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 = {
|
||||
var type:String;
|
||||
var platform:Platform;
|
||||
var type:PackageType;
|
||||
var path:String;
|
||||
var filename:String;
|
||||
var url:String;
|
||||
@@ -22,7 +31,7 @@ class Updater {
|
||||
|
||||
private static inline var TAG = "Update";
|
||||
|
||||
public var type(get, null):String;
|
||||
public var type(get, null):PackageType;
|
||||
public var bundle(default, null):PackagesBundle;
|
||||
|
||||
private var url:String;
|
||||
@@ -33,14 +42,13 @@ class Updater {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private function get_type():String {
|
||||
#if android
|
||||
return "android";
|
||||
#elseif linux
|
||||
return "debian";
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
private function get_type():PackageType {
|
||||
return switch Device.platform {
|
||||
case ANDROID: APK;
|
||||
case LINUX: DEB;
|
||||
case WINDOWS: EXE;
|
||||
case _: null;
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveBundle():Promise<PackagesBundle> {
|
||||
@@ -53,14 +61,16 @@ class Updater {
|
||||
public function check():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle):Bool {
|
||||
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> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle) {
|
||||
for (item in bundle.packages) {
|
||||
if (item.type == type) {
|
||||
if (item.platform == Device.platform && item.type == type) {
|
||||
L.i(TAG, 'download: ${item.url}');
|
||||
Lib.getURL(new URLRequest(item.url));
|
||||
return true;
|
||||
|
||||
@@ -19,7 +19,7 @@ class Package {
|
||||
static getPlatform(filename) {
|
||||
for (const [platform, r] of [
|
||||
['android', /^.*?\.apk$/],
|
||||
['debian', /^.*?\.deb$/],
|
||||
['linux', /^.*?\.deb$/],
|
||||
['linux', /^.*?linux\.tar\.gz$/],
|
||||
['windows', /^.*?win\.zip$/],
|
||||
['windows', /^.*?\.exe$/],
|
||||
@@ -37,7 +37,7 @@ class Package {
|
||||
['deb', /^.*?\.deb$/],
|
||||
['archive', /^.*?\.tar\.gz$/],
|
||||
['archive', /^.*?\.zip$/],
|
||||
['installer', /^.*?\.exe$/],
|
||||
['exe', /^.*?\.exe$/],
|
||||
]) {
|
||||
if (r.test(filename)) {
|
||||
return type;
|
||||
|
||||
Reference in New Issue
Block a user