This commit is contained in:
Alessandro Autiero
2022-09-24 20:17:30 +02:00
parent 1a0fbbdf30
commit 52af8ac646
18 changed files with 584 additions and 176 deletions

View File

@@ -5,6 +5,11 @@ import 'package:reboot_launcher/src/model/fortnite_build.dart';
class BuildController extends GetxController { class BuildController extends GetxController {
List<FortniteBuild>? builds; List<FortniteBuild>? builds;
FortniteBuild? _selectedBuild; FortniteBuild? _selectedBuild;
late RxBool cancelledDownload;
BuildController() {
cancelledDownload = RxBool(false);
}
FortniteBuild get selectedBuild => _selectedBuild ?? builds!.elementAt(0); FortniteBuild get selectedBuild => _selectedBuild ?? builds!.elementAt(0);

View File

@@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'package:get/get.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
class FortniteVersion { class FortniteVersion {
@@ -12,11 +13,21 @@ class FortniteVersion {
FortniteVersion({required this.name, required this.location}); FortniteVersion({required this.name, required this.location});
static File findExecutable(Directory directory, String name) { static File findExecutable(Directory directory, String name) {
var home = path.basename(directory.path) == "FortniteGame" if(path.basename(directory.path) == "FortniteGame"){
? directory return File("$directory/Binaries/Win64/$name");
: directory.listSync(recursive: true).firstWhere( }
(element) => path.basename(element.path) == "FortniteGame");
return File("${home.path}/Binaries/Win64/$name"); try{
var gameDirectory = directory.listSync(recursive: true)
.firstWhereOrNull((element) => path.basename(element.path) == "FortniteGame");
if(gameDirectory == null){
return File("${directory.path}/Binaries/Win64/$name");
}
return File("${gameDirectory.path}/Binaries/Win64/$name");
}catch(_){
return File("${directory.path}/Binaries/Win64/$name");
}
} }
File get executable { File get executable {

View File

@@ -1,5 +1,8 @@
import 'dart:ui';
import 'package:fluent_ui/fluent_ui.dart'; import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:get_storage/get_storage.dart'; import 'package:get_storage/get_storage.dart';
import 'package:reboot_launcher/src/page/info_page.dart'; import 'package:reboot_launcher/src/page/info_page.dart';
import 'package:reboot_launcher/src/page/launcher_page.dart'; import 'package:reboot_launcher/src/page/launcher_page.dart';
@@ -9,7 +12,10 @@ import 'package:reboot_launcher/src/widget/window_border.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
import 'package:reboot_launcher/src/util/os.dart'; import 'package:reboot_launcher/src/util/os.dart';
import 'package:reboot_launcher/src/util/reboot.dart'; import 'package:get/get.dart';
import '../controller/build_controller.dart';
import '../util/reboot.dart';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key); const HomePage({Key? key}) : super(key: key);
@@ -67,18 +73,11 @@ class _HomePageState extends State<HomePage> with WindowListener {
trailing: WindowTitleBar(focused: _focused)), trailing: WindowTitleBar(focused: _focused)),
content: FutureBuilder( content: FutureBuilder(
future: _future, future: _future,
builder: (context, snapshot) { builder: (context, snapshot) => NavigationBody(
if (snapshot.hasError) {
return Center(
child: Text(
"An error occurred while loading the launcher: ${snapshot.error}",
textAlign: TextAlign.center));
}
return NavigationBody(
index: _index, index: _index,
children: _createPages(snapshot.hasData)); children: _createPages(snapshot)
}) )
)
), ),
if(_focused && isWin11) if(_focused && isWin11)
@@ -87,30 +86,19 @@ class _HomePageState extends State<HomePage> with WindowListener {
); );
} }
List<Widget> _createPages(bool data) { List<Widget> _createPages(AsyncSnapshot snapshot) {
return [ return [
data ? const LauncherPage() : _createDownloadWarning(), LauncherPage(
ready: snapshot.hasData,
error: snapshot.error,
stackTrace: snapshot.stackTrace
),
ServerPage(), ServerPage(),
const InfoPage() const InfoPage()
]; ];
} }
Widget _createDownloadWarning() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
ProgressRing(),
SizedBox(height: 16.0),
Text("Updating Reboot DLL...")
],
),
],
);
}
PaneItem _createPane(String label, IconData icon) { PaneItem _createPane(String label, IconData icon) {
return PaneItem(icon: Icon(icon), title: Text(label)); return PaneItem(icon: Icon(icon), title: Text(label));
} }

