From 827fa2fba546209513b0ef3965afb25963ab8e58 Mon Sep 17 00:00:00 2001 From: TaYaKi71751 Date: Tue, 29 Oct 2024 15:43:08 +0900 Subject: [PATCH] Add try-catch --- lib/boot_launcher_flow.dart | 71 ++++++++++++++++----------------- lib/main.dart | 19 ++++++++- lib/startup_meta.dart | 79 ++++++++++++++++++------------------- 3 files changed, 92 insertions(+), 77 deletions(-) diff --git a/lib/boot_launcher_flow.dart b/lib/boot_launcher_flow.dart index ddf5ec4..2c721b5 100644 --- a/lib/boot_launcher_flow.dart +++ b/lib/boot_launcher_flow.dart @@ -3,8 +3,8 @@ import 'dart:io'; class BootLauncherFlow { static List getBytes(String unique_session_code) { - List result = []; - List prefix = """ + List result = []; + List prefix = """ boot_flow @@ -323,40 +323,39 @@ class BootLauncherFlow { """ - .split('\n'); - for (String line in prefix) { - result.addAll(utf8.encode(line)); - result.add(0x0d); - } - return result; - } + .split('\n'); + for (String line in prefix) { + result.addAll(utf8.encode(line)); + result.add(0x0d); + } + return result; + } - static Future apply( - List game_directories, String unique_session_code) async { - for (Directory game_directory in game_directories) { - File file; - if (Platform.isWindows) { - file = File(game_directory.path + '\\x64\\boot_launcher_flow.ymt'); - } else if (Platform.isLinux || Platform.isMacOS) { - file = File(game_directory.path + '/x64/boot_launcher_flow.ymt'); - } else { - throw Error(); - } - await file.writeAsBytes(getBytes(unique_session_code)); - } - } + static Future apply(List game_directories, String unique_session_code) async { + for (Directory game_directory in game_directories) { + File file; + if (Platform.isWindows) { + file = File(game_directory.path + '\\x64\\boot_launcher_flow.ymt'); + } else if (Platform.isLinux || Platform.isMacOS) { + file = File(game_directory.path + '/x64/boot_launcher_flow.ymt'); + } else { + throw Error(); + } + await file.delete(); + } + } - static Future delete(List game_directories) async { - for (Directory game_directory in game_directories) { - File file; - if (Platform.isWindows) { - file = File(game_directory.path + '\\x64\\boot_launcher_flow.ymt'); - } else if (Platform.isLinux || Platform.isMacOS) { - file = File(game_directory.path + '/x64/boot_launcher_flow.ymt'); - } else { - throw Error(); - } - await file.delete(); - } - } + static Future delete(List game_directories) async { + for (Directory game_directory in game_directories) { + File file; + if (Platform.isWindows) { + file = File(game_directory.path + '\\x64\\boot_launcher_flow.ymt'); + } else if (Platform.isLinux || Platform.isMacOS) { + file = File(game_directory.path + '/x64/boot_launcher_flow.ymt'); + } else { + throw Error(); + } + await file.delete(); + } + } } diff --git a/lib/main.dart b/lib/main.dart index f15a09f..15fccda 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:io'; -import 'dart:math'; import 'package:flutter/material.dart'; import 'package:rdr2_session/boot_launcher_flow.dart'; @@ -42,6 +41,12 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { final passcode = TextEditingController(); String _status = ''; + + Future _catch(dynamic e) async { + setState(() { + _status = e.toString(); + }); + } Future _random() async { var helper = RsaKeyHelper(); @@ -53,6 +58,7 @@ class _MyHomePageState extends State { } Future _kill() async { + try { List processList = 'PlayRDR2.exe,RDR2.exe'.split(','); for (String process in processList) { setState(() { @@ -63,9 +69,13 @@ class _MyHomePageState extends State { _status = 'Killed $process'; }); } + } catch(e) { + _status = e.toString(); + } } Future _apply() async { + try { setState(() { _status = 'Finding Game Paths'; }); @@ -84,9 +94,13 @@ class _MyHomePageState extends State { setState(() { _status = 'Applied'; }); + } catch(e) { + _status = e.toString(); + } } Future _delete() async { + try { setState(() { _status = 'Finding Game Paths'; }); @@ -105,6 +119,9 @@ class _MyHomePageState extends State { setState(() { _status = 'Deleted'; }); + } catch(e) { + _status = e.toString(); + } } @override diff --git a/lib/startup_meta.dart b/lib/startup_meta.dart index 7d50a7a..d65adfa 100644 --- a/lib/startup_meta.dart +++ b/lib/startup_meta.dart @@ -2,9 +2,9 @@ import 'dart:convert'; import 'dart:io'; class StartupMeta { - static List getBytes(String unique_session_code) { - List result = []; - List prefix = """ + static List getBytes(String unique_session_code) { + List result = []; + List prefix = """ @@ -57,43 +57,42 @@ class StartupMeta { """ - .split('\n'); - for (String line in prefix) { - result.addAll(utf8.encode(line)); - result.add(0x0d); - } - result.addAll(utf8.encode('')); - result.add(0x0d); - result.add(0x0a); - return result; - } + .split('\n'); + for (String line in prefix) { + result.addAll(utf8.encode(line)); + result.add(0x0d); + } + result.addAll(utf8.encode('')); + result.add(0x0d); + result.add(0x0a); + return result; + } - static Future apply( - List game_directories, String unique_session_code) async { - for (Directory game_directory in game_directories) { - File file; - if (Platform.isWindows) { - file = File(game_directory.path + '\\x64\\data\\startup.meta'); - } else if (Platform.isLinux || Platform.isMacOS) { - file = File(game_directory.path + '/x64/data/startup.meta'); - } else { - throw Error(); - } - await file.writeAsBytes(getBytes(unique_session_code)); - } - } + static Future apply(List game_directories, String unique_session_code) async { + for (Directory game_directory in game_directories) { + File file; + if (Platform.isWindows) { + file = File(game_directory.path + '\\x64\\data\\startup.meta'); + } else if (Platform.isLinux || Platform.isMacOS) { + file = File(game_directory.path + '/x64/data/startup.meta'); + } else { + throw Error(); + } + await file.writeAsBytes(getBytes(unique_session_code)); + } + } - static Future delete(List game_directories) async { - for (Directory game_directory in game_directories) { - File file; - if (Platform.isWindows) { - file = File(game_directory.path + '\\x64\\data\\startup.meta'); - } else if (Platform.isLinux || Platform.isMacOS) { - file = File(game_directory.path + '/x64/data/startup.meta'); - } else { - throw Error(); - } - await file.delete(); - } - } + static Future delete(List game_directories) async { + for (Directory game_directory in game_directories) { + File file; + if (Platform.isWindows) { + file = File(game_directory.path + '\\x64\\data\\startup.meta'); + } else if (Platform.isLinux || Platform.isMacOS) { + file = File(game_directory.path + '/x64/data/startup.meta'); + } else { + throw Error(); + } + await file.delete(); + } + } }