mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat.初步完成c#侧抓模拟器adb路径的逻辑
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -440,3 +440,4 @@ resource/infrast
|
||||
|
||||
# Nuke
|
||||
.nuke/temp/*
|
||||
/tools/ItemMappingCvt/Arknights-Bot-Resource
|
||||
|
||||
@@ -70,7 +70,6 @@ Global
|
||||
{C9EA2837-0A4B-488F-A289-643B9D0BFCEB}.Release|x86.ActiveCfg = Release|Win32
|
||||
{C9EA2837-0A4B-488F-A289-643B9D0BFCEB}.Release|x86.Build.0 = Release|Win32
|
||||
{C9EA2837-0A4B-488F-A289-643B9D0BFCEB}.RelWithDebInfo|x64.ActiveCfg = Release|x64
|
||||
{C9EA2837-0A4B-488F-A289-643B9D0BFCEB}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{C9EA2837-0A4B-488F-A289-643B9D0BFCEB}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
|
||||
{C9EA2837-0A4B-488F-A289-643B9D0BFCEB}.RelWithDebInfo|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
|
||||
@@ -137,7 +137,8 @@ namespace MeoAsstGui
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
|
||||
case AsstMsg.ConnectionError:
|
||||
case AsstMsg.ConnectionInfo:
|
||||
procConnectInfo(details);
|
||||
break;
|
||||
|
||||
case AsstMsg.AllTasksCompleted:
|
||||
@@ -157,6 +158,15 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private void procConnectInfo(JObject details)
|
||||
{
|
||||
if (details["what"].ToString() == "Connected")
|
||||
{
|
||||
var svm = _container.Get<SettingsViewModel>();
|
||||
svm.ConnectAddress = details["details"]["address"].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void procTaskChainMsg(AsstMsg msg, JObject details)
|
||||
{
|
||||
string taskChain = details["taskchain"].ToString();
|
||||
@@ -587,18 +597,23 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
public bool AsstConnect()
|
||||
public bool AsstConnect(ref string error)
|
||||
{
|
||||
var settings = _container.Get<SettingsViewModel>();
|
||||
if (settings.AdbPath == String.Empty ||
|
||||
settings.ConnectAddress == String.Empty)
|
||||
{
|
||||
return false;
|
||||
if (!settings.RefreshAdbConfig(ref error))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
bool ret = AsstConnect(_handle, settings.AdbPath, settings.ConnectAddress, settings.ConnectConfig);
|
||||
if (!ret)
|
||||
{
|
||||
return AsstConnect(_handle, settings.AdbPath, settings.ConnectAddress, settings.ConnectConfig);
|
||||
error = "连接失败\n请检查连接设置";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private bool AsstAppendTaskWithEncoding(string type, JObject task_params = null)
|
||||
@@ -720,7 +735,7 @@ namespace MeoAsstGui
|
||||
/* Global Info */
|
||||
InternalError = 0, // 内部错误
|
||||
InitFailed, // 初始化失败
|
||||
ConnectionError, // 连接相关错误
|
||||
ConnectionInfo, // 连接相关错误
|
||||
AllTasksCompleted, // 全部任务完成
|
||||
/* TaskChain Info */
|
||||
TaskChainError = 10000, // 任务链执行/识别错误
|
||||
|
||||
81
src/MeoAsstGui/Helper/WinAdapter.cs
Normal file
81
src/MeoAsstGui/Helper/WinAdapter.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
// MeoAsstGui - A part of the MeoAssistantArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program 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
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace MeoAsstGui
|
||||
{
|
||||
public class WinAdapter
|
||||
{
|
||||
private static readonly Dictionary<string, string> emulatorIdDict = new Dictionary<string, string> {
|
||||
{ "HD-Player", "BlueStacks"},
|
||||
{ "LdVBoxHeadless", "LDPlayer"},
|
||||
{ "NoxVMHandle", "Nox"},
|
||||
{ "NemuHeadless", "MuMuEmulator"},
|
||||
{ "MEmuHeadless", "XYAZ"}
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, List<string>> adbRelativePathDict = new Dictionary<string, List<string>> {
|
||||
{ "BlueStacks", new List<string> {
|
||||
".\\HD-Adb.exe",
|
||||
".\\Engine\\ProgramFiles\\HD-Adb.exe"
|
||||
} },
|
||||
{ "LDPlayer", new List<string> { ".\\adb.exe" } },
|
||||
{ "Nox", new List<string> { ".\\nox_adb.exe" } },
|
||||
{ "MuMuEmulator", new List<string> {
|
||||
"..\\vmonitor\\bin\\adb_server.exe",
|
||||
"..\\..\\MuMu\\emulator\\nemu\\vmonitor\\bin\\adb_server.exe"
|
||||
} },
|
||||
{ "XYAZ", new List<string> { ".\\adb.exe"} }
|
||||
};
|
||||
|
||||
private Dictionary<string, string> adbAbsoultePathDict = new Dictionary<string, string>();
|
||||
|
||||
public List<string> RefreshEmulatorsInfo()
|
||||
{
|
||||
var allProcess = Process.GetProcesses();
|
||||
var emulators = new List<string>();
|
||||
foreach (var process in allProcess)
|
||||
{
|
||||
if (emulatorIdDict.Keys.Contains(process.ProcessName))
|
||||
{
|
||||
var emulatorId = emulatorIdDict[process.ProcessName];
|
||||
emulators.Add(emulatorId);
|
||||
var processPath = process.MainModule.FileName;
|
||||
foreach (var path in adbRelativePathDict[emulatorId])
|
||||
{
|
||||
var adbPath = Path.GetDirectoryName(processPath) + "\\" + path;
|
||||
if (File.Exists(adbPath))
|
||||
{
|
||||
adbAbsoultePathDict.Add(emulatorId, adbPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return emulators;
|
||||
}
|
||||
|
||||
public string GetAdbPathByEmulatorName(string emulatorName)
|
||||
{
|
||||
if (adbAbsoultePathDict.Keys.Contains(emulatorName))
|
||||
{
|
||||
return adbAbsoultePathDict[emulatorName];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@
|
||||
<Compile Include="Helper\ScrollViewerBinding.cs" />
|
||||
<Compile Include="Helper\ViewStatusStorage.cs" />
|
||||
<Compile Include="Helper\FlowDocumentPagePadding.cs" />
|
||||
<Compile Include="Helper\WinAdapter.cs" />
|
||||
<Compile Include="UserControl\AutoRecruitSettingsUserControl.xaml.cs">
|
||||
<DependentUpon>AutoRecruitSettingsUserControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -98,17 +98,18 @@ namespace MeoAsstGui
|
||||
AddLog("正在连接模拟器……");
|
||||
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
string errMsg = "";
|
||||
if (!_catched)
|
||||
{
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
return asstProxy.AsstConnect();
|
||||
return asstProxy.AsstConnect(ref errMsg);
|
||||
});
|
||||
_catched = await task;
|
||||
}
|
||||
if (!_catched)
|
||||
{
|
||||
AddLog("连接模拟器失败\n请检查连接设置", "darkred");
|
||||
AddLog(errMsg, "darkred");
|
||||
return;
|
||||
}
|
||||
if (Filename.Length == 0 || !File.Exists(Filename))
|
||||
|
||||
@@ -115,18 +115,19 @@ namespace MeoAsstGui
|
||||
public async void StartCalc()
|
||||
{
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
string errMsg = "";
|
||||
if (!_catched)
|
||||
{
|
||||
RecruitInfo = "正在连接模拟器……";
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
return asstProxy.AsstConnect();
|
||||
return asstProxy.AsstConnect(ref errMsg);
|
||||
});
|
||||
_catched = await task;
|
||||
}
|
||||
if (!_catched)
|
||||
{
|
||||
RecruitInfo = "连接模拟器失败,请检查连接设置";
|
||||
RecruitInfo = errMsg;
|
||||
return;
|
||||
}
|
||||
RecruitInfo = "正在识别……";
|
||||
|
||||
@@ -131,11 +131,6 @@ namespace MeoAsstGui
|
||||
};
|
||||
|
||||
ConnectAddressList = new ObservableCollection<string>();
|
||||
|
||||
if (ConnectAddress.Length == 0)
|
||||
{
|
||||
UpdateAddressByConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _idle = true;
|
||||
@@ -891,7 +886,7 @@ namespace MeoAsstGui
|
||||
{ "WSA", new List<string> { "127.0.0.1:58526" } },
|
||||
};
|
||||
|
||||
public void UpdateAddressByConfig()
|
||||
private void UpdateAddressByConfig()
|
||||
{
|
||||
var addresses = ConfigAddressesMapping[ConnectConfig];
|
||||
ConnectAddress = addresses.FirstOrDefault();
|
||||
@@ -902,6 +897,26 @@ namespace MeoAsstGui
|
||||
//}
|
||||
}
|
||||
|
||||
public bool RefreshAdbConfig(ref string error)
|
||||
{
|
||||
var adapter = new WinAdapter();
|
||||
var emulators = adapter.RefreshEmulatorsInfo();
|
||||
if (emulators.Count == 0)
|
||||
{
|
||||
error = "未检测到任何模拟器\n请尝试使用管理员权限打开本软件\n或手动设置连接";
|
||||
return false;
|
||||
}
|
||||
else if (emulators.Count > 1)
|
||||
{
|
||||
error = "检测到多个模拟器\n请关闭不需要的模拟器\n或手动设置连接";
|
||||
return false;
|
||||
}
|
||||
ConnectConfig = emulators.First();
|
||||
AdbPath = adapter.GetAdbPathByEmulatorName(ConnectConfig) ?? AdbPath;
|
||||
UpdateAddressByConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SelectFile()
|
||||
{
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog();
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace MeoAsstGui
|
||||
//new CombData { Display = "SN-8", Value = "SN-8" },
|
||||
//new CombData { Display = "SN-9", Value = "SN-9" },
|
||||
//new CombData { Display = "SN-10", Value = "SN-10" },
|
||||
|
||||
|
||||
//// “风雪过境” 活动关卡
|
||||
//new CombData { Display = "BI-7", Value = "BI-7" },
|
||||
//new CombData { Display = "BI-8", Value = "BI-8" }
|
||||
@@ -139,14 +139,15 @@ namespace MeoAsstGui
|
||||
AddLog("正在连接模拟器……");
|
||||
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
string errMsg = "";
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
return asstProxy.AsstConnect();
|
||||
return asstProxy.AsstConnect(ref errMsg);
|
||||
});
|
||||
bool catchd = await task;
|
||||
if (!catchd)
|
||||
{
|
||||
AddLog("连接模拟器失败\n请检查连接设置", "darkred");
|
||||
AddLog(errMsg, "darkred");
|
||||
Idle = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user