From 372c4e1b744f16ffeb03b8862ddcad9a7afec3b7 Mon Sep 17 00:00:00 2001 From: Zontreck Date: Fri, 3 Nov 2023 01:30:26 -0700 Subject: [PATCH] Adjust proton functionality --- lib/proton.dart | 74 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/lib/proton.dart b/lib/proton.dart index f7a3f96..28288ff 100644 --- a/lib/proton.dart +++ b/lib/proton.dart @@ -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 { Settings settings; ProtonState({required this.settings}); + Future runProton(String command, List 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 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( @@ -24,35 +50,23 @@ class ProtonState extends State { backgroundColor: Color.fromARGB(255, 100, 0, 0), ), body: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.all(16), - 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 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); - }, - ) - ]), - )), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + children: [ + ListTile( + title: Text("Init Prefix"), + subtitle: Text("Resets proton prefix"), + leading: Icon(CupertinoIcons.folder_fill), + onTap: () { + runProton( + "echo", ["hello"]); // Change to "cmd" to execute 'cmd' + }, + ) + ], + ), + ), + ), ); } }