public Package ScanPackageDirectory(string directory, bool checkCertificates) { try { var headerPath = Path.Combine(directory, "pkg.json"); Package discoveredPkg; // get the package name and the installed version if (PathHelper.IsValidPath(headerPath)) { discoveredPkg = Package.FromJson(headerPath, AsLogger()); if (discoveredPkg == null) { throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.MalformedHeaderPackage, headerPath)); } } else { throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.NoHeaderPackage, headerPath)); } // prevent loading unsigned packages if the certificates are required on package dlls if (checkCertificates) { CheckPackageNodeLibraryCertificates(directory, discoveredPkg); } // prevent duplicates if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name)) { this.Add(discoveredPkg); return(discoveredPkg); // success } throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); } catch (Exception e) { Log(String.Format(Properties.Resources.ExceptionEncountered, directory), WarningLevel.Error); Log(e); } return(null); }
public Package ScanPackageDirectory(string directory) { try { var headerPath = Path.Combine(directory, "pkg.json"); Package discoveredPkg; // get the package name and the installed version if (File.Exists(headerPath)) { discoveredPkg = Package.FromJson(headerPath, AsLogger()); if (discoveredPkg == null) { throw new Exception(String.Format(Properties.Resources.MalformedHeaderPackage, headerPath)); } } else { throw new Exception(String.Format(Properties.Resources.NoHeaderPackage, headerPath)); } // prevent duplicates if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name)) { this.Add(discoveredPkg); return(discoveredPkg); // success } throw new Exception(String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); } catch (Exception e) { Log(String.Format(Properties.Resources.ExceptionEncountered, this.RootPackagesDirectory), WarningLevel.Error); Log(e); } return(null); }