コード例 #1
0
        public static async Task GetMetaData()
        {
            List <Task> tlist = new List <Task>();

            vehicles.ForEach(a =>
            {
                try
                {
                    var newurl = String.Format(url, a);
                    var file   = Path.Combine(Settings.GetDataDirectory(), "LogMessages" + a + ".xml.xz");
                    if (File.Exists(file))
                    {
                        if (new FileInfo(file).LastWriteTime.AddDays(7) > DateTime.Now)
                        {
                            return;
                        }
                    }
                    var dltask = Download.getFilefromNetAsync(newurl, file);
                    tlist.Add(dltask);
                }
                catch (Exception ex) { log.Error(ex); }
            });

            await Task.WhenAll(tlist);

            vehicles.ForEach(a =>
            {
                try
                {
                    var fileout = Path.Combine(Settings.GetDataDirectory(), "LogMessages" + a + ".xml");
                    var file    = Path.Combine(Settings.GetDataDirectory(), "LogMessages" + a + ".xml.xz");
                    if (File.Exists(file))
                    {
                        using (var read = File.OpenRead(file))
                        {
                            if (XZStream.IsXZStream(read))
                            {
                                read.Position = 0;
                                var stream    = new XZStream(read);
                                using (var outst = File.OpenWrite(fileout))
                                {
                                    try
                                    {
                                        stream.CopyTo(outst);
                                    }
                                    catch (XZIndexMarkerReachedException)
                                    {
                                        // ignore
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            });
        }
コード例 #2
0
        private static void Template(string xzFileName, string originFileName, bool useSpan)
        {
            byte[] decompDigest;
            byte[] originDigest;

            string xzFile     = Path.Combine(TestSetup.SampleDir, xzFileName);
            string originFile = Path.Combine(TestSetup.SampleDir, originFileName);

            using (MemoryStream decompMs = new MemoryStream())
            {
                XZDecompressOptions decompOpts = new XZDecompressOptions();

                using (FileStream compFs = new FileStream(xzFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (XZStream xz = new XZStream(compFs, decompOpts))
                    {
#if !NETFRAMEWORK
                        if (useSpan)
                        {
                            byte[] buffer = new byte[64 * 1024];

                            int bytesRead;
                            do
                            {
                                bytesRead = xz.Read(buffer.AsSpan());
                                decompMs.Write(buffer.AsSpan(0, bytesRead));
                            } while (0 < bytesRead);
                        }
                        else
#endif
                        {
                            xz.CopyTo(decompMs);
                        }

                        decompMs.Flush();
                        xz.GetProgress(out ulong finalIn, out ulong finalOut);

                        Assert.AreEqual(compFs.Length, xz.TotalIn);
                        Assert.AreEqual(decompMs.Length, xz.TotalOut);
                        Assert.AreEqual((ulong)compFs.Length, finalIn);
                        Assert.AreEqual((ulong)decompMs.Length, finalOut);
                    }
                decompMs.Position = 0;

                using (HashAlgorithm hash = SHA256.Create())
                {
                    decompDigest = hash.ComputeHash(decompMs);
                }
            }

            using (FileStream originFs = new FileStream(originFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (HashAlgorithm hash = SHA256.Create())
                {
                    originDigest = hash.ComputeHash(originFs);
                }
            }

            Assert.IsTrue(decompDigest.SequenceEqual(originDigest));
        }
コード例 #3
0
ファイル: DecompMgcBench.cs プロジェクト: pebakery/pebakery
        public void NativeXZ()
        {
            byte[] buffer = _srcFileBytesDict[DecompMethod.NativeXZ];

            using (MemoryStream decompMs = new MemoryStream((int)_magicFileLen))
                using (MemoryStream compMs = new MemoryStream(buffer))
                    using (XZStream xzs = new XZStream(compMs, new XZDecompressOptions()))
                    {
                        xzs.CopyTo(decompMs);
                    }
        }
コード例 #4
0
        /// <inheritdoc/>
        public override byte[] Decompress(byte[] compressedData, int blockLength)
        {
            XZDecompressOptions decompOpts = new XZDecompressOptions();

            using (MemoryStream inputStream = new MemoryStream(compressedData, 0, blockLength))
                using (MemoryStream outputStream = new MemoryStream())
                    using (XZStream xzStream = new XZStream(inputStream, decompOpts))
                    {
                        xzStream.CopyTo(outputStream);
                        xzStream.Flush();
                        return(outputStream.ToArray());
                    }
        }
コード例 #5
0
        public static string DecompressXZFile(string sourceFilePath, string destinationDirectory, TaskLoggingHelper logger)
        {
            var destFile = Path.Combine(destinationDirectory, Path.GetFileName(sourceFilePath)) + ".uncompressed";

            if (File.Exists(destFile))
            {
                LogMessage($"Uncompressed tar file already exists: {destFile}", logger);
                return(destFile);
            }

            using (Stream xz = new XZStream(File.OpenRead(sourceFilePath)))
                using (Stream outputStream = new FileStream(destFile, FileMode.CreateNew))
                {
                    xz.CopyTo(outputStream);
                }
            return(destFile);
        }
コード例 #6
0
 public int OnExecute(IConsole console)
 {
     try
     {
         using (var istm = Util.OpenInputStream(InputFile))
             using (var ostm = Util.OpenOutputStream(OutputFile, true))
             {
                 using (var izstm = new XZStream(istm))
                 {
                     izstm.CopyTo(ostm);
                 }
             }
     }
     catch (Exception e)
     {
         console.Error.WriteLine($"failed xz decompression:{e}");
         return(1);
     }
     return(0);
 }
コード例 #7
0
ファイル: XZ.cs プロジェクト: mnadareski/BurnOutSharp
        /// <inheritdoc/>
        public ConcurrentDictionary <string, ConcurrentQueue <string> > Scan(Scanner scanner, Stream stream, string file)
        {
            // If the xz file itself fails
            try
            {
                string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                Directory.CreateDirectory(tempPath);

                using (XZStream xzFile = new XZStream(stream))
                {
                    // If an individual entry fails
                    try
                    {
                        string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
                        using (FileStream fs = File.OpenWrite(tempFile))
                        {
                            xzFile.CopyTo(fs);
                        }
                    }
                    catch { }
                }

                // Collect and format all found protections
                var protections = scanner.GetProtections(tempPath);

                // If temp directory cleanup fails
                try
                {
                    Directory.Delete(tempPath, true);
                }
                catch { }

                // Remove temporary path references
                Utilities.StripFromKeys(protections, tempPath);

                return(protections);
            }
            catch { }

            return(null);
        }
コード例 #8
0
        /// <summary>
        /// Attempt to extract a file as an archive
        /// </summary>
        /// <param name="outDir">Output directory for archive extraction</param>
        /// <returns>True if the extraction was a success, false otherwise</returns>
        public override bool CopyAll(string outDir)
        {
            bool encounteredErrors = true;

            try
            {
                // Create the temp directory
                Directory.CreateDirectory(outDir);

                // Decompress the _filename stream
                FileStream outstream = FileExtensions.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
                var        xz        = new XZStream(File.OpenRead(this.Filename));
                xz.CopyTo(outstream);

                // Dispose of the streams
                outstream.Dispose();
                xz.Dispose();

                encounteredErrors = false;
            }
            catch (EndOfStreamException ex)
            {
                // Catch this but don't count it as an error because SharpCompress is unsafe
                logger.Verbose(ex);
            }
            catch (InvalidOperationException ex)
            {
                logger.Warning(ex);
                encounteredErrors = true;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                encounteredErrors = true;
            }

            return(encounteredErrors);
        }