using SevenZip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Install.Core.Common
{
    public static class SeverZipExt
    {
        public static void Uncompress(string path_7z, string dstPath)
        {
            string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;// Assembly.GetExecutingAssembly().Location;
            path = Path.GetDirectoryName(path);
            //exe的根目录
            //设置7z.dll 路径
            path = Path.Combine(path, Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
            SevenZip.SevenZipBase.SetLibraryPath(path);

            //先删除
            if (Directory.Exists(dstPath))
            {
                Directory.Delete(dstPath, true);
            }

            using (var tmp = new SevenZipExtractor(path_7z))
            {
                tmp.ExtractArchive(dstPath);
                //for (var i = 0; i < tmp.ArchiveFileData.Count; i++)
                //{
                //    tmp.ExtractFiles($@"{dstPath}\", tmp.ArchiveFileData[i].Index);
                //}
            }
            //删除xxx.7z
            //File.Delete(filePath);
            // return true;
        }
    }
}
