import 'dart:io'; import 'package:libac_dart/utils/IOTools.dart'; import 'package:servermanager/statemachine.dart'; import 'package:servermanager/structs/settings.dart'; // A patch to allow windows to run software using the below methods. Future requiresWine() async { if (Platform.isWindows) return false; return true; } Future runWine(String command, List argx) async { bool requiredWine = await requiresWine(); Settings settings = Settings(); Directory dir = Directory(settings.getWinePrefixPath()); if (dir.existsSync()) { await dir.delete(recursive: true); } await dir.create(recursive: true); Map env = Map.from(Platform.environment); env["WINEPREFIX"] = dir.path; try { List args = [command]; args.addAll(argx); ProcessResult? res; if (requiredWine) res = await Process.run( "wine", args, // Run arbitrary command with arguments environment: env, ); else res = await Process.run(args[0], args.length > 1 ? args.sublist(1) : [], environment: {}); print('Exit code: ${res.exitCode}'); print('stdout: ${res.stdout}'); print('stderr: ${res.stderr}'); } catch (e) { print('Error executing command: $e'); } } Future runWinetrick(String trick) async { if (!(await requiresWine())) return; Settings settings = Settings(); Directory dir = Directory(settings.getWinePrefixPath()); if (dir.existsSync()) { await dir.delete(recursive: true); } await dir.create(recursive: true); Map env = Map.from(Platform.environment); //env["WINEPREFIX"] = dir.path; try { List args = ["-q", trick]; ProcessResult res = await Process.run( "winetricks", 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'); } } Future runDetachedWine( String command, List argx, String workingDir) async { bool requiredWine = await requiresWine(); Settings settings = Settings(); Directory dir = Directory(PathHelper.builder(settings.base_path).resolve("pfx").build()); if (dir.existsSync()) { await dir.delete(recursive: true); } await dir.create(recursive: true); Map env = Map.from(Platform.environment); //env["WINEPREFIX"] = dir.path; try { List args = [command]; args.addAll(argx); if (requiredWine) StateMachine.PROC = await Process.start( "wine", args, // Run arbitrary command with arguments environment: env, workingDirectory: workingDir, mode: ProcessStartMode.detachedWithStdio); else StateMachine.PROC = await Process.start( args[0], args.length > 1 ? args.sublist(1) : [], environment: {}, workingDirectory: workingDir, mode: ProcessStartMode.detachedWithStdio); try { StateMachine.PROC!.stdout.forEach((line) {}); StateMachine.PROC!.stderr.forEach((line) {}); } catch (E) {} StateMachine.monitorProcess(); } catch (e) { print('Error executing command: $e'); } }