View File

@@ -31,7 +31,7 @@ class InfoPage extends StatelessWidget {
), ),
const Expanded( const Expanded(
child: Align( child: Align(
alignment: Alignment.bottomLeft, child: Text("Version 3.5${kDebugMode ? '-DEBUG' : ''}"))) alignment: Alignment.bottomLeft, child: Text("Version 3.6${kDebugMode ? '-DEBUG' : ''}")))
], ],
); );
} }

View File

@@ -1,19 +1,89 @@
import 'dart:io';
import 'package:fluent_ui/fluent_ui.dart'; import 'package:fluent_ui/fluent_ui.dart';
import 'package:reboot_launcher/src/controller/build_controller.dart';
import 'package:reboot_launcher/src/util/os.dart';
import 'package:reboot_launcher/src/widget/deployment_selector.dart'; import 'package:reboot_launcher/src/widget/deployment_selector.dart';
import 'package:reboot_launcher/src/widget/launch_button.dart'; import 'package:reboot_launcher/src/widget/launch_button.dart';
import 'package:reboot_launcher/src/widget/username_box.dart'; import 'package:reboot_launcher/src/widget/username_box.dart';
import 'package:get/get.dart';
import 'package:reboot_launcher/src/widget/version_selector.dart'; import 'package:reboot_launcher/src/widget/version_selector.dart';
import 'package:url_launcher/url_launcher.dart';
class LauncherPage extends StatelessWidget { import '../widget/warning_info.dart';
const LauncherPage({Key? key}) : super(key: key);
class LauncherPage extends StatefulWidget {
final bool ready;
final Object? error;
final StackTrace? stackTrace;
const LauncherPage(
{Key? key, required this.ready, required this.error, this.stackTrace})
: super(key: key);
@override
State<LauncherPage> createState() => _LauncherPageState();
}
class _LauncherPageState extends State<LauncherPage> {
final BuildController _buildController = Get.find<BuildController>();
bool shouldWriteError = true;
@override
void initState() {
_buildController.cancelledDownload
.listen((value) => value ? _onCancelWarning() : {});
super.initState();
}
void _onCancelWarning() {
WidgetsBinding.instance.addPostFrameCallback((_) {
showSnackbar(context,
const Snackbar(content: Text("Download cancelled")));
_buildController.cancelledDownload.value = false;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (!widget.ready && widget.error == null) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
ProgressRing(),
SizedBox(height: 16.0),
Text("Updating Reboot DLL...")
],
),
],
);
}
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if(widget.error != null)
WarningInfo(
text: "Cannot update Reboot DLL",
icon: FluentIcons.info,
severity: InfoBarSeverity.warning,
onPressed: () async {
if (shouldWriteError) {
await errorFile.writeAsString(
"Error: ${widget.error}\nStacktrace: ${widget.stackTrace}",
mode: FileMode.write
);
shouldWriteError = false;
}
launchUrl(errorFile.uri);
},
),
UsernameBox(), UsernameBox(),
VersionSelector(), VersionSelector(),
DeploymentSelector(enabled: true), DeploymentSelector(enabled: true),

View File

@@ -1,7 +1,7 @@
import 'package:fluent_ui/fluent_ui.dart'; import 'package:fluent_ui/fluent_ui.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:reboot_launcher/src/controller/server_controller.dart'; import 'package:reboot_launcher/src/controller/server_controller.dart';
import 'package:reboot_launcher/src/widget/lawin_warning.dart'; import 'package:reboot_launcher/src/widget/warning_info.dart';
import 'package:reboot_launcher/src/widget/local_server_switch.dart'; import 'package:reboot_launcher/src/widget/local_server_switch.dart';
import 'package:reboot_launcher/src/widget/port_input.dart'; import 'package:reboot_launcher/src/widget/port_input.dart';
@@ -20,7 +20,9 @@ class ServerPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if(_serverController.warning.value) if(_serverController.warning.value)
LawinWarning( WarningInfo(
text: "The lawin server handles authentication and parties, not game hosting",
icon: FluentIcons.accept,
onPressed: () => _serverController.warning.value = false onPressed: () => _serverController.warning.value = false
), ),
HostInput(), HostInput(),

