[VMware Launcher 2.0.9.5]

- Refactored code.
- Fixed bug: "#1 Welcome message shows despite VMware not being installed"
This commit is contained in:
2021-03-26 20:20:46 +00:00
parent 1cbdbccf77
commit 6d7fec03b4
10 changed files with 79 additions and 83 deletions
Binary file not shown.
+10 -7
View File
@@ -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
+13
View File
@@ -0,0 +1,13 @@
using System;
namespace VMwareLauncher
{
public static class ApplicationControl
{
public static void Shutdown(int exitCode)
{
Startup.trayIcon.Destroy();
Environment.Exit(exitCode);
}
}
}
+12 -14
View File
@@ -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);
}
}
}
}
}
+6 -6
View File
@@ -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()
+3 -3
View File
@@ -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")]
+8 -6
View File
@@ -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<string> DefaultVmwareServices = new List<string> { "VMnetDHCP", "VMUSBArbService", "VMware NAT Service", "VMwareHostd", "VMAuthdService" }; //Array of services to close
public List<string> ServiceList { get; set; }
public static readonly List<string> VMwareServiceList = new List<string> //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)
+11 -29
View File
@@ -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);
}
}
}
+14 -17
View File
@@ -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();
}
/// <summary>
+2 -1
View File
@@ -15,7 +15,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@@ -64,6 +64,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ApplicationControl.cs" />
<Compile Include="CheckDependencies.cs" />
<Compile Include="ProcessControl.cs" />
<Compile Include="Properties\Resources.Designer.cs">