public GhostscriptVersionInfo(string customDllPath) { _version = new Version(); _dllPath = customDllPath; _libPath = string.Empty; _licenseType = GhostscriptLicense.GPL; }
/// <summary> /// Initializes a new instance of the Ghostscript.NET.GhostscriptVersionInfo class. /// </summary> /// <param name="version">Ghostscript version.</param> /// <param name="dllPath">Ghostscript native library path.</param> /// <param name="libPath">Ghostscript lib path.</param> /// <param name="licenseType">Ghostscript license type.</param> public GhostscriptVersionInfo(Version version, string dllPath, string libPath, GhostscriptLicense licenseType) { _version = version; _dllPath = dllPath; _libPath = libPath; _licenseType = licenseType; }
/// <summary> /// Gets lastest installed Ghostscript version. /// </summary> /// <param name="licenseType">L</param> /// <param name="licensePriority">If there are a same verio</param> /// <returns>GhostscriptVersionInfo object of the last installed Ghostscript version based on priority license.</returns> public static GhostscriptVersionInfo GetLastInstalledVersion(GhostscriptLicense licenseType, GhostscriptLicense licensePriority) { List <GhostscriptVersionInfo> gsVerList = GetInstalledVersions(licenseType); int versionsCount = gsVerList.Count; if (versionsCount == 1) { return(gsVerList[0]); } else if (versionsCount > 1) { GhostscriptVersionInfo lastGsVer = gsVerList[0]; for (int index = 1; index < versionsCount; index++) { GhostscriptVersionInfo gs = gsVerList[index]; if (gs.Version > lastGsVer.Version) { if (gs.LicenseType == licensePriority) { lastGsVer = gsVerList[index]; } } } return(lastGsVer); } return(null); }
/// <summary> /// Gets top installed Ghostscript version. /// </summary> /// <param name="licenseType">Serch for the specific Ghostscript version based on the Ghostscript license.</param> /// <param name="licensePriority">If there are both license types installed, which one should have the prilorty.</param> /// <returns>GhostscriptVersionInfo object of the last installed Ghostscript version based on priority license.</returns> public static GhostscriptVersionInfo GetLastInstalledVersion(GhostscriptLicense licenseType, GhostscriptLicense licensePriority) { // gets installed Ghostscript versions list List <GhostscriptVersionInfo> gsVerList = GetInstalledVersions(licenseType); // cache the list count int versionsCount = gsVerList.Count; // check if there is only 1 version of the Ghostscript installed // if yes, then we don't need a deeper search if (versionsCount == 1) { // simply return the first one return(gsVerList[0]); } else if (versionsCount > 1) { // get the first one GhostscriptVersionInfo lastGsVer = gsVerList[0]; // loop through all others for (int index = 1; index < versionsCount; index++) { // get one from the list GhostscriptVersionInfo gs = gsVerList[index]; // compare if it's a newer version if (gs.Version > lastGsVer.Version) { // check if this version has license with larger priority if (gs.LicenseType == licensePriority) { // set top version lastGsVer = gsVerList[index]; } } } // return top GhostscriptVersionInfo instance return(lastGsVer); } // inform the user that we didn't find Ghostscript installed on this system throw new GhostscriptLibraryNotInstalledException(); }
/// <summary> /// Gets installed Ghostscript versions list. /// </summary> /// <returns>A GhostscriptVersionInfo list of the Ghostscript installations found on the local system.</returns> public static List <GhostscriptVersionInfo> GetInstalledVersions(GhostscriptLicense licenseType) { // create a search list instance List <GhostscriptLicense> licenses = new List <GhostscriptLicense>(); // check if we need to search for AFPL installations if ((licenseType & GhostscriptLicense.AFPL) == GhostscriptLicense.AFPL) { // yep, add this license in the search list licenses.Add(GhostscriptLicense.AFPL); } // check if we need to search for GPL installations if ((licenseType & GhostscriptLicense.GPL) == GhostscriptLicense.GPL) { // yep, add this license in the search list licenses.Add(GhostscriptLicense.GPL); } // check if we need to search for GPL installations if ((licenseType & GhostscriptLicense.Artifex) == GhostscriptLicense.Artifex) { // yep, add this license in the search list licenses.Add(GhostscriptLicense.Artifex); } // create new return list instance List <GhostscriptVersionInfo> versions = new List <GhostscriptVersionInfo>(); // loop through the search list //foreach (GhostscriptLicense license in licenses) //{ // RegistryKey hklm = null; // RegistryKey rkGs = null; // // check if we are running in 64 bit process // if (Environment.Is64BitProcess) // { // // user 64 bit registry key // hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); // } // else // { // // user 32 bit registry key // hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); // } // // check the license type // if (license == GhostscriptLicense.AFPL) // { // // get the AFPL registry key // rkGs = hklm.OpenSubKey("SOFTWARE\\AFPL Ghostscript\\"); // } // else if (license == GhostscriptLicense.GPL) // { // // get the GPL registry key // rkGs = hklm.OpenSubKey("SOFTWARE\\GPL Ghostscript\\"); // } // else if (license == GhostscriptLicense.Artifex) // { // rkGs = hklm.OpenSubKey("SOFTWARE\\Artifex Ghostscript\\"); // } // // check if we found the registry key // if (rkGs != null) // { // // get this registry key sub-keys // // each sub-key represents a version of the installed Ghostscript library // string[] subkeys = rkGs.GetSubKeyNames(); // // loop through all sub-keys // for (int index = 0; index < subkeys.Length; index++) // { // // get the subkey / Ghostscript library version // string versionKey = subkeys[index]; // try // { // // open the sub key // RegistryKey rkVer = rkGs.OpenSubKey(versionKey); // // get the Ghostscript native library path // string gsdll = rkVer.GetValue("GS_DLL", string.Empty) as string; // // get the Ghostscript lib path // string gslib = rkVer.GetValue("GS_LIB", string.Empty) as string; // bool compatibile = false; // // check if we can use this dll in this process // if (System.Environment.Is64BitProcess && gsdll.Contains("gsdll64.dll")) // { // // both process and dll are 64 bit, we can use it // compatibile = true; // } // else if (!System.Environment.Is64BitProcess && gsdll.Contains("gsdll32.dll")) // { // // both process and dll are 32 bit, we can use it // compatibile = true; // } // if (compatibile) // { // // put this version in the return list // versions.Add(new GhostscriptVersionInfo(new Version(versionKey), gsdll, gslib, license)); // } // } // catch { } // } // } //} return(versions); }
/// <summary> /// Gets top installed Ghostscript version. /// </summary> /// <param name="licenseType">Serch for the specific Ghostscript version based on the Ghostscript license.</param> /// <param name="licensePriority">If there are both license types installed, which one should have the prilorty.</param> /// <returns>GhostscriptVersionInfo object of the last installed Ghostscript version based on priority license.</returns> public static GhostscriptVersionInfo GetLastInstalledVersion(GhostscriptLicense licenseType, GhostscriptLicense licensePriority) { // gets installed Ghostscript versions list List<GhostscriptVersionInfo> gsVerList = GetInstalledVersions(licenseType); // cache the list count int versionsCount = gsVerList.Count; // check if there is only 1 version of the Ghostscript installed // if yes, then we don't need a deeper search if (versionsCount == 1) { // simply return the first one return gsVerList[0]; } else if (versionsCount > 1) { // get the first one GhostscriptVersionInfo lastGsVer = gsVerList[0]; // loop through all others for (int index = 1; index < versionsCount; index++) { // get one from the list GhostscriptVersionInfo gs = gsVerList[index]; // compare if it's a newer version if (gs.Version > lastGsVer.Version) { // check if this version has license with larger priority if (gs.LicenseType == licensePriority) { // set top version lastGsVer = gsVerList[index]; } } } // return top GhostscriptVersionInfo instance return lastGsVer; } // inform the user that we didn't find Ghostscript installed on this system throw new GhostscriptLibraryNotInstalledException(); }
/// <summary> /// Gets installed Ghostscript versions list. /// </summary> /// <returns>A GhostscriptVersionInfo list of the Ghostscript installations found on the local system.</returns> public static List<GhostscriptVersionInfo> GetInstalledVersions(GhostscriptLicense licenseType) { // create a search list instance List<GhostscriptLicense> licenses = new List<GhostscriptLicense>(); // check if we need to search for AFPL installations if ((licenseType & GhostscriptLicense.AFPL) == GhostscriptLicense.AFPL) { // yep, add this license in the search list licenses.Add(GhostscriptLicense.AFPL); } // check if we need to search for GPL installations if ((licenseType & GhostscriptLicense.GPL) == GhostscriptLicense.GPL) { // yep, add this license in the search list licenses.Add(GhostscriptLicense.GPL); } // check if we need to search for GPL installations if ((licenseType & GhostscriptLicense.Artifex) == GhostscriptLicense.Artifex) { // yep, add this license in the search list licenses.Add(GhostscriptLicense.Artifex); } // create new return list instance List<GhostscriptVersionInfo> versions = new List<GhostscriptVersionInfo>(); // loop through the search list foreach (GhostscriptLicense license in licenses) { RegistryKey hklm = null; RegistryKey rkGs = null; // check if we are running in 64 bit process if (Environment.Is64BitProcess) { // user 64 bit registry key hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); } else { // user 32 bit registry key hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); } // check the license type if (license == GhostscriptLicense.AFPL) { // get the AFPL registry key rkGs = hklm.OpenSubKey("SOFTWARE\\AFPL Ghostscript\\"); } else if (license == GhostscriptLicense.GPL) { // get the GPL registry key rkGs = hklm.OpenSubKey("SOFTWARE\\GPL Ghostscript\\"); } else if (license == GhostscriptLicense.Artifex) { rkGs = hklm.OpenSubKey("SOFTWARE\\Artifex Ghostscript\\"); } // check if we found the registry key if (rkGs != null) { // get this registry key sub-keys // each sub-key represents a version of the installed Ghostscript library string[] subkeys = rkGs.GetSubKeyNames(); // loop through all sub-keys for (int index = 0; index < subkeys.Length; index++) { // get the subkey / Ghostscript library version string versionKey = subkeys[index]; try { // open the sub key RegistryKey rkVer = rkGs.OpenSubKey(versionKey); // get the Ghostscript native library path string gsdll = rkVer.GetValue("GS_DLL", string.Empty) as string; // get the Ghostscript lib path string gslib = rkVer.GetValue("GS_LIB", string.Empty) as string; bool compatibile = false; // check if we can use this dll in this process if (System.Environment.Is64BitProcess && gsdll.Contains("gsdll64.dll")) { // both process and dll are 64 bit, we can use it compatibile = true; } else if (!System.Environment.Is64BitProcess && gsdll.Contains("gsdll32.dll")) { // both process and dll are 32 bit, we can use it compatibile = true; } if (compatibile) { // put this version in the return list versions.Add(new GhostscriptVersionInfo(new Version(versionKey), gsdll, gslib, license)); } } catch { } } } } return versions; }
/// <summary> /// Gets lastest installed Ghostscript version. /// </summary> /// <param name="licenseType">L</param> /// <param name="licensePriority">If there are a same verio</param> /// <returns>GhostscriptVersionInfo object of the last installed Ghostscript version based on priority license.</returns> public static GhostscriptVersionInfo GetLastInstalledVersion(GhostscriptLicense licenseType, GhostscriptLicense licensePriority) { List<GhostscriptVersionInfo> gsVerList = GetInstalledVersions(licenseType); int versionsCount = gsVerList.Count; if (versionsCount == 1) { return gsVerList[0]; } else if (versionsCount > 1) { GhostscriptVersionInfo lastGsVer = gsVerList[0]; for (int index = 1; index < versionsCount; index++) { GhostscriptVersionInfo gs = gsVerList[index]; if (gs.Version > lastGsVer.Version) { if (gs.LicenseType == licensePriority) { lastGsVer = gsVerList[index]; } } } return lastGsVer; } throw new GhostscriptLibraryNotInstalledException(); }
/// <summary> /// Gets installed Ghostscript versions list. /// </summary> /// <returns>A GhostscriptVersionInfo list of the installed Ghostscript versions.</returns> public static List<GhostscriptVersionInfo> GetInstalledVersions(GhostscriptLicense licenseType) { List<GhostscriptLicense> licenses = new List<GhostscriptLicense>(); if ((licenseType & GhostscriptLicense.AFPL) == GhostscriptLicense.AFPL) { licenses.Add(GhostscriptLicense.AFPL); } if ((licenseType & GhostscriptLicense.GPL) == GhostscriptLicense.GPL) { licenses.Add(GhostscriptLicense.GPL); } List<GhostscriptVersionInfo> versions = new List<GhostscriptVersionInfo>(); foreach (GhostscriptLicense license in licenses) { RegistryKey hklm = null; RegistryKey rkGs = null; if (Environment.Is64BitProcess) { hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); } else { hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); } if (license == GhostscriptLicense.AFPL) { rkGs = hklm.OpenSubKey("SOFTWARE\\AFPL Ghostscript\\"); } else if (license == GhostscriptLicense.GPL) { rkGs = hklm.OpenSubKey("SOFTWARE\\GPL Ghostscript\\"); } if (rkGs != null) { string[] subkeys = rkGs.GetSubKeyNames(); for (int index = 0; index < subkeys.Length; index++) { string versionKey = subkeys[index]; try { RegistryKey rkVer = rkGs.OpenSubKey(versionKey); string gsdll = rkVer.GetValue("GS_DLL", string.Empty) as string; string gslib = rkVer.GetValue("GS_LIB", string.Empty) as string; bool compatibile = false; if (System.Environment.Is64BitProcess && gsdll.Contains("gsdll64.dll")) { compatibile = true; } else if (!System.Environment.Is64BitProcess && gsdll.Contains("gsdll32.dll")) { compatibile = true; } if (compatibile) { versions.Add(new GhostscriptVersionInfo(new Version(versionKey), gsdll, gslib, license)); } } catch { } } } } return versions; }
/// <summary> /// Gets installed Ghostscript versions list. /// </summary> /// <returns>A GhostscriptVersionInfo list of the installed Ghostscript versions.</returns> public static List <GhostscriptVersionInfo> GetInstalledVersions(GhostscriptLicense licenseType) { List <GhostscriptLicense> licenses = new List <GhostscriptLicense>(); if ((licenseType & GhostscriptLicense.AFPL) == GhostscriptLicense.AFPL) { licenses.Add(GhostscriptLicense.AFPL); } if ((licenseType & GhostscriptLicense.GPL) == GhostscriptLicense.GPL) { licenses.Add(GhostscriptLicense.GPL); } List <GhostscriptVersionInfo> versions = new List <GhostscriptVersionInfo>(); foreach (GhostscriptLicense license in licenses) { RegistryKey rkGs = null; if (license == GhostscriptLicense.AFPL) { rkGs = Registry.LocalMachine.OpenSubKey("SOFTWARE\\AFPL Ghostscript\\"); } else if (license == GhostscriptLicense.GPL) { rkGs = Registry.LocalMachine.OpenSubKey("SOFTWARE\\GPL Ghostscript\\"); } if (rkGs != null) { string[] subkeys = rkGs.GetSubKeyNames(); for (int index = 0; index < subkeys.Length; index++) { string versionKey = subkeys[index]; try { RegistryKey rkVer = rkGs.OpenSubKey(versionKey); string gsdll = rkVer.GetValue("GS_DLL", string.Empty) as string; string gslib = rkVer.GetValue("GS_LIB", string.Empty) as string; bool compatibile = false; if (System.Environment.Is64BitProcess && gsdll.Contains("gsdll64.dll")) { compatibile = true; } else if (!System.Environment.Is64BitProcess && gsdll.Contains("gsdll32.dll")) { compatibile = true; } if (compatibile) { versions.Add(new GhostscriptVersionInfo(new Version(versionKey), gsdll, gslib, license)); } } catch { } } } } return(versions); }