diff --git a/src/QtScrcpy.pro.user b/src/QtScrcpy.pro.user index 24ede2b..ec4b260 100644 --- a/src/QtScrcpy.pro.user +++ b/src/QtScrcpy.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {37b22fe7-3e02-43d3-85e3-251a3ebe4093} + {49c3991c-71bb-4f46-826d-1d1cf5cba2d4} ProjectExplorer.Project.ActiveTarget diff --git a/src/QtScrcpy.pro.user.37b22fe b/src/QtScrcpy.pro.user.37b22fe new file mode 100644 index 0000000..24ede2b --- /dev/null +++ b/src/QtScrcpy.pro.user.37b22fe @@ -0,0 +1,318 @@ + + + + + + EnvironmentId + {37b22fe7-3e02-43d3-85e3-251a3ebe4093} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.9.6 MSVC2015 32bit + Desktop Qt 5.9.6 MSVC2015 32bit + qt.596.win32_msvc2015_kit + 0 + 0 + 0 + + G:/mygitcode/QtScrcpy/build-QtScrcpy-Desktop_Qt_5_9_6_MSVC2015_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + G:/mygitcode/QtScrcpy/build-QtScrcpy-Desktop_Qt_5_9_6_MSVC2015_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + G:/mygitcode/QtScrcpy/build-QtScrcpy-Desktop_Qt_5_9_6_MSVC2015_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 部署设置 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + QtScrcpy + + Qt4ProjectManager.Qt4RunConfiguration:G:/mygitcode/QtScrcpy/src/QtScrcpy.pro + true + + QtScrcpy.pro + false + + G:/mygitcode/QtScrcpy/build-QtScrcpy-Desktop_Qt_5_9_6_MSVC2015_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/adbprocess.cpp b/src/adbprocess.cpp index 036a38a..bd2d054 100644 --- a/src/adbprocess.cpp +++ b/src/adbprocess.cpp @@ -83,6 +83,7 @@ void AdbProcess::execute(const QString& serial, const QStringList& args) adbArgs << "-s" << serial; } adbArgs << args; + qDebug() << adbArgs.join(" "); start(getAdbPath(), adbArgs); //start("C:\\Users\\Barry\\Desktop\\sockettool.exe", Q_NULLPTR); } diff --git a/src/dialog.cpp b/src/dialog.cpp index 1a2c7db..53d7f91 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -2,11 +2,13 @@ #include "ui_dialog.h" #include "adbprocess.h" + Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); + server = new Server(); } Dialog::~Dialog() @@ -22,3 +24,13 @@ void Dialog::on_adbProcess_clicked() }); adb->execute("", QStringList() << "devices"); } + +void Dialog::on_startServerBtn_clicked() +{ + server->start("P7C0218510000537", 27183, 0, 8000000, ""); +} + +void Dialog::on_stopServerBtn_clicked() +{ + server->stop(); +} diff --git a/src/dialog.h b/src/dialog.h index 4152a2c..f0506f5 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -3,6 +3,8 @@ #include +#include "server.h" + namespace Ui { class Dialog; } @@ -18,8 +20,13 @@ public: private slots: void on_adbProcess_clicked(); + void on_startServerBtn_clicked(); + + void on_stopServerBtn_clicked(); + private: Ui::Dialog *ui; + Server* server; }; #endif // DIALOG_H diff --git a/src/dialog.ui b/src/dialog.ui index 7f52460..8fda0b6 100644 --- a/src/dialog.ui +++ b/src/dialog.ui @@ -18,12 +18,38 @@ 30 20 - 93 + 111 28 - PushButton + adbProcess + + + + + + 30 + 60 + 111 + 28 + + + + startServer + + + + + + 30 + 100 + 111 + 28 + + + + stopServer diff --git a/src/main.cpp b/src/main.cpp index e4c90bc..1734bf8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,8 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - qputenv("QTSCRCPY_ADB_PATH", "C:\\Users\\Barry\\Desktop\\scrcpy-win64\\adb.exe"); + qputenv("QTSCRCPY_ADB_PATH", "C:\\Users\\Barry\\Desktop\\scrcpy-win64\\adb.exe"); + qputenv("QTSCRCPY_SERVER_PATH", "G:\\mygitcode\\QtScrcpy\\src\\scrcpy-server.jar"); Dialog w; w.show(); diff --git a/src/server.cpp b/src/server.cpp index 9e002db..eda9814 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -13,7 +13,11 @@ Server::Server(QObject *parent) : QObject(parent) connect(&m_serverSocket, &QTcpServer::newConnection, this, [this](){ m_deviceSocket = m_serverSocket.nextPendingConnection(); connect(m_deviceSocket, &QTcpSocket::disconnected, m_deviceSocket, &QTcpSocket::deleteLater); - connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater); + //connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater); + connect(m_deviceSocket, &QTcpSocket::readyRead, this, [this](){ + qDebug() << "ready read"; + m_deviceSocket->readAll(); + }); }); } @@ -128,6 +132,7 @@ bool Server::start(const QString& serial, quint16 localPort, quint16 maxSize, qu return false; } + m_serial = serial; m_localPort = localPort; m_maxSize = maxSize; m_bitRate = bitRate; @@ -142,7 +147,11 @@ void Server::connectTo() if (m_tunnelForward) { m_deviceSocket = new QTcpSocket(this); connect(m_deviceSocket, &QTcpSocket::disconnected, m_deviceSocket, &QTcpSocket::deleteLater); - connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater); + //connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater); + connect(m_deviceSocket, &QTcpSocket::readyRead, this, [this](){ + qDebug() << "ready read"; + m_deviceSocket->readAll(); + }); m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort); } @@ -155,7 +164,8 @@ void Server::connectTo() bool success = false; if (m_tunnelForward) { if (m_deviceSocket->isValid()) { - if (m_deviceSocket->read(1)) { + QByteArray ar = m_deviceSocket->read(1); + if (!ar.isEmpty()) { success = true; } else { success = false; @@ -166,12 +176,26 @@ void Server::connectTo() } } else { if (m_deviceSocket->isValid()) { + // we don't need the server socket anymore + // just m_deviceSocket is ok + m_serverSocket.close(); success = true; } else { m_deviceSocket->deleteLater(); success = false; } } + if (success) { + // the server is started, we can clean up the jar from the temporary folder + removeServer(); + m_serverCopiedToDevice = false; + // we don't need the adb tunnel anymore + if (m_tunnelForward) { + disableTunnelForward(); + } else { + disableTunnelReverse(); + } + } emit connectToResult(success); }); } @@ -190,7 +214,7 @@ void Server::stop() if (m_serverCopiedToDevice) { removeServer(); } - m_serverSocket.disconnect(); + m_serverSocket.close(); if (m_deviceSocket) { m_deviceSocket->disconnectFromHost(); } @@ -204,6 +228,7 @@ bool Server::startServerByStep() switch (m_serverStartStep) { case SSS_PUSH: stepSuccess = pushServer(); + break; case SSS_ENABLE_TUNNEL_REVERSE: stepSuccess = enableTunnelReverse(); break;