Esempio n. 1
0
 public FileViewModel(FileType type, AppxFile file) : this(type)
 {
     this.Name           = file.Name;
     this.UpdateImpact   = file.UpdateImpact;
     this.SizeDifference = type == FileType.Unchanged ? 0 : file.SizeDifference;
 }
Esempio n. 2
0
        private async Task <IList <AppxFile> > GetFiles(Stream appxBlockMap, CancellationToken cancellationToken, IProgress <ProgressData> progress = null)
        {
            progress?.Report(new ProgressData(0, "Reading AppxBlockMap.xml..."));
            IList <AppxFile> list = new List <AppxFile>();
            var document          = await XDocument.LoadAsync(appxBlockMap, LoadOptions.None, cancellationToken);

            var blockMap = document.Root;

            if (blockMap == null || blockMap.Name.LocalName != "BlockMap")
            {
                return(list);
            }

            var ns = XNamespace.Get("http://schemas.microsoft.com/appx/2010/blockmap");

            const int maxBlockSize = 64 * 1024; // 64 kilobytes

            progress?.Report(new ProgressData(50, "Reading files..."));
            foreach (var item in blockMap.Elements(ns + "File"))
            {
                long.TryParse(item.Attribute("Size")?.Value ?? "0", out var fileSize);

                ushort headerLength;
                var    headerSize = item.Attribute("LfhSize");
                if (headerSize == null)
                {
                    headerLength = 30;
                }
                else
                {
                    ushort.TryParse(headerSize.Value, out headerLength);
                }

                var fileName = item.Attribute("Name")?.Value;
                var file     = new AppxFile(fileName, fileSize, headerLength);

                foreach (var fileBlock in item.Elements(ns + "Block"))
                {
                    long blockLength;
                    var  blockSize = fileBlock.Attribute("Size");
                    if (blockSize == null)
                    {
                        // If this is null, the block is uncompressed.
                        if (fileSize > maxBlockSize)
                        {
                            blockLength = maxBlockSize;
                        }
                        else
                        {
                            blockLength = fileSize;
                        }

                        fileSize -= maxBlockSize;
                    }
                    else
                    {
                        long.TryParse(blockSize.Value, out blockLength);
                    }

                    file.Blocks.Add(new AppxBlock(fileBlock.Attribute("Hash")?.Value, blockLength)
                    {
                        Status = ComparisonStatus.Unchanged
                    });
                }

                list.Add(file);
            }

            return(list);
        }
Esempio n. 3
0
 public FileViewModel(AppxFile changedFile) : this(FileType.Changed)
 {
     this.Name           = changedFile.Name;
     this.UpdateImpact   = changedFile.UpdateImpact;
     this.SizeDifference = changedFile.SizeDifference;
 }