Skip to content

Commit aa802f0

Browse files
gave92Marco Gavelli
authored andcommitted
Moved Terminal under Utils
1 parent ccc7379 commit aa802f0

26 files changed

+75
-74
lines changed

src/Files.App/UserControls/TerminalView.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CommunityToolkit.WinUI;
22
using CommunityToolkit.WinUI.Helpers;
3-
using Files.App.Terminal;
3+
using Files.App.Utils.Terminal;
4+
using Files.App.Utils.Terminal.ConPTY;
45
using Microsoft.Extensions.Logging;
56
using Microsoft.UI.Xaml.Controls;
67
using Microsoft.UI.Xaml.Media;
@@ -114,7 +115,7 @@ private async Task ResizeTask()
114115

115116
public WebView2 WebView => WebViewControl;
116117

117-
private Terminal.Terminal _terminal;
118+
private Terminal _terminal;
118119
private BufferedReader _reader;
119120

120121
public TerminalView()
@@ -130,7 +131,7 @@ private async void WebViewControl_LoadedAsync(object sender, Microsoft.UI.Xaml.R
130131
WebViewControl.NavigationStarting += WebViewControl_NavigationStarting;
131132
WebViewControl.CoreWebView2.SetVirtualHostNameToFolderMapping(
132133
"terminal.files",
133-
Path.Combine(Package.Current.InstalledLocation.Path, "Files.App", "Terminal", "UI"),
134+
Path.Combine(Package.Current.InstalledLocation.Path, "Files.App", "Utils", "Terminal", "UI"),
134135
CoreWebView2HostResourceAccessKind.DenyCors);
135136
WebViewControl.Source = new Uri("http://terminal.files/index.html");
136137

@@ -350,7 +351,7 @@ private void StartShellProcess(TerminalSize size, ShellProfile profile)
350351
? $"\"{profile.Location}\" {profile.Arguments}"
351352
: profile.Arguments;
352353

353-
_terminal = new Terminal.Terminal();
354+
_terminal = new Terminal();
354355
_terminal.OutputReady += (s, e) =>
355356
{
356357
_reader = new BufferedReader(_terminal.ConsoleOutStream, OutputReceivedCallback, true);

src/Files.App/Terminal/BufferedReader.cs renamed to src/Files.App/Utils/Terminal/BufferedReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Text;
66
using System.Threading.Tasks;
77

8-
namespace Files.App.Terminal
8+
namespace Files.App.Utils.Terminal
99
{
1010
/// <summary>
1111
/// Code modified from https://github.com/felixse/FluentTerminal

src/Files.App/Terminal/ConPTY/Native/ConsoleApi.cs renamed to src/Files.App/Utils/Terminal/ConPTY/Native/ConsoleApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.Win32.SafeHandles;
22
using System.Runtime.InteropServices;
33

4-
namespace Files.App.Terminal.Native
4+
namespace Files.App.Utils.Terminal.ConPTY
55
{
66
/// <summary>
77
/// PInvoke signatures for win32 console api
@@ -16,7 +16,7 @@ static class ConsoleApi
1616
internal static extern bool AllocConsole();
1717

1818
[DllImport("kernel32.dll", SetLastError = true)]
19-
internal static extern IntPtr GetConsoleWindow();
19+
internal static extern nint GetConsoleWindow();
2020

2121
[DllImport("kernel32.dll", SetLastError = true)]
2222
internal static extern SafeFileHandle GetStdHandle(int nStdHandle);
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Runtime.InteropServices;
33

4-
namespace Files.App.Terminal.Native
4+
namespace Files.App.Utils.Terminal.ConPTY
55
{
66
/// <summary>
77
/// PInvoke signatures for win32 process api
@@ -14,37 +14,37 @@ static class ProcessApi
1414
internal struct STARTUPINFOEX
1515
{
1616
public STARTUPINFO StartupInfo;
17-
public IntPtr lpAttributeList;
17+
public nint lpAttributeList;
1818
}
1919

2020
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
2121
internal struct STARTUPINFO
2222
{
23-
public Int32 cb;
23+
public int cb;
2424
public string lpReserved;
2525
public string lpDesktop;
2626
public string lpTitle;
27-
public Int32 dwX;
28-
public Int32 dwY;
29-
public Int32 dwXSize;
30-
public Int32 dwYSize;
31-
public Int32 dwXCountChars;
32-
public Int32 dwYCountChars;
33-
public Int32 dwFillAttribute;
34-
public Int32 dwFlags;
35-
public Int16 wShowWindow;
36-
public Int16 cbReserved2;
37-
public IntPtr lpReserved2;
38-
public IntPtr hStdInput;
39-
public IntPtr hStdOutput;
40-
public IntPtr hStdError;
27+
public int dwX;
28+
public int dwY;
29+
public int dwXSize;
30+
public int dwYSize;
31+
public int dwXCountChars;
32+
public int dwYCountChars;
33+
public int dwFillAttribute;
34+
public int dwFlags;
35+
public short wShowWindow;
36+
public short cbReserved2;
37+
public nint lpReserved2;
38+
public nint hStdInput;
39+
public nint hStdOutput;
40+
public nint hStdError;
4141
}
4242

4343
[StructLayout(LayoutKind.Sequential)]
4444
internal struct PROCESS_INFORMATION
4545
{
46-
public IntPtr hProcess;
47-
public IntPtr hThread;
46+
public nint hProcess;
47+
public nint hThread;
4848
public int dwProcessId;
4949
public int dwThreadId;
5050
}
@@ -53,34 +53,34 @@ internal struct PROCESS_INFORMATION
5353
internal struct SECURITY_ATTRIBUTES
5454
{
5555
public int nLength;
56-
public IntPtr lpSecurityDescriptor;
56+
public nint lpSecurityDescriptor;
5757
public int bInheritHandle;
5858
}
5959

6060
[DllImport("kernel32.dll", SetLastError = true)]
6161
[return: MarshalAs(UnmanagedType.Bool)]
6262
internal static extern bool InitializeProcThreadAttributeList(
63-
IntPtr lpAttributeList, int dwAttributeCount, int dwFlags, ref IntPtr lpSize);
63+
nint lpAttributeList, int dwAttributeCount, int dwFlags, ref nint lpSize);
6464

6565
[DllImport("kernel32.dll", SetLastError = true)]
6666
[return: MarshalAs(UnmanagedType.Bool)]
6767
internal static extern bool UpdateProcThreadAttribute(
68-
IntPtr lpAttributeList, uint dwFlags, IntPtr attribute, IntPtr lpValue,
69-
IntPtr cbSize, IntPtr lpPreviousValue, IntPtr lpReturnSize);
68+
nint lpAttributeList, uint dwFlags, nint attribute, nint lpValue,
69+
nint cbSize, nint lpPreviousValue, nint lpReturnSize);
7070

7171
[DllImport("kernel32.dll")]
7272
[return: MarshalAs(UnmanagedType.Bool)]
7373
internal static extern bool CreateProcess(
7474
string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes,
7575
ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags,
76-
IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo,
76+
nint lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo,
7777
out PROCESS_INFORMATION lpProcessInformation);
7878

7979
[DllImport("kernel32.dll", SetLastError = true)]
8080
[return: MarshalAs(UnmanagedType.Bool)]
81-
internal static extern bool DeleteProcThreadAttributeList(IntPtr lpAttributeList);
81+
internal static extern bool DeleteProcThreadAttributeList(nint lpAttributeList);
8282

8383
[DllImport("kernel32.dll", SetLastError = true)]
84-
internal static extern bool CloseHandle(IntPtr hObject);
84+
internal static extern bool CloseHandle(nint hObject);
8585
}
8686
}

src/Files.App/Terminal/ConPTY/Native/PseudoConsoleApi.cs renamed to src/Files.App/Utils/Terminal/ConPTY/Native/PseudoConsoleApi.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System;
33
using System.Runtime.InteropServices;
44

5-
namespace Files.App.Terminal.Native
5+
namespace Files.App.Utils.Terminal.ConPTY
66
{
77
/// <summary>
88
/// PInvoke signatures for win32 pseudo console api
@@ -19,15 +19,15 @@ internal struct COORD
1919
}
2020

2121
[DllImport("kernel32.dll", SetLastError = true)]
22-
internal static extern int CreatePseudoConsole(COORD size, SafeFileHandle hInput, SafeFileHandle hOutput, uint dwFlags, out IntPtr phPC);
22+
internal static extern int CreatePseudoConsole(COORD size, SafeFileHandle hInput, SafeFileHandle hOutput, uint dwFlags, out nint phPC);
2323

2424
[DllImport("kernel32.dll", SetLastError = true)]
25-
internal static extern int ResizePseudoConsole(IntPtr hPC, COORD size);
25+
internal static extern int ResizePseudoConsole(nint hPC, COORD size);
2626

2727
[DllImport("kernel32.dll", SetLastError = true)]
28-
internal static extern int ClosePseudoConsole(IntPtr hPC);
28+
internal static extern int ClosePseudoConsole(nint hPC);
2929

3030
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
31-
internal static extern bool CreatePipe(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, IntPtr lpPipeAttributes, int nSize);
31+
internal static extern bool CreatePipe(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, nint lpPipeAttributes, int nSize);
3232
}
3333
}

