162 lines
4.5 KiB
Dart
Executable File
162 lines
4.5 KiB
Dart
Executable File
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:crc/crc.dart';
|
|
import 'package:crclib/catalog.dart';
|
|
import 'package:crypto/crypto.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bugly/flutter_bugly.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:star_lock/flavors.dart';
|
|
import 'package:star_lock/mine/about/debug/debug_tool.dart';
|
|
import 'package:star_lock/network/api_provider.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/network/start_chart_api.dart';
|
|
import 'package:star_lock/tools/bugly/bugly_tool.dart';
|
|
import 'package:star_lock/tools/device_info_service.dart';
|
|
import 'package:star_lock/tools/platform_info_services.dart';
|
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
import 'package:star_lock/translations/trans_lib.dart';
|
|
|
|
import 'app.dart';
|
|
import 'app_settings/app_settings.dart';
|
|
import 'tools/store_service.dart';
|
|
|
|
// 该文件不可作为编译入口,请查看 flavorizr.yaml 中的说明
|
|
FutureOr<void> main() async {
|
|
FlutterBugly.postCatchedException(() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await _setCommonServices();
|
|
|
|
// 设置国际化信息
|
|
await _initTranslation();
|
|
|
|
final bool isLogin = await getLoginStatus();
|
|
if (isLogin) {
|
|
await privacySDKInitialization();
|
|
}
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
final bool? openDeBug = await Storage.getBool(isOpenDeBug);
|
|
if (openDeBug == true) {
|
|
DeBug.showFloatWidget();
|
|
}
|
|
});
|
|
runApp(MyApp(isLogin: isLogin));
|
|
});
|
|
|
|
if (AppPlatform.isAndroid) {
|
|
const SystemUiOverlayStyle systemUiOverlayStyle =
|
|
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
|
|
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
|
|
}
|
|
|
|
// checkChinese();
|
|
}
|
|
|
|
// 设置国际化信息
|
|
Future<void> _initTranslation() async => TranslationLoader.loadTranslation();
|
|
|
|
// 设置包名服务设备信息
|
|
Future<void> _setCommonServices() async {
|
|
await Get.putAsync(() => StoreService().init());
|
|
Get.put(ApiProvider());
|
|
Get.put(StartChartApi());
|
|
Get.put(ApiRepository(Get.find<ApiProvider>()));
|
|
if (F.isLite) {
|
|
//上架审核注释 获取设备信息
|
|
// await Get.putAsync(() => DeviceInfoService().init());
|
|
} else {
|
|
await Get.putAsync(() => DeviceInfoService().init());
|
|
}
|
|
}
|
|
|
|
//关于隐私协议的初始化
|
|
Future<void> privacySDKInitialization() async {
|
|
await Get.putAsync(() => PlatformInfoService().init());
|
|
await BuglyTool.init();
|
|
// 初始化JPush服务
|
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
|
await jpushProvider.initJPushService();
|
|
}
|
|
|
|
void checkChinese() {
|
|
// 获取当前脚本的目录
|
|
final String scriptDir = path.dirname(Platform.script.path);
|
|
|
|
// 遍历这个目录下的所有 .dart 文件
|
|
findChineseCharacters(Directory(scriptDir));
|
|
}
|
|
|
|
void findChineseCharacters(Directory directory) {
|
|
final List<FileSystemEntity> files = directory.listSync(recursive: true);
|
|
for (FileSystemEntity file in files) {
|
|
if (file is File && file.path.endsWith('.dart')) {
|
|
final String content = file.readAsStringSync(encoding: utf8);
|
|
if (hasChineseCharacters(content)) {
|
|
print('Found Chinese characters in ${file.path}');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool hasChineseCharacters(String input) {
|
|
return RegExp(r'[\u4e00-\u9fa5]').hasMatch(input);
|
|
}
|
|
|
|
|
|
//ToDo: 挪到可用位置这里可删掉
|
|
/**
|
|
* 计算 CRC16 校验值
|
|
void calculateCrc16() {
|
|
const String payload = 'hello';
|
|
|
|
// 将字符串转换为 Uint8List
|
|
final Uint8List uint8Payload = stringToUint8List(payload);
|
|
|
|
// 使用自定义 CRC32 算法
|
|
final int crc32Value = crc32Uint16(uint8Payload);
|
|
|
|
print('************ input 为 "$payload" 的 CRC32 值为 $crc32Value');
|
|
}
|
|
|
|
// 将字符串转换为 Uint8List
|
|
Uint8List stringToUint8List(String input) {
|
|
return Uint8List.fromList(utf8.encode(input));
|
|
}
|
|
|
|
// 自定义 CRC32 实现
|
|
int crc32Uint16(Uint8List data) {
|
|
const int polynomial = 0xD5828281;
|
|
|
|
// 创建 CRC32 表
|
|
final List<int> table = List<int>.generate(256, (i) {
|
|
int crc = i;
|
|
for (int j = 0; j < 8; j++) {
|
|
if ((crc & 1) != 0) {
|
|
crc = (crc >> 1) ^ polynomial;
|
|
} else {
|
|
crc >>= 1;
|
|
}
|
|
}
|
|
return crc;
|
|
});
|
|
|
|
// 计算 CRC32 校验值
|
|
int crc = 0xFFFFFFFF;
|
|
for (final int byte in data) {
|
|
crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
|
|
}
|
|
|
|
crc ^= 0xFFFFFFFF;
|
|
|
|
// 返回 CRC32 的低 16 位
|
|
return crc & 0xFFFF;
|
|
}
|
|
*/
|