示例#1
0
        public void PopulateFile(List <VirtualFileDataObject.FileDescriptor> files, FileEntry parent, string path = "")
        {
            if (parent.BundleEntries.Count == 0)
            {
                return;
            }

            string name = this.OutputFullPaths ? parent.Path : path;

            VirtualFileDataObject.FileDescriptor fileDescriptor = new VirtualFileDataObject.FileDescriptor()
            {
                Name           = name,
                StreamContents = () =>
                {
                    MemoryStream     stream         = new MemoryStream();
                    PackageFileEntry maxBundleEntry = parent.MaxBundleEntry();
                    Console.WriteLine("Extracted {0} from package: {1}", name, maxBundleEntry.PackageName.ToString());
                    byte[] bytes = parent.FileBytes(maxBundleEntry);
                    if (bytes != null)
                    {
                        stream.Write(bytes, 0, bytes.Length);
                    }
                    return(stream);
                }
            };
            files.Add(fileDescriptor);
        }
      public void PopulateFile(List <VirtualFileDataObject.FileDescriptor> files, FileEntry parent, string removeDirectory)
      {
          if (parent.BundleEntries.Count == 0)
          {
              return;
          }

          string name = parent.EntryPath;

          if (!OutputFullPaths && !string.IsNullOrEmpty(removeDirectory))
          {
              name = name.Replace(removeDirectory, "");
          }

          files.Add(new VirtualFileDataObject.FileDescriptor()
            {
                Name           = name,
                StreamContents = (stream) =>
                {
                    i++;
                    int total = files.Count;

                    PackageFileEntry maxBundleEntry = parent.MaxBundleEntry();

                    byte[] bytes = parent.FileBytes(maxBundleEntry);
                    if (bytes != null)
                    {
                        stream.Write(bytes, 0, bytes.Length);
                    }
                    else
                    {
                        Console.WriteLine("Failed to extract {0} from package: {1}", name, maxBundleEntry.PackageName.ToString());
                    }

                    if (Progress != null)
                    {
                        if (Progress.IsClosed)
                        {
                            throw new Exception(); //No clue how to really stop that other than exceptions lol.
                        }
                        else
                        {
                            Progress.SetProgress($"Copying {parent.EntryPath}", i, files.Count);
                        }
                    }
                }
            });
      }
示例#3
0
    /*private void ProcessFolder(IParent folder)
     * {
     *  foreach (IChild child in folder.Children.Values)
     *  {
     *      if (child is FileEntry)
     *          this.ProcessFile(child as FileEntry);
     *      else if (child is IParent)
     *          this.ProcessFolder(child as IParent);
     *  }
     * }*/

    private void WriteFile(FileEntry entry, byte[] byt = null)
    {
        Idstring ids = HashIndex.Get(entry.Path);

        if (entry.BundleEntries.Count == 0 || this.ExtractedPaths.Contains(ids))
        {
            return;
        }

        string path   = Path.Combine(this.OutputPath, entry.Path);
        string folder = Path.GetDirectoryName(path);

        if (!Directory.Exists(folder))
        {
            Directory.CreateDirectory(folder);
        }

        byte[] bytes = byt ?? entry.FileBytes() ?? new byte[0];

        File.WriteAllBytes(path, bytes);
        this.ExtractedPaths.Add(ids);
    }