批量提取IE缓冲美术资源

工具下载


麻蛋,本来是想用IE缓冲文件提取页游美术资源的

结果每次只能复制一张图片搞毛线啊

所以写了下面这个提取器



路径无论是 "/" 或 "\\" 都没所谓反正会转




其实就是利用cmd进行复制

先提取文件名到1.txt

然后生成copy命令


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class QFile;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

signals:
    void readyReadStandardOutput();
    void finished();

private slots:

    void on_ExtractButton_clicked();

    void on_DirectoryButton_clicked();

    void on_coverBox_stateChanged(int arg1);

private:
    void setUIEnabled(bool isEnabled);
    void startExtraction(const QString &savePath, const QString &buffPath);
    void writeCommand(QFile &file, const QString &savePath);
    void writeDirectory(QFile &file, const QString &buffPath);
    QString replace(const QString &path);
    QStringList readTextFile(const QString &path);
    void writeTextFile(const QString &path, const QStringList &command);
    QString command(const QString path, const QString &copyPath);
    QString synthesisCommand(const QString &path, const QString &copyPath);

private:
    Ui::MainWindow *ui;
    QString _applicationDirPath;
    bool _check;
};

#endif // MAINWINDOW_H

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtConcurrent>
#include <QFileDialog>
#include <QTextStream>
#include <QFileInfo>
#include <QProcess>
#include <QFile>
#include <QDir>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    _check = false;
    _applicationDirPath = QCoreApplication::applicationDirPath();

//    QLabel *label = new QLabel("123",this);
//    connect(this, &MainWindow::readyReadStandardOutput,this,[=,&label](){
//        QProcess *pro = (QProcess*)QObject::sender();
//        label->setText("321");
//        //ui->statusBar->showMessage(QString::fromLocal8Bit( pro->readAllStandardOutput()));
//    });

    connect(this,&MainWindow::finished, this, [=](){
        setUIEnabled(true);
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_ExtractButton_clicked()
{
    QString save = ui->SaveEidt->text();
    QString buff = ui->BuffEdit->text();
    if(save.isEmpty() || buff.isEmpty())
        return;

    save = replace(save);
    buff = replace(buff);

    setUIEnabled(false);
    QtConcurrent::run([=,save,buff](){
        startExtraction(save,buff);
    });

}

void MainWindow::on_DirectoryButton_clicked()
{
    QString dirName = QFileDialog::getExistingDirectory(this);
    if(!dirName.isEmpty())
        ui->SaveEidt->setText(dirName);
}

void MainWindow::setUIEnabled(bool isEnabled)
{
    ui->ExtractButton->setEnabled(isEnabled);
    ui->SaveEidt->setEnabled(isEnabled);
    ui->BuffEdit->setEnabled(isEnabled);
    ui->DirectoryButton->setEnabled(isEnabled);
    ui->coverBox->setEnabled(isEnabled);
}

void MainWindow::startExtraction(const QString &savePath, const QString &buffPath)
{
    QFile file(_applicationDirPath+"/1.bat");
    if(!file.open(QIODevice::Text|QIODevice::WriteOnly)){
        return ;
    }
    if(!file.exists()){
        file.close();
    }

    writeDirectory(file,buffPath);

    QProcess *pro = new QProcess(this);
    //不知为何没有输出
//    connect(pro, &QProcess::readyReadStandardOutput,this, &MainWindow::readyReadStandardOutput);
//    pro->start(_applicationDirPath+"/1.bat");
    pro->execute(_applicationDirPath+"/1.bat");

    writeCommand(file, savePath);
    pro->execute(_applicationDirPath+"/2.bat");

    emit finished();
    QFile::remove(_applicationDirPath+"/1.bat");
    QFile::remove(_applicationDirPath+"/2.bat");
    QFile::remove(_applicationDirPath+"/1.txt");
    //disconnect(pro,&QProcess::readyReadStandardOutput,this,&MainWindow::readyReadStandardOutput);
}

void MainWindow::writeCommand(QFile &file, const QString &savePath)
{
    while(!file.exists());
    auto list = this->readTextFile(_applicationDirPath+"/1.txt");

    for(int i=0;i<list.length();i++){
        list[i] = this->command(list[i],savePath);
    }

    this->writeTextFile(_applicationDirPath+"/2.bat",list);
}

void MainWindow::writeDirectory(QFile &file, const QString &buffPath)
{
    QTextStream cin(&file);
    cin.setCodec("ANSI");
    cin << "F:"<<endl;
    cin << "cd "+buffPath<<endl;
    cin << "dir *.* /s /b > "+_applicationDirPath+"/1.txt"<<endl;
    file.close();
}

QString MainWindow::replace(const QString &path)
{
    return ((QString)path).replace("/","\\");
}

QStringList MainWindow::readTextFile(const QString &path){
    QStringList str;
    QFile file(path);

    if(!file.open(QIODevice::Text|QIODevice::ReadOnly)){
        return str;
    }

    QTextStream out(&file);
    while(!out.atEnd()){
        str << out.readLine();
    }
    file.close();
    return str;
}

void MainWindow::writeTextFile(const QString &path, const QStringList &command){
    QFile file(path);
    if(!file.open(QIODevice::Text|QIODevice::ReadWrite)){
        return;
    }

    QTextStream cin(&file);
    cin.setCodec("ANSI");
    foreach(auto str, command){
        cin << str<<endl;
    }

    file.close();
}

QString MainWindow::command(const QString path,const QString &copyPath){
    QFileInfo info(path);
    QString Folder = ((QString)copyPath).replace("\\","/") + "/"+info.suffix();

    QDir dir;
    //如果没有文件夹
    if(!dir.exists(Folder)){
        //如果创建失败
        if(!dir.mkdir(Folder)){

            return synthesisCommand(path,Folder);

//            file.setFileName(QString("\"%2\\%3\"").arg(copyPath).arg(QFileInfo(path).fileName()));
//            if(file.exists() && !_check)
//                return "-1";

//            return QString("copy \"%1\" %2").arg(path).arg(file.fileName());
        }
    }


    Folder = Folder.replace("/","\\");
    return synthesisCommand(path,Folder);
    /*file.setFileName(QString("\"%2\\%3\"").arg(Folder).arg(QFileInfo(path).fileName()));
    if(file.exists() && !_check)
        return "-1";

    return QString("copy \"%1\" %2").arg(path).arg(file.fileName());*/
}

QString MainWindow::synthesisCommand(const QString &path, const QString &copyPath)
{
    QFile file(QString("\"%2\\%3\"").arg(copyPath).arg(QFileInfo(path).fileName()));
    if(file.exists() && !_check)
        return "";

    return QString("copy \"%1\" %2").arg(path).arg(file.fileName());
}

void MainWindow::on_coverBox_stateChanged(int arg1)
{
    if(arg1 == Qt::Checked){
        _check = true;
    }
    else{
        _check = false;
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鱼游戏开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值