Exemplo n.º 1
0
        public async Task SaveImageAsync(StorageFile file, uint width)
        {
            try
            {
                //await Functions.SaveStreamToFile(GetStream(), file);
                using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                {
                    var s      = Entry.OpenEntryStream();
                    var buffer = new byte[s.Length];
                    await s.ReadAsync(buffer, 0, (int)s.Length);

                    var ibuffer = buffer.AsBuffer();
                    await fileStream.WriteAsync(ibuffer);
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to extracts the original filename for the OLE object out of the ObjectReplacement file
        /// </summary>
        /// <param name="zipEntry"></param>
        /// <returns></returns>
        internal static string GetFileNameFromObjectReplacementFile(SharpCompress.Archives.IArchiveEntry zipEntry)
        {
            try
            {
                using (var zipEntryStream = zipEntry.OpenEntryStream())
                    using (var zipEntryMemoryStream = new MemoryStream())
                    {
                        zipEntryStream.CopyTo(zipEntryMemoryStream);
                        zipEntryMemoryStream.Position = 0x4470;
                        using (var binaryReader = new BinaryReader(zipEntryMemoryStream))
                        {
                            while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
                            {
                                var value = binaryReader.ReadUInt16();

                                // We have found the start position from where we are going to read
                                // the original filename
                                if (value != 0x8000 || binaryReader.PeekChar() != 0x46)
                                {
                                    continue;
                                }
                                // Skip the peeked char
                                zipEntryMemoryStream.Position += 2;

                                // Read until we find the next 0x46 value
                                while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
                                {
                                    value = binaryReader.ReadUInt16();
                                    if (value != 0x46)
                                    {
                                        continue;
                                    }
                                    // Skip the next 6 bytes
                                    binaryReader.ReadBytes(6);

                                    // Get the length of name string
                                    var length = binaryReader.ReadUInt16();

                                    // Skip the next 2 bytes
                                    zipEntryMemoryStream.Position += 2;

                                    // Read the filename bytes
                                    var fileNameBytes = binaryReader.ReadBytes(length);
                                    var fileName      = Encoding.Unicode.GetString(fileNameBytes);
                                    fileName = fileName.Replace("\0", string.Empty);
                                    return(fileName);
                                }
                            }
                        }
                    }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
Exemplo n.º 3
0
 public CompressedPage(SharpCompress.Archives.IArchiveEntry Entry)
 {
     //this.Entry = Entry;
     Cache = new MemoryStreamCache()
     {
         MemoryStreamProvider = async(th) =>
         {
             using var s = Entry.OpenEntryStream();
             return(await th.GetMemoryStreamAsync(s));
         }
     };
 }