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

Commit

Permalink
修復:修復4個bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SiongSng committed Sep 13, 2021
1 parent 2a0f247 commit 7a8b3d4
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 60 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "dart",
"args": [
"--dart-define",
"build_id=none",
"build_id=10000000",
"--dart-define",
"version_type=alpha",
"--dart-define",
Expand All @@ -24,7 +24,7 @@
"flutterMode": "profile",
"args": [
"--dart-define",
"build_id=none",
"build_id=10000000",
"--dart-define",
"version_type=alpha",
"--dart-define",
Expand All @@ -38,7 +38,7 @@
"flutterMode": "release",
"args": [
"--dart-define",
"build_id=none",
"build_id=10000000",
"--dart-define",
"version_type=alpha",
"--dart-define",
Expand Down
6 changes: 3 additions & 3 deletions lib/Account/MSAccountHandler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:rpmlauncher/Launcher/APIs.dart';
import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/main.dart';

class MSAccountHandler {
/*
Expand All @@ -26,7 +27,7 @@ class MSAccountHandler {
String body = await response.stream.bytesToString();
return json.decode(body);
} else {
Logger.send(response.reasonPhrase);
logger.send(response.reasonPhrase);
return [];
}
}
Expand All @@ -42,7 +43,6 @@ class MSAccountHandler {

http.StreamedResponse response = await request.send();

Map data = json.decode(await response.stream.bytesToString());
return data.containsKey("id");
return response.statusCode == 200;
}
}
3 changes: 2 additions & 1 deletion lib/Account/MojangAccountHandler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Utility/utility.dart';
import 'package:http_parser/http_parser.dart';
import 'package:rpmlauncher/main.dart';

class MojangHandler {
/*
Expand Down Expand Up @@ -91,7 +92,7 @@ API Docs: https://wiki.vg/Authentication

bool Success = response.stream.bytesToString().toString().isNotEmpty;
if (!Success) {
Logger.send(response.reasonPhrase);
logger.send(response.reasonPhrase);
}

return Success;
Expand Down
14 changes: 7 additions & 7 deletions lib/Launcher/Forge/Processors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:rpmlauncher/Launcher/GameRepository.dart';
import 'package:rpmlauncher/Launcher/InstanceRepository.dart';
import 'package:rpmlauncher/Launcher/Libraries.dart';
import 'package:rpmlauncher/Utility/Config.dart';
import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/Utility/utility.dart';
import 'package:archive/archive.dart';
import 'package:path/path.dart';
import 'package:rpmlauncher/main.dart';

import '../../path.dart';

Expand Down Expand Up @@ -87,7 +87,7 @@ class Processor {
String? MainClass = utility.getJarMainClass(ProcessorJarFile);

if (MainClass == null) {
Logger.send("No MainClass found in " + jar); //如果找不到程式進入點
logger.send("No MainClass found in " + jar); //如果找不到程式進入點
return;
} else {
MainClass = MainClass.replaceAll(" ", "")
Expand Down Expand Up @@ -133,7 +133,7 @@ class Processor {
String DataPath =
clientData.split("[").join("").split("]").join(""); //去除方括號
List split_ = utility.split(DataPath, ":", max: 4);
if (split_.length != 3 && split_.length != 4) Logger.send("err");
if (split_.length != 3 && split_.length != 4) logger.send("err");

String? extension_ = null;
int last = split_.length - 1;
Expand All @@ -142,7 +142,7 @@ class Processor {
split_[last] = splitted[0];
extension_ = splitted[1];
} else if (splitted.length > 2) {
Logger.send("err");
logger.send("err");
}
var group = split_[0].toString().replaceAll("\\", "/");
var name = split_[1];
Expand Down Expand Up @@ -202,13 +202,13 @@ class Processor {
});
await process.stderr.transform(utf8.decoder).listen((data) {
errorLog += data;
Logger.send("$jar - error: $data");
logger.send("$jar - error: $data");
});
} catch (err) {}
await process.exitCode.then((code) {
Logger.send("$jar - Forge process is exited, exit code: $code");
logger.send("$jar - Forge process is exited, exit code: $code");
if (code != 0) {
Logger.send(
logger.send(
"$jar - An unknown error occurred while running the Forge process:\n$errorLog\n$runLog");
}
process = null;
Expand Down
5 changes: 2 additions & 3 deletions lib/Launcher/MinecraftClient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import 'package:archive/archive.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:path/path.dart';
import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/Utility/ModLoader.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Utility/utility.dart';
import 'package:rpmlauncher/main.dart';

import '../path.dart';
import 'Arguments.dart';
Expand Down Expand Up @@ -53,7 +52,7 @@ class MinecraftClientHandler {
await file.writeAsBytes(response.bodyBytes);
});
} catch (err) {
Logger.send(err);
logger.send(err);
}
DoneTaskLength++; //Download Done
ChangeProgress(SetState_);
Expand Down
3 changes: 2 additions & 1 deletion lib/Screen/CurseForgeMod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Widget/CurseForgeModVersion.dart';
import 'package:flutter/material.dart';
import 'package:rpmlauncher/main.dart';
import 'package:url_launcher/url_launcher.dart';

class CurseForgeMod_ extends State<CurseForgeMod> {
Expand Down Expand Up @@ -194,7 +195,7 @@ class CurseForgeMod_ extends State<CurseForgeMod> {
if (await canLaunch(PageUrl)) {
launch(PageUrl);
} else {
Logger.send("Can't open the url $PageUrl");
logger.send("Can't open the url $PageUrl");
}
},
icon: Icon(Icons.open_in_browser),
Expand Down
5 changes: 3 additions & 2 deletions lib/Screen/CurseForgeModPack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:path/path.dart';
import 'package:rpmlauncher/main.dart';
import 'package:url_launcher/url_launcher.dart';

class CurseForgeModPack_ extends State<CurseForgeModPack> {
Expand Down Expand Up @@ -225,7 +226,7 @@ class CurseForgeModPack_ extends State<CurseForgeModPack> {
if (await canLaunch(PageUrl)) {
launch(PageUrl);
} else {
Logger.send("Can't open the url $PageUrl");
logger.send("Can't open the url $PageUrl");
}
},
icon: Icon(Icons.open_in_browser),
Expand Down Expand Up @@ -442,7 +443,7 @@ class Task_ extends State<Task> {
port.send(1.0);
},
onError: (e) {
Logger.send(e);
logger.send(e);
},
cancelOnError: true,
);
Expand Down
3 changes: 1 addition & 2 deletions lib/Screen/Edit.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:auto_size_text/auto_size_text.dart';
Expand Down Expand Up @@ -1018,7 +1017,7 @@ class EditInstance_ extends State<EditInstance> {
WorldDirEvent.cancel();
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => LauncherHome()),
new MaterialPageRoute(builder: (context) => HomePage()),
);
},
),
Expand Down
3 changes: 2 additions & 1 deletion lib/Screen/MSOauth2Login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:rpmlauncher/Account/MSAccountHandler.dart';
import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Widget/OkClose.dart';
import 'package:rpmlauncher/main.dart';
import 'package:url_launcher/url_launcher.dart';

final _authorizationEndpoint =
Expand Down Expand Up @@ -171,7 +172,7 @@ class _MSLoginState extends State<MSLoginWidget> {
if (await canLaunch(url)) {
await launch(url);
} else {
Logger.send("Can't open the url $url");
logger.send("Can't open the url $url");
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Screen/ModrinthMod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:rpmlauncher/Utility/Loggger.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Widget/ModrinthModVersion.dart';
import 'package:flutter/material.dart';
import 'package:rpmlauncher/main.dart';
import 'package:url_launcher/url_launcher.dart';

class ModrinthMod_ extends State<ModrinthMod> {
Expand Down Expand Up @@ -195,7 +196,7 @@ class ModrinthMod_ extends State<ModrinthMod> {
if (await canLaunch(PageUrl)) {
launch(PageUrl);
} else {
Logger.send("Can't open the url $PageUrl");
logger.send("Can't open the url $PageUrl");
}
},
icon: Icon(Icons.open_in_browser),
Expand Down
2 changes: 2 additions & 0 deletions lib/Screen/RefreshMSToken.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:oauth2/oauth2.dart';
import 'package:rpmlauncher/Account/Account.dart';
import 'package:rpmlauncher/Utility/i18n.dart';
import 'package:rpmlauncher/Widget/OkClose.dart';
import 'package:rpmlauncher/main.dart';

import 'MSOauth2Login.dart';

Expand Down Expand Up @@ -40,6 +41,7 @@ class _RefreshMsTokenScreenState extends State<RefreshMsTokenScreen> {
actions: [OkClose()],
);
} else if (snapshot.hasError) {
logger.send(snapshot.error);
return AlertDialog(
title: Text(i18n.Format('gui.error.info')),
content: Text("自動更新登入憑證失敗,請手動重新登入"),
Expand Down
13 changes: 6 additions & 7 deletions lib/Utility/Loggger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import 'dart:io';
import 'package:path/path.dart';
import 'package:rpmlauncher/path.dart';

late final File LogFile;

class Logger {
static void init() {
late final File _LogFile;
Logger() {
DateTime now = DateTime.now();
LogFile = File(join(dataHome.absolute.path, 'logs',
_LogFile = File(join(dataHome.absolute.path, 'logs',
'${now.year}-${now.month}-${now.day}-${now.hour}-${now.minute}-${now.second}-log.txt'));
LogFile.createSync(recursive: true);
_LogFile.createSync(recursive: true);
}

static void send(Object? object) {
void send(Object? object) {
print(object);
LogFile.writeAsStringSync("[${DateTime.now().toIso8601String()}] $object\n",
_LogFile.writeAsStringSync("[${DateTime.now().toIso8601String()}] $object\n",
mode: FileMode.append);
}
}
14 changes: 7 additions & 7 deletions lib/Utility/Updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class Updater {
throw Exception("Unsupported OS");
}
break;
case "macos":
downloadUrl = info.downloadUrl!.macos;
break;
// case "macos":
// downloadUrl = info.downloadUrl!.macos;
// break;
default:
throw Exception("Unknown operating system");
}
Expand Down Expand Up @@ -179,7 +179,7 @@ class Updater {
return true;
}

Future RunUpdater() async {
Future RunUpdater() async {
String nowPath = Directory.current.absolute.path;
switch (operatingSystem) {
case "linux":
Expand Down Expand Up @@ -342,18 +342,18 @@ class DownloadUrl {
final String windows_10_11;
final String windows_7;
final String linux;
final String macos;
// final String macos;

const DownloadUrl({
required this.windows_10_11,
required this.windows_7,
required this.linux,
required this.macos,
// required this.macos,
});
factory DownloadUrl.fromJson(Map json) => DownloadUrl(
windows_10_11: json['windows_10_11'],
windows_7: json['windows_7'],
linux: json['linux'],
macos: json['macos'],
// macos: json['macos'],
);
}
3 changes: 2 additions & 1 deletion lib/Utility/utility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:rpmlauncher/Account/MojangAccountHandler.dart';
import 'package:rpmlauncher/Launcher/APIs.dart';
import 'package:rpmlauncher/Widget/CheckAssets.dart';
import 'package:rpmlauncher/Widget/DownloadJava.dart';
import 'package:rpmlauncher/main.dart';
import 'package:url_launcher/url_launcher.dart';

import 'Config.dart';
Expand Down Expand Up @@ -287,7 +288,7 @@ class utility {
if (await canLaunch(url)) {
launch(url);
} else {
Logger.send("Can't open the url $url");
logger.send("Can't open the url $url");
}
}

Expand Down
11 changes: 5 additions & 6 deletions lib/Widget/CheckAssets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import 'dart:io';
import 'dart:isolate';

import 'package:flutter/foundation.dart';
import 'package:rpmlauncher/Account/Account.dart';
import 'package:rpmlauncher/Launcher/InstanceRepository.dart';
import 'package:rpmlauncher/Screen/Account.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart';
Expand Down Expand Up @@ -37,7 +34,10 @@ class CheckAssetsScreen_ extends State<CheckAssetsScreen> {

Thread() async {
ReceivePort port = ReceivePort();
compute(InstanceAssets, [port.sendPort, InstanceDir, dataHome]);
compute(InstanceAssets, [port.sendPort, InstanceDir, dataHome])
.then((value) => setState(() {
CheckAssetsProgress = 1.0;
}));
port.listen((message) {
setState(() {
CheckAssetsProgress = double.parse(message.toString());
Expand All @@ -61,8 +61,7 @@ class CheckAssetsScreen_ extends State<CheckAssetsScreen> {
join(dataHome.absolute.path, "assets", "indexes", "${VersionID}.json"));
Directory AssetsObjectDir =
Directory(join(dataHome.absolute.path, "assets", "objects"));
Map<String, dynamic> IndexObject =
jsonDecode(IndexFile.readAsStringSync());
Map<String, dynamic> IndexObject = jsonDecode(IndexFile.readAsStringSync());

TotalAssetsFiles = IndexObject["objects"].keys.length;

Expand Down
4 changes: 2 additions & 2 deletions lib/Widget/CurseForgeModVersion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'dart:isolate';

import 'package:rpmlauncher/Mod/CurseForge/Handler.dart';
import 'package:rpmlauncher/Utility/Config.dart';
import 'package:rpmlauncher/Utility/Loggger.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;
Expand Down Expand Up @@ -252,7 +252,7 @@ class Task_ extends State<Task> {
await ModFile.writeAsBytes(bytes);
},
onError: (e) {
Logger.send(e);
logger.send(e);
},
cancelOnError: true,
);
Expand Down
Loading

0 comments on commit 7a8b3d4

Please sign in to comment.