View File

@@ -96,7 +96,8 @@ Future<Process> downloadManifestBuild(
Future<void> downloadArchiveBuild(String archiveUrl, String destination, Future<void> downloadArchiveBuild(String archiveUrl, String destination,
Function(double) onProgress, Function() onRar) async { Function(double) onProgress, Function() onRar) async {
var tempFile = File( var tempFile = File(
"${Platform.environment["Temp"]}\\FortniteBuild${Random.secure().nextInt(1000000)}.rar"); "$destination\\.temp\\FortniteBuild${Random.secure().nextInt(1000000)}.rar");
await tempFile.parent.create(recursive: true);
try { try {
var client = http.Client(); var client = http.Client();
var request = http.Request("GET", Uri.parse(archiveUrl)); var request = http.Request("GET", Uri.parse(archiveUrl));

View File

@@ -1,5 +1,10 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter_desktop_folder_picker/flutter_desktop_folder_picker.dart';
import 'package:path/path.dart' as path;
File errorFile = File("${Platform.environment["Temp"]}/error.txt");
const int appBarSize = 2; const int appBarSize = 2;
final RegExp _regex = RegExp(r'(?<=\(Build )(.*)(?=\))'); final RegExp _regex = RegExp(r'(?<=\(Build )(.*)(?=\))');
@@ -12,3 +17,30 @@ bool get isWin11 {
var intBuild = int.tryParse(result); var intBuild = int.tryParse(result);
return intBuild != null && intBuild > 22000; return intBuild != null && intBuild > 22000;
} }
Future<String?> openFilePicker(String title) async =>
FlutterDesktopFolderPicker.openFolderPickerDialog(title: title);
Future<List<Directory>> scanInstallations(String input) => Directory(input)
.list(recursive: true)
.handleError((_) {}, test: (e) => e is FileSystemException)
.where((element) => path.basename(element.path) == "FortniteClient-Win64-Shipping.exe")
.map((element) => findContainer(File(element.path)))
.where((element) => element != null)
.map((element) => element!)
.toList();
Directory? findContainer(File file){
var last = file.parent;
for(var x = 0; x < 5; x++){
var name = path.basename(last.path);
if(name != "FortniteGame" || name == "Fortnite"){
last = last.parent;
continue;
}
return last.parent;
}
return null;
}

View File

@@ -20,8 +20,10 @@ class AddLocalVersion extends StatelessWidget {
return Form( return Form(
child: Builder( child: Builder(
builder: (formContext) => ContentDialog( builder: (formContext) => ContentDialog(
constraints: style: const ContentDialogThemeData(
const BoxConstraints(maxWidth: 368, maxHeight: 278), padding: EdgeInsets.only(left: 20, right: 20, top: 15.0, bottom: 5.0)
),
constraints: const BoxConstraints(maxWidth: 368, maxHeight: 258),
content: _createLocalVersionDialogBody(), content: _createLocalVersionDialogBody(),
actions: _createLocalVersionActions(formContext)))); actions: _createLocalVersionActions(formContext))));
} }
@@ -65,16 +67,17 @@ class AddLocalVersion extends StatelessWidget {
autofocus: true, autofocus: true,
validator: (text) { validator: (text) {
if (text == null || text.isEmpty) { if (text == null || text.isEmpty) {
return 'Invalid version name'; return 'Empty version name';
} }
if (_gameController.versions.value.any((element) => element.name == text)) { if (_gameController.versions.value.any((element) => element.name == text)) {
return 'Existent game version'; return 'This version already exists';
} }
return null; return null;
}, },
), ),
SelectFile( SelectFile(
label: "Location", label: "Location",
placeholder: "Type the game folder", placeholder: "Type the game folder",
@@ -87,16 +90,12 @@ class AddLocalVersion extends StatelessWidget {
String? _checkGameFolder(text) { String? _checkGameFolder(text) {
if (text == null || text.isEmpty) { if (text == null || text.isEmpty) {
return 'Invalid game path'; return 'Empty game path';
} }
var directory = Directory(text); var directory = Directory(text);
if (!directory.existsSync()) { if (!directory.existsSync()) {
return "Nonexistent game path"; return "Directory doesn't exist";
}
if (!directory.existsSync()) {
return "Nonexistent game path";
} }
if (!FortniteVersion.findExecutable(directory, "FortniteClient-Win64-Shipping.exe").existsSync()) { if (!FortniteVersion.findExecutable(directory, "FortniteClient-Win64-Shipping.exe").existsSync()) {

View File

@@ -33,6 +33,10 @@ class _AddServerVersionState extends State<AddServerVersion> {
late Future _future; late Future _future;
DownloadStatus _status = DownloadStatus.none; DownloadStatus _status = DownloadStatus.none;
double _downloadProgress = 0; double _downloadProgress = 0;
DateTime? _downloadStartTime;
DateTime? _lastUpdateTime;
Duration? _lastUpdateTimeLeft;
String? _lastUpdateTimeFormatted;
String? _error; String? _error;
Process? _manifestDownloadProcess; Process? _manifestDownloadProcess;
CancelableOperation? _driveDownloadOperation; CancelableOperation? _driveDownloadOperation;
@@ -62,7 +66,7 @@ class _AddServerVersionState extends State<AddServerVersion> {
if (_manifestDownloadProcess != null) { if (_manifestDownloadProcess != null) {
loadBinary("stop.bat", false) loadBinary("stop.bat", false)
.then((value) => Process.runSync(value.path, [])); // kill doesn't work :/ .then((value) => Process.runSync(value.path, [])); // kill doesn't work :/
_onCancelDownload(); _buildController.cancelledDownload.value = true;
return; return;
} }
@@ -71,13 +75,7 @@ class _AddServerVersionState extends State<AddServerVersion> {
} }
_driveDownloadOperation!.cancel(); _driveDownloadOperation!.cancel();
_onCancelDownload(); _buildController.cancelledDownload.value = true;
}
void _onCancelDownload() {
WidgetsBinding.instance.addPostFrameCallback((_) =>
showSnackbar(context,
const Snackbar(content: Text("Download cancelled"))));
} }
@override @override
@@ -85,8 +83,10 @@ class _AddServerVersionState extends State<AddServerVersion> {
return Form( return Form(
child: Builder( child: Builder(
builder: (context) => ContentDialog( builder: (context) => ContentDialog(
constraints: style: const ContentDialogThemeData(
const BoxConstraints(maxWidth: 368, maxHeight: 338), padding: EdgeInsets.only(left: 20, right: 20, top: 15.0, bottom: 5.0)
),
constraints: const BoxConstraints(maxWidth: 368, maxHeight: 321),
content: _createDownloadVersionBody(), content: _createDownloadVersionBody(),
actions: _createDownloadVersionOption(context)))); actions: _createDownloadVersionOption(context))));
} }
@@ -131,7 +131,7 @@ class _AddServerVersionState extends State<AddServerVersion> {
} }
void _onClose() { void _onClose() {
Navigator.of(context).pop(true); Navigator.of(context).pop();
} }
void _startDownload(BuildContext context) async { void _startDownload(BuildContext context) async {
@@ -198,6 +198,7 @@ class _AddServerVersionState extends State<AddServerVersion> {
return; return;
} }
_downloadStartTime ??= DateTime.now();
setState(() { setState(() {
_status = DownloadStatus.downloading; _status = DownloadStatus.downloading;
_downloadProgress = progress; _downloadProgress = progress;
@@ -209,16 +210,24 @@ class _AddServerVersionState extends State<AddServerVersion> {
future: _future, future: _future,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasError) { if (snapshot.hasError) {
snapshot.printError(); WidgetsBinding.instance.addPostFrameCallback((_) =>
return Text("Cannot fetch builds: ${snapshot.error}", setState(() => _status = DownloadStatus.error));
textAlign: TextAlign.center); return Container(
width: double.infinity,
padding: const EdgeInsets.only(bottom: 16.0),
child: Text("Cannot fetch builds: ${snapshot.error}",
textAlign: TextAlign.center),
);
} }
if (!snapshot.hasData) { if (!snapshot.hasData) {
return const InfoLabel( return InfoLabel(
label: "Fetching builds...", label: "Fetching builds...",
child: SizedBox( child: Container(
width: double.infinity, child: ProgressBar()), padding: const EdgeInsets.only(bottom: 16.0),
width: double.infinity,
child: const ProgressBar()
),
); );
} }
@@ -234,53 +243,130 @@ class _AddServerVersionState extends State<AddServerVersion> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const BuildSelector(), const BuildSelector(),
const SizedBox(height: 16.0),
VersionNameInput(controller: _nameController), VersionNameInput(controller: _nameController),
SelectFile( SelectFile(
label: "Destination", label: "Destination",
placeholder: "Type the download destination", placeholder: "Type the download destination",
windowTitle: "Select download destination", windowTitle: "Select download destination",
allowNavigator: false,
controller: _pathController, controller: _pathController,
validator: _checkDownloadDestination), validator: _checkDownloadDestination
),
], ],
); );
case DownloadStatus.downloading: case DownloadStatus.downloading:
return InfoLabel( var timeLeft = _timeLeft;
label: "Downloading", return Column(
child: InfoLabel( mainAxisSize: MainAxisSize.min,
label: "${_downloadProgress.round()}%", children: [
child: SizedBox( Align(
alignment: Alignment.centerLeft,
child: Text(
"Downloading...",
style: FluentTheme.maybeOf(context)?.typography.body,
textAlign: TextAlign.start,
),
),
const SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"${_downloadProgress.round()}%",
style: FluentTheme.maybeOf(context)?.typography.body,
),
Text(
"Time left: ${timeLeft ?? "00:00:00"}",
style: FluentTheme.maybeOf(context)?.typography.body,
),
],
),
const SizedBox(
height: 8,
),
SizedBox(
width: double.infinity, width: double.infinity,
child: ProgressBar(value: _downloadProgress.toDouble()))), child: ProgressBar(value: _downloadProgress.toDouble())
),
const SizedBox(
height: 16,
)
],
); );
case DownloadStatus.extracting: case DownloadStatus.extracting:
return const InfoLabel( return const Padding(
label: "Extracting", padding: EdgeInsets.only(bottom: 16),
child: InfoLabel(
label: "Extracting...",
child: SizedBox(width: double.infinity, child: ProgressBar()) child: SizedBox(width: double.infinity, child: ProgressBar())
),
); );
case DownloadStatus.done: case DownloadStatus.done:
return const SizedBox( return const Padding(
padding: EdgeInsets.only(bottom: 16),
child: SizedBox(
width: double.infinity, width: double.infinity,
child: Text("The download was completed successfully!", child: Text("The download was completed successfully!",
textAlign: TextAlign.center)); textAlign: TextAlign.center)),
);
case DownloadStatus.error: case DownloadStatus.error:
return SizedBox( return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: SizedBox(
width: double.infinity, width: double.infinity,
child: Text( child: Text(
"An exception was thrown during the download process:$_error", "An error was occurred while downloading:$_error",
textAlign: TextAlign.center)); textAlign: TextAlign.center)),
);
} }
} }
String? get _timeLeft {
if(_downloadStartTime == null){
return null;
}
var now = DateTime.now();
var elapsed = now.difference(_downloadStartTime!);
var msLeft = (elapsed.inMilliseconds * 100) / _downloadProgress;
if(!msLeft.isFinite){
return null;
}
var timeLeft = Duration(milliseconds: msLeft.round() - elapsed.inMilliseconds);
var delta = _lastUpdateTime == null || _lastUpdateTimeLeft == null ? -1
: timeLeft.inMilliseconds - _lastUpdateTimeLeft!.inMilliseconds;
var shouldSkip = delta == -1 || now.difference(_lastUpdateTime!).inMilliseconds > delta.abs() * 3;
_lastUpdateTime = now;
_lastUpdateTimeLeft = timeLeft;
if(shouldSkip){
return _lastUpdateTimeFormatted;
}
var twoDigitMinutes = _twoDigits(timeLeft.inMinutes.remainder(60));
var twoDigitSeconds = _twoDigits(timeLeft.inSeconds.remainder(60));
return _lastUpdateTimeFormatted =
"${_twoDigits(timeLeft.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
}
String _twoDigits(int n) => n.toString().padLeft(2, "0");
String? _checkDownloadDestination(text) { String? _checkDownloadDestination(text) {
if (text == null || text.isEmpty) { if (text == null || text.isEmpty) {
return 'Invalid download path'; return 'Invalid download path';
} }
if (Directory(text).existsSync()) {
return "Existent download destination";
}
return null; return null;
} }
} }

View File

@@ -110,16 +110,9 @@ class _LaunchButtonState extends State<LaunchButton> {
return; return;
} }
if (!line.contains("Game Engine Initialized")) { if (line.contains("[UFortUIManagerWidget_NUI::SetUIState]") && line.contains("FrontEnd")) {
return; _injectOrShowError(_gameController.host.value ? "reboot.dll" : "console.dll");
} }
if (!_gameController.host.value) {
_injectOrShowError("console.dll");
return;
}
_injectOrShowError("reboot.dll");
} }
Future<Object?> _onError(exception) { Future<Object?> _onError(exception) {

View File

@@ -1,19 +0,0 @@
import 'package:fluent_ui/fluent_ui.dart';
class LawinWarning extends StatelessWidget {
final VoidCallback onPressed;
const LawinWarning({Key? key, required this.onPressed}) : super(key: key);
@override
Widget build(BuildContext context) {
return InfoBar(
title: const Text(
"The lawin server handles authentication and parties, not game hosting"),
action: IconButton(
icon: const Icon(FluentIcons.accept),
onPressed: onPressed
)
);
}
}

View File

@@ -0,0 +1,170 @@
import 'dart:io';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:reboot_launcher/src/util/os.dart';
import 'package:reboot_launcher/src/widget/select_file.dart';
import 'package:path/path.dart' as path;
class ScanLocalVersion extends StatefulWidget {
const ScanLocalVersion({Key? key})
: super(key: key);
@override
State<ScanLocalVersion> createState() => _ScanLocalVersionState();
}
class _ScanLocalVersionState extends State<ScanLocalVersion> {
final TextEditingController _folderController = TextEditingController();
Future<List<Directory>>? _future;
@override
Widget build(BuildContext context) {
return Form(
child: Builder(
builder: (formContext) => ContentDialog(
style: const ContentDialogThemeData(
padding: EdgeInsets.only(left: 20, right: 20, top: 20.0, bottom: 0.0)
),
constraints: const BoxConstraints(maxWidth: 368, maxHeight: 169),
content: _createLocalVersionDialogBody(),
actions: _createLocalVersionActions(formContext))));
}
List<Widget> _createLocalVersionActions(BuildContext context) {
if(_future == null) {
return [
FilledButton(
onPressed: () => Navigator.of(context).pop(),
style: ButtonStyle(backgroundColor: ButtonState.all(Colors.red)),
child: const Text('Close'),
),
FilledButton(
child: const Text('Scan'),
onPressed: () => _scanFolder(context, true))
];
}
return [
FutureBuilder(
future: _future,
builder: (context, snapshot) {
if(!snapshot.hasData || snapshot.hasError) {
return SizedBox(
width: double.infinity,
child: FilledButton(
onPressed: () => Navigator.of(context).pop(),
style: ButtonStyle(backgroundColor: ButtonState.all(Colors.red)),
child: const Text('Close'),
),
);
}
return SizedBox(
width: double.infinity,
child: FilledButton(
child: const Text('Save'),
onPressed: () => Navigator.of(context).pop()
)
);
}
)
];
}
Future<void> _scanFolder(BuildContext context, bool save) async {
setState(() {
_future = compute(scanInstallations, _folderController.text);
});
}
Widget _createLocalVersionDialogBody() {
if(_future == null) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SelectFile(
label: "Location",
placeholder: "Type the folder to scan",
windowTitle: "Select the folder to scan",
controller: _folderController,
validator: _checkScanFolder)
],
);
}
return FutureBuilder<List<Directory>>(
future: _future,
builder: (context, snapshot) {
if(snapshot.hasError) {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: SizedBox(
width: double.infinity,
child: Text(
"An error was occurred while scanning:${snapshot.error}",
textAlign: TextAlign.center)),
);
}
if(!snapshot.hasData){
return const Padding(
padding: EdgeInsets.only(bottom: 16),
child: InfoLabel(
label: "Searching...",
child: SizedBox(width: double.infinity, child: ProgressBar())
),
);
}
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: SizedBox(
width: double.infinity,
child: Column(
children: [
const Text(
"Successfully completed scan",
textAlign: TextAlign.center),
_createResultsDropDown(snapshot.data!)
],
)),
);
}
);
}
Widget _createResultsDropDown(List<Directory> data) {
return Expanded(
child: DropDownButton(
leading: const Text("Results"),
items: data.map((element) => _createResultItem(element)).toList()
),
);
}
MenuFlyoutItem _createResultItem(element) {
return MenuFlyoutItem(
text: SizedBox(
width: double.infinity,
child: Text(path.basename(element.path))
),
trailing: const Expanded(child: SizedBox()),
onPressed: () {});
}
String? _checkScanFolder(text) {
if (text == null || text.isEmpty) {
return 'Invalid folder to scan';
}
var directory = Directory(text);
if (!directory.existsSync()) {
return "Directory doesn't exist";
}
return null;
}
}

