Put the InfInstaller back in the project

This commit is contained in:
Lars Brubaker 2014-11-14 11:03:13 -08:00
parent b5d3034a6a
commit d09b8ea3f8
5 changed files with 73 additions and 47 deletions

View file

@ -425,5 +425,9 @@
<Project>{657DBC6D-C3EA-4398-A3FA-DDB73C14F71B}</Project>
<Name>Agg</Name>
</ProjectReference>
<ProjectReference Include="PrinterDriverInstaller\InfInstaller.csproj">
<Project>{990a9ad3-b6a4-407b-9dfc-9c722af7c9b9}</Project>
<Name>InfInstaller</Name>
</ProjectReference>
</ItemGroup>
</Project>

View file

@ -95,6 +95,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudServices", "..\CloudSe
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "agg-sharp", "agg-sharp", "{2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfInstaller", "PrinterDriverInstaller\InfInstaller.csproj", "{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -627,6 +629,26 @@ Global
{6782BF37-8139-4DC6-885E-98D22D1FB258}.Release64|Any CPU.Build.0 = Release|Any CPU
{6782BF37-8139-4DC6-885E-98D22D1FB258}.Release64|x64.ActiveCfg = Release|Any CPU
{6782BF37-8139-4DC6-885E-98D22D1FB258}.Release64|x86.ActiveCfg = Release|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug|x64.ActiveCfg = Debug|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug|x64.Build.0 = Debug|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug|x86.ActiveCfg = Debug|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug64|Any CPU.ActiveCfg = Debug64|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug64|Any CPU.Build.0 = Debug64|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug64|x64.ActiveCfg = Debug64|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug64|x64.Build.0 = Debug64|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Debug64|x86.ActiveCfg = Debug64|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release|Any CPU.Build.0 = Release|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release|x64.ActiveCfg = Release|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release|x64.Build.0 = Release|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release|x86.ActiveCfg = Release|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release64|Any CPU.ActiveCfg = Release64|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release64|Any CPU.Build.0 = Release64|Any CPU
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release64|x64.ActiveCfg = Release64|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release64|x64.Build.0 = Release64|x64
{990A9AD3-B6A4-407B-9DFC-9C722AF7C9B9}.Release64|x86.ActiveCfg = Release64|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -116,53 +116,23 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
if (Path.GetExtension(fileName).ToUpper() == ".INF")
{
var driverInstallerProcess = new Process();
Process driverInstallerProcess = new Process();
// Prepare the process to run
// Enter in the command line arguments, everything you would enter after the executable name itself
driverInstallerProcess.StartInfo.Arguments = "/a {0}".FormatWith(Path.GetFullPath(fileName));
driverInstallerProcess.StartInfo.Arguments = Path.GetFullPath(fileName);
// Enter the executable to run, including the complete path
string printerDriverInstallerExePathAndFileName = Path.Combine(".", "InfInstaller.exe");
driverInstallerProcess.StartInfo.CreateNoWindow = true;
driverInstallerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
string pnpUtilFileName = "PnPUtil.exe";
string pnPUtilPathAndFileName = "";
string[] locationsToTry =
{
"C:/Windows/System32",
"C:/WIndows/winsxs/amd64_microsoft-windows-pnputil_31bf3856ad364e35_6.1.7600.16385_none_5958b438d6388d15",
};
// find the location of pnputil.exe
for(int i=0; i<locationsToTry.Length; i++)
{
if(File.Exists(Path.Combine(locationsToTry[i], pnpUtilFileName)))
{
pnPUtilPathAndFileName = Path.Combine(locationsToTry[i], pnpUtilFileName);
break;
}
}
driverInstallerProcess.StartInfo.FileName = Path.GetFullPath(printerDriverInstallerExePathAndFileName);
driverInstallerProcess.StartInfo.Verb = "runas";
driverInstallerProcess.StartInfo.UseShellExecute = true;
if(pnPUtilPathAndFileName == "")
{
// search for it
List<string> files = new List<string>(Directory.GetFiles("C:/Windows/winsxs", pnpUtilFileName, SearchOption.AllDirectories));
if(files.Count > 0)
{
pnPUtilPathAndFileName = files[0];
}
}
if (pnPUtilPathAndFileName != "")
{
driverInstallerProcess.StartInfo.FileName = pnPUtilPathAndFileName;
driverInstallerProcess.StartInfo.Verb = "runas";
driverInstallerProcess.StartInfo.UseShellExecute = true;
driverInstallerProcess.Start();
driverInstallerProcess.WaitForExit();
// Retrieve the app's exit code
var exitCode = driverInstallerProcess.ExitCode;
}
driverInstallerProcess.Start();
driverInstallerProcess.WaitForExit();
}
else
{

View file

@ -15,20 +15,47 @@ namespace MatterHackers.InfInstaller
{
public class InfInstallerApp
{
[DllImport("Setupapi.dll", EntryPoint = "InstallHinfSection", CallingConvention = CallingConvention.StdCall)]
public static extern void InstallHinfSection(
[In] IntPtr hwnd,
[In] IntPtr ModuleHandle,
[In, MarshalAs(UnmanagedType.LPWStr)] string CmdLineBuffer,
int nCmdShow);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
public InfInstallerApp()
{
Debugger.Launch();
}
public void InstallInfDriverFile(string pathAndDriverToInstall)
{
InstallHinfSection(IntPtr.Zero, IntPtr.Zero, pathAndDriverToInstall, 0);
Process driverInstallerProcess = new Process();
driverInstallerProcess.StartInfo.Arguments = "/a {0}".FormatWith(Path.GetFullPath(pathAndDriverToInstall));
driverInstallerProcess.StartInfo.CreateNoWindow = true;
driverInstallerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
string pnpUtilFileName = "PnPUtil.exe";
string pnPUtilPathAndFileName = Path.Combine("C:/WIndows/winsxs/amd64_microsoft-windows-pnputil_31bf3856ad364e35_6.1.7600.16385_none_5958b438d6388d15", pnpUtilFileName);
// Disable redirection
IntPtr ptr = new IntPtr();
bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
if (isWow64FsRedirectionDisabled)
{
pnPUtilPathAndFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), pnpUtilFileName);
}
driverInstallerProcess.StartInfo.FileName = pnPUtilPathAndFileName;
driverInstallerProcess.StartInfo.Verb = "runas";
driverInstallerProcess.StartInfo.UseShellExecute = true;
driverInstallerProcess.Start();
driverInstallerProcess.WaitForExit();
// Restore redirection
Wow64RevertWow64FsRedirection(ptr);
}
[STAThread]

View file

@ -2849,3 +2849,6 @@ Translated:{0} is not available
English:Invalid printer response
Translated:Invalid printer response
English:Could not find a selected button.
Translated:Could not find a selected button.