public override void Move(VsixFileNode targetNode) { if (this.Parent != targetNode) { this.Parent.Nodes.Remove((VsixFileNode)this); this.Parent = targetNode; this.Parent.Nodes.Add((VsixFileNode)this); } string uriString = this.Part.Uri.OriginalString.Substring(this.Part.Uri.OriginalString.LastIndexOf('/')); VsixFileNode vsixFileNode; for (vsixFileNode = targetNode; vsixFileNode != null && !(vsixFileNode is VsixPackageNode); vsixFileNode = vsixFileNode.Parent) { uriString = "/" + vsixFileNode.Name + uriString; } if (vsixFileNode == null || !(uriString != this.Part.Uri.OriginalString)) { return; } PackagePart part = (vsixFileNode as VsixPackageNode).Package.CreatePart(new Uri(uriString, UriKind.Relative), this.Part.ContentType, System.IO.Packaging.CompressionOption.Maximum); Stream stream1 = part.GetStream(FileMode.OpenOrCreate, FileAccess.Write); Stream stream2 = this.Part.GetStream(FileMode.Open, FileAccess.Read); byte[] buffer = new byte[4096]; int count; while ((count = stream2.Read(buffer, 0, 4096)) > 0) { stream1.Write(buffer, 0, count); } stream1.Close(); this.Part.Package.DeletePart(this.Part.Uri); this.Part = part; }
private VsixFileNode CreateFileNodeFromPart(PackagePart part, VsixFileNode parentNode) { string str = part.Uri.OriginalString.Substring(part.Uri.OriginalString.LastIndexOf('/') + 1); VsixFileNode vsixFileNode; if (str.EndsWith(".vsix")) { VsixFile vsixFile = (VsixFile)null; try { vsixFile = new VsixFile(part, str, this.IsWritable ? FileAccess.ReadWrite : FileAccess.Read); } catch (Exception) { } if (vsixFile != null) { vsixFileNode = Enumerable.First <VsixFileNode>((IEnumerable <VsixFileNode>)vsixFile.Nodes); vsixFileNode.Parent = parentNode; } else { vsixFileNode = (VsixFileNode) new VsixPackagePartNode(str, parentNode, part); } } else { vsixFileNode = string.Compare(str, "extension.vsixmanifest", true) != 0 ? (string.Compare(str, "extension.vsixlangpack", true) != 0 ? (VsixFileNode) new VsixPackagePartNode(str, parentNode, part) : (VsixFileNode) new VsixLangPackManifestNode(str, parentNode, part)) : (VsixFileNode) new VsixManifestNode(str, parentNode, part); } return(vsixFileNode); }
public override void Move(VsixFileNode targetNode) { this.Parent.Nodes.Remove((VsixFileNode)this); this.Parent = targetNode; this.Parent.Nodes.Add((VsixFileNode)this); foreach (VsixFileNode vsixFileNode in (IEnumerable <VsixFileNode>) this.Nodes) { vsixFileNode.Move((VsixFileNode)this); } }
public override void RebindParentPackage() { VsixFileNode parent = this.Parent; while (parent != null && !(parent is VsixPackageNode)) { parent = parent.Parent; } this.Part = (parent as VsixPackageNode).Package.GetPart(this.Part.Uri); }
public void AddDirectory(VsixFileNode targetNode, string directoryPath) { VsixFolderNode vsixFolderNode = new VsixFolderNode(Path.GetFileName(directoryPath), targetNode); targetNode.Nodes.Add((VsixFileNode)vsixFolderNode); foreach (string directoryPath1 in Directory.GetDirectories(directoryPath)) { this.AddDirectory((VsixFileNode)vsixFolderNode, directoryPath1); } foreach (string filePath in Directory.GetFiles(directoryPath)) { this.AddFile((VsixFileNode)vsixFolderNode, filePath); } }
public void AddFile(VsixFileNode targetNode, string fileName, Stream fileStream) { string str = "/"; VsixFileNode vsixFileNode; for (vsixFileNode = targetNode; vsixFileNode != null && !(vsixFileNode is VsixPackageNode); vsixFileNode = vsixFileNode.Parent) { str = "/" + vsixFileNode.Name + str; } if (vsixFileNode == null) { return; } VsixPackageNode vsixPackageNode = vsixFileNode as VsixPackageNode; Uri partUri = PackUriHelper.CreatePartUri(new Uri(str + fileName, UriKind.Relative)); if (vsixPackageNode.Package.PartExists(partUri)) { Enumerable.FirstOrDefault <VsixFileNode>((IEnumerable <VsixFileNode>)targetNode.Nodes, (Func <VsixFileNode, bool>)(node => { if (node is VsixPackagePartNode) { return((node as VsixPackagePartNode).Part.Uri == partUri); } else { return(false); } })).Remove(true); } PackagePart part = vsixPackageNode.Package.CreatePart(partUri, "application/octet-stream", CompressionOption.Maximum); Stream stream = part.GetStream(FileMode.OpenOrCreate, FileAccess.Write); byte[] buffer = new byte[4096]; fileStream.Seek(0L, SeekOrigin.Begin); int count; while ((count = fileStream.Read(buffer, 0, 4096)) > 0) { stream.Write(buffer, 0, count); } stream.Close(); fileStream.Seek(0L, SeekOrigin.Begin); targetNode.Nodes.Add(this.CreateFileNodeFromPart(part, targetNode)); }
public override void Rename() { string str = "/"; for (VsixFileNode parent = this.Parent; parent != null && !(parent is VsixPackageNode); parent = parent.Parent) { str = "/" + parent.Name + str; } Uri partUri = PackUriHelper.CreatePartUri(new Uri(str + this.Name, UriKind.RelativeOrAbsolute)); if (this.Part.Package.PartExists(partUri)) { return; } PackagePart part = this.Part.Package.CreatePart(partUri, this.Part.ContentType); Utilities.CopyStream(this.Part.GetStream(), part.GetStream(FileMode.Open, FileAccess.Write)); this.Part.Package.DeletePart(this.Part.Uri); this.Part = part; }
public VsixManifestNode(string name, VsixFileNode parent, PackagePart packagePart) : base(name, parent, packagePart) { }
public VsixFolderNode(string name, VsixFileNode parent, IList <VsixFileNode> nodes) : base(name, parent, nodes) { }
public VsixFolderNode(string name, VsixFileNode parent) : base(name, parent) { }
public VsixPackagePartNode(string name, VsixFileNode parent, PackagePart packagePart) : base(name, parent) { this.Part = packagePart; }
public VsixPackageNode(string name, VsixFileNode parent, ZipPackage package, PackagePart parentPackagePart) : base(name, parent, parentPackagePart) { this.Package = package; }
public void AddFile(VsixFileNode targetNode, string filePath) { using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) this.AddFile(targetNode, Path.GetFileName(filePath), (Stream)fileStream); }
private IList <VsixFileNode> CreateFileTree(IEnumerable <KeyValuePair <string, PackagePart> > parts, VsixFileNode parent) { List <VsixFileNode> list = new List <VsixFileNode>(); while (Enumerable.Count <KeyValuePair <string, PackagePart> >(parts) > 0) { string[] strArray = Enumerable.First <KeyValuePair <string, PackagePart> >(parts).Key.Split(new char[1] { '/' }, 2, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length > 1) { string topNodeDirectory = strArray[0] + "/"; IEnumerable <KeyValuePair <string, PackagePart> > source = Enumerable.Where <KeyValuePair <string, PackagePart> >(parts, (Func <KeyValuePair <string, PackagePart>, bool>)(x => x.Key.StartsWith(topNodeDirectory))); SortedList <string, PackagePart> sortedList = new SortedList <string, PackagePart>(); foreach (KeyValuePair <string, PackagePart> keyValuePair in source) { sortedList.Add(keyValuePair.Key.Substring(topNodeDirectory.Length), keyValuePair.Value); } VsixFolderNode vsixFolderNode = new VsixFolderNode(strArray[0], parent); vsixFolderNode.Nodes = new SortedObservableCollection <VsixFileNode>((IEnumerable <VsixFileNode>) this.CreateFileTree((IEnumerable <KeyValuePair <string, PackagePart> >)sortedList, (VsixFileNode)vsixFolderNode)); list.Add((VsixFileNode)vsixFolderNode); parts = Enumerable.Skip <KeyValuePair <string, PackagePart> >(parts, Enumerable.Count <KeyValuePair <string, PackagePart> >(source)); } else { PackagePart part = Enumerable.First <KeyValuePair <string, PackagePart> >(parts).Value; list.Add(this.CreateFileNodeFromPart(part, parent)); parts = Enumerable.Skip <KeyValuePair <string, PackagePart> >(parts, 1); } } return((IList <VsixFileNode>)list); }