From 59b5306fb716eea97e39ed83865a1dc4a86db187 Mon Sep 17 00:00:00 2001 From: Chip Locke Date: Fri, 28 Sep 2018 23:55:09 -0700 Subject: [PATCH] add goofball wpf app, move some code --- ConsoleBuffer.sln | 8 +- .../ConsoleBuffer}/ConsoleBuffer.csproj | 0 .../ConsoleBuffer}/ConsoleWrapper.cs | 48 +++++-- .../ConsoleBuffer}/NativeMethods.cs | 3 + .../ConsoleBuffer}/Properties/AssemblyInfo.cs | 0 src/condo/App.config | 6 + src/condo/App.xaml | 9 ++ src/condo/App.xaml.cs | 17 +++ src/condo/MainWindow.xaml | 12 ++ src/condo/MainWindow.xaml.cs | 34 +++++ src/condo/Properties/AssemblyInfo.cs | 55 ++++++++ src/condo/Properties/Resources.Designer.cs | 71 +++++++++++ src/condo/Properties/Resources.resx | 117 ++++++++++++++++++ src/condo/Properties/Settings.Designer.cs | 30 +++++ src/condo/Properties/Settings.settings | 7 ++ src/condo/condo.csproj | 104 ++++++++++++++++ 16 files changed, 507 insertions(+), 14 deletions(-) rename {ConsoleBuffer => src/ConsoleBuffer}/ConsoleBuffer.csproj (100%) rename {ConsoleBuffer => src/ConsoleBuffer}/ConsoleWrapper.cs (89%) rename {ConsoleBuffer => src/ConsoleBuffer}/NativeMethods.cs (96%) rename {ConsoleBuffer => src/ConsoleBuffer}/Properties/AssemblyInfo.cs (100%) create mode 100644 src/condo/App.config create mode 100644 src/condo/App.xaml create mode 100644 src/condo/App.xaml.cs create mode 100644 src/condo/MainWindow.xaml create mode 100644 src/condo/MainWindow.xaml.cs create mode 100644 src/condo/Properties/AssemblyInfo.cs create mode 100644 src/condo/Properties/Resources.Designer.cs create mode 100644 src/condo/Properties/Resources.resx create mode 100644 src/condo/Properties/Settings.Designer.cs create mode 100644 src/condo/Properties/Settings.settings create mode 100644 src/condo/condo.csproj diff --git a/ConsoleBuffer.sln b/ConsoleBuffer.sln index bb43cd1..0279023 100644 --- a/ConsoleBuffer.sln +++ b/ConsoleBuffer.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28010.2036 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleBuffer", "ConsoleBuffer\ConsoleBuffer.csproj", "{A16D11B0-4785-434F-8514-ABCC16DDFBFD}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleBuffer", "src\ConsoleBuffer\ConsoleBuffer.csproj", "{A16D11B0-4785-434F-8514-ABCC16DDFBFD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "condo", "src\condo\condo.csproj", "{D890EB09-11B9-41A8-B9A7-C1D159312A32}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {A16D11B0-4785-434F-8514-ABCC16DDFBFD}.Debug|Any CPU.Build.0 = Debug|Any CPU {A16D11B0-4785-434F-8514-ABCC16DDFBFD}.Release|Any CPU.ActiveCfg = Release|Any CPU {A16D11B0-4785-434F-8514-ABCC16DDFBFD}.Release|Any CPU.Build.0 = Release|Any CPU + {D890EB09-11B9-41A8-B9A7-C1D159312A32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D890EB09-11B9-41A8-B9A7-C1D159312A32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D890EB09-11B9-41A8-B9A7-C1D159312A32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D890EB09-11B9-41A8-B9A7-C1D159312A32}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ConsoleBuffer/ConsoleBuffer.csproj b/src/ConsoleBuffer/ConsoleBuffer.csproj similarity index 100% rename from ConsoleBuffer/ConsoleBuffer.csproj rename to src/ConsoleBuffer/ConsoleBuffer.csproj diff --git a/ConsoleBuffer/ConsoleWrapper.cs b/src/ConsoleBuffer/ConsoleWrapper.cs similarity index 89% rename from ConsoleBuffer/ConsoleWrapper.cs rename to src/ConsoleBuffer/ConsoleWrapper.cs index cc859ab..0981752 100644 --- a/ConsoleBuffer/ConsoleWrapper.cs +++ b/src/ConsoleBuffer/ConsoleWrapper.cs @@ -1,14 +1,27 @@ namespace ConsoleBuffer { using System; + using System.ComponentModel; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Win32.SafeHandles; - public sealed class ConsoleWrapper : IDisposable + public sealed class ConsoleWrapper : IDisposable, INotifyPropertyChanged { - public string Contents { get; private set; } + private string contents; + public string Contents + { + get + { + return this.contents; + } + set + { + this.contents = value; + this.OnPropertyChanged(nameof(Contents)); + } + } public string Command { get; private set; } @@ -134,19 +147,34 @@ private static void ThrowForHResult(int hr, string exceptionMessage) throw new InvalidOperationException($"{exceptionMessage}: {Marshal.GetHRForLastWin32Error()}"); } - #region IDisposable Support + #region INotifyPropertyChanged + public event PropertyChangedEventHandler PropertyChanged; + public void OnPropertyChanged(string name) + { + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + #endregion + + #region IDisposable private bool disposed = false; // To detect redundant calls void Dispose(bool disposing) { if (!this.disposed) { - this.disposed = true; + if (disposing) + { + this.readHandle?.Dispose(); + this.readHandle = null; + this.writeHandle?.Dispose(); + this.writeHandle = null; + } - // We want to clear out managed resources first to allow our reader task to die naturally from having the other side of its - // pipe closed. if (this.processInfo.hProcess != IntPtr.Zero) { + // XXX: maybe don't? + NativeMethods.TerminateProcess(this.processInfo.hProcess, uint.MaxValue); + NativeMethods.CloseHandle(this.processInfo.hProcess); this.processInfo.hProcess = IntPtr.Zero; } @@ -169,13 +197,7 @@ void Dispose(bool disposing) this.startupInfo.lpAttributeList = IntPtr.Zero; } - if (disposing) - { - this.readHandle?.Dispose(); - this.readHandle = null; - this.writeHandle?.Dispose(); - this.writeHandle = null; - } + this.disposed = true; } } diff --git a/ConsoleBuffer/NativeMethods.cs b/src/ConsoleBuffer/NativeMethods.cs similarity index 96% rename from ConsoleBuffer/NativeMethods.cs rename to src/ConsoleBuffer/NativeMethods.cs index 8b3a14f..fa79f07 100644 --- a/ConsoleBuffer/NativeMethods.cs +++ b/src/ConsoleBuffer/NativeMethods.cs @@ -78,6 +78,9 @@ internal static extern bool CreateProcess(string lpApplicationName, string lpCom ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool TerminateProcess(IntPtr hProcess, uint exitCode); [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] diff --git a/ConsoleBuffer/Properties/AssemblyInfo.cs b/src/ConsoleBuffer/Properties/AssemblyInfo.cs similarity index 100% rename from ConsoleBuffer/Properties/AssemblyInfo.cs rename to src/ConsoleBuffer/Properties/AssemblyInfo.cs diff --git a/src/condo/App.config b/src/condo/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/src/condo/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/condo/App.xaml b/src/condo/App.xaml new file mode 100644 index 0000000..e415c21 --- /dev/null +++ b/src/condo/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/src/condo/App.xaml.cs b/src/condo/App.xaml.cs new file mode 100644 index 0000000..ca5887f --- /dev/null +++ b/src/condo/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace condo +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/src/condo/MainWindow.xaml b/src/condo/MainWindow.xaml new file mode 100644 index 0000000..87922ea --- /dev/null +++ b/src/condo/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/src/condo/MainWindow.xaml.cs b/src/condo/MainWindow.xaml.cs new file mode 100644 index 0000000..e593666 --- /dev/null +++ b/src/condo/MainWindow.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace condo +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private ConsoleBuffer.ConsoleWrapper consoleWrapper; + + public MainWindow() + { + InitializeComponent(); + + this.consoleWrapper = new ConsoleBuffer.ConsoleWrapper("debian run yes"); + this.stuff.DataContext = this.consoleWrapper; + this.stuff.Text = this.consoleWrapper.Contents; + } + } +} diff --git a/src/condo/Properties/AssemblyInfo.cs b/src/condo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cad628e --- /dev/null +++ b/src/condo/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("condo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("condo")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/condo/Properties/Resources.Designer.cs b/src/condo/Properties/Resources.Designer.cs new file mode 100644 index 0000000..424fd4e --- /dev/null +++ b/src/condo/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace condo.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("condo.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/src/condo/Properties/Resources.resx b/src/condo/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/src/condo/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/condo/Properties/Settings.Designer.cs b/src/condo/Properties/Settings.Designer.cs new file mode 100644 index 0000000..79e8af3 --- /dev/null +++ b/src/condo/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace condo.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/src/condo/Properties/Settings.settings b/src/condo/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/src/condo/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/condo/condo.csproj b/src/condo/condo.csproj new file mode 100644 index 0000000..4392656 --- /dev/null +++ b/src/condo/condo.csproj @@ -0,0 +1,104 @@ + + + + + Debug + AnyCPU + {D890EB09-11B9-41A8-B9A7-C1D159312A32} + WinExe + condo + condo + v4.7.2 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + {a16d11b0-4785-434f-8514-abcc16ddfbfd} + ConsoleBuffer + + + + \ No newline at end of file