From b6f0728e2ca0d1a1d94ea5e621d40683d7aca497 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Mon, 13 Nov 2023 22:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E5=8A=A8=E6=80=81UAC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/conf.dart | 5 +--- lib/common/helper/system_helper.dart | 41 ++-------------------------- lib/global_ui_model.dart | 27 ------------------ lib/ui/home/home_ui_model.dart | 16 ++--------- lib/ui/tools/tools_ui_model.dart | 7 ----- pubspec.yaml | 7 +++-- windows/runner/CMakeLists.txt | 2 ++ 7 files changed, 12 insertions(+), 93 deletions(-) diff --git a/lib/common/conf.dart b/lib/common/conf.dart index 9c149e3..eeb0362 100644 --- a/lib/common/conf.dart +++ b/lib/common/conf.dart @@ -17,7 +17,7 @@ import 'package:window_manager/window_manager.dart'; import '../base/ui.dart'; 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 String appVersionDate = "2023-11-11"; @@ -40,8 +40,6 @@ class AppConf { static bool offlineMode = false; - static bool isRunningAdmin = false; - static late final WindowsDeviceInfo windowsDeviceInfo; static Color? colorBackground; @@ -83,7 +81,6 @@ class AppConf { } dPrint("---- rust bridge inited -----"); await SystemHelper.initPowershellPath(); - isRunningAdmin = await globalUIModel.checkAdmin(); /// init defaultColor colorBackground = HexColor("#132431").withOpacity(.75); diff --git a/lib/common/helper/system_helper.dart b/lib/common/helper/system_helper.dart index 22db331..b898783 100644 --- a/lib/common/helper/system_helper.dart +++ b/lib/common/helper/system_helper.dart @@ -1,6 +1,5 @@ import 'dart:io'; -import 'package:starcitizen_doctor/common/conf.dart'; import 'package:starcitizen_doctor/common/utils/base_utils.dart'; class SystemHelper { @@ -44,7 +43,7 @@ class SystemHelper { } static Future addNvmePatch() async { - var result = await powershellAdminRun([ + var result = await Process.run(powershellPath, [ 'New-ItemProperty', "-Path", "\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"", @@ -60,7 +59,7 @@ class SystemHelper { static doRemoveNvmePath() async { try { - var result = await powershellAdminRun([ + var result = await Process.run(powershellPath, [ "Clear-ItemProperty", "-Path", "\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"", @@ -202,40 +201,4 @@ foreach ($adapter in $adapterMemory) { } catch (_) {} return totalSize; } - - static Future powershellAdminRun(List 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 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; - } } diff --git a/lib/global_ui_model.dart b/lib/global_ui_model.dart index 6118547..e40577a 100644 --- a/lib/global_ui_model.dart +++ b/lib/global_ui_model.dart @@ -1,15 +1,12 @@ // ignore_for_file: use_build_context_synchronously import 'dart:async'; -import 'dart:io'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hexcolor/hexcolor.dart'; -import 'package:hive/hive.dart'; import 'base/ui_model.dart'; import 'common/conf.dart'; -import 'common/helper/system_helper.dart'; import 'ui/settings/upgrade_dialog_ui.dart'; import 'ui/settings/upgrade_dialog_ui_model.dart'; @@ -51,30 +48,6 @@ class AppGlobalUIModel extends BaseUIModel { return false; } - Future 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() { if (activityThemeColorTimer != null) { activityThemeColorTimer?.cancel(); diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index c6f20aa..9d4be76 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -162,9 +162,6 @@ class HomeUIModel extends BaseUIModel { VoidCallback? doCheck() { if (isChecking) return null; return () async { - if (!AppConf.isRunningAdmin) { - await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。"); - } isChecking = true; lastScreenInfo = "正在分析..."; await _statCheck(); @@ -299,8 +296,7 @@ class HomeUIModel extends BaseUIModel { return; case "no_live_path": try { - SystemHelper.powershellAdminRun( - ['New-Item -ItemType Directory -Path "${item.value}" -Force']); + await Directory(item.value).create(recursive: true); showToast(context!, "创建文件夹成功,请尝试继续下载游戏!"); checkResult?.remove(item); notifyListeners(); @@ -329,8 +325,8 @@ class HomeUIModel extends BaseUIModel { final Map eacJson = json.decode(utf8.decode(eacJsonData)); final eacID = eacJson["productid"]; try { - var result = await SystemHelper.powershellAdminRun( - ["${item.value}\\EasyAntiCheat_EOS_Setup.exe", "install", eacID]); + var result = await Process.run( + "${item.value}\\EasyAntiCheat_EOS_Setup.exe", ["install", eacID]); dPrint("${item.value}\\EasyAntiCheat_EOS_Setup.exe install $eacID"); if (result.stderr == "") { showToast(context!, "修复成功,请尝试启动游戏。(若问题无法解决,请使用工具箱的 《重装 EAC》)"); @@ -370,9 +366,6 @@ class HomeUIModel extends BaseUIModel { showToast(context!, "该功能需要一个有效的安装位置"); return; } - if (!AppConf.isRunningAdmin) { - await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。"); - } showDialog( context: context!, dismissWithEsc: false, @@ -387,9 +380,6 @@ class HomeUIModel extends BaseUIModel { showToast(context!, "该功能需要一个有效的安装位置"); return; } - if (!AppConf.isRunningAdmin) { - await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。"); - } AnalyticsApi.touch("performance_launch"); BaseUIContainer( uiCreate: () => PerformanceUI(), diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart index ea39b06..163a400 100644 --- a/lib/ui/tools/tools_ui_model.dart +++ b/lib/ui/tools/tools_ui_model.dart @@ -211,9 +211,6 @@ class ToolsUIModel extends BaseUIModel { showToast(context!, "该功能需要一个有效的游戏安装目录"); return; } - if (!AppConf.isRunningAdmin) { - await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。"); - } working = true; try { final eacPath = "$scInstalledPath\\EasyAntiCheat"; @@ -354,10 +351,6 @@ class ToolsUIModel extends BaseUIModel { "P4k 是星际公民的核心游戏文件,高达近 100GB,盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。" "\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。"); - if (!AppConf.isRunningAdmin) { - await showToast(context!, "因微软商店版本权限限制,若功能异常请 关闭盒子,右键 '以管理员身份运行'。"); - } - AnalyticsApi.touch("p4k_download"); final r = await showDialog( context: context!, diff --git a/pubspec.yaml b/pubspec.yaml index a72ec07..299515d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -126,8 +126,9 @@ msix_config: publisher_display_name: xkeyC Studio identity_name: 56575xkeyC.MSE 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 - capabilities: internetClient + capabilities: internetClient,allowElevation languages: zh-cn - windows_build_args: --dart-define="MSE=true" \ No newline at end of file + windows_build_args: --dart-define="MSE=true" + store: true \ No newline at end of file diff --git a/windows/runner/CMakeLists.txt b/windows/runner/CMakeLists.txt index 394917c..fe3b29b 100644 --- a/windows/runner/CMakeLists.txt +++ b/windows/runner/CMakeLists.txt @@ -16,6 +16,8 @@ add_executable(${BINARY_NAME} WIN32 "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 # that need different build settings. apply_standard_settings(${BINARY_NAME})