Skip to content

Commit

Permalink
1.添加网络更新功能
Browse files Browse the repository at this point in the history
2.资源文件合并至20211117
3.重新提交1.1.3
  • Loading branch information
jay committed Jan 4, 2022
1 parent 8b19169 commit 485df74
Show file tree
Hide file tree
Showing 16 changed files with 618 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ assets/*
!assets/assets.zip
# !assets/db
# !assets/update.pub


lib/bmob.dart
lib/api_service.dart

windows/

Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"todo-tree.tree.showBadges": true,
"todo-tree.tree.showCountsInTree": true
}
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

属性算法来源:[Feh | Fire Emblem Wiki | Fandom](https://fireemblem.fandom.com/wiki/Feh)

flutter 版本:2.5.1(理论支持 2.2 到 2.5.1,但是大版本升级存在一些破环性更新,建议使用最新的版本)
flutter 版本:2.5.3(理论支持 2.2 到 2.5.3,但是大版本升级存在一些破环性更新,建议使用最新的版本)

使用说明:

Expand All @@ -25,7 +25,21 @@ flutter 版本:2.5.1(理论支持 2.2 到 2.5.1,但是大版本升级存
2. flutter pub get
3. 编译运行

备注:github 仅作为代码开源仓库,不会随时更新。
备注:
1.github 仅作为代码开源仓库,不会随时更新

2.考虑到使用云数据库的安全问题,涉及的网络操作 api 没有公开,可以参考以下代码

```dart
class ApiService extends GetxService {
// eg
Future get(){
}
}
```



截图:

Expand Down
31 changes: 24 additions & 7 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (flutterVersionName == null) {
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('d:\\key.properties')
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
Expand All @@ -47,14 +47,31 @@ android {
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
release {
if (keystorePropertiesFile.exists()) {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
// release {
// keyAlias keystoreProperties['keyAlias']
// keyPassword keystoreProperties['keyPassword']
// storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
// storePassword keystoreProperties['storePassword']
// }
}
buildTypes {
// release {
// if (keystorePropertiesFile.exists()) {
// signingConfig signingConfigs.release
// println "Signing with key.properties"
// } else {
// signingConfig signingConfigs.debug
// println "Signing with debug keys"
// }
// }
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.feh_rebuilder">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> -->
<application
android:label="feh_rebuilder"
Expand Down
63 changes: 36 additions & 27 deletions lib/data_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class DataService extends GetxService {
late GetStorage weaponBox;
late GetStorage weaponRefineBox;
late GetStorage customBox;
// late String appVersionAlias;
late String appVersionAlias;
late int appVersion;
int get assetsVersion {
return int.parse(customBox.read("dataVersion"));
}

Map<String, dynamic> defaultConfig = const {
"initialed": false,
Expand Down Expand Up @@ -49,7 +55,7 @@ class DataService extends GetxService {

Directory appPath;
Directory tempDir;
late String version;

DataService({required this.appPath, required this.tempDir});

Future<void> releaseData() async {
Expand All @@ -75,6 +81,32 @@ class DataService extends GetxService {
customBox.write("initialed", true);
}

Future<DataService> init() async {
/// 检测启动环境是否是web,并加载相应服务(web环境数据由后端服务提供,本地环境由本地数据库或json提供)
Utils.debug("init dataService");

PackageInfo packageInfo = await PackageInfo.fromPlatform();
appVersionAlias = packageInfo.version;

// assetsVersion =
Utils.debug(appVersionAlias);

if (GetPlatform.isWeb) {
Utils.debug("web");
} else if (GetPlatform.isMobile) {
appVersion = int.parse(packageInfo.buildNumber);
await initMobile();
} else if (GetPlatform.isDesktop) {
appVersion = 13;
await initDesktop();
} else {
throw "未知平台";
}

return this;
}

Future<void> initMobile() async {
customBox = GetStorage('custom', p.join(appPath.path, "dataBox", "custom"));
await GetStorage.init("custom");
Expand All @@ -86,14 +118,13 @@ class DataService extends GetxService {
});
}

Utils.debug("当前软件版本:$version");
Utils.debug("当前app版本:$appVersionAlias");
// 首次启动或更新软件版本启动
bool initialed = isInitialed(version);
bool initialed = isInitialed(appVersionAlias);
if (!initialed) {
await releaseData();
customBox.write("currentVersion", version);
customBox.write("currentVersion", appVersionAlias);
// 把data.version里的时间戳写入customBox

}
// 检测数据版本是否变化并写入,update.flag存在时代表更新了数据版本,initialed为false表示更新了程序版本
File f1 = File(p.join(appPath.path, "assets", "update.flag"));
Expand Down Expand Up @@ -172,26 +203,4 @@ class DataService extends GetxService {
moveBox = GetStorage('moveBox', r"assets\dataBox\moveBox");
await GetStorage.init("moveBox");
}

Future<DataService> init() async {
/// 检测启动环境是否是web,并加载相应服务(web环境数据由后端服务提供,本地环境由本地数据库或json提供)
Utils.debug("init dataService");

PackageInfo packageInfo = await PackageInfo.fromPlatform();
version = packageInfo.version;
Utils.debug(version);

if (GetPlatform.isWeb) {
Utils.debug("web");
} else if (GetPlatform.isMobile) {
await initMobile();
} else if (GetPlatform.isDesktop) {
await initDesktop();
} else {
throw "未知平台";
}

return this;
}
}
6 changes: 6 additions & 0 deletions lib/global/enum/web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum UpdateResult {
error,
unnecessary,
hasNewAppVersion,
hasNewDataVersion,
}
7 changes: 5 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'package:feh_rebuilder/api_service.dart';
import 'package:feh_rebuilder/data_service.dart';
import 'package:feh_rebuilder/pages/heroDetail/bindings.dart';
import 'package:feh_rebuilder/pages/home/bindings.dart';
Expand Down Expand Up @@ -33,8 +34,8 @@ void main() async {
: Directory(p.join(Directory.current.absolute.path, "cache"));

await compute(Utils.updateAssets, [appDir, tempDir]);

await Utils.cleanCache(tempDir);
// 清理file_picker选择缓存的文件
await Utils.cleanCache(Directory(p.join(tempDir.path, "file_picker")));

await initServices(appDir, tempDir);

Expand All @@ -46,6 +47,8 @@ Future<void> initServices(Directory appPath, Directory tempDir) async {

await Get.putAsync(
() => DataService(appPath: appPath, tempDir: tempDir).init());

Get.lazyPut(() => ApiService().init());
Utils.debug('all services inited ...');
}

Expand Down
88 changes: 88 additions & 0 deletions lib/models/update_resp/update_resp.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// To parse this JSON data, do
//
// final updateInfo = updateInfoFromJson(jsonString);

import 'dart:convert';

UpdateResp updateInfoFromJson(String str) =>
UpdateResp.fromJson(json.decode(str));

String updateInfoToJson(UpdateResp data) => json.encode(data.toJson());

class UpdateResp {
UpdateResp({
this.results = const [],
});

List<UpdateInfo> results;

factory UpdateResp.fromJson(Map<String, dynamic> json) => UpdateResp(
results: json["results"] == null
? const []
: List<UpdateInfo>.from(
json["results"].map((x) => UpdateInfo.fromJson(x))),
);

Map<String, dynamic> toJson() => {
"results": List<dynamic>.from(results.map((x) => x.toJson())),
};
}

class UpdateInfo {
UpdateInfo({
this.alias,
this.checksum,
this.createdAt,
required this.id,
this.info,
required this.minimalVersion,
this.objectId,
required this.serverVersion,
required this.type,
this.updatedAt,
this.url,
});
String? alias;
String? checksum;
DateTime? createdAt;
int id;
String? info;
int minimalVersion;
String? objectId;
int serverVersion;
int type;
DateTime? updatedAt;
String? url;

factory UpdateInfo.fromJson(Map<String, dynamic> json) => UpdateInfo(
alias: json["alias"],
checksum: json["checksum"],
createdAt: json["createdAt"] == null
? null
: DateTime.parse(json["createdAt"]),
id: json["id"],
info: json["info"],
minimalVersion: json["minimal_version"],
objectId: json["objectId"],
serverVersion: json["server_version"],
type: json["type"],
updatedAt: json["updatedAt"] == null
? null
: DateTime.parse(json["updatedAt"]),
url: json["url"],
);

Map<String, dynamic> toJson() => {
"alias": alias,
"checksum": checksum,
"createdAt": createdAt == null ? null : createdAt!.toIso8601String(),
"id": id,
"info": info,
"objectId": objectId,
"minimal_version": minimalVersion,
"server_version": serverVersion,
"type": type,
"updatedAt": updatedAt == null ? null : updatedAt!.toIso8601String(),
"url": url,
};
}
30 changes: 22 additions & 8 deletions lib/pages/home/subview/others.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:feh_rebuilder/pages/heroDetail/widgets/picker.dart';
import 'package:feh_rebuilder/pages/home/widgets/backup_dialog.dart';
import 'package:feh_rebuilder/pages/home/widgets/update_dialog.dart';
import 'package:feh_rebuilder/pages/skillsBrowse/controller.dart';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart' show DateFormat;
Expand Down Expand Up @@ -110,10 +109,11 @@ class OthersPage extends GetView<OthersPageController> {
children: [
const Text("数据版本"),
IconButton(
onPressed: () {
Get.dialog(const UpdateDialog());
},
icon: const Icon(Icons.upgrade_rounded)),
onPressed: () {
Get.dialog(const UpdateDialog());
},
icon: const Icon(Icons.upgrade_rounded),
),
const Spacer(),
TextButton(
onPressed: () {
Expand All @@ -123,22 +123,35 @@ class OthersPage extends GetView<OthersPageController> {
title: const Text("完整版本号"),
children: [
Center(
child: Text(controller.dataVersion),
child: Text(
controller.data.assetsVersion.toString()),
)
],
));
},
child: Text(
DateFormat("yyyyMMdd").format(
DateTime.fromMillisecondsSinceEpoch(
int.parse(controller.dataVersion),
controller.data.assetsVersion,
),
),
),
),
],
),
),
ListTile(
title: Row(
children: [
const Text("检查更新"),
const Spacer(),
Obx(() => Text(controller.findNewVersion.value)),
],
),
onTap: () async {
controller.checkUpdate();
},
),
ListTile(
title: Row(
children: const [
Expand All @@ -148,7 +161,8 @@ class OthersPage extends GetView<OthersPageController> {
),
onTap: () {
showLicensePage(
context: context, applicationVersion: controller.data.version);
context: context,
applicationVersion: controller.data.appVersionAlias);
},
),
]);
Expand Down
Loading

0 comments on commit 485df74

Please sign in to comment.