示例#1
0
        internal PackageDirectory(string name, string fullName, PackageDirectory parent)
        {
            Name     = name;
            FullName = fullName;
            Parent   = parent;

            Directories = new PackageDirectoryCollection();
            Resources   = new PackageResourceCollection();
        }
示例#2
0
        public static PackageExplorer Load(string packagePath)
        {
            var packageFileInfo = new FileInfo(packagePath);

            using var fileStream = new FileStream(packagePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            using var archive    = new ZipArchive(fileStream, ZipArchiveMode.Read, true);

            var package = new PackageExplorer
            {
                PackagePath    = packagePath,
                CompressedSize = packageFileInfo.Length
            };

            var definitionEntry    = archive.GetEntry("definition.json");
            var definitionDocument = LoadJsonDocument <PackageDefinition>(definitionEntry);

            var tagsEntry    = archive.GetEntry("tags.json");
            var tagsDocument = LoadJsonDocument <IReadOnlyDictionary <string, IReadOnlyList <string> > >(tagsEntry);
            var tags         = new Dictionary <string, IResourceCollection>();

            var rootDirectiory = new PackageDirectory();

            foreach (var projectEntry in archive.Entries)
            {
                if (!projectEntry.FullName.StartsWith("data/"))
                {
                    continue;
                }

                var resource = new PackageResource(package, projectEntry);
                package.resources.Add(resource);

                foreach (var tagCategory in tagsDocument)
                {
                    if (tagCategory.Value.Contains(resource.FullName))
                    {
                        if (!tags.TryGetValue(tagCategory.Key, out var taggedResourcesCollection))
                        {
                            taggedResourcesCollection = new PackageResourceCollection();
                            tags[tagCategory.Key]     = taggedResourcesCollection;
                        }

                        var taggedResources = (PackageResourceCollection)taggedResourcesCollection;

                        taggedResources.Add(resource);
                        resource.Tags.tags.Add(tagCategory.Key);
                    }
                }
            }

            package.tags       = new PackageTagsCollection(tags);
            package.definition = definitionDocument;

            return(package);
        }
			public PackageResourceCollectionDebugView(PackageResourceCollection source)
			{
				this.source = source;
			}
示例#4
0
 private PackageExplorer()
 {
     resources = new PackageResourceCollection();
 }
示例#5
0
        public static async Task <PackageExplorer> LoadAsync(IReadOnlyArchiveDirectory source)
        {
            var definitionEntry    = source.Files.GetFile("definition.json");
            var definitionDocument = LoadJsonDocument <PackageDefinition>(definitionEntry);

            var tagsEntry    = source.Files.GetFile("tags.json");
            var tagsDocument = LoadJsonDocument <IReadOnlyDictionary <string, IReadOnlyList <string> > >(tagsEntry);
            var tags         = new Dictionary <string, IResourceCollection>();

            var rootDirectiory = new PackageDirectory("", "", null);

            var packageExplorer = new PackageExplorer
            {
                Source        = source,
                RootDirectory = rootDirectiory,
                Definition    = definitionDocument
            };

            void ImportDirectory(IReadOnlyArchiveDirectory directory, PackageDirectory packageDirectory)
            {
                foreach (var childDirectory in directory.Directories)
                {
                    ImportDirectory(childDirectory,
                                    new PackageDirectory(childDirectory.Name, childDirectory.FullName, packageDirectory));
                }

                foreach (var file in directory.Files)
                {
                    if (!file.FullName.EndsWith(".pkgmeta"))
                    {
                        continue;
                    }
                    var contentEntry = directory.Files.GetFile(file.Name.Substring(0, file.Name.Length - 8));

                    var metadataModel = LoadJsonDocument <PackageResourceMetadataModel>(file);

                    var resource = new PackageResource(packageExplorer, packageDirectory, contentEntry, metadataModel);

                    packageExplorer.Resources.Add(resource.FullName, resource);
                    packageDirectory.Resources.Add(resource.Name, resource);

                    foreach (var tagCategory in tagsDocument)
                    {
                        if (tagCategory.Value.Contains(resource.FullName))
                        {
                            if (!tags.TryGetValue(tagCategory.Key, out var taggedResourcesCollection))
                            {
                                taggedResourcesCollection = new PackageResourceCollection();
                                tags[tagCategory.Key]     = taggedResourcesCollection;
                            }

                            var taggedResources = (PackageResourceCollection)taggedResourcesCollection;

                            taggedResources.Add(resource.FullName, resource);
                            resource.Tags.tags.Add(tagCategory.Key);
                        }
                    }
                }
            }

            ImportDirectory(source, rootDirectiory);

            packageExplorer.Tags = new PackageTagsCollection(tags);

            return(packageExplorer);
        }
示例#6
0
        public static async Task <PackageExplorer> LoadAsync(IReadOnlyArchive archive)
        {
            var definitionEntry    = archive.Files.GetFile("definition.json");
            var definitionDocument = LoadJsonDocument <PackageDefinition>(definitionEntry);

            var tagsEntry    = archive.Files.GetFile("tags.json");
            var tagsDocument = LoadJsonDocument <IReadOnlyDictionary <string, IReadOnlyList <string> > >(tagsEntry);
            var tags         = new Dictionary <string, IResourceCollection>();

            var rootDirectiory = new PackageDirectory("", "", null);

            PackageDirectory ForPath(string path)
            {
                int currentIndex     = 5;
                var currentDirectory = rootDirectiory;

                while (true)
                {
                    int nextIndex = path.IndexOf('/', currentIndex);
                    if (nextIndex == -1)
                    {
                        break;
                    }
                    string segment = path.Substring(currentIndex, nextIndex - currentIndex);

                    bool found = false;
                    foreach (var directory in currentDirectory.Directories)
                    {
                        if (directory.Name == segment)
                        {
                            currentDirectory = directory;
                            found            = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        var newDirectory = new PackageDirectory(segment, path.Substring(5, nextIndex - 5), currentDirectory);
                        currentDirectory.Directories.Add(newDirectory);
                        currentDirectory = newDirectory;
                    }

                    currentIndex = nextIndex + 1;
                }

                return(currentDirectory);
            }

            var package = new PackageExplorer
            {
                Archive       = archive,
                RootDirectory = rootDirectiory,
                Definition    = definitionDocument
            };

            foreach (var metadataEntry in archive.Files)
            {
                /*
                 * if (!packageEntry.FullName.StartsWith("data/")
                 || packageEntry.FullName.EndsWith(".pkgmeta"))
                 ||{
                 ||     continue;
                 ||}
                 ||var metadataEntry = archive.Files.GetFile($"{packageEntry.FullName}.pkgmeta");
                 */

                if (!metadataEntry.FullName.EndsWith(".pkgmeta"))
                {
                    continue;
                }
                var contentEntry = archive.Files.GetFile(metadataEntry.FullName.Substring(0, metadataEntry.FullName.Length - 8));

                var metadataModel = LoadJsonDocument <PackageResourceMetadataModel>(metadataEntry);

                var forPath = ForPath(contentEntry.FullName);

                var resource = new PackageResource(package, forPath, contentEntry, metadataModel);

                package.Resources.Add(resource.FullName, resource);
                forPath.Resources.Add(resource.Name, resource);

                foreach (var tagCategory in tagsDocument)
                {
                    if (tagCategory.Value.Contains(resource.FullName))
                    {
                        if (!tags.TryGetValue(tagCategory.Key, out var taggedResourcesCollection))
                        {
                            taggedResourcesCollection = new PackageResourceCollection();
                            tags[tagCategory.Key]     = taggedResourcesCollection;
                        }

                        var taggedResources = (PackageResourceCollection)taggedResourcesCollection;

                        taggedResources.Add(resource.FullName, resource);
                        resource.Tags.tags.Add(tagCategory.Key);
                    }
                }
            }

            package.Tags = new PackageTagsCollection(tags);

            return(package);
        }
示例#7
0
        public static async Task <PackageExplorer> LoadAsync(IReadOnlyArchiveDirectory source)
        {
            var definitionEntry    = source.Files.GetFile("definition.json");
            var definitionDocument = LoadJsonDocument <PackageDefinition>(definitionEntry);

            var tagsEntry    = source.Files.GetFile("tags.json");
            var tagsDocument = LoadJsonDocument <IReadOnlyDictionary <string, IReadOnlyList <string> > >(tagsEntry);
            var tags         = new Dictionary <string, IResourceCollection>();

            var rootDirectiory = new PackageDirectory("", null);

            var packageExplorer = new PackageExplorer
            {
                Source        = source,
                RootDirectory = rootDirectiory,
                Definition    = definitionDocument
            };

            var resourcesDirectory = source.Directories.GetDirectory("resources");
            var contentsDirectory  = source.Directories.GetDirectory("contents");

            // Does this package contain any resources?
            if (resourcesDirectory != null)
            {
                foreach (var resourceFile in resourcesDirectory.Files)
                {
                    var metadataModel = LoadJsonDocument <PackageResourceMetadataModel>(resourceFile);

                    // Directory
                    string[] elements = metadataModel.FullName
                                        .Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    var parentDirectory = rootDirectiory;
                    for (int i = 0; i < elements.Length - 1; i++)
                    {
                        string element = elements[i];

                        PackageDirectory findDirectory = null;
                        foreach (var directory in parentDirectory.Directories)
                        {
                            if (directory.Name == element)
                            {
                                findDirectory = directory;
                                break;
                            }
                        }
                        if (findDirectory == null)
                        {
                            findDirectory = new PackageDirectory(element, parentDirectory);
                            parentDirectory.Directories.Add(findDirectory);
                        }
                        parentDirectory = findDirectory;
                    }

                    // Resource
                    var contentFile = contentsDirectory.Files.GetFile(metadataModel.ContentId);
                    var resource    = new PackageResource(packageExplorer, parentDirectory, contentFile, metadataModel);

                    packageExplorer.Resources.Add(resource.FullName, resource);
                    parentDirectory.Resources.Add(resource.Name, resource);

                    // Tags
                    foreach (var tagCategory in tagsDocument)
                    {
                        if (tagCategory.Value.Contains(resource.FullName))
                        {
                            if (!tags.TryGetValue(tagCategory.Key, out var taggedResourcesCollection))
                            {
                                taggedResourcesCollection = new PackageResourceCollection();
                                tags[tagCategory.Key]     = taggedResourcesCollection;
                            }

                            var taggedResources = (PackageResourceCollection)taggedResourcesCollection;

                            taggedResources.Add(resource.FullName, resource);
                            resource.Tags.tags.Add(tagCategory.Key);
                        }
                    }
                }
            }

            packageExplorer.Tags = new PackageTagsCollection(tags);

            return(packageExplorer);
        }