Qt自定义安装包

能够将放在QT的资源文件中,在解压本地 .或者先复制到本地再解压,支持多线程.

核心代码:

void UncompressThread::uncompressFile(QString file,QString path)
{
    QString m_strAppPath =path;
    //QString strInFileName /*= "D:\\QtCore\\Uncompress\\release\\Qt5.7-static"*/;

    QStringList OutFileList;
    OutFileList<< file;
    qDebug()<<OutFileList;

    for(int i = 0;i < OutFileList.count();i++)
    {

        //SubFunExtractFile(strInFileName, OutFileList.at(i));


        bool bRet = SubFunExtractDir(OutFileList.at(i), m_strAppPath);
        if (bRet != true)
        {
            SendUncompressInfomationSig(QString::fromLocal8Bit("提取文件错误."));
        }
        SendUncompressInfomationSig(QString::fromLocal8Bit("提取文件完成."));
    }

    emit WorkerThreadFinishSig();
}


bool UncompressThread::SubFunExtractFile(QString strInFile, QString strOutFile)
{
    QFile infile(strInFile);
    if (!infile.open(QIODevice::ReadOnly))
    {
        return(false);
    }
    QByteArray data = infile.readAll();
    QFile outfile(strOutFile);
    if (!outfile.open(QIODevice::WriteOnly | QIODevice::Append))
    {
        return(false);
    }
    outfile.write(data);
    infile.close();
    outfile.close();
    return(true);
}

bool UncompressThread::SubFunExtractDir(QString strInFile, QString strOutPath)
{
    QuaZip zipInFile(strInFile);
    if (!zipInFile.open(QuaZip::mdUnzip))
    {
        qDebug()<<"zipInFile open failed";
        return(false);
    }

    int nFileCount = zipInFile.getEntriesCount();


    int nFileProgress = 0;
    bool hasFile = zipInFile.goToFirstFile();
    while(hasFile)
    {
        bool bRet = SubFubExtractZipFile(zipInFile.getZipName(), zipInFile.getCurrentFileName(), strOutPath);
        if (bRet != true)
        {
            qDebug()<<"SubFubExtractZipFile failed";
            return(false);
        }
        nFileProgress++;
        emit SendProgressValueSig(100*nFileProgress/nFileCount);
        bRet = zipInFile.goToNextFile();
        if (bRet != true)
            break;
    }
    return(true);
}

bool UncompressThread::SubFubExtractZipFile(QString strInFile, QString strInFilePath, QString strOutPath)
{
    QuaZipFile infile(strInFile, strInFilePath);
    if (!infile.open(QIODevice::ReadOnly))
    {
        return(false);
    }
    QByteArray data = infile.readAll();
    QString outPath = strOutPath +'\\'+ strInFilePath;
    if (outPath.endsWith("/") == true)
    {
        QDir appDir(outPath);
        if (appDir.exists() != true)
        {
            appDir.mkpath(outPath);
        }
        return(true);
    }
    outPath.remove('\\');

    QFile outfile(outPath);
    QString file = outPath.remove(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation)[0]);
    emit SendCurrentFileSig(file);
    SendUncompressInfomationSig(QString::fromLocal8Bit("正在提取文件")+file);
    if (!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        return(false);
    }
    outfile.write(data);
    infile.close();
    outfile.close();
    return(true);
}

需要的quazip已编译打包

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值