mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Dart code now supports the full flow that the C++ code used to: version check, download, replace app bundle. Bonus: the Dart code is much easier to follow, thanks to async/await! This is part 2 of a 3-part change. The first part added new mojom interfaces, PathService and UpdateService, to the sky_services package.
33 lines
1.0 KiB
Dart
33 lines
1.0 KiB
Dart
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:math';
|
|
|
|
// This class represents a dot-separated version string. Used for comparing
|
|
// versions.
|
|
// Usage: assert(new Version('1.1.0') < new Version('1.2.1'));
|
|
class Version {
|
|
Version(String versionStr) :
|
|
_parts = versionStr.split('.').map((val) => int.parse(val)).toList();
|
|
|
|
List<int> _parts;
|
|
|
|
bool operator<(Version other) => _compare(other) < 0;
|
|
bool operator==(dynamic other) => other is Version && _compare(other) == 0;
|
|
bool operator>(Version other) => _compare(other) > 0;
|
|
|
|
int _compare(Version other) {
|
|
int length = min(_parts.length, other._parts.length);
|
|
for (int i = 0; i < length; ++i) {
|
|
if (_parts[i] < other._parts[i])
|
|
return -1;
|
|
if (_parts[i] > other._parts[i])
|
|
return 1;
|
|
}
|
|
return _parts.length - other._parts.length; // results in 1.0 < 1.0.0
|
|
}
|
|
|
|
int get hashCode => _parts.fold(373, (acc, part) => 37*acc + part);
|
|
}
|