mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-25 10:05:49 +08:00
补充km+shell
This commit is contained in:
@@ -188,7 +188,7 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
else if (Type == "KeyMouse")
|
||||
{
|
||||
// 加载并执行
|
||||
var json = await File.ReadAllTextAsync(Global.Absolute(@$"User\KeyMouseScript\{Name}"));
|
||||
var json = await File.ReadAllTextAsync(Path.Combine(KeyMouseRecordPageViewModel.ScriptPath, Name));
|
||||
await KeyMouseMacroPlayer.PlayMacro(json, CancellationContext.Instance.Cts.Token, false);
|
||||
}
|
||||
else if (Type == "Pathing")
|
||||
|
||||
@@ -51,9 +51,10 @@ public partial class GearTaskViewModel : ObservableObject
|
||||
|
||||
/// <summary>
|
||||
/// 任务参数,存储为JSON字符串
|
||||
/// shell 脚本存储 shell 命令
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _parameters = "{}";
|
||||
private string _parameters = "";
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
|
||||
@@ -4,11 +4,15 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BetterGenshinImpact.ViewModel.Pages.Component;
|
||||
using BetterGenshinImpact.Service;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
using BetterGenshinImpact.View.Windows.GearTask;
|
||||
using BetterGenshinImpact.ViewModel.Windows;
|
||||
@@ -380,6 +384,52 @@ public partial class GearTaskListPageViewModel : ViewModel
|
||||
return; // 用户取消了操作
|
||||
}
|
||||
}
|
||||
else if (taskType == "Shell")
|
||||
{
|
||||
var list = LoadAllKmScripts();
|
||||
var folder = KeyMouseRecordPageViewModel.ScriptPath;
|
||||
var combobox = new ComboBox
|
||||
{
|
||||
VerticalAlignment = VerticalAlignment.Top
|
||||
};
|
||||
|
||||
foreach (var fileInfo in list)
|
||||
{
|
||||
// 计算相对于 KeyMouseScript 文件夹的相对路径
|
||||
var relativePath = Path.GetRelativePath(folder, fileInfo.FullName);
|
||||
combobox.Items.Add(relativePath);
|
||||
}
|
||||
|
||||
var str = PromptDialog.Prompt("请选择需要添加的键鼠脚本", "请选择需要添加的键鼠脚本", combobox);
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
newTask = new GearTaskViewModel(str)
|
||||
{
|
||||
TaskType = "Javascript",
|
||||
Path = @$"{{kmUserFolder}}\{str}\"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (taskType == "Shell")
|
||||
{
|
||||
var str = PromptDialog.Prompt("执行 shell 操作存在极大风险!请勿输入你看不懂的指令!以免引发安全隐患并损坏系统!\n执行 shell 的时候,游戏可能会失去焦点", "请输入需要执行的shell");
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
newTask = new GearTaskViewModel(str)
|
||||
{
|
||||
TaskType = "Shell",
|
||||
Parameters = str
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 其他类型使用原有的对话框
|
||||
@@ -410,6 +460,16 @@ public partial class GearTaskListPageViewModel : ViewModel
|
||||
// 自动保存到文件
|
||||
await _storageService.SaveTaskDefinitionAsync(SelectedTaskDefinition);
|
||||
}
|
||||
|
||||
private List<FileInfo> LoadAllKmScripts()
|
||||
{
|
||||
var folder = KeyMouseRecordPageViewModel.ScriptPath;
|
||||
// 获取所有脚本项目
|
||||
var files = Directory.GetFiles(folder, "*.*",
|
||||
SearchOption.AllDirectories);
|
||||
|
||||
return files.Select(file => new FileInfo(file)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加任务组
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
public partial class KeyMouseRecordPageViewModel : ViewModel
|
||||
{
|
||||
private readonly ILogger<KeyMouseRecordPageViewModel> _logger = App.GetLogger<KeyMouseRecordPageViewModel>();
|
||||
private readonly string scriptPath = Global.Absolute(@"User\KeyMouseScript");
|
||||
public static readonly string ScriptPath = Global.Absolute(@"User\KeyMouseScript");
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<KeyMouseScriptItem> _scriptItems = [];
|
||||
@@ -45,7 +45,7 @@ public partial class KeyMouseRecordPageViewModel : ViewModel
|
||||
private void InitScriptListViewData()
|
||||
{
|
||||
ScriptItems.Clear();
|
||||
var fileInfos = LoadScriptFiles(scriptPath)
|
||||
var fileInfos = LoadScriptFiles(ScriptPath)
|
||||
.OrderByDescending(f => f.CreationTime)
|
||||
.ToList();
|
||||
foreach (var f in fileInfos)
|
||||
@@ -102,7 +102,7 @@ public partial class KeyMouseRecordPageViewModel : ViewModel
|
||||
{
|
||||
var macro = GlobalKeyMouseRecord.Instance.StopRecord();
|
||||
// Genshin Copilot Macro
|
||||
File.WriteAllText(Path.Combine(scriptPath, $"BetterGI_GCM_{DateTime.Now:yyyyMMddHHmmssffff}.json"), macro);
|
||||
File.WriteAllText(Path.Combine(ScriptPath, $"BetterGI_GCM_{DateTime.Now:yyyyMMddHHmmssffff}.json"), macro);
|
||||
// 刷新ListView
|
||||
InitScriptListViewData();
|
||||
IsRecording = false;
|
||||
@@ -140,7 +140,7 @@ public partial class KeyMouseRecordPageViewModel : ViewModel
|
||||
[RelayCommand]
|
||||
public void OnOpenScriptFolder()
|
||||
{
|
||||
Process.Start("explorer.exe", scriptPath);
|
||||
Process.Start("explorer.exe", ScriptPath);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
||||
@@ -1558,7 +1558,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
|
||||
private List<FileInfo> LoadAllKmScripts()
|
||||
{
|
||||
var folder = Global.Absolute(@"User\KeyMouseScript");
|
||||
var folder = KeyMouseRecordPageViewModel.ScriptPath;
|
||||
// 获取所有脚本项目
|
||||
var files = Directory.GetFiles(folder, "*.*",
|
||||
SearchOption.AllDirectories);
|
||||
@@ -1742,7 +1742,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
path = Path.Combine(Global.ScriptPath(), item.FolderName);
|
||||
break;
|
||||
case "KeyMouse":
|
||||
path = Global.Absolute(@"User\KeyMouseScript");
|
||||
path = KeyMouseRecordPageViewModel.ScriptPath;
|
||||
break;
|
||||
case "Pathing":
|
||||
path = Path.Combine(MapPathingViewModel.PathJsonPath, item.FolderName);
|
||||
|
||||
Reference in New Issue
Block a user