Changed project names
This commit is contained in:
parent
b4c4aa4010
commit
a29e57e66d
130 changed files with 501 additions and 504 deletions
82
Installer/AmagnoVirtualPrinter.SetupDriver/Shell.cs
Normal file
82
Installer/AmagnoVirtualPrinter.SetupDriver/Shell.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using AmagnoVirtualPrinter.Logging;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace AmagnoVirtualPrinter.SetupDriver
|
||||
{
|
||||
internal class Shell
|
||||
{
|
||||
private static readonly string WinFolder;
|
||||
|
||||
private static readonly IVirtualPrinterLogger<Shell> Logger = new VirtualPrinterLogger<Shell>();
|
||||
|
||||
static Shell()
|
||||
{
|
||||
WinFolder = Environment.GetEnvironmentVariable("windir") ?? @"C:\Windows";
|
||||
}
|
||||
|
||||
[NotNull]
|
||||
internal static string GetPrintInf()
|
||||
{
|
||||
try
|
||||
{
|
||||
var winFolder = Environment.GetEnvironmentVariable("windir") ?? @"C:\Windows";
|
||||
return Path.Combine(winFolder, "inf", "ntprint.inf");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LogError(exception, "Cannot get PrintInf");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[NotNull]
|
||||
internal static string GetPrintVbs()
|
||||
{
|
||||
try
|
||||
{
|
||||
var printScripts = Path.Combine(WinFolder, "System32", "Printing_Admin_Scripts");
|
||||
return Directory.GetFiles(printScripts, "*port.vbs", SearchOption.AllDirectories).First();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LogError(exception, "Cannot get PrintVbs");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Execute([NotNull]string exe, [NotNull]string args)
|
||||
{
|
||||
if (exe == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(exe));
|
||||
}
|
||||
|
||||
if (args == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine(exe + " " + args);
|
||||
using(var proc = Process.Start(exe, args))
|
||||
{
|
||||
proc?.WaitForExit();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LogError(exception, "Cannot execute {exe} with the following args: {args}", exe, args);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LogError(Exception exception, string message, params object[] args)
|
||||
{
|
||||
Logger.Error(exception, message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue