Adjust proton functionality

This commit is contained in:
Zontreck 2023-11-03 01:30:26 -07:00
parent 1400818384
commit 372c4e1b74

View file

@ -1,5 +1,4 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:servermanager/settings.dart'; import 'package:servermanager/settings.dart';
@ -16,6 +15,33 @@ class ProtonState extends State<Proton> {
Settings settings; Settings settings;
ProtonState({required this.settings}); ProtonState({required this.settings});
Future<void> runProton(String command, List<String> args) async {
Directory dir =
Directory(settings.game_path + Platform.pathSeparator + "pfx");
if (dir.existsSync()) {
await dir.delete(recursive: true);
}
await dir.create(recursive: true);
Map<String, String> env = Platform.environment;
env["STEAM_COMPAT_CLIENT_INSTALL_PATH"] = "~/.steam";
env["STEAM_COMPAT_DATA_PATH"] = dir.path;
try {
ProcessResult res = await Process.run(
command, args, // Run arbitrary command with arguments
environment: env,
);
print('Exit code: ${res.exitCode}');
print('stdout: ${res.stdout}');
print('stderr: ${res.stderr}');
} catch (e) {
print('Error executing command: $e');
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -24,35 +50,23 @@ class ProtonState extends State<Proton> {
backgroundColor: Color.fromARGB(255, 100, 0, 0), backgroundColor: Color.fromARGB(255, 100, 0, 0),
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
child: Padding( child: Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Column(children: [ child: Column(
ListTile( children: [
title: Text("Init Prefix"), ListTile(
subtitle: Text("Resets proton prefix"), title: Text("Init Prefix"),
leading: Icon(CupertinoIcons.folder_fill), subtitle: Text("Resets proton prefix"),
onTap: () async { leading: Icon(CupertinoIcons.folder_fill),
Directory dir = Directory( onTap: () {
settings.game_path + Platform.pathSeparator + "pfx"); runProton(
// Invoke Proton and reset the prefix. "echo", ["hello"]); // Change to "cmd" to execute 'cmd'
if (dir.existsSync()) { },
await dir.delete(recursive: true); )
],
await dir.create(recursive: true); ),
} else { ),
await dir.create(recursive: true); ),
}
Map<String, String> env = Map();
env.putIfAbsent(
"STEAM_COMPAT_CLIENT_INSTALL_PATH", () => "~/.steam");
env.putIfAbsent("STEAM_COMPAT_DATA_PATH", () => dir.path);
var res = await Process.run("proton", ["run", "exit"],
environment: env);
},
)
]),
)),
); );
} }
} }