Exemple #1
0
 public void Add(PackageAsset asset)
 {
     if (items == null)
     {
         items = new Dictionary <string, PackageAsset>();
     }
     items.Add(asset.ToString(), asset);
 }
Exemple #2
0
        public static PackageExplorer Load(string path)
        {
            var package = new PackageExplorer
            {
                Path = path
            };

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Read, true))
                {
                    var entry = archive.GetEntry("Main.bmft");

                    byte[] buffer = new byte[entry.Length];
                    using (var zipStream = entry.Open())
                    {
                        zipStream.Read(buffer, 0, (int)entry.Length);
                        string json = Encoding.UTF8.GetString(buffer);
                    }

                    string pathPrefix  = null;
                    var    pathEntries = new List <ZipArchiveEntry>();
                    foreach (var projectEntry in archive.Entries)
                    {
                        int pathPrefixIndex = projectEntry.FullName.IndexOf('/');
                        if (pathPrefixIndex == -1)
                        {
                            Console.WriteLine("Not adding \"" + projectEntry.FullName + "\" as an item.");
                            continue;
                        }
                        string newPathIndex = projectEntry.FullName.Substring(0, pathPrefixIndex);

                        if (pathPrefix == null)
                        {
                            pathPrefix = newPathIndex;
                        }

                        if (pathPrefix != newPathIndex)
                        {
                            var asset = new PackageAsset(package, pathPrefix, pathEntries.ToArray());
                            pathEntries.Clear();
                            package.Assets.Add(asset);
                            pathPrefix = newPathIndex;
                        }
                        pathEntries.Add(projectEntry);
                    }
                    if (pathEntries.Count != 0)
                    {
                        var asset = new PackageAsset(package, pathPrefix, pathEntries.ToArray());
                        package.Assets.Add(asset);
                    }
                }
                fileStream.Close();
            }

            return(package);
        }