parent
8f853fab56
commit
35684c0a54
|
@ -52,6 +52,7 @@
|
|||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.10" />
|
||||
<PackageReference Include="NLog" Version="5.2.4" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.4" />
|
||||
<PackageReference Include="RegParserDotNet" Version="1.0.3" />
|
||||
<PackageReference Include="rix0rrr.BeaconLib" Version="1.0.2" />
|
||||
<PackageReference Include="swashbuckle" Version="5.6.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
@inject IMessageService MessageService
|
||||
|
||||
<Modal Visible="Visible" OkText="@("Insert")" OnOk="Parse" OnCancel="Close" Width="800" Title="Paste Export File Contents">
|
||||
<StandaloneCodeEditor @ref="Editor" ConstructionOptions="EditorConstructionOptions" />
|
||||
</Modal>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback<string> OnParsed { get; set; }
|
||||
|
||||
bool Visible = false;
|
||||
string Contents = "";
|
||||
|
||||
StandaloneCodeEditor? Editor;
|
||||
|
||||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
||||
{
|
||||
return new StandaloneEditorConstructionOptions
|
||||
{
|
||||
AutomaticLayout = true,
|
||||
Language = "ini",
|
||||
Value = Contents,
|
||||
Theme = "vs-dark",
|
||||
};
|
||||
}
|
||||
|
||||
private async Task Parse()
|
||||
{
|
||||
Contents = await Editor.GetValue();
|
||||
|
||||
var parser = new RegParserDotNet.RegParser();
|
||||
var lines = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
var keys = parser.Parse(Contents);
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
switch (key.Type)
|
||||
{
|
||||
case RegParserDotNet.RegistryValueType.REG_KEY:
|
||||
if (lines.Count > 0)
|
||||
lines.Add("");
|
||||
|
||||
lines.Add($"New-Item -Path \"registry::\\{key.Path}\"");
|
||||
break;
|
||||
|
||||
case RegParserDotNet.RegistryValueType.REG_SZ:
|
||||
lines.Add($"New-ItemProperty -Path \"registry::\\{key.Path}\" -Name \"{key.Property}\" -Value \"{(string)key.Value}\" -Force");
|
||||
break;
|
||||
|
||||
case RegParserDotNet.RegistryValueType.REG_DWORD:
|
||||
lines.Add($"New-ItemProperty -Path \"registry::\\{key.Path}\" -Name \"{key.Property}\" -Value {(int)key.Value} -Force");
|
||||
break;
|
||||
|
||||
case RegParserDotNet.RegistryValueType.REG_BINARY:
|
||||
var bytes = key.Value as byte[];
|
||||
var convertedBytes = String.Join("\\\n", bytes.Chunk(32).Select(c => String.Join(", ", c.Select(b => "0x" + b.ToString("X2")))));
|
||||
lines.Add($"New-ItemProperty -Path \"registry::\\{key.Path}\" -Name \"{key.Property}\" -PropertyType Binary -Value [byte[]]({convertedBytes}) -Force");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (OnParsed.HasDelegate)
|
||||
await OnParsed.InvokeAsync(String.Join('\n', lines));
|
||||
|
||||
Close();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageService.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
Visible = false;
|
||||
}
|
||||
}
|
|
@ -43,6 +43,8 @@
|
|||
{
|
||||
<Button Icon="@IconType.Outline.FolderOpen" OnClick="BrowseForPath" Type="@ButtonType.Text">Browse</Button>
|
||||
}
|
||||
|
||||
<Button Icon="@IconType.Outline.Build" OnClick="() => RegToPowerShell.Open()" Type="@ButtonType.Text">Import .reg</Button>
|
||||
</FormItem>
|
||||
|
||||
<FormItem>
|
||||
|
@ -70,6 +72,8 @@
|
|||
</Form>
|
||||
</Modal>
|
||||
|
||||
<RegToPowerShell @ref="RegToPowerShell" OnParsed="(text) => InsertText(text)" />
|
||||
|
||||
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
|
||||
<SpaceItem>
|
||||
<Table TItem="Script" DataSource="@Scripts" HidePagination="true" Responsive>
|
||||
|
@ -119,6 +123,7 @@
|
|||
|
||||
IEnumerable<Snippet> Snippets { get; set; }
|
||||
StandaloneCodeEditor? Editor;
|
||||
RegToPowerShell RegToPowerShell;
|
||||
|
||||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
||||
{
|
||||
|
@ -195,31 +200,46 @@
|
|||
await MessageService.Success("Script saved!");
|
||||
}
|
||||
|
||||
private async void InsertSnippet(Snippet snippet)
|
||||
private async Task InsertText(string text)
|
||||
{
|
||||
await Editor.Trigger("keyboard", "type", new
|
||||
var line = await Editor.GetPosition();
|
||||
var range = new BlazorMonaco.Range(line.LineNumber, 1, line.LineNumber, 1);
|
||||
|
||||
var currentSelections = await Editor.GetSelections();
|
||||
|
||||
await Editor.ExecuteEdits("ScriptEditor", new List<IdentifiedSingleEditOperation>()
|
||||
{
|
||||
text = snippet.Content
|
||||
});
|
||||
new IdentifiedSingleEditOperation
|
||||
{
|
||||
Range = range,
|
||||
Text = text,
|
||||
ForceMoveMarkers = true
|
||||
}
|
||||
}, currentSelections);
|
||||
}
|
||||
|
||||
private async Task InsertSnippet(Snippet snippet)
|
||||
{
|
||||
await InsertText(snippet.Content);
|
||||
}
|
||||
|
||||
private async void BrowseForPath()
|
||||
{
|
||||
var modalOptions = new ModalOptions()
|
||||
{
|
||||
Title = "Choose Reference",
|
||||
Maximizable = false,
|
||||
DefaultMaximized = true,
|
||||
Closable = true,
|
||||
OkText = "Insert File Path"
|
||||
};
|
||||
{
|
||||
Title = "Choose Reference",
|
||||
Maximizable = false,
|
||||
DefaultMaximized = true,
|
||||
Closable = true,
|
||||
OkText = "Insert File Path"
|
||||
};
|
||||
|
||||
var browserOptions = new FilePickerOptions()
|
||||
{
|
||||
ArchiveId = ArchiveId,
|
||||
Select = true,
|
||||
Multiple = false
|
||||
};
|
||||
{
|
||||
ArchiveId = ArchiveId,
|
||||
Select = true,
|
||||
Multiple = false
|
||||
};
|
||||
|
||||
var modalRef = await ModalService.CreateModalAsync<FilePickerDialog, FilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
|
||||
|
||||
|
@ -227,10 +247,7 @@
|
|||
{
|
||||
var path = results.FirstOrDefault().Path;
|
||||
|
||||
Editor.Trigger("keyboard", "type", new
|
||||
{
|
||||
text = $"$InstallDir\\{path.Replace('/', '\\')}"
|
||||
});
|
||||
InsertText($"$InstallDir\\{path.Replace('/', '\\')}");
|
||||
|
||||
StateHasChanged();
|
||||
return Task.CompletedTask;
|
||||
|
|
Loading…
Reference in New Issue