You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.1 KiB
85 lines
2.1 KiB
5 years ago
|
/*
|
||
|
|
||
|
Copyright 2019 fuwa
|
||
|
|
||
|
This file is part of CyberWOW.
|
||
|
|
||
|
CyberWOW is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
CyberWOW is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
*/
|
||
|
|
||
|
import 'package:path_provider/path_provider.dart';
|
||
|
import 'package:flutter/foundation.dart';
|
||
|
|
||
|
import 'dart:io';
|
||
|
import 'dart:async';
|
||
|
import 'dart:convert';
|
||
|
|
||
5 years ago
|
import '../helper.dart';
|
||
|
import '../../config.dart' as config;
|
||
|
import '../../logging.dart';
|
||
5 years ago
|
|
||
5 years ago
|
Stream<String> runBinary (String name, {Stream<String> input}) async* {
|
||
5 years ago
|
final newPath = await getBinaryPath(name);
|
||
|
|
||
|
final appDocDir = await getApplicationDocumentsDirectory();
|
||
|
final appDocPath = appDocDir.path;
|
||
5 years ago
|
final binDir = new Directory(appDocDir.path + "/" + config.c.appPath);
|
||
5 years ago
|
|
||
|
await binDir.create();
|
||
|
|
||
|
// print('binDir: ' + binDir.path);
|
||
5 years ago
|
const List<String> debugArgs =
|
||
5 years ago
|
[
|
||
|
];
|
||
5 years ago
|
const List<String> releaseArgs =
|
||
5 years ago
|
[
|
||
|
"--restricted-rpc"
|
||
|
];
|
||
|
|
||
|
const extraArgs = kReleaseMode ? releaseArgs : debugArgs;
|
||
|
|
||
|
final args =
|
||
|
[
|
||
|
"--data-dir",
|
||
|
binDir.path,
|
||
5 years ago
|
] + extraArgs + config.c.extraArgs;
|
||
5 years ago
|
|
||
5 years ago
|
log.info('args: ' + args.toString());
|
||
5 years ago
|
|
||
|
final outputProcess = await Process.start(newPath, args);
|
||
5 years ago
|
|
||
|
Future<void> printInput() async {
|
||
|
await for (final line in input) {
|
||
|
log.finest('process input: ' + line);
|
||
|
outputProcess.stdin.writeln(line);
|
||
|
outputProcess.stdin.flush();
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
if (input != null) {
|
||
5 years ago
|
printInput();
|
||
5 years ago
|
}
|
||
5 years ago
|
await for (final line in outputProcess.stdout.transform(utf8.decoder)) {
|
||
5 years ago
|
log.finest('process output: ' + line);
|
||
5 years ago
|
yield line;
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
if (config.isEmu) return;
|
||
5 years ago
|
|
||
5 years ago
|
// the app should never reach here
|
||
5 years ago
|
log.severe('Daemon is gone!');
|
||
5 years ago
|
exit(1);
|
||
5 years ago
|
}
|