Skip to content

Commit

Permalink
feature: allow to set encoding for reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticLampyrid committed Aug 12, 2020
1 parent 8aa77b8 commit 6615821
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ConsoleHub/ConsoleHub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\AppIcon.ico</ApplicationIcon>
<Version>1.3.0</Version>
<Version>1.4.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
20 changes: 14 additions & 6 deletions ConsoleHub/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public partial class MainWindow : Window
{
private readonly MainViewModel ViewModel = new MainViewModel();
[DllImport("kernel32.dll", SetLastError = true)]
private static extern int GetConsoleCP();
[DllImport("kernel32.dll", SetLastError = true)]
private static extern int GetConsoleOutputCP();
private static extern int GetOEMCP();
private static int codepage = GetOEMCP();
public MainWindow()
{
this.DataContext = ViewModel;
Expand Down Expand Up @@ -118,6 +117,15 @@ private async Task ExecuteCommand(string fileName, string arguments)
await Task.Delay(Convert.ToInt32(arguments));
return;
}
if (fileName.ToLowerInvariant() == "*codepage")
{
codepage = Convert.ToInt32(arguments);
if (codepage == 0)
{
codepage = GetOEMCP();
}
return;
}
if (string.IsNullOrWhiteSpace(fileName))
{
return;
Expand All @@ -132,9 +140,9 @@ private async Task ExecuteCommand(string fileName, string arguments)
model.Content.StartProcess(new ProcessStartInfo() {
FileName = fileName,
Arguments = arguments,
StandardOutputEncoding = Encoding.GetEncoding(GetConsoleOutputCP()),
StandardErrorEncoding = Encoding.GetEncoding(GetConsoleOutputCP()),
StandardInputEncoding = Encoding.GetEncoding(GetConsoleCP())
StandardOutputEncoding = Encoding.GetEncoding(codepage),
StandardErrorEncoding = Encoding.GetEncoding(codepage),
StandardInputEncoding = Encoding.GetEncoding(codepage)
});
try
{
Expand Down

0 comments on commit 6615821

Please sign in to comment.