mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 06:33:43 +08:00
动态 UAC
This commit is contained in:
parent
4776aa5647
commit
52591f4899
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "windows/corrosion"]
|
||||||
|
path = windows/corrosion
|
||||||
|
url = https://github.com/corrosion-rs/corrosion.git
|
@ -77,8 +77,8 @@ class AppConf {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
dPrint("---- rust bridge inited -----");
|
dPrint("---- rust bridge inited -----");
|
||||||
|
await SystemHelper.initPowershellPath();
|
||||||
isRunningAdmin = await globalUIModel.checkAdmin();
|
isRunningAdmin = await globalUIModel.checkAdmin();
|
||||||
await SystemHelper.initPowerShellPath();
|
|
||||||
|
|
||||||
/// init windows
|
/// init windows
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:starcitizen_doctor/common/conf.dart';
|
||||||
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||||
|
|
||||||
class SystemHelper {
|
class SystemHelper {
|
||||||
static String powershellPath = "powershell.exe";
|
static String powershellPath = "powershell.exe";
|
||||||
|
|
||||||
static initPowerShellPath() async {
|
static initPowershellPath() async {
|
||||||
var result = await Process.run(powershellPath, ["echo", "ping"]);
|
var result = await Process.run(powershellPath, ["echo", "ping"]);
|
||||||
if (!result.stdout.toString().startsWith("ping") &&
|
if (!result.stdout.toString().startsWith("ping") &&
|
||||||
powershellPath == "powershell.exe") {
|
powershellPath == "powershell.exe") {
|
||||||
@ -16,7 +17,7 @@ class SystemHelper {
|
|||||||
"$systemRoot\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
"$systemRoot\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
||||||
dPrint("auto search powershell path === $autoSearchPath");
|
dPrint("auto search powershell path === $autoSearchPath");
|
||||||
powershellPath = autoSearchPath;
|
powershellPath = autoSearchPath;
|
||||||
initPowerShellPath();
|
initPowershellPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,7 +44,7 @@ class SystemHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> addNvmePatch() async {
|
static Future<String> addNvmePatch() async {
|
||||||
var result = await Process.run(SystemHelper.powershellPath, [
|
var result = await powershellAdminRun([
|
||||||
'New-ItemProperty',
|
'New-ItemProperty',
|
||||||
"-Path",
|
"-Path",
|
||||||
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
||||||
@ -59,7 +60,7 @@ class SystemHelper {
|
|||||||
|
|
||||||
static doRemoveNvmePath() async {
|
static doRemoveNvmePath() async {
|
||||||
try {
|
try {
|
||||||
var result = await Process.run(SystemHelper.powershellPath, [
|
var result = await powershellAdminRun([
|
||||||
"Clear-ItemProperty",
|
"Clear-ItemProperty",
|
||||||
"-Path",
|
"-Path",
|
||||||
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
|
||||||
@ -98,7 +99,7 @@ class SystemHelper {
|
|||||||
|
|
||||||
static killRSILauncher() async {
|
static killRSILauncher() async {
|
||||||
var psr = await Process.run(
|
var psr = await Process.run(
|
||||||
"powershell", ["ps", "\"RSI Launcher\"", "|select -expand id"]);
|
powershellPath, ["ps", "\"RSI Launcher\"", "|select -expand id"]);
|
||||||
if (psr.stderr == "") {
|
if (psr.stderr == "") {
|
||||||
for (var value in (psr.stdout ?? "").toString().split("\n")) {
|
for (var value in (psr.stdout ?? "").toString().split("\n")) {
|
||||||
dPrint(value);
|
dPrint(value);
|
||||||
@ -110,7 +111,7 @@ class SystemHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<String>> getPID(String name) async {
|
static Future<List<String>> getPID(String name) async {
|
||||||
final r = await Process.run("powershell", ["(ps $name).Id"]);
|
final r = await Process.run(powershellPath, ["(ps $name).Id"]);
|
||||||
final str = r.stdout.toString().trim();
|
final str = r.stdout.toString().trim();
|
||||||
dPrint(str);
|
dPrint(str);
|
||||||
if (str.isEmpty) return [];
|
if (str.isEmpty) return [];
|
||||||
@ -121,14 +122,18 @@ class SystemHelper {
|
|||||||
// check running and kill
|
// check running and kill
|
||||||
await killRSILauncher();
|
await killRSILauncher();
|
||||||
// launch
|
// launch
|
||||||
final r = await Process.run("powershell", ["start", "\"$path\""]);
|
final r = await Process.run(powershellPath, [
|
||||||
|
'Start-Process',
|
||||||
|
"'$path'",
|
||||||
|
'-Verb RunAs',
|
||||||
|
]);
|
||||||
dPrint(path);
|
dPrint(path);
|
||||||
dPrint(r.stdout);
|
dPrint(r.stdout);
|
||||||
dPrint(r.stderr);
|
dPrint(r.stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<int> getSystemMemorySizeGB() async {
|
static Future<int> getSystemMemorySizeGB() async {
|
||||||
final r = await Process.run("powershell", [
|
final r = await Process.run(powershellPath, [
|
||||||
"(Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb"
|
"(Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb"
|
||||||
]);
|
]);
|
||||||
return int.tryParse(r.stdout.toString().trim()) ?? 0;
|
return int.tryParse(r.stdout.toString().trim()) ?? 0;
|
||||||
@ -137,19 +142,19 @@ class SystemHelper {
|
|||||||
static Future<String> getSystemCimInstance(String win32InstanceName,
|
static Future<String> getSystemCimInstance(String win32InstanceName,
|
||||||
{pathName = "Name"}) async {
|
{pathName = "Name"}) async {
|
||||||
final r = await Process.run(
|
final r = await Process.run(
|
||||||
"powershell", ["(Get-CimInstance $win32InstanceName).$pathName"]);
|
powershellPath, ["(Get-CimInstance $win32InstanceName).$pathName"]);
|
||||||
return r.stdout.toString().trim();
|
return r.stdout.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> getSystemName() async {
|
static Future<String> getSystemName() async {
|
||||||
final r = await Process.run(
|
final r = await Process.run(
|
||||||
"powershell", ["(Get-ComputerInfo | Select-Object -expand OsName)"]);
|
powershellPath, ["(Get-ComputerInfo | Select-Object -expand OsName)"]);
|
||||||
return r.stdout.toString().trim();
|
return r.stdout.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> getCpuName() async {
|
static Future<String> getCpuName() async {
|
||||||
final r = await Process.run(
|
final r = await Process.run(
|
||||||
"powershell", ["(Get-WmiObject -Class Win32_Processor).Name"]);
|
powershellPath, ["(Get-WmiObject -Class Win32_Processor).Name"]);
|
||||||
return r.stdout.toString().trim();
|
return r.stdout.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,12 +168,12 @@ foreach ($adapter in $adapterMemory) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
final r = await Process.run("powershell", [cmd]);
|
final r = await Process.run(powershellPath, [cmd]);
|
||||||
return r.stdout.toString().trim();
|
return r.stdout.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> getDiskInfo() async {
|
static Future<String> getDiskInfo() async {
|
||||||
return (await Process.run("powershell",
|
return (await Process.run(powershellPath,
|
||||||
["Get-PhysicalDisk | format-table BusType,FriendlyName,Size"]))
|
["Get-PhysicalDisk | format-table BusType,FriendlyName,Size"]))
|
||||||
.stdout
|
.stdout
|
||||||
.toString()
|
.toString()
|
||||||
@ -197,4 +202,40 @@ foreach ($adapter in $adapterMemory) {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
return totalSize;
|
return totalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<ProcessResult> powershellAdminRun(List<String> args) async {
|
||||||
|
// 创建 PowerShell 脚本文件
|
||||||
|
final scriptContent = """
|
||||||
|
${args.join(' ')}
|
||||||
|
""";
|
||||||
|
|
||||||
|
// 将脚本内容写入临时文件
|
||||||
|
final scriptFile =
|
||||||
|
File('${AppConf.applicationSupportDir}\\temp\\psh_script.ps1');
|
||||||
|
if (await scriptFile.exists()) {
|
||||||
|
await scriptFile.delete();
|
||||||
|
}
|
||||||
|
if (!await scriptFile.exists()) {
|
||||||
|
await scriptFile.create(recursive: true);
|
||||||
|
}
|
||||||
|
await scriptFile.writeAsString(scriptContent);
|
||||||
|
|
||||||
|
List<String> command = [
|
||||||
|
'Start-Process',
|
||||||
|
'powershell.exe',
|
||||||
|
'-Verb RunAs',
|
||||||
|
'-ArgumentList',
|
||||||
|
"'-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File','${scriptFile.absolute.path}'",
|
||||||
|
'-Wait',
|
||||||
|
'-PassThru '
|
||||||
|
];
|
||||||
|
|
||||||
|
final r = await Process.run(
|
||||||
|
'powershell.exe',
|
||||||
|
command,
|
||||||
|
runInShell: true,
|
||||||
|
);
|
||||||
|
await scriptFile.delete();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
|
||||||
|
|
||||||
import 'api/api.dart';
|
import 'api/api.dart';
|
||||||
import 'base/ui_model.dart';
|
import 'base/ui_model.dart';
|
||||||
@ -58,13 +57,6 @@ class AppGlobalUIModel extends BaseUIModel {
|
|||||||
} else {
|
} else {
|
||||||
if (!AppConf.isMSE) {
|
if (!AppConf.isMSE) {
|
||||||
await _runAsAdmin();
|
await _runAsAdmin();
|
||||||
} else {
|
|
||||||
final logPath = await SCLoggerHelper.getLogFilePath();
|
|
||||||
if (logPath != null) {
|
|
||||||
if (await File(logPath).exists()) {
|
|
||||||
await _runAsAdmin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -73,11 +65,8 @@ class AppGlobalUIModel extends BaseUIModel {
|
|||||||
_runAsAdmin() async {
|
_runAsAdmin() async {
|
||||||
final box = await Hive.openBox("app_conf");
|
final box = await Hive.openBox("app_conf");
|
||||||
await box.close();
|
await box.close();
|
||||||
await Process.run(SystemHelper.powershellPath, [
|
await Process.run(SystemHelper.powershellPath,
|
||||||
"""
|
["Start-Process '${Platform.resolvedExecutable}' -Verb RunAs"]);
|
||||||
Start-Process powershell -Verb RunAs -ArgumentList "Start-Process '${Platform.resolvedExecutable}' -Verb RunAs"
|
|
||||||
"""
|
|
||||||
]);
|
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ class MDContentDialogUI extends BaseUI<MDContentDialogUIModel> {
|
|||||||
padding: const EdgeInsets.only(left: 12, right: 12),
|
padding: const EdgeInsets.only(left: 12, right: 12),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: makeMarkdownView(model.data ?? ""),
|
children: makeMarkdownView(model.data ?? ""),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -296,7 +296,8 @@ class HomeUIModel extends BaseUIModel {
|
|||||||
return;
|
return;
|
||||||
case "no_live_path":
|
case "no_live_path":
|
||||||
try {
|
try {
|
||||||
await Directory(item.value).create(recursive: true);
|
SystemHelper.powershellAdminRun(
|
||||||
|
['New-Item -ItemType Directory -Path "${item.value}" -Force']);
|
||||||
showToast(context!, "创建文件夹成功,请尝试继续下载游戏!");
|
showToast(context!, "创建文件夹成功,请尝试继续下载游戏!");
|
||||||
checkResult?.remove(item);
|
checkResult?.remove(item);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -325,8 +326,8 @@ class HomeUIModel extends BaseUIModel {
|
|||||||
final Map eacJson = json.decode(utf8.decode(eacJsonData));
|
final Map eacJson = json.decode(utf8.decode(eacJsonData));
|
||||||
final eacID = eacJson["productid"];
|
final eacID = eacJson["productid"];
|
||||||
try {
|
try {
|
||||||
var result = await Process.run(
|
var result = await SystemHelper.powershellAdminRun(
|
||||||
"${item.value}\\EasyAntiCheat_EOS_Setup.exe", ["install", eacID]);
|
["${item.value}\\EasyAntiCheat_EOS_Setup.exe", "install", eacID]);
|
||||||
dPrint("${item.value}\\EasyAntiCheat_EOS_Setup.exe install $eacID");
|
dPrint("${item.value}\\EasyAntiCheat_EOS_Setup.exe install $eacID");
|
||||||
if (result.stderr == "") {
|
if (result.stderr == "") {
|
||||||
showToast(context!, "修复成功,请尝试启动游戏。(若问题无法解决,请使用工具箱的 《重装 EAC》)");
|
showToast(context!, "修复成功,请尝试启动游戏。(若问题无法解决,请使用工具箱的 《重装 EAC》)");
|
||||||
|
@ -55,8 +55,8 @@ class UpgradeDialogUIModel extends BaseUIModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final r =
|
final r = await (Process.run(
|
||||||
await (Process.run("powershell", ["start", fileName, "/SILENT"]));
|
SystemHelper.powershellPath, ["start", fileName, "/SILENT"]));
|
||||||
if (r.stderr.toString().isNotEmpty) {
|
if (r.stderr.toString().isNotEmpty) {
|
||||||
throw r.stderr;
|
throw r.stderr;
|
||||||
}
|
}
|
||||||
|
1
windows/corrosion
Submodule
1
windows/corrosion
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e9aaa32e233dd9c96aed45b5a006e366a0a779d3
|
@ -4,15 +4,7 @@
|
|||||||
# Once done, uncomment this line:
|
# Once done, uncomment this line:
|
||||||
# find_package(Corrosion REQUIRED)
|
# find_package(Corrosion REQUIRED)
|
||||||
|
|
||||||
include(FetchContent)
|
add_subdirectory(./corrosion)
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
Corrosion
|
|
||||||
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git
|
|
||||||
GIT_TAG origin/master # Optionally specify a version tag or branch here
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(Corrosion)
|
|
||||||
|
|
||||||
corrosion_import_crate(MANIFEST_PATH ../rust/Cargo.toml IMPORTED_CRATES imported_crates)
|
corrosion_import_crate(MANIFEST_PATH ../rust/Cargo.toml IMPORTED_CRATES imported_crates)
|
||||||
target_link_libraries(${BINARY_NAME} PRIVATE ${imported_crates})
|
target_link_libraries(${BINARY_NAME} PRIVATE ${imported_crates})
|
||||||
|
Loading…
Reference in New Issue
Block a user