Adjust proton functionality
This commit is contained in:
parent
1400818384
commit
372c4e1b74
1 changed files with 44 additions and 30 deletions
|
@ -1,5 +1,4 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:servermanager/settings.dart';
|
||||
|
@ -16,6 +15,33 @@ class ProtonState extends State<Proton> {
|
|||
Settings 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
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -26,33 +52,21 @@ class ProtonState extends State<Proton> {
|
|||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(children: [
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text("Init Prefix"),
|
||||
subtitle: Text("Resets proton prefix"),
|
||||
leading: Icon(CupertinoIcons.folder_fill),
|
||||
onTap: () async {
|
||||
Directory dir = Directory(
|
||||
settings.game_path + Platform.pathSeparator + "pfx");
|
||||
// Invoke Proton and reset the prefix.
|
||||
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);
|
||||
onTap: () {
|
||||
runProton(
|
||||
"echo", ["hello"]); // Change to "cmd" to execute 'cmd'
|
||||
},
|
||||
)
|
||||
]),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue