Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
新增:Debug版本類型,作為開發人員除錯版專用
Browse files Browse the repository at this point in the history
  • Loading branch information
SiongSng committed Sep 16, 2021
1 parent 7a8b3d4 commit bcc9d61
Show file tree
Hide file tree
Showing 11 changed files with 746 additions and 43 deletions.
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"type": "dart",
"args": [
"--dart-define",
"build_id=10000000",
"build_id=none",
"--dart-define",
"version_type=alpha",
"version_type=debug",
"--dart-define",
"version=1.0.0"
]
Expand All @@ -24,9 +24,9 @@
"flutterMode": "profile",
"args": [
"--dart-define",
"build_id=10000000",
"build_id=none",
"--dart-define",
"version_type=alpha",
"version_type=debug",
"--dart-define",
"version=1.0.0"
]
Expand All @@ -38,9 +38,9 @@
"flutterMode": "release",
"args": [
"--dart-define",
"build_id=10000000",
"build_id=none",
"--dart-define",
"version_type=alpha",
"version_type=debug",
"--dart-define",
"version=1.0.0"
]
Expand Down
5 changes: 3 additions & 2 deletions lang/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@
"settings.advanced.title": "進階設定",
"settings.advanced.assets.check": "檢查資源檔案完整性",
"settings.advanced.max.log": "遊戲日誌紀錄最大行數",
"settings.advanced.channel.stable": "穩定版更新通道",
"settings.advanced.channel.dev": "開發版更新通道",
"settings.advanced.channel.stable": "穩定版",
"settings.advanced.channel.dev": "開發版",
"settings.advanced.channel.debug":"開發人員除錯版",
"edit.instance.title": "編輯安裝檔",
"edit.instance.homepage.instance.name": "安裝檔名稱: ",
"edit.instance.homepage.instance.enter": "請輸入安裝檔名稱",
Expand Down
22 changes: 15 additions & 7 deletions lib/LauncherInfo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:rpmlauncher/Utility/Updater.dart';
import 'package:rpmlauncher/Utility/i18n.dart';

