Exemplo n.º 1
0
        public void LoadPacketDefiniton()
        {
            var fileName = Path.Combine(_folderContainsUpdate, _packetdefinitionXml);
            if (File.Exists(fileName))
            {
                PacketDefinitionsLoader loader = new PacketDefinitionsLoader();
                Definition = loader.LoadPacket(fileName);
            }

        }
Exemplo n.º 2
0
 public void LoadPacketTest()
 {
     PacketDefinitionsLoader definitionsLoader = new PacketDefinitionsLoader();
     var packet = definitionsLoader.LoadPacket(@"D:\programming\Uppy\UPPY.Updater\Examples\ExamplePacket.xml");
     Assert.IsNotNull(packet);
 }
Exemplo n.º 3
0
        public Packet UnpackFile(string archFileName, string outFolder)
        {
            ZipFile zf = null;
            try
            {
                FileStream fs = File.OpenRead(archFileName);
                zf = new ZipFile(fs);

                foreach (ZipEntry zipEntry in zf)
                {
                    if (!zipEntry.IsFile)
                    {
                        continue; // Ignore directories
                    }

                    var entryFileName = zipEntry.Name;
                    // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
                    // Optionally match entrynames against a selection list here to skip as desired.
                    // The unpacked length is available in the zipEntry.Size property.

                    byte[] buffer = new byte[4096]; // 4K is optimum
                    Stream zipStream = zf.GetInputStream(zipEntry);

                    // Manipulate the output filename here as desired.
                    String fullZipToPath = Path.Combine(outFolder, entryFileName);
                    string directoryName = Path.GetDirectoryName(fullZipToPath);
                    if (directoryName.Length > 0)
                        Directory.CreateDirectory(directoryName);

                    // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
                    // of the file, but does not waste memory.
                    // The "using" will close the stream even if an exception occurs.
                    using (FileStream streamWriter = File.Create(fullZipToPath))
                    {
                        StreamUtils.Copy(zipStream, streamWriter, buffer);
                    }
                }

            }
            catch (Exception)
            {
                return null;
            }
            finally
            {
                if (zf != null)
                {
                    zf.IsStreamOwner = true; // Makes close also shut the underlying stream
                    zf.Close(); // Ensure we release resources
                }
            }

            var fileDef = Path.Combine(outFolder, _packetdefinitionXml);

            if (!File.Exists(fileDef))
            {
                return null;
            }

            var loader = new PacketDefinitionsLoader();
            return loader.LoadPacket(fileDef);
        }