src/Files.App/Terminal/ConPTY/Processes/Process.cs renamed to src/Files.App/Utils/Terminal/ConPTY/Processes/Process.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Runtime.InteropServices;
3-
using static Files.App.Terminal.Native.ProcessApi;
3+
using static Files.App.Utils.Terminal.ConPTY.ProcessApi;
44

5-
namespace Files.App.Terminal
5+
namespace Files.App.Utils.Terminal.ConPTY
66
{
77
/// <summary>
88
/// Represents an instance of a process.
@@ -34,18 +34,18 @@ void Dispose(bool disposing)
3434
// dispose unmanaged state
3535

3636
// Free the attribute list
37-
if (StartupInfo.lpAttributeList != IntPtr.Zero)
37+
if (StartupInfo.lpAttributeList != nint.Zero)
3838
{
3939
DeleteProcThreadAttributeList(StartupInfo.lpAttributeList);
4040
Marshal.FreeHGlobal(StartupInfo.lpAttributeList);
4141
}
4242

4343
// Close process and thread handles
44-
if (ProcessInfo.hProcess != IntPtr.Zero)
44+
if (ProcessInfo.hProcess != nint.Zero)
4545
{
4646
CloseHandle(ProcessInfo.hProcess);
4747
}
48-
if (ProcessInfo.hThread != IntPtr.Zero)
48+
if (ProcessInfo.hThread != nint.Zero)
4949
{
5050
CloseHandle(ProcessInfo.hThread);
5151
}

src/Files.App/Terminal/ConPTY/Processes/ProcessFactory.cs renamed to src/Files.App/Utils/Terminal/ConPTY/Processes/ProcessFactory.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Runtime.InteropServices;
3-
using static Files.App.Terminal.Native.ProcessApi;
3+
using static Files.App.Utils.Terminal.ConPTY.ProcessApi;
44

5-
namespace Files.App.Terminal
5+
namespace Files.App.Utils.Terminal.ConPTY
66
{
77
/// <summary>
88
/// Support for starting and configuring processes.
@@ -15,25 +15,25 @@ static class ProcessFactory
1515
/// <summary>
1616
/// Start and configure a process. The return value represents the process and should be disposed.
1717
/// </summary>
18-
internal static Process Start(string command, string directory, IntPtr attributes, IntPtr hPC)
18+
internal static Process Start(string command, string directory, nint attributes, nint hPC)
1919
{
2020
var startupInfo = ConfigureProcessThread(hPC, attributes);
2121
var processInfo = RunProcess(ref startupInfo, command, directory);
2222
return new Process(startupInfo, processInfo);
2323
}
2424

25-
private static STARTUPINFOEX ConfigureProcessThread(IntPtr hPC, IntPtr attributes)
25+
private static STARTUPINFOEX ConfigureProcessThread(nint hPC, nint attributes)
2626
{
2727
// this method implements the behavior described in https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#preparing-for-creation-of-the-child-process
2828

29-
var lpSize = IntPtr.Zero;
29+
var lpSize = nint.Zero;
3030
var success = InitializeProcThreadAttributeList(
31-
lpAttributeList: IntPtr.Zero,
31+
lpAttributeList: nint.Zero,
3232
dwAttributeCount: 1,
3333
dwFlags: 0,
3434
lpSize: ref lpSize
3535
);
36-
if (success || lpSize == IntPtr.Zero) // we're not expecting `success` here, we just want to get the calculated lpSize
36+
if (success || lpSize == nint.Zero) // we're not expecting `success` here, we just want to get the calculated lpSize
3737
{
3838
throw new InvalidOperationException("Could not calculate the number of bytes for the attribute list. " + Marshal.GetLastWin32Error());
3939
}
@@ -58,9 +58,9 @@ private static STARTUPINFOEX ConfigureProcessThread(IntPtr hPC, IntPtr attribute
5858
dwFlags: 0,
5959
attribute: attributes,
6060
lpValue: hPC,
61-
cbSize: (IntPtr)IntPtr.Size,
62-
lpPreviousValue: IntPtr.Zero,
63-
lpReturnSize: IntPtr.Zero
61+
cbSize: nint.Size,
62+
lpPreviousValue: nint.Zero,
63+
lpReturnSize: nint.Zero
6464
);
6565
if (!success)
6666
{
@@ -82,7 +82,7 @@ private static PROCESS_INFORMATION RunProcess(ref STARTUPINFOEX sInfoEx, string
8282
lpThreadAttributes: ref tSec,
8383
bInheritHandles: false,
8484
dwCreationFlags: EXTENDED_STARTUPINFO_PRESENT,
85-
lpEnvironment: IntPtr.Zero,
85+
lpEnvironment: nint.Zero,
8686
lpCurrentDirectory: directory,
8787
lpStartupInfo: ref sInfoEx,
8888
lpProcessInformation: out PROCESS_INFORMATION pInfo

src/Files.App/Terminal/ConPTY/PseudoConsole.cs renamed to src/Files.App/Utils/Terminal/ConPTY/PseudoConsole.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
using Microsoft.Win32.SafeHandles;
22
using System;
3-
using static Files.App.Terminal.Native.PseudoConsoleApi;
3+
using static Files.App.Utils.Terminal.ConPTY.PseudoConsoleApi;
44

5-
namespace Files.App.Terminal
5+
namespace Files.App.Utils.Terminal.ConPTY
66
{
77
/// <summary>
88
/// Utility functions around the new Pseudo Console APIs
99
/// </summary>
1010
internal sealed class PseudoConsole : IDisposable
1111
{
12-
public static readonly IntPtr PseudoConsoleThreadAttribute = (IntPtr)PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE;
12+
public static readonly nint PseudoConsoleThreadAttribute = (nint)PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE;
1313

14-
public IntPtr Handle { get; }
14+
public nint Handle { get; }
1515

16-
private PseudoConsole(IntPtr handle)
16+
private PseudoConsole(nint handle)
1717
{
18-
this.Handle = handle;
18+
Handle = handle;
1919
}
2020

2121
internal static PseudoConsole Create(SafeFileHandle inputReadSide, SafeFileHandle outputWriteSide, int width, int height)
2222
{
2323
var createResult = CreatePseudoConsole(
2424
new COORD { X = (short)width, Y = (short)height },
2525
inputReadSide, outputWriteSide,
26-
0, out IntPtr hPC);
27-
if(createResult != 0)
26+
0, out nint hPC);
27+
if (createResult != 0)
2828
{
2929
throw new InvalidOperationException("Could not create pseudo console. Error Code " + createResult);
3030
}

src/Files.App/Terminal/ConPTY/PseudoConsolePipe.cs renamed to src/Files.App/Utils/Terminal/ConPTY/PseudoConsolePipe.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Microsoft.Win32.SafeHandles;
22
using System;
3-
using static Files.App.Terminal.Native.PseudoConsoleApi;
3+
using static Files.App.Utils.Terminal.ConPTY.PseudoConsoleApi;
44

5-
namespace Files.App.Terminal
5+
namespace Files.App.Utils.Terminal.ConPTY
66
{
77
/// <summary>
88
/// A pipe used to talk to the pseudoconsole, as described in:
@@ -18,7 +18,7 @@ internal sealed class PseudoConsolePipe : IDisposable
1818

1919
public PseudoConsolePipe()
2020
{
21-
if (!CreatePipe(out ReadSide, out WriteSide, IntPtr.Zero, 0))
21+
if (!CreatePipe(out ReadSide, out WriteSide, nint.Zero, 0))
2222
{
2323
throw new InvalidOperationException("failed to create pipe");
2424
}

src/Files.App/Terminal/ConPTY/Terminal.cs renamed to src/Files.App/Utils/Terminal/ConPTY/Terminal.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using System.IO;
33
using System.Runtime.InteropServices;
44
using Vanara.PInvoke;
5-
using static Files.App.Terminal.Native.ConsoleApi;
5+
using static Files.App.Utils.Terminal.ConPTY.ConsoleApi;
66

7-
namespace Files.App.Terminal
7+
namespace Files.App.Utils.Terminal.ConPTY
88
{
99
/// <summary>
1010
/// The UI of the terminal. It's just a normal console window, but we're managing the input/output.
@@ -34,7 +34,7 @@ public Terminal()
3434
{
3535
// By default, UI applications don't have a console associated with them.
3636
// So first, we check to see if this process has a console.
37-
if (GetConsoleWindow() == IntPtr.Zero)
37+
if (GetConsoleWindow() == nint.Zero)
3838
{
3939
// If it doesn't ask Windows to allocate one to it for us.
4040
bool createConsoleSuccess = AllocConsole();
@@ -141,9 +141,9 @@ private static SafeFileHandle GetConsoleScreenBuffer()
141141
null,
142142
FileMode.Open,
143143
FileFlagsAndAttributes.FILE_ATTRIBUTE_NORMAL,
144-
IntPtr.Zero);
144+
nint.Zero);
145145

146-
if (file == new IntPtr(-1))
146+
if (file == new nint(-1))
147147
{
148148
throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not get console screen buffer.");
149149
}

0 commit comments

Comments
 (0)