Skip to content

Commit

Permalink
add threadpool
Browse files Browse the repository at this point in the history
Majjcom committed Dec 21, 2023
1 parent 82b7fc1 commit b776a3f
Showing 7 changed files with 78 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

一个用C++编写的极速ncm转换工具。

从v1.2开始支持多线程解密。

多线程命令行版本见[Majjcom/ncmpp](https://github.com/Majjcom/ncmpp)

## 使用方法
2 changes: 1 addition & 1 deletion ncmppGui/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<manifest package="site.majjcom.ncmppgui" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.1.0" android:versionCode="100100000" android:installLocation="auto">
<manifest package="site.majjcom.ncmppgui" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.2.0" android:versionCode="100200000" android:installLocation="auto">


<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
8 changes: 5 additions & 3 deletions ncmppGui/ncmppGui.pro
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ SOURCES += \
src/pkcs7.cpp \
src/qlistwidget_withdrop.cpp \
src/unlocker.cpp \
src/getpath.cpp
src/getpath.cpp \
src/unlockrunner.cpp

HEADERS += \
src/base64.h \
@@ -33,7 +34,8 @@ HEADERS += \
src/pkcs7.h \
src/qlistwidget_withdrop.h \
src/unlocker.h \
src/getpath.h
src/getpath.h \
src/unlockrunner.h

FORMS += \
ui/mainwindow.ui
@@ -56,7 +58,7 @@ DEPENDPATH += $$PWD/ext/include
win32:!win32-g++: PRE_TARGETDEPS += \
$$PWD/ext/lib/libssl_static.lib \
$$PWD/ext/lib/libcrypto_static.lib
android: include(E:/Android/android-sdk-windows/android_openssl/openssl_use.pri)
android: include(E:/Android/android-sdk-windows/android_openssl/openssl_use_armv7.pri)

android: DISTFILES += \
android/AndroidManifest.xml \
25 changes: 21 additions & 4 deletions ncmppGui/src/unlocker.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "unlocker.h"

#include "unlockrunner.h"
#include "ncmdump.h"

Unlocker::Unlocker(QObject *parent)
: pool(new QThreadPool(this))
, unlocked_count(0)
{
this->setParent(parent);
}
@@ -15,13 +18,27 @@ void Unlocker::setUp(QListWidget_withDrop* list_obj_, QString out_dir_)

void Unlocker::run()
{
int count = this->list_obj->getFileCount();
count = this->list_obj->getFileCount();
for (int i = 0; i < count; i++)
{
using std::string;
QString file = this->list_obj->getNextFile();
ncm::ncmDump(file, this->out_dir);
emit this->unlocked(i + 1, count);
UnlockRunner* runner = new UnlockRunner(file, this->out_dir);
connect(runner, SIGNAL(finish()), this, SLOT(runner_finished()));
bool ok = false;
while (!ok)
{
ok = pool->tryStart(runner);
}
// pool->start(runner);

// ncm::ncmDump(file, this->out_dir);
// emit this->unlocked(i + 1, count);
}
this->exit();
}

void Unlocker::runner_finished()
{
unlocked_count++;
emit unlocked(unlocked_count, count);
}
9 changes: 8 additions & 1 deletion ncmppGui/src/unlocker.h
Original file line number Diff line number Diff line change
@@ -3,21 +3,28 @@

#include "qlistwidget_withdrop.h"
#include <QObject>
#include <QThreadPool>
#include <QThread>

class Unlocker : public QThread
{
Q_OBJECT
public:
explicit Unlocker(QObject *parent = nullptr);
explicit Unlocker(QObject* parent = nullptr);
void setUp(QListWidget_withDrop* list_obj_, QString out_dir_);

protected:
void run() override;

private slots:
void runner_finished();

private:
QListWidget_withDrop* list_obj;
QThreadPool* pool;
QString out_dir;
int unlocked_count;
int count = 0;

signals:
void unlocked(int count, int total);
18 changes: 18 additions & 0 deletions ncmppGui/src/unlockrunner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "unlockrunner.h"

#include "ncmdump.h"

UnlockRunner::UnlockRunner(QString path_, QString out_)
: QObject{}
, QRunnable{}
, path(path_)
, out(out_)
{
setAutoDelete(true);
}

void UnlockRunner::run()
{
ncm::ncmDump(path, out);
emit finish();
}
23 changes: 23 additions & 0 deletions ncmppGui/src/unlockrunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef UNLOCKRUNNER_H
#define UNLOCKRUNNER_H

#include <QObject>
#include <QRunnable>

class UnlockRunner : public QObject, public QRunnable
{
Q_OBJECT
public:
explicit UnlockRunner(QString path_, QString out_);

void run() override;

private:
QString path;
QString out;

signals:
void finish();
};

#endif // UNLOCKRUNNER_H

0 comments on commit b776a3f

Please sign in to comment.