mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 01:53:41 +08:00
Powershell 自动探测
This commit is contained in:
parent
183864054e
commit
7257e34653
@ -6,6 +6,7 @@ import 'package:hive/hive.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/ffi.dart';
|
||||
import 'package:starcitizen_doctor/data/app_version_data.dart';
|
||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
||||
@ -80,6 +81,7 @@ class AppConf {
|
||||
}
|
||||
dPrint("---- rust bridge inited -----");
|
||||
isRunningAdmin = await globalUIModel.checkAdmin();
|
||||
await SystemHelper.initPowerShellPath();
|
||||
|
||||
/// init windows
|
||||
await windowManager.ensureInitialized();
|
||||
|
@ -4,9 +4,27 @@ import 'package:starcitizen_doctor/common/conf.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||
|
||||
class SystemHelper {
|
||||
static String powershellPath = "powershell.exe";
|
||||
|
||||
static initPowerShellPath() async {
|
||||
var result = await Process.run(powershellPath, ["echo", "ping"]);
|
||||
if (!result.stdout.toString().startsWith("ping") &&
|
||||
powershellPath == "powershell.exe") {
|
||||
Map<String, String> envVars = Platform.environment;
|
||||
final systemRoot = envVars["SYSTEMROOT"];
|
||||
if (systemRoot != null) {
|
||||
final autoSearchPath =
|
||||
"$systemRoot\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
||||
dPrint("auto search powershell path === $autoSearchPath");
|
||||
powershellPath = autoSearchPath;
|
||||
initPowerShellPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> checkNvmePatchStatus() async {
|
||||
try {
|
||||
var result = await Process.run('powershell.exe', [
|
||||
var result = await Process.run(SystemHelper.powershellPath, [
|
||||
"Get-ItemProperty",
|
||||
"-Path",
|
||||
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
||||
@ -26,7 +44,7 @@ class SystemHelper {
|
||||
}
|
||||
|
||||
static Future<String> addNvmePatch() async {
|
||||
var result = await Process.run('powershell.exe', [
|
||||
var result = await Process.run(SystemHelper.powershellPath, [
|
||||
'New-ItemProperty',
|
||||
"-Path",
|
||||
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
||||
@ -42,7 +60,7 @@ class SystemHelper {
|
||||
|
||||
static doRemoveNvmePath() async {
|
||||
try {
|
||||
var result = await Process.run('powershell.exe', [
|
||||
var result = await Process.run(SystemHelper.powershellPath, [
|
||||
"Clear-ItemProperty",
|
||||
"-Path",
|
||||
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
||||
@ -68,7 +86,7 @@ class SystemHelper {
|
||||
"$programDataPath\\Microsoft\\Windows\\Start Menu\\Programs\\Roberts Space Industries\\RSI Launcher.lnk";
|
||||
final rsiLinkFile = File(rsiFilePath);
|
||||
if (await rsiLinkFile.exists()) {
|
||||
final r = await Process.run("powershell.exe", [
|
||||
final r = await Process.run(SystemHelper.powershellPath, [
|
||||
"(New-Object -ComObject WScript.Shell).CreateShortcut(\"$rsiFilePath\").targetpath"
|
||||
]);
|
||||
if (r.stdout.toString().contains("RSI Launcher.exe")) {
|
||||
|
@ -50,7 +50,7 @@ class AppGlobalUIModel extends BaseUIModel {
|
||||
Future<bool> checkAdmin() async {
|
||||
const checkAdmin =
|
||||
r"if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { exit 0 } else { exit 1 }";
|
||||
final r = await Process.run("powershell.exe", [checkAdmin]);
|
||||
final r = await Process.run(SystemHelper.powershellPath, [checkAdmin]);
|
||||
dPrint("code == ${r.exitCode} msg == ${r.stdout} err = ${r.stderr}");
|
||||
if (r.exitCode == 0) {
|
||||
return true;
|
||||
@ -71,7 +71,8 @@ class AppGlobalUIModel extends BaseUIModel {
|
||||
|
||||
_runAsAdmin() async {
|
||||
await SystemHelper.initVBS();
|
||||
await Process.run("powershell.exe", [AppConf.launchHelperPath]);
|
||||
await Process.run(
|
||||
SystemHelper.powershellPath, [AppConf.launchHelperPath]);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ class HomeUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
openDir(rsiLauncherInstalledPath) async {
|
||||
await Process.run("powershell.exe",
|
||||
await Process.run(SystemHelper.powershellPath,
|
||||
["explorer.exe", "/select,\"$rsiLauncherInstalledPath\""]);
|
||||
}
|
||||
|
||||
@ -489,7 +489,7 @@ class HomeUIModel extends BaseUIModel {
|
||||
return;
|
||||
}
|
||||
if (isCurGameRunning) {
|
||||
await Process.run("powershell.exe", ["ps \"StarCitizen\" | kill"]);
|
||||
await Process.run(SystemHelper.powershellPath, ["ps \"StarCitizen\" | kill"]);
|
||||
return;
|
||||
}
|
||||
AnalyticsApi.touch("gameLaunch");
|
||||
|
@ -8,6 +8,7 @@ import 'package:starcitizen_doctor/api/analytics.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||
|
||||
class LocalizationUIModel extends BaseUIModel {
|
||||
@ -212,7 +213,7 @@ class LocalizationUIModel extends BaseUIModel {
|
||||
openDir() async {
|
||||
showToast(context!,
|
||||
"即将打开本地化文件夹,请将自定义的 任意名称.ini 文件放入 Customize_ini 文件夹。\n\n添加新文件后未显示请使用右上角刷新按钮。\n\n安装时请确保选择了正确的语言。");
|
||||
await Process.run("powershell.exe",
|
||||
await Process.run(SystemHelper.powershellPath,
|
||||
["explorer.exe", "/select,\"${customizeDir.absolute.path}\"\\"]);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
||||
import 'package:starcitizen_doctor/ui/about/about_ui_model.dart';
|
||||
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
|
||||
@ -64,7 +65,7 @@ class IndexUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
try {
|
||||
var result = await Process.run('powershell.exe', ["echo", "ping"]);
|
||||
var result = await Process.run(SystemHelper.powershellPath, ["echo", "ping"]);
|
||||
if (result.stdout.toString().startsWith("ping")) {
|
||||
dPrint("powershell check pass");
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
|
||||
class UpgradeDialogUIModel extends BaseUIModel {
|
||||
String? description;
|
||||
@ -64,7 +65,8 @@ class UpgradeDialogUIModel extends BaseUIModel {
|
||||
isUpgrading = false;
|
||||
progress = null;
|
||||
showToast(context!, "运行失败,请尝试手动安装!");
|
||||
Process.run("powershell.exe", ["explorer.exe", "/select,\"$fileName\""]);
|
||||
Process.run(SystemHelper.powershellPath,
|
||||
["explorer.exe", "/select,\"$fileName\""]);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ class ToolsUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
openDir(path) async {
|
||||
await Process.run("powershell.exe", ["explorer.exe", "/select,\"$path\""]);
|
||||
await Process.run(SystemHelper.powershellPath, ["explorer.exe", "/select,\"$path\""]);
|
||||
}
|
||||
|
||||
Future _showSystemInfo() async {
|
||||
|
Loading…
Reference in New Issue
Block a user