#include "LoginAndCheckAccountsZiraatScript.h" #include "adb/AdbUtils.h" #include "dao/AccountDAO.h" #include "dao/ApplicationDAO.h" #include "dao/DeviceDAO.h" LoginAndCheckAccountsZiraatScript::LoginAndCheckAccountsZiraatScript( QString deviceId, QString appCode, QObject *parent ) : CommonZiraatScript(parent), m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)) { } LoginAndCheckAccountsZiraatScript::~LoginAndCheckAccountsZiraatScript() = default; void LoginAndCheckAccountsZiraatScript::doStart() { const DeviceInfo device = DeviceDAO::getDeviceById(m_deviceId); const ApplicationInfo app = ApplicationDAO::getApplication(m_deviceId, m_appCode); if (device.id.isEmpty() || app.id == -1) { m_error = "Device or app not found: " + m_deviceId + " " + m_appCode; qCritical() << m_error; emit finishedWithResult(m_error); return; } xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter)); if (!runAppAndGoToHomeScreen(device.id, app.package, app.pinCode, device.screenWidth, device.screenHeight)) { m_error = "Cant open the home screen: " + m_deviceId + " " + m_appCode; qWarning() << m_error; if (!ApplicationDAO::updatePinCodeStatus(app.id, "no", "Не прошла проверка [дата]")) { qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode; } AdbUtils::tryToKillApplication(m_deviceId, app.package); emit finishedWithResult(m_error); return; } else { if (!ApplicationDAO::updatePinCodeStatus(app.id, "yes", "")) { qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode; } if (goToAllProducts(device.id, device.screenWidth, device.screenHeight)) { xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter)); QList accounts = xmlScreenParser.parseAccountsInfo(); for (auto account: accounts) { account.deviceId = m_deviceId; account.appCode = m_appCode; account.status = AccountStatus::Active; if (!AccountDAO::upsertAccount(account)) { m_error = "Not updated: " + account.lastNumbers; qCritical() << m_error; } } postAccountsData(accounts); } else { qWarning() << "Cant go to all products: " << m_deviceId << " " << m_appCode; } } AdbUtils::tryToKillApplication(m_deviceId, app.package); emit finishedWithResult(m_error); }