99 lines
2.5 KiB
Dart
99 lines
2.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:libac_dart/utils/IOTools.dart';
|
|
import 'package:servermanager/statemachine.dart';
|
|
import 'package:servermanager/structs/settings.dart';
|
|
|
|
Future<void> runWine(String command, List<String> argx) async {
|
|
Settings settings = Settings();
|
|
Directory dir = Directory(settings.getWinePrefixPath());
|
|
|
|
if (dir.existsSync()) {
|
|
await dir.delete(recursive: true);
|
|
}
|
|
await dir.create(recursive: true);
|
|
|
|
Map<String, String> env = Map.from(Platform.environment);
|
|
env["WINEPREFIX"] = dir.path;
|
|
|
|
try {
|
|
List<String> args = [command];
|
|
args.addAll(argx);
|
|
|
|
ProcessResult res = await Process.run(
|
|
"wine",
|
|
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<void> runWinetrick(String trick) async {
|
|
Settings settings = Settings();
|
|
Directory dir = Directory(settings.getWinePrefixPath());
|
|
|
|
if (dir.existsSync()) {
|
|
await dir.delete(recursive: true);
|
|
}
|
|
await dir.create(recursive: true);
|
|
|
|
Map<String, String> env = Map.from(Platform.environment);
|
|
//env["WINEPREFIX"] = dir.path;
|
|
|
|
try {
|
|
List<String> 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<void> runDetachedWine(
|
|
String command, List<String> argx, String workingDir) async {
|
|
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<String, String> env = Map.from(Platform.environment);
|
|
//env["WINEPREFIX"] = dir.path;
|
|
|
|
try {
|
|
List<String> args = [command];
|
|
args.addAll(argx);
|
|
|
|
StateMachine.PROC = await Process.start(
|
|
"wine", args, // Run arbitrary command with arguments
|
|
environment: env,
|
|
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');
|
|
}
|
|
}
|