diff --git a/.vs/VmwareLauncher/v16/.suo b/.vs/VmwareLauncher/v16/.suo new file mode 100644 index 0000000..5acb896 Binary files /dev/null and b/.vs/VmwareLauncher/v16/.suo differ diff --git a/VmwareLauncher.sln b/VmwareLauncher.sln index 7a6dc15..9e62233 100644 --- a/VmwareLauncher.sln +++ b/VmwareLauncher.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2013 for Windows Desktop -VisualStudioVersion = 12.0.21005.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31025.194 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VmwareLauncher", "VmwareLauncher\VmwareLauncher.csproj", "{40A28143-CEF4-41B4-8476-3466822AAAA5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VmwareLauncher", "VmwareLauncher\VmwareLauncher.csproj", "{89E29C69-15E2-43ED-9B98-4BFE9C6D7A2A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,12 +11,15 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {40A28143-CEF4-41B4-8476-3466822AAAA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {40A28143-CEF4-41B4-8476-3466822AAAA5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {40A28143-CEF4-41B4-8476-3466822AAAA5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {40A28143-CEF4-41B4-8476-3466822AAAA5}.Release|Any CPU.Build.0 = Release|Any CPU + {89E29C69-15E2-43ED-9B98-4BFE9C6D7A2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89E29C69-15E2-43ED-9B98-4BFE9C6D7A2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89E29C69-15E2-43ED-9B98-4BFE9C6D7A2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89E29C69-15E2-43ED-9B98-4BFE9C6D7A2A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D877D8E5-8AB4-41AD-A601-EFBD24992B7E} + EndGlobalSection EndGlobal diff --git a/VmwareLauncher/ApplicationControl.cs b/VmwareLauncher/ApplicationControl.cs new file mode 100644 index 0000000..b0e83a4 --- /dev/null +++ b/VmwareLauncher/ApplicationControl.cs @@ -0,0 +1,13 @@ +using System; + +namespace VMwareLauncher +{ + public static class ApplicationControl + { + public static void Shutdown(int exitCode) + { + Startup.trayIcon.Destroy(); + Environment.Exit(exitCode); + } + } +} diff --git a/VmwareLauncher/CheckDependencies.cs b/VmwareLauncher/CheckDependencies.cs index e7da84f..3479e6d 100644 --- a/VmwareLauncher/CheckDependencies.cs +++ b/VmwareLauncher/CheckDependencies.cs @@ -6,7 +6,7 @@ namespace VMwareLauncher { public class CheckDependencies { - private BackgroundWorker performInitialChecks = new BackgroundWorker(); + private readonly BackgroundWorker performInitialChecks = new BackgroundWorker(); public void PerformCheck() { @@ -14,22 +14,20 @@ namespace VMwareLauncher if (!File.Exists(ProcessControl.DefaultVmwarePath)) { MessageHandler.Show(MessageHandler.MessageCode.VmwareNotInstalled); - - ApplicationControl.BlockingErrors = true; + ApplicationControl.Shutdown(-1); } - - // Determine if VML has ever run before. - string vmlPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\VmwareLauncher"; - string vmlKey = "HasBeenSetup"; - - if (Registry.GetValue(vmlPath, vmlKey, null) == null) + else { - Registry.SetValue(vmlPath, vmlKey, 1); - MessageHandler.Show(MessageHandler.MessageCode.WelcomeMessage); - } + // Determine if VML has ever run before. + string vmlPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\VmwareLauncher"; + string vmlKey = "HasBeenSetup"; - // Modify service status to manual. - ApplicationControl.BlockingErrors = Startup.serviceControl.ForceServicesManual(); + if (Registry.GetValue(vmlPath, vmlKey, null) == null) + { + Registry.SetValue(vmlPath, vmlKey, 1); + MessageHandler.Show(MessageHandler.MessageCode.WelcomeMessage); + } + } } } } \ No newline at end of file diff --git a/VmwareLauncher/ProcessControl.cs b/VmwareLauncher/ProcessControl.cs index 4d7815f..1ee9aa0 100644 --- a/VmwareLauncher/ProcessControl.cs +++ b/VmwareLauncher/ProcessControl.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; +using System.Diagnostics; using System.IO; using System.Linq; @@ -10,8 +7,11 @@ namespace VMwareLauncher public class ProcessControl { public readonly static string DefaultVmwareExe = "vmware"; - public readonly static string DefaultVmwarePath = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation", "InstallPath", null) + $"{DefaultVmwareExe}.exe"; - public readonly static string DefaultVmlPath = "vmwarelauncher"; + public readonly static string DefaultVmwarePath = (string) Microsoft.Win32.Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation", + "InstallPath", null) + + $"{DefaultVmwareExe}.exe"; + public readonly static string DefaultVmLauncherPath = "vmwarelauncher"; public string ProcessName { get; set; } public void StartProcess() diff --git a/VmwareLauncher/Properties/AssemblyInfo.cs b/VmwareLauncher/Properties/AssemblyInfo.cs index d3764c0..844a818 100644 --- a/VmwareLauncher/Properties/AssemblyInfo.cs +++ b/VmwareLauncher/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ using System.Windows; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("VMware Launcher")] -[assembly: AssemblyCopyright("Rebound Software - 2017")] +[assembly: AssemblyCopyright("Rebound Software - 2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -51,5 +51,5 @@ using System.Windows; // 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("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.0.9.5")] +[assembly: AssemblyFileVersion("2.0.9.5")] diff --git a/VmwareLauncher/ServiceControl.cs b/VmwareLauncher/ServiceControl.cs index b8b8475..3808388 100644 --- a/VmwareLauncher/ServiceControl.cs +++ b/VmwareLauncher/ServiceControl.cs @@ -1,16 +1,18 @@ using Microsoft.Win32; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VMwareLauncher { public class ServiceControl { - public static readonly List DefaultVmwareServices = new List { "VMnetDHCP", "VMUSBArbService", "VMware NAT Service", "VMwareHostd", "VMAuthdService" }; //Array of services to close - public List ServiceList { get; set; } + public static readonly List VMwareServiceList = new List //Array of services to close + { + "VMnetDHCP", + "VMUSBArbService", + "VMware NAT Service", + "VMwareHostd", + "VMAuthdService" }; public bool ForceServicesManual() { @@ -19,7 +21,7 @@ namespace VMwareLauncher try { - foreach (var service in ServiceList) + foreach (var service in VMwareServiceList) { string currentService = winServices + "\\" + service; if ((int)Registry.GetValue(currentService, "Start", null) != 3) diff --git a/VmwareLauncher/Startup.xaml.cs b/VmwareLauncher/Startup.xaml.cs index 8cfd657..fea2572 100644 --- a/VmwareLauncher/Startup.xaml.cs +++ b/VmwareLauncher/Startup.xaml.cs @@ -1,5 +1,4 @@ -using System; -using System.Windows; +using System.Windows; namespace VMwareLauncher { @@ -17,44 +16,27 @@ namespace VMwareLauncher { InitializeComponent(); - serviceControl.ServiceList = ServiceControl.DefaultVmwareServices; + ProcessControl vmWStationControl = new ProcessControl(); + vmWStationControl.ProcessName = ProcessControl.DefaultVmwarePath; - ProcessControl vmwareControl = new ProcessControl(); - vmwareControl.ProcessName = ProcessControl.DefaultVmwarePath; + ProcessControl vmLauncherControl = new ProcessControl(); + vmLauncherControl.ProcessName = ProcessControl.DefaultVmLauncherPath; - ProcessControl vmlControl = new ProcessControl(); - vmlControl.ProcessName = ProcessControl.DefaultVmlPath; - - // Only continue if no errors have been detected. checkDependencies.PerformCheck(); - if (ApplicationControl.BlockingErrors) - ApplicationControl.Shutdown(); - if (!vmlControl.IsProcessRunning()) + // Modify service status to manual. + serviceControl.ForceServicesManual(); + + if (!vmLauncherControl.IsProcessRunning()) { statusWindow.Show(); trayIcon.Create(); } else { - vmwareControl.StartProcess(); - ApplicationControl.Shutdown(); + vmWStationControl.StartProcess(); + ApplicationControl.Shutdown(0); } } } - - public static class ApplicationControl - { - public static bool BlockingErrors { get; set; } - - public static void Shutdown() - { - Startup.trayIcon.Destroy(); - - if (BlockingErrors) - Environment.Exit(1); - else - Environment.Exit(0); - } - } } diff --git a/VmwareLauncher/StatusWindow.xaml.cs b/VmwareLauncher/StatusWindow.xaml.cs index 76b7a4f..55e34f7 100644 --- a/VmwareLauncher/StatusWindow.xaml.cs +++ b/VmwareLauncher/StatusWindow.xaml.cs @@ -46,7 +46,7 @@ namespace VMwareLauncher { try { - foreach (string service in Startup.serviceControl.ServiceList) + foreach (string service in ServiceControl.VMwareServiceList) { ServiceController sc = new ServiceController(service, Environment.MachineName.ToString()); @@ -56,14 +56,14 @@ namespace VMwareLauncher sc.WaitForStatus(ServiceControllerStatus.Stopped); } } - ApplicationControl.Shutdown(); + ApplicationControl.Shutdown(0); } catch (Exception) { throw; } } private void LoadServices_DoWork(object sender, DoWorkEventArgs e) { - foreach (string service in Startup.serviceControl.ServiceList) + foreach (string service in ServiceControl.VMwareServiceList) { ServiceController sc = new ServiceController(service, Environment.MachineName.ToString()); @@ -85,23 +85,20 @@ namespace VMwareLauncher private void RunProcess_DoWork(object sender, DoWorkEventArgs e) { - if (!ApplicationControl.BlockingErrors) + ProcessControl processControl = new ProcessControl(); + processControl.ProcessName = ProcessControl.DefaultVmwarePath; + processControl.StartProcess(); + + bool isVmwareRunning = true; + while (isVmwareRunning || TrayIcon.KeepLauncherRunning) { - ProcessControl processControl = new ProcessControl(); - processControl.ProcessName = ProcessControl.DefaultVmwarePath; - processControl.StartProcess(); + Thread.Sleep(3000); - bool isVmwareRunning = true; - while (isVmwareRunning || TrayIcon.KeepLauncherRunning) - { - Thread.Sleep(3000); - - isVmwareRunning = false; // Default value. - foreach (Process instance in Process.GetProcessesByName(ProcessControl.DefaultVmwareExe)) - isVmwareRunning = true; - } - stopServices.RunWorkerAsync(); + isVmwareRunning = false; // Default value. + foreach (Process instance in Process.GetProcessesByName(ProcessControl.DefaultVmwareExe)) + isVmwareRunning = true; } + stopServices.RunWorkerAsync(); } /// diff --git a/VmwareLauncher/VmwareLauncher.csproj b/VmwareLauncher/VmwareLauncher.csproj index 1ebd45e..e70099e 100644 --- a/VmwareLauncher/VmwareLauncher.csproj +++ b/VmwareLauncher/VmwareLauncher.csproj @@ -15,7 +15,7 @@ true - AnyCPU + x64 true full false @@ -64,6 +64,7 @@ MSBuild:Compile Designer +