Ejemplo n.º 1
0
        //@Brief Descomprime y comprueba el archivo de actualización
        //@Return Boolean True si la operación se ha realizado correctamente
        private bool UncompressUpdateFile()
        {
            bool   bOk        = false;
            string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "JBC\\Manager", System.Convert.ToString(My.Settings.Default.TempUpdateFolder));
            string filePath   = Path.Combine(tempFolder, System.Convert.ToString(My.Settings.Default.AppCompressFileName));

            if (File.Exists(filePath))
            {
                string newFile = Path.ChangeExtension(filePath, "tar.gz");

                try
                {
                    File.Move(filePath, newFile);

                    //Descomprimir .tar.gz
                    Stream inStream   = File.OpenRead(newFile);
                    Stream gzipStream = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(inStream);
                    ICSharpCode.SharpZipLib.Tar.TarArchive tarArchive = ICSharpCode.SharpZipLib.Tar.TarArchive.CreateInputTarArchive(gzipStream);

                    tarArchive.ExtractContents(tempFolder);

                    tarArchive.Close();
                    gzipStream.Close();
                    inStream.Close();

                    //Comprobar que existe el .exe
                    bOk = Directory.GetFiles(tempFolder, "*.exe").Length > 0;
                }
                catch (Exception)
                {
                }
            }

            return(bOk);
        }
Ejemplo n.º 2
0
 public static void ExtractTarToDirectory(string sourceFilePath, string destinationDirectory, TaskLoggingHelper logger)
 {
     using (var outputStream = new FileStream(sourceFilePath, FileMode.Open))
     {
         ICSharpCode.SharpZipLib.Tar.TarArchive tarArchive = ICSharpCode.SharpZipLib.Tar.TarArchive.CreateInputTarArchive(outputStream);
         tarArchive.ExtractContents(destinationDirectory);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Decompress the update file
        /// </summary>
        /// <returns>True if the operation was successful</returns>
        private bool UncompressUpdateFile()
        {
            bool   bOk       = false;
            string sTempDir  = Path.Combine(Path.GetTempPath(), System.Convert.ToString(My.Settings.Default.TempDirName));
            string sTempFile = Path.Combine(sTempDir, System.Convert.ToString(My.Settings.Default.AppCompressFileName));

            if (File.Exists(sTempFile))
            {
                string sTempCompressFile = Path.ChangeExtension(sTempFile, "tar.gz");

                try
                {
                    File.Move(sTempFile, sTempCompressFile);

                    //Descomprimir .tar.gz
                    Stream inStream   = File.OpenRead(sTempCompressFile);
                    Stream gzipStream = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(inStream);
                    ICSharpCode.SharpZipLib.Tar.TarArchive tarArchive = ICSharpCode.SharpZipLib.Tar.TarArchive.CreateInputTarArchive(gzipStream);

                    tarArchive.ExtractContents(sTempDir);

                    tarArchive.Close();
                    gzipStream.Close();
                    inStream.Close();

                    //Eliminamos el archivo comprimido
                    if (File.Exists(sTempCompressFile))
                    {
                        File.Delete(sTempCompressFile);
                    }

                    bOk = true;
                }
                catch (Exception ex)
                {
                    LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message);
                }
            }
            else
            {
                LoggerModule.logger.Warn(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". File doesn't exists: " + sTempFile);
            }

            return(bOk);
        }
Ejemplo n.º 4
0
        } // End Function Sha1

        public static void UnTarBz2(string fileName)
        {
            string tempTarFile = System.IO.Path.GetTempFileName();

            using (System.IO.FileStream dest = System.IO.File.OpenWrite(tempTarFile))
            {
                using (System.IO.FileStream fs = System.IO.File.OpenRead(fileName))
                {
                    byte[] buffer = new byte[4096];

                    using (ICSharpCode.SharpZipLib.BZip2.BZip2InputStream bz2 = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(fs))
                    {
                        int bytesRead;
                        while ((bytesRead = bz2.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            dest.Write(buffer, 0, bytesRead);
                            dest.Flush();
                        } // Whend
                    }     // End using bz2

                    fs.Flush();
                } // End using fs
            }     // End Using dest

            // https://stackoverflow.com/questions/8863875/decompress-tar-files-using-c-sharp
            // https://code.google.com/archive/p/tar-cs/

            string trash = CreateTemporaryDirectory();

            using (System.IO.FileStream fs = System.IO.File.OpenRead(tempTarFile))
            {
                using (ICSharpCode.SharpZipLib.Tar.TarArchive tarArchive = ICSharpCode.SharpZipLib.Tar.TarArchive.CreateInputTarArchive(fs))
                {
                    tarArchive.ExtractContents(trash);
                    tarArchive.Close();
                } // End Using tarArchive

                // using (ICSharpCode.SharpZipLib.Tar.TarInputStream tar = new ICSharpCode.SharpZipLib.Tar.TarInputStream(fs)) { }
            } // End Using fs

            System.IO.File.Delete(tempTarFile);
        } // End Sub UnTarBz2