class LauncherInfo {
Expand All @@ -22,21 +23,28 @@ class LauncherInfo {
return "RWL";
}

static Text getVersionType() {
static VersionTypes getVersionType() {
String type = const String.fromEnvironment('version_type');

if (type == "release") {
return Text(i18n.Format("edit.instance.mods.release"),
VersionTypes ChannelType = Updater.getVersionTypeFromString(type);
return ChannelType;
}

static Text getVersionTypeText() {
String type = const String.fromEnvironment('version_type');

if (type == "stable") {
return Text(i18n.Format("settings.advanced.channel.stable"),
style: TextStyle(
color: Colors.lightGreen,
),
textAlign: TextAlign.center);
} else if (type == "beta") {
return Text(i18n.Format("edit.instance.mods.beta"),
} else if (type == "dev") {
return Text(i18n.Format("settings.advanced.channel.dev"),
style: TextStyle(color: Colors.lightBlue, fontSize: 20),
textAlign: TextAlign.center);
} else if (type == "alpha") {
return Text(i18n.Format("edit.instance.mods.alpha"),
} else if (type == "debug") {
return Text(i18n.Format("settings.advanced.channel.debug"),
style: TextStyle(color: Colors.red, fontSize: 20),
textAlign: TextAlign.center);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Screen/About.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AboutScreen_ extends State<AboutScreen> {
children: [
Text(i18n.Format("about.version.type") + " ",
style: title_, textAlign: TextAlign.center),
LauncherInfo.getVersionType(),
LauncherInfo.getVersionTypeText(),
],
),
Text(
Expand Down
290 changes: 290 additions & 0 deletions lib/Screen/CurseForgeModVersion.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
import 'dart:io';
import 'dart:isolate';

import 'package:rpmlauncher/Mod/CurseForge/Handler.dart';
import 'package:rpmlauncher/Utility/Config.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Utility/utility.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:path/path.dart';
import 'package:rpmlauncher/main.dart';

class CurseForgeModVersion extends StatefulWidget {
late List Files;
late int CurseID;
late Directory ModDir;
late Map InstanceConfig;

CurseForgeModVersion(Files_, CurseID_, ModDir_, InstanceConfig_) {
Files = Files_;
CurseID = CurseID_;
ModDir = ModDir_;
InstanceConfig = InstanceConfig_;
}

@override
CurseForgeModVersion_ createState() =>
CurseForgeModVersion_(Files, CurseID, ModDir, InstanceConfig);
}

class CurseForgeModVersion_ extends State<CurseForgeModVersion> {
late List Files;
late int CurseID;
late Directory ModDir;
late Map InstanceConfig;
late List<FileSystemEntity> ModFileList;

List<FileSystemEntity> InstalledFiles = [];

CurseForgeModVersion_(Files_, CurseID_, Directory ModDir_, InstanceConfig_) {
Files = Files_;
CurseID = CurseID_;
ModDir = ModDir_;
InstanceConfig = InstanceConfig_;
ModFileList = ModDir_.listSync().where((file) => file is File).toList();
}

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(i18n.Format("edit.instance.mods.download.select.version")),
content: Container(
height: MediaQuery.of(context).size.height / 3,
width: MediaQuery.of(context).size.width / 3,
child: ListView.builder(
itemCount: Files.length,
itemBuilder: (BuildContext FileBuildContext, int FileIndex) {
return FutureBuilder(
future: CurseForgeHandler.getFileInfoByVersion(
CurseID,
InstanceConfig["version"],
InstanceConfig["loader"],
Files[FileIndex]["modLoader"],
Files[FileIndex]["projectFileId"]),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container();
} else if (snapshot.hasData) {
Map FileInfo = snapshot.data;

bool IsInstalled = ModFileList.any((file) {
if (utility.murmurhash2(File(file.absolute.path)) ==
FileInfo["packageFingerLogger.send"]) {
InstalledFiles.add(file);
return true;
} else {
return false;
}
});
late Widget InstalledWidget;

if (IsInstalled) {
InstalledWidget = Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.check),
Text(i18n.Format("edit.instance.mods.installed"),
textAlign: TextAlign.center)
],
);
} else {
InstalledWidget = Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.close),
Text(
i18n.Format("edit.instance.mods.uninstalled"),
textAlign: TextAlign.center)
],
);
}

return ListTile(
leading: InstalledWidget,
title: Text(
FileInfo["displayName"].replaceAll(".jar", "")),
subtitle: CurseForgeHandler.ParseReleaseType(
FileInfo["releaseType"]),
onTap: () {
InstalledFiles.forEach((file) {
file.deleteSync(recursive: true);
});
showDialog(
barrierDismissible: false,
context: context,
builder: (context) => Task(
FileInfo,
ModDir,
InstanceConfig["version"],
InstanceConfig["loader"],
Files[FileIndex]["modLoader"]),
);
},
);
} else {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [CircularProgressIndicator()],
);
}
});
})),
actions: <Widget>[
IconButton(
icon: Icon(Icons.close_sharp),
tooltip: i18n.Format("gui.close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}
}

class Task extends StatefulWidget {
late var FileInfo;
late Directory ModDir;
late var VersionID;
late var Loader;
late var FileLoader;

Task(FileInfo_, ModDir_, VersionID_, Loader_, FileLoader_) {
FileInfo = FileInfo_;
ModDir = ModDir_;
VersionID = VersionID_;
Loader = Loader_;
FileLoader = FileLoader_;
}

@override
Task_ createState() => Task_(FileInfo, ModDir, VersionID, Loader, FileLoader);
}

class Task_ extends State<Task> {
late var FileInfo;
late Directory ModDir;
late var VersionID;
late var Loader;
late var FileLoader;

Task_(FileInfo_, ModDir_, VersionID_, Loader_, FileLoader_) {
FileInfo = FileInfo_;
ModDir = ModDir_;
VersionID = VersionID_;
Loader = Loader_;
FileLoader = FileLoader_;
}

@override
void initState() {
super.initState();

File ModFile = File(join(ModDir.absolute.path, FileInfo["fileName"]));

final url = FileInfo["downloadUrl"];
Thread(url, ModFile);

if (Config.GetValue("auto_dependencies")) {
DownloadDependenciesFileInfo();
}
}

static double _progress = 0;
static int downloadedLength = 0;
static int contentLength = 0;

DownloadDependenciesFileInfo() async {
if (FileInfo.containsKey("dependencies")) {
for (var Dependency in FileInfo["dependencies"]) {
List DependencyFileInfo =
await CurseForgeHandler.getAddonFilesByVersion(
Dependency["addonId"], VersionID, Loader, FileLoader);
if (DependencyFileInfo.length < 1) return;
File ModFile =
File(join(ModDir.absolute.path, DependencyFileInfo[0]["fileName"]));
final url = DependencyFileInfo[0]["downloadUrl"];
Thread(url, ModFile);
}
}
}

Thread(url, ModFile) async {
var port = ReceivePort();
var isolate =
await Isolate.spawn(Downloading, [url, ModFile, port.sendPort]);
var exit = ReceivePort();
isolate.addOnExitListener(exit.sendPort);
exit.listen((message) {
if (message == null) {
// A null message means the isolate exited
}
});
port.listen((message) {
setState(() {
_progress = message;
});
});
}

static Downloading(List args) async {
String url = args[0];
File ModFile = args[1];
SendPort port = args[2];
final request = Request('GET', Uri.parse(url));
final StreamedResponse response = await Client().send(request);
contentLength += response.contentLength!;
List<int> bytes = [];
response.stream.listen(
(List<int> newBytes) {
bytes.addAll(newBytes);
downloadedLength += newBytes.length;
port.send(downloadedLength / contentLength);
},
onDone: () async {
await ModFile.writeAsBytes(bytes);
},
onError: (e) {
logger.send(e);
},
cancelOnError: true,
);
}

@override
Widget build(BuildContext context) {
if (_progress == 1) {
return AlertDialog(
title: Text(i18n.Format("gui.download.done")),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pop();
},
child: Text(i18n.Format("gui.close")))
],
);
} else {
return AlertDialog(
title: Text(
"${i18n.Format("gui.download.ing")} ${FileInfo["displayName"].replaceAll(".jar", "")}"),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text("${(_progress * 100).toStringAsFixed(3)}%"),
LinearProgressIndicator(value: _progress)
],
),
);
}
}
}
Loading

0 comments on commit bcc9d61

Please sign in to comment.