回滚动态UAC

This commit is contained in:
xkeyC 2023-11-13 22:52:40 +08:00
parent 2594f85f25
commit b6f0728e2c
7 changed files with 12 additions and 93 deletions

View File

@ -17,7 +17,7 @@ import 'package:window_manager/window_manager.dart';
import '../base/ui.dart'; import '../base/ui.dart';
class AppConf { class AppConf {
static const String appVersion = "2.9.13 Beta"; static const String appVersion = "2.9.14 Beta";
static const int appVersionCode = 28; static const int appVersionCode = 28;
static const String appVersionDate = "2023-11-11"; static const String appVersionDate = "2023-11-11";
@ -40,8 +40,6 @@ class AppConf {
static bool offlineMode = false; static bool offlineMode = false;
static bool isRunningAdmin = false;
static late final WindowsDeviceInfo windowsDeviceInfo; static late final WindowsDeviceInfo windowsDeviceInfo;
static Color? colorBackground; static Color? colorBackground;
@ -83,7 +81,6 @@ class AppConf {
} }
dPrint("---- rust bridge inited -----"); dPrint("---- rust bridge inited -----");
await SystemHelper.initPowershellPath(); await SystemHelper.initPowershellPath();
isRunningAdmin = await globalUIModel.checkAdmin();
/// init defaultColor /// init defaultColor
colorBackground = HexColor("#132431").withOpacity(.75); colorBackground = HexColor("#132431").withOpacity(.75);

View File

@ -1,6 +1,5 @@
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 {
@ -44,7 +43,7 @@ class SystemHelper {
} }
static Future<String> addNvmePatch() async { static Future<String> addNvmePatch() async {
var result = await powershellAdminRun([ var result = await Process.run(powershellPath, [
'New-ItemProperty', 'New-ItemProperty',
"-Path", "-Path",
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"", "\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
@ -60,7 +59,7 @@ class SystemHelper {
static doRemoveNvmePath() async { static doRemoveNvmePath() async {
try { try {
var result = await powershellAdminRun([ var result = await Process.run(powershellPath, [
"Clear-ItemProperty", "Clear-ItemProperty",
"-Path", "-Path",
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"", "\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
@ -202,40 +201,4 @@ 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;
}
} }

View File

@ -1,15 +1,12 @@
// ignore_for_file: use_build_context_synchronously // ignore_for_file: use_build_context_synchronously
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:hive/hive.dart';
import 'base/ui_model.dart'; import 'base/ui_model.dart';
import 'common/conf.dart'; import 'common/conf.dart';
import 'common/helper/system_helper.dart';
import 'ui/settings/upgrade_dialog_ui.dart'; import 'ui/settings/upgrade_dialog_ui.dart';
import 'ui/settings/upgrade_dialog_ui_model.dart'; import 'ui/settings/upgrade_dialog_ui_model.dart';
@ -51,30 +48,6 @@ class AppGlobalUIModel extends BaseUIModel {
return false; return false;
} }
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(SystemHelper.powershellPath, [checkAdmin]);
dPrint("code == ${r.exitCode} msg == ${r.stdout} err = ${r.stderr}");
if (r.exitCode == 0) {
return true;
} else {
if (!AppConf.isMSE) {
await _runAsAdmin();
}
return false;
}
}
_runAsAdmin() async {
final box = await Hive.openBox("app_conf");
await box.close();
await Process.run(SystemHelper.powershellPath,
["Start-Process '${Platform.resolvedExecutable}' -Verb RunAs"]);
await Future.delayed(const Duration(seconds: 2));
exit(0);
}
checkActivityThemeColor() { checkActivityThemeColor() {
if (activityThemeColorTimer != null) { if (activityThemeColorTimer != null) {
activityThemeColorTimer?.cancel(); activityThemeColorTimer?.cancel();

View File

@ -162,9 +162,6 @@ class HomeUIModel extends BaseUIModel {
VoidCallback? doCheck() { VoidCallback? doCheck() {
if (isChecking) return null; if (isChecking) return null;
return () async { return () async {
if (!AppConf.isRunningAdmin) {
await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。");
}
isChecking = true; isChecking = true;
lastScreenInfo = "正在分析..."; lastScreenInfo = "正在分析...";
await _statCheck(); await _statCheck();
@ -299,8 +296,7 @@ class HomeUIModel extends BaseUIModel {
return; return;
case "no_live_path": case "no_live_path":
try { try {
SystemHelper.powershellAdminRun( await Directory(item.value).create(recursive: true);
['New-Item -ItemType Directory -Path "${item.value}" -Force']);
showToast(context!, "创建文件夹成功,请尝试继续下载游戏!"); showToast(context!, "创建文件夹成功,请尝试继续下载游戏!");
checkResult?.remove(item); checkResult?.remove(item);
notifyListeners(); notifyListeners();
@ -329,8 +325,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 SystemHelper.powershellAdminRun( var result = await Process.run(
["${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》");
@ -370,9 +366,6 @@ class HomeUIModel extends BaseUIModel {
showToast(context!, "该功能需要一个有效的安装位置"); showToast(context!, "该功能需要一个有效的安装位置");
return; return;
} }
if (!AppConf.isRunningAdmin) {
await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。");
}
showDialog( showDialog(
context: context!, context: context!,
dismissWithEsc: false, dismissWithEsc: false,
@ -387,9 +380,6 @@ class HomeUIModel extends BaseUIModel {
showToast(context!, "该功能需要一个有效的安装位置"); showToast(context!, "该功能需要一个有效的安装位置");
return; return;
} }
if (!AppConf.isRunningAdmin) {
await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。");
}
AnalyticsApi.touch("performance_launch"); AnalyticsApi.touch("performance_launch");
BaseUIContainer( BaseUIContainer(
uiCreate: () => PerformanceUI(), uiCreate: () => PerformanceUI(),

View File

@ -211,9 +211,6 @@ class ToolsUIModel extends BaseUIModel {
showToast(context!, "该功能需要一个有效的游戏安装目录"); showToast(context!, "该功能需要一个有效的游戏安装目录");
return; return;
} }
if (!AppConf.isRunningAdmin) {
await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。");
}
working = true; working = true;
try { try {
final eacPath = "$scInstalledPath\\EasyAntiCheat"; final eacPath = "$scInstalledPath\\EasyAntiCheat";
@ -354,10 +351,6 @@ class ToolsUIModel extends BaseUIModel {
"P4k 是星际公民的核心游戏文件,高达近 100GB盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。" "P4k 是星际公民的核心游戏文件,高达近 100GB盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。"
"\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。"); "\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。");
if (!AppConf.isRunningAdmin) {
await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。");
}
AnalyticsApi.touch("p4k_download"); AnalyticsApi.touch("p4k_download");
final r = await showDialog( final r = await showDialog(
context: context!, context: context!,

View File

@ -126,8 +126,9 @@ msix_config:
publisher_display_name: xkeyC Studio publisher_display_name: xkeyC Studio
identity_name: 56575xkeyC.MSE identity_name: 56575xkeyC.MSE
publisher: CN=B54C897B-C263-4680-B6AB-4913C603DF87 publisher: CN=B54C897B-C263-4680-B6AB-4913C603DF87
msix_version: 2.9.13.0 msix_version: 2.9.14.0
logo_path: ./assets/app_logo.png logo_path: ./assets/app_logo.png
capabilities: internetClient capabilities: internetClient,allowElevation
languages: zh-cn languages: zh-cn
windows_build_args: --dart-define="MSE=true" windows_build_args: --dart-define="MSE=true"
store: true

View File

@ -16,6 +16,8 @@ add_executable(${BINARY_NAME} WIN32
"runner.exe.manifest" "runner.exe.manifest"
) )
SET_TARGET_PROPERTIES(${BINARY_NAME} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS")
# Apply the standard set of build settings. This can be removed for applications # Apply the standard set of build settings. This can be removed for applications
# that need different build settings. # that need different build settings.
apply_standard_settings(${BINARY_NAME}) apply_standard_settings(${BINARY_NAME})