2025-02-23 09:17:46 -06:00
|
|
|
@using LANCommander.SDK.Enums
|
|
|
|
|
@inherits FeedbackComponent<ScriptEditorOptions, Script>
|
2025-02-01 02:21:34 -06:00
|
|
|
@inject ScriptService ScriptService
|
2025-12-08 00:51:32 -06:00
|
|
|
@inject ArchiveService ArchiveService
|
|
|
|
|
@inject ServerService ServerService
|
2025-02-23 09:17:46 -06:00
|
|
|
@inject ModalService ModalService
|
2023-11-28 20:48:03 -06:00
|
|
|
@inject IMessageService MessageService
|
2024-01-04 18:23:54 -06:00
|
|
|
@inject ILogger<ScriptEditorDialog> Logger
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
<Form @ref="@_form" Model="@_script" Layout="@FormLayout.Vertical">
|
2025-02-23 09:17:46 -06:00
|
|
|
<FormItem>
|
|
|
|
|
@foreach (var group in Snippets.Select(s => s.Group).Distinct())
|
|
|
|
|
{
|
|
|
|
|
<Dropdown>
|
|
|
|
|
<Overlay>
|
|
|
|
|
<Menu>
|
|
|
|
|
@foreach (var snippet in Snippets.Where(s => s.Group == group))
|
|
|
|
|
{
|
|
|
|
|
<MenuItem OnClick="() => InsertSnippet(snippet)">
|
|
|
|
|
@snippet.Name
|
|
|
|
|
</MenuItem>
|
|
|
|
|
}
|
|
|
|
|
</Menu>
|
|
|
|
|
</Overlay>
|
|
|
|
|
|
|
|
|
|
<ChildContent>
|
|
|
|
|
<Button Type="@ButtonType.Primary">@group</Button>
|
|
|
|
|
</ChildContent>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 00:51:32 -06:00
|
|
|
@if (_archive != null)
|
2025-02-23 09:17:46 -06:00
|
|
|
{
|
|
|
|
|
<Button Icon="@IconType.Outline.FolderOpen" OnClick="BrowseForPath" Type="@ButtonType.Text">Browse</Button>
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
<Button Icon="@IconType.Outline.Build" OnClick="() => _regToPowerShell.Open()" Type="@ButtonType.Text">Import .reg</Button>
|
2025-12-10 20:55:38 -06:00
|
|
|
|
|
|
|
|
@if (Options.GameId.HasValue && Options.GameId != Guid.Empty && IsDebuggable)
|
|
|
|
|
{
|
|
|
|
|
<Tooltip Title="Debug">
|
2025-12-10 21:46:46 -06:00
|
|
|
<Button Icon="@IconType.Outline.CaretRight" Type="@ButtonType.Text" OnClick="Debug" Disabled="@_debugging" />
|
2025-12-10 20:55:38 -06:00
|
|
|
</Tooltip>
|
|
|
|
|
}
|
2025-02-23 09:17:46 -06:00
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem>
|
2026-03-20 00:01:12 -05:00
|
|
|
<CodeInput @ref="_codeInput" @bind-Value="context.Contents" Language="Languages.PowerShell" OnSave="Save" />
|
|
|
|
|
|
|
|
|
|
<PowerShellConsole @ref="_console" Id="_id" @bind-Active="_debugging"/>
|
2025-02-23 09:17:46 -06:00
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem Label="Name" Required Rules=@(new[] { new FormValidationRule { Required = true } })>
|
|
|
|
|
<Input @bind-Value="@context.Name" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem Label="Type">
|
|
|
|
|
<Select @bind-Value="context.Type" TItem="ScriptType" TItemValue="ScriptType" DataSource="Enum.GetValues<ScriptType>().Where(st => Options.AllowedTypes == null || Options.AllowedTypes.Contains(st))">
|
|
|
|
|
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
|
|
|
|
|
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
|
|
|
|
|
</Select>
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem>
|
|
|
|
|
<Checkbox @bind-Checked="context.RequiresAdmin">Requires Admin</Checkbox>
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem Label="Description">
|
|
|
|
|
<TextArea @bind-Value="context.Description" MaxLength=500 ShowCount />
|
|
|
|
|
</FormItem>
|
2025-12-10 20:55:38 -06:00
|
|
|
|
2025-02-23 09:17:46 -06:00
|
|
|
</Form>
|
|
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
<RegToPowerShell @ref="_regToPowerShell" OnParsed="(text) => InsertText(text)" />
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-03-11 17:38:29 -05:00
|
|
|
@code {
|
2026-03-20 00:01:12 -05:00
|
|
|
Guid _id = Guid.NewGuid();
|
2025-02-23 09:17:46 -06:00
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
Form<Script>? _form;
|
|
|
|
|
CodeInput? _codeInput;
|
|
|
|
|
RegToPowerShell? _regToPowerShell;
|
|
|
|
|
PowerShellConsole? _console;
|
|
|
|
|
IEnumerable<Snippet> Snippets { get; set; } = [];
|
2025-12-08 00:51:32 -06:00
|
|
|
|
2025-12-10 21:46:46 -06:00
|
|
|
bool _debugging;
|
|
|
|
|
|
2025-12-08 00:51:32 -06:00
|
|
|
Archive? _archive;
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
Script _script = new();
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2025-12-10 20:55:38 -06:00
|
|
|
bool IsDebuggable =>
|
2026-03-20 00:01:12 -05:00
|
|
|
_script.Type == ScriptType.Package;
|
2025-12-10 20:55:38 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
if (Options.ScriptId != Guid.Empty)
|
2026-03-20 00:01:12 -05:00
|
|
|
_script = await ScriptService.GetAsync(Options.ScriptId);
|
2026-03-08 14:10:41 -05:00
|
|
|
else if (Options.GameId.HasValue && Options.GameId != Guid.Empty)
|
2025-12-08 00:51:32 -06:00
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
_script = new Script
|
2025-02-01 02:21:34 -06:00
|
|
|
{
|
|
|
|
|
GameId = Options.GameId
|
|
|
|
|
};
|
2025-12-08 00:51:32 -06:00
|
|
|
|
|
|
|
|
_archive = await ArchiveService.GetLatestArchiveAsync(a => a.GameId == Options.GameId);
|
|
|
|
|
}
|
2026-03-08 14:10:41 -05:00
|
|
|
else if (Options.RedistributableId.HasValue && Options.RedistributableId != Guid.Empty)
|
2025-12-08 00:51:32 -06:00
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
_script = new Script()
|
2025-02-01 02:21:34 -06:00
|
|
|
{
|
|
|
|
|
RedistributableId = Options.RedistributableId
|
|
|
|
|
};
|
2025-12-08 00:51:32 -06:00
|
|
|
|
|
|
|
|
_archive = await ArchiveService.GetLatestArchiveAsync(a => a.RedistributableId == Options.RedistributableId);
|
|
|
|
|
}
|
2026-03-08 14:10:41 -05:00
|
|
|
else if (Options.ServerId.HasValue && Options.ServerId != Guid.Empty)
|
2025-12-08 00:51:32 -06:00
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
_script = new Script()
|
2025-02-01 02:21:34 -06:00
|
|
|
{
|
|
|
|
|
ServerId = Options.ServerId
|
|
|
|
|
};
|
2025-12-08 00:51:32 -06:00
|
|
|
|
|
|
|
|
var server = await ServerService.GetAsync(Options.ServerId.Value);
|
|
|
|
|
|
|
|
|
|
_archive = await ArchiveService.GetLatestArchiveAsync(a => a.GameId == server.GameId);
|
|
|
|
|
}
|
2026-03-08 14:10:41 -05:00
|
|
|
else if (Options.ToolId.HasValue && Options.ToolId != Guid.Empty)
|
2026-02-08 02:24:53 -06:00
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
_script = new Script()
|
2026-02-08 02:24:53 -06:00
|
|
|
{
|
|
|
|
|
ToolId = Options.ToolId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_archive = await ArchiveService.GetLatestArchiveAsync(a => a.ToolId == Options.ToolId);
|
|
|
|
|
}
|
2025-02-23 09:17:46 -06:00
|
|
|
|
|
|
|
|
Snippets = ScriptService.GetSnippets();
|
2023-12-05 19:10:34 -06:00
|
|
|
}
|
|
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
|
|
|
|
|
{
|
2024-03-11 17:38:29 -05:00
|
|
|
var success = await Save();
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-03-11 17:38:29 -05:00
|
|
|
if (success)
|
2026-03-20 00:01:12 -05:00
|
|
|
await base.OkCancelRefWithResult!.OnOk(_script);
|
2024-03-11 17:38:29 -05:00
|
|
|
else
|
|
|
|
|
args.Reject();
|
2023-11-28 20:48:03 -06:00
|
|
|
}
|
|
|
|
|
|
2024-11-22 02:04:04 -06:00
|
|
|
async Task<bool> Save()
|
2023-11-28 20:48:03 -06:00
|
|
|
{
|
2024-11-22 02:04:04 -06:00
|
|
|
try
|
2023-11-28 20:48:03 -06:00
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
if (_form.Validate())
|
2025-02-23 09:17:46 -06:00
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
if (_script.Id == Guid.Empty)
|
|
|
|
|
_script = await ScriptService.AddAsync(_script);
|
2025-02-23 09:17:46 -06:00
|
|
|
else
|
2026-03-20 00:01:12 -05:00
|
|
|
_script = await ScriptService.UpdateAsync(_script);
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2025-02-23 09:17:46 -06:00
|
|
|
MessageService.Success("Script saved!");
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2025-02-23 09:17:46 -06:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2024-11-22 02:04:04 -06:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2023-11-30 19:12:25 -06:00
|
|
|
{
|
2024-11-22 02:04:04 -06:00
|
|
|
MessageService.Error("Script could not be saved!");
|
|
|
|
|
Logger.LogError(ex, "Script could not be saved!");
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-03-11 17:38:29 -05:00
|
|
|
return false;
|
2024-11-22 02:04:04 -06:00
|
|
|
}
|
2023-11-28 20:48:03 -06:00
|
|
|
}
|
2025-12-10 21:46:46 -06:00
|
|
|
|
|
|
|
|
async Task Debug()
|
|
|
|
|
{
|
|
|
|
|
if (!IsDebuggable)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var saved = await Save();
|
|
|
|
|
|
|
|
|
|
if (!saved)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (Options.GameId.HasValue)
|
|
|
|
|
await _console.DebugPackagingScript(Options.GameId.Value);
|
|
|
|
|
}
|
2025-02-23 09:17:46 -06:00
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
async Task BrowseForPath()
|
2025-02-23 09:17:46 -06:00
|
|
|
{
|
|
|
|
|
var modalOptions = new ModalOptions()
|
|
|
|
|
{
|
|
|
|
|
Title = "Choose Reference",
|
|
|
|
|
Maximizable = false,
|
|
|
|
|
DefaultMaximized = true,
|
|
|
|
|
Closable = true,
|
|
|
|
|
OkText = "Insert File Path"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var browserOptions = new FilePickerOptions()
|
|
|
|
|
{
|
2025-12-08 00:51:32 -06:00
|
|
|
ArchiveId = _archive?.Id ?? Guid.Empty,
|
2025-02-23 09:17:46 -06:00
|
|
|
Select = true,
|
|
|
|
|
Multiple = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var modalRef = await ModalService.CreateModalAsync<FilePickerDialog, FilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
|
|
|
|
|
|
|
|
|
|
modalRef.OnOk = (results) =>
|
|
|
|
|
{
|
|
|
|
|
var path = results.FirstOrDefault().Path;
|
|
|
|
|
|
|
|
|
|
InsertText($"$InstallDirectory\\{path.Replace('/', '\\')}");
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task InsertText(string text)
|
|
|
|
|
{
|
2026-03-20 00:01:12 -05:00
|
|
|
if (_codeInput != null)
|
|
|
|
|
await _codeInput.InsertText(text);
|
2025-02-23 09:17:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task InsertSnippet(Snippet snippet)
|
|
|
|
|
{
|
|
|
|
|
await InsertText(snippet.Content);
|
|
|
|
|
}
|
2023-11-28 20:48:03 -06:00
|
|
|
}
|