[client] compare versions in updater
This commit is contained in:
@@ -30,6 +30,7 @@ import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.NetworkStorage;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
class Init {
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
@@ -15,6 +14,7 @@ import ru.m.tankz.view.common.PackView;
|
||||
import ru.m.tankz.view.network.RoomFrame;
|
||||
import ru.m.tankz.view.network.RoomListFrame;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package ru.m;
|
||||
package ru.m.update;
|
||||
|
||||
import haxework.net.JsonLoader;
|
||||
import openfl.Lib;
|
||||
import openfl.net.URLRequest;
|
||||
import promhx.Promise;
|
||||
import ru.m.Device;
|
||||
import ru.m.update.Version;
|
||||
|
||||
@:enum abstract PackageType(String) from String to String {
|
||||
var APK = "apk";
|
||||
@@ -19,6 +20,7 @@ typedef PackageInfo = {
|
||||
var path:String;
|
||||
var filename:String;
|
||||
var url:String;
|
||||
var version:String;
|
||||
}
|
||||
|
||||
typedef PackagesBundle = {
|
||||
@@ -35,7 +37,7 @@ class Updater {
|
||||
public var bundle(default, null):PackagesBundle;
|
||||
|
||||
private var url:String;
|
||||
private var version:String;
|
||||
private var version:Version;
|
||||
|
||||
public function new(version:String, url:String) {
|
||||
this.url = url;
|
||||
@@ -61,9 +63,11 @@ 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.platform == Device.platform && item.type == type;
|
||||
});
|
||||
return Lambda.exists(bundle.packages, function(item) return (
|
||||
item.platform == Device.platform &&
|
||||
item.type == type &&
|
||||
version < Version.fromString(item.version)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
53
src/client/haxe/ru/m/update/Version.hx
Normal file
53
src/client/haxe/ru/m/update/Version.hx
Normal file
@@ -0,0 +1,53 @@
|
||||
package ru.m.update;
|
||||
|
||||
abstract Version(Array<Int>) {
|
||||
|
||||
public function new(mayor:Int, minor:Int, patch:Int, snapshot:Bool = false) {
|
||||
this = [
|
||||
mayor,
|
||||
minor,
|
||||
patch,
|
||||
snapshot ? -1 : 0,
|
||||
];
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(key:Int) return this[key];
|
||||
|
||||
public function compare(other:Version):Int {
|
||||
if (other == null) {
|
||||
return 1;
|
||||
}
|
||||
for (i in 0...4) {
|
||||
var d = this[i] - other[i];
|
||||
if (d != 0) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:op(A > B) static function gt(a:Version, b:Version):Bool return a.compare(b) > 0;
|
||||
|
||||
@:op(A == B) static function eq(a:Version, b:Version):Bool return a.compare(b) == 0;
|
||||
|
||||
@:op(A < B) static function lt(a:Version, b:Version):Bool return a.compare(b) < 0;
|
||||
|
||||
@:from public static function fromString(value:String):Version {
|
||||
trace("!fromString", value);
|
||||
var r = ~/(\d+)\.(\d+)\.(\d+)(-SNAPSHOT)?/;
|
||||
return if (r.match(value)) {
|
||||
new Version(
|
||||
Std.parseInt(r.matched(1)),
|
||||
Std.parseInt(r.matched(2)),
|
||||
Std.parseInt(r.matched(3)),
|
||||
r.matched(4) != null
|
||||
);
|
||||
} else {
|
||||
new Version(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@:to public function toString():String {
|
||||
return '${this[0]}.${this[1]}.${this[2]}${this[3] < 0 ? "-SNAPSHOT" : ""}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user