View File

@@ -1,5 +1,7 @@
import 'package:fluent_ui/fluent_ui.dart'; import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_desktop_folder_picker/flutter_desktop_folder_picker.dart'; import 'package:flutter/foundation.dart';
import '../util/os.dart';
class SelectFile extends StatefulWidget { class SelectFile extends StatefulWidget {
final String label; final String label;
@@ -24,6 +26,8 @@ class SelectFile extends StatefulWidget {
} }
class _SelectFileState extends State<SelectFile> { class _SelectFileState extends State<SelectFile> {
bool _selecting = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InfoLabel( return InfoLabel(
@@ -34,19 +38,36 @@ class _SelectFileState extends State<SelectFile> {
child: TextFormBox( child: TextFormBox(
controller: widget.controller, controller: widget.controller,
placeholder: widget.placeholder, placeholder: widget.placeholder,
validator: widget.validator)), validator: widget.validator,
hidePadding: true
)
),
if (widget.allowNavigator) const SizedBox(width: 8.0), if (widget.allowNavigator) const SizedBox(width: 8.0),
if (widget.allowNavigator) if (widget.allowNavigator)
IconButton( Padding(
icon: const Icon(FluentIcons.open_folder_horizontal), padding: const EdgeInsets.only(bottom: 21.0),
onPressed: _onPressed) child: Tooltip(
message: "Select a folder",
child: Button(
onPressed: _onPressed,
child: const Icon(FluentIcons.open_folder_horizontal)
),
),
)
], ],
)); )
);
} }
void _onPressed() async { void _onPressed() {
var result = await FlutterDesktopFolderPicker.openFolderPickerDialog( if(_selecting){
title: "Select the game folder"); showSnackbar(context, const Snackbar(content: Text("Folder selector is already opened")));
widget.controller.text = result ?? ""; return;
}
_selecting = true;
compute(openFilePicker, "Select the game folder")
.then((value) => widget.controller.text = value ?? "")
.then((_) => _selecting = false);
} }
} }

View File

@@ -22,11 +22,11 @@ class VersionNameInput extends StatelessWidget {
String? _validate(String? text) { String? _validate(String? text) {
if (text == null || text.isEmpty) { if (text == null || text.isEmpty) {
return 'Invalid version name'; return 'Empty version name';
} }
if (_gameController.versions.value.any((element) => element.name == text)) { if (_gameController.versions.value.any((element) => element.name == text)) {
return 'Existent game version'; return 'This version already exists';
} }
return null; return null;

View File

@@ -14,17 +14,19 @@ import 'package:reboot_launcher/src/widget/add_server_version.dart';
import 'package:reboot_launcher/src/model/fortnite_version.dart'; import 'package:reboot_launcher/src/model/fortnite_version.dart';
import 'package:reboot_launcher/src/controller/game_controller.dart'; import 'package:reboot_launcher/src/controller/game_controller.dart';
import 'package:reboot_launcher/src/widget/scan_local_version.dart';
import '../controller/build_controller.dart';
class VersionSelector extends StatelessWidget { class VersionSelector extends StatelessWidget {
final GameController _gameController = Get.find<GameController>(); final GameController _gameController = Get.find<GameController>();
final bool enableScanner;
VersionSelector({Key? key}) : super(key: key); VersionSelector({Key? key, this.enableScanner = false}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Tooltip( return InfoLabel(
message: "The version of Fortnite to launch",
child: InfoLabel(
label: "Version", label: "Version",
child: Align( child: Align(
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
@@ -38,24 +40,36 @@ class VersionSelector extends StatelessWidget {
message: "Add a local fortnite build to the versions list", message: "Add a local fortnite build to the versions list",
child: Button( child: Button(
child: const Icon(FluentIcons.open_file), child: const Icon(FluentIcons.open_file),
onPressed: () => _openLocalVersionDialog(context)), onPressed: () => _openAddLocalVersionDialog(context)),
), ),
const SizedBox( const SizedBox(
width: 16, width: 16,
), ),
if(enableScanner)
Tooltip(
message: "Scan all fortnite builds in a directory",
child: Button(
child: const Icon(FluentIcons.site_scan),
onPressed: () => _openScanLocalVersionDialog(context)),
),
if(enableScanner)
const SizedBox(
width: 16,
),
Tooltip( Tooltip(
message: "Download a fortnite build from the archive", message: "Download a fortnite build from the archive",
child: Button( child: Button(
child: const Icon(FluentIcons.download), child: const Icon(FluentIcons.download),
onPressed: () => _openDownloadVersionDialog(context)), onPressed: () => _openDownloadVersionDialog(context)),
) ),
], ],
))), )));
);
} }
Widget _createSelector(BuildContext context) { Widget _createSelector(BuildContext context) {
return SizedBox( return Tooltip(
message: "The version of Fortnite to launch",
child: SizedBox(
width: double.infinity, width: double.infinity,
child: Obx(() => DropDownButton( child: Obx(() => DropDownButton(
leading: Text(_gameController.selectedVersionObs.value?.name ?? leading: Text(_gameController.selectedVersionObs.value?.name ??
@@ -65,6 +79,7 @@ class VersionSelector extends StatelessWidget {
: _gameController.versions.value : _gameController.versions.value
.map((version) => _createVersionItem(context, version)) .map((version) => _createVersionItem(context, version))
.toList())) .toList()))
),
); );
} }
@@ -100,12 +115,18 @@ class VersionSelector extends StatelessWidget {
); );
} }
void _openLocalVersionDialog(BuildContext context) async { void _openAddLocalVersionDialog(BuildContext context) async {
await showDialog<bool>( await showDialog<bool>(
context: context, context: context,
builder: (context) => AddLocalVersion()); builder: (context) => AddLocalVersion());
} }
void _openScanLocalVersionDialog(BuildContext context) async {
await showDialog<bool>(
context: context,
builder: (context) => ScanLocalVersion());
}
Future<void> _openMenu( Future<void> _openMenu(
BuildContext context, FortniteVersion version, Offset offset) async { BuildContext context, FortniteVersion version, Offset offset) async {
var result = await showMenu( var result = await showMenu(
@@ -142,7 +163,7 @@ class VersionSelector extends StatelessWidget {
builder: (context) => ContentDialog( builder: (context) => ContentDialog(
content: const SizedBox( content: const SizedBox(
width: double.infinity, width: double.infinity,
child: Text("Delete associated game path?", child: Text("Do you want to also delete the files for this version?",
textAlign: TextAlign.center)), textAlign: TextAlign.center)),
actions: [ actions: [
FilledButton( FilledButton(

View File

@@ -0,0 +1,28 @@
import 'package:fluent_ui/fluent_ui.dart';
class WarningInfo extends StatelessWidget {
final String text;
final VoidCallback onPressed;
final IconData icon;
final InfoBarSeverity severity;
const WarningInfo(
{Key? key,
required this.text,
required this.icon,
required this.onPressed,
this.severity = InfoBarSeverity.info})
: super(key: key);
@override
Widget build(BuildContext context) {
return InfoBar(
severity: severity,
title: Text(text),
action: IconButton(
icon: Icon(icon),
onPressed: onPressed
)
);
}
}

View File

@@ -1,6 +1,6 @@
name: reboot_launcher name: reboot_launcher
description: Launcher for project reboot description: Launcher for project reboot
version: "3.5.0" version: "3.6.0"
publish_to: 'none' publish_to: 'none'
@@ -48,7 +48,7 @@ msix_config:
display_name: Reboot Launcher display_name: Reboot Launcher
publisher_display_name: Auties00 publisher_display_name: Auties00
identity_name: 31868Auties00.RebootLauncher identity_name: 31868Auties00.RebootLauncher
msix_version: 3.5.0.0 msix_version: 3.6.0.0
publisher: CN=E6CD08C6-DECF-4034-A3EB-2D5FA2CA8029 publisher: CN=E6CD08C6-DECF-4034-A3EB-2D5FA2CA8029
logo_path: ./assets/icons/reboot.ico logo_path: ./assets/icons/reboot.ico
architecture: x64 architecture: x64