internal bool SaveMetadataAfterEditSource(string editedFilePath) { if (!File.Exists(editedFilePath)) { return(true); } using (Stream metadataFileStream = File.OpenRead(editedFilePath)) { try { using (var str = ManifestUtility.ReadManifest(metadataFileStream)) { Manifest manifest = Manifest.ReadFrom(str, true); var newMetadata = new EditablePackageMetadata(manifest.Metadata, _uiServices); PackageMetadata = newMetadata; return(true); } } catch (Exception exception) { bool confirmExit = UIServices.ConfirmCloseEditor( "There is an error in the metadata source.", exception.GetBaseException().Message + Environment.NewLine + Environment.NewLine + "Do you want to cancel your changes and return?"); return(confirmExit); } } }
private bool OpenLocalPackageCore(string packagePath) { IPackage package = null; try { var extension = Path.GetExtension(packagePath); if (extension.Equals(Constants.PackageExtension, StringComparison.OrdinalIgnoreCase)) { package = new ZipPackage(packagePath); } else if (extension.Equals(Constants.ManifestExtension, StringComparison.OrdinalIgnoreCase)) { using (var str = ManifestUtility.ReadManifest(packagePath)) { var builder = new PackageBuilder(str, Path.GetDirectoryName(packagePath)); package = builder.Build(); } } if (package != null) { LoadPackage(package, packagePath, PackageType.LocalPackage); return(true); } } catch (Exception ex) { UIServices.Show(ex.Message, MessageLevel.Error); return(false); } return(false); }
private bool OpenLocalPackageCore(string packagePath) { IPackage?package = null; string?tempFile = null; try { tempFile = Path.GetTempFileName(); File.Copy(packagePath, tempFile, overwrite: true); var extension = Path.GetExtension(packagePath); if (Constants.PackageExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) || Constants.SymbolPackageExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { DiagnosticsClient.TrackPageView("View Existing Package"); #pragma warning disable CA2000 // Dispose objects before losing scope package = new ZipPackage(tempFile); #pragma warning restore CA2000 // Dispose objects before losing scope } else if (Constants.ManifestExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { DiagnosticsClient.TrackPageView("View Nuspec"); using var str = ManifestUtility.ReadManifest(tempFile); var builder = new PackageBuilder(str, Path.GetDirectoryName(packagePath)); package = builder.Build(); } if (package != null) { LoadPackage(package, packagePath, packagePath, PackageType.LocalPackage); _tempFile = tempFile; return(true); } } catch (Exception ex) { package?.Dispose(); package = null; UIServices.Show(ex.Message, MessageLevel.Error); return(false); } finally { if (package == null && tempFile != null && File.Exists(tempFile)) { try { File.Delete(tempFile); } catch { /* ignore */ } } } return(false); }
private bool OpenLocalPackageCore(string packagePath) { IPackage package = null; string tempFile = null; try { tempFile = Path.GetTempFileName(); File.Copy(packagePath, tempFile, overwrite: true); var extension = Path.GetExtension(packagePath); if (extension.Equals(Constants.PackageExtension, StringComparison.OrdinalIgnoreCase) || extension.Equals(Constants.SymbolPackageExtension, StringComparison.OrdinalIgnoreCase)) { package = new ZipPackage(tempFile); } else if (extension.Equals(Constants.ManifestExtension, StringComparison.OrdinalIgnoreCase)) { using (var str = ManifestUtility.ReadManifest(tempFile)) { var builder = new PackageBuilder(str, Path.GetDirectoryName(packagePath)); package = builder.Build(); } } if (package != null) { LoadPackage(package, packagePath, PackageType.LocalPackage); _tempFile = tempFile; return(true); } } catch (Exception ex) { package = null; UIServices.Show(ex.Message, MessageLevel.Error); return(false); } finally { if (package == null && tempFile != null && File.Exists(tempFile)) { try { File.Delete(tempFile); } catch { /* ignore */ } } } return(false); }