Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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;
        }
Beispiel #8
0
 public VsixManifestNode(string name, VsixFileNode parent, PackagePart packagePart)
     : base(name, parent, packagePart)
 {
 }
Beispiel #9
0
 public VsixFolderNode(string name, VsixFileNode parent, IList <VsixFileNode> nodes)
     : base(name, parent, nodes)
 {
 }
Beispiel #10
0
 public VsixFolderNode(string name, VsixFileNode parent)
     : base(name, parent)
 {
 }
Beispiel #11
0
 public VsixPackagePartNode(string name, VsixFileNode parent, PackagePart packagePart)
     : base(name, parent)
 {
     this.Part = packagePart;
 }
Beispiel #12
0
 public VsixPackageNode(string name, VsixFileNode parent, ZipPackage package, PackagePart parentPackagePart)
     : base(name, parent, parentPackagePart)
 {
     this.Package = package;
 }
Beispiel #13
0
 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);
 }
Beispiel #14
0
        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);
        }