/* ----------------------------------------------------------------- */ /// /// ResolveDependencies /// /// <summary> /// Resolves dependencies of the specified configuration. /// </summary> /// /* ----------------------------------------------------------------- */ private void ResolveDependencies(DeviceConfig dest) => new DeviceConfigResolver( dest, Printer.GetElements(), PrinterDriver.GetElements(), PortMonitor.GetElements() ).Invoke();
/* ----------------------------------------------------------------- */ /// /// Copy /// /// <summary> /// Copies resources from the specified directory. /// </summary> /// /// <param name="src">Printer driver object.</param> /// <param name="user">User resource directory.</param> /// <param name="io">I/O handler.</param> /// /// <remarks> /// データファイル (PPD) は、常にユーザが指定したディレクトリから /// コピーします。 /// </remarks> /// /* ----------------------------------------------------------------- */ public static void Copy(this PrinterDriver src, string user, IO io) { var system = src.GetRepository(io); var from = system.HasValue() && io.Exists(system) ? system : user; var to = src.TargetDirectory; io.Copy(src.Data, user, to); // see remarks. io.Copy(src.FileName, from, to); io.Copy(src.Config, from, to); io.Copy(src.Help, from, to); foreach (var f in src.Dependencies) { io.Copy(f, from, to); } }
/* ----------------------------------------------------------------- */ /// /// GetRepository /// /// <summary> /// Gets the directory path from the specified configuration. /// </summary> /// /// <param name="src">Printer driver object.</param> /// <param name="io">I/O handler.</param> /// /// <returns>Path of the repository</returns> /// /* ----------------------------------------------------------------- */ public static string GetRepository(this PrinterDriver src, IO io) { if (!src.Repository.HasValue()) { return(string.Empty); } var root = io.Combine(Environment.SpecialFolder.System.GetName(), @"DriverStore\FileRepository"); var arch = IntPtr.Size == 4 ? "x86" : "amd64"; var sub = IntPtr.Size == 4 ? "i386" : "amd64"; var dest = io.GetDirectories(root, $"{src.Repository}.inf_{arch}*") .SelectMany(e => new[] { io.Combine(e, sub), e }) .Where(e => { var ok = io.Exists(e) && io.GetFiles(e, "*.dll").Length > 0; src.LogDebug($"{e} ({ok})"); return(ok); }) .OrderByDescending(e => io.Get(e).LastWriteTime) .FirstOrDefault(); return(dest.HasValue() ? dest : string.Empty); }
/* ----------------------------------------------------------------- */ /// /// Convert /// /// <summary> /// Creates a collection of the printer drivers from the specified /// configuration. /// </summary> /// /// <param name="src">Printer driver configuration.</param> /// /// <returns>Collection of printer drivers.</returns> /// /* ----------------------------------------------------------------- */ public static IEnumerable <PrinterDriver> Convert(this IEnumerable <PrinterDriverConfig> src) => src.Convert(PrinterDriver.GetElements());
/* ----------------------------------------------------------------- */ /// /// Exists /// /// <summary> /// Determines whether the specified filename exists in the /// specified directory. /// </summary> /// /// <param name="src">Printer driver object.</param> /// <param name="filename">Target filename.</param> /// <param name="io">I/O handler.</param> /// /// <returns>true for exists; otherwise false.</returns> /// /* ----------------------------------------------------------------- */ internal static bool Exists(this PrinterDriver src, string filename, IO io) => io.Exists(io.Combine(src.TargetDirectory, filename));