예제 #1
0
void AntiPiracy::checkValidityAndSetScene(AbstractPane* root, QString urlToBypassHash) {
    // Save internally for future use
    if (root) { m_normalRoot = root; }
    m_urlToBypassHash = urlToBypassHash;

    // Check if the unlock key was already entered previously
    QSettings settings;
    settings.beginGroup("AntiPiracy");
    if ((settings.contains("unlockKeyEnteredByUser")) && (this->hashThis(settings.value("unlockKeyEnteredByUser", "").toString()) == m_unlockKeyHash)) {
        // User already entered the correct key previously
        m_appInstalledFromBBW = true;
    }
    else {
        // The next code will check if the app was downloaded from BBW
        QDir dir("/pps/system/installer/appdetails/");
        dir.setFilter(QDir::Files | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot | QDir::AllEntries);
        QFileInfoList fileInfoList = dir.entryInfoList();

        for (int i = 0; i < fileInfoList.size(); i++) {
            QString completePath = fileInfoList[i].path() + "/" + fileInfoList[i].fileName() + (fileInfoList[i].isDir() ? "/" : "");
            if (this->checkFile(completePath)) { break; };
        }
    }

    if ((m_appInstalledFromBBW) || (m_appInstalledFromBetaZone)) {
        // App was either installed from BBW/BetaZone or unlock key was previously entered correctly.
        // Set the normal main.qml as Scene
        Application::instance()->setScene(root);

        this->deleteLater();
    }
    else {
        /*
         * Load a custom Page constructed in C++ to make sure it can't be altered
         * The Page is only a Label and an ActivityIndicator, but it's mostly used to be the
         * scene where the unlock key prompt will be shown
         */
        Page *keyPromptPage = new Page(this);

        Container *keyPromptContainer = new Container();
        keyPromptContainer->setLayout(new DockLayout());

        Label *label = new Label();
        label->setText(tr("Checking validity, please wait..."));
        label->setHorizontalAlignment(HorizontalAlignment::Center);

        ActivityIndicator *activityIndicator = new ActivityIndicator();
        activityIndicator->setHorizontalAlignment(HorizontalAlignment::Center);
        activityIndicator->setMinHeight(300);
        activityIndicator->setMinWidth(activityIndicator->minHeight());

        Container *container = new Container();
        container->setHorizontalAlignment(HorizontalAlignment::Center);
        container->setVerticalAlignment(VerticalAlignment::Center);
        container->add(label);
        container->add(activityIndicator);

        keyPromptContainer->add(container);
        keyPromptPage->setContent(keyPromptContainer);

        Application::instance()->setScene(keyPromptPage);

        activityIndicator->start();

        /*
         * Check online for a bypass.
         * This can be used while your app is in review period to avoid having the unlock prompt
         * shown to a BBW reviewer. To construct the bypass hash, use the function
         * printToConsoleHashOfThisKey() and pass the app version you'd like to whitelist
         * as a parameter. Use the hash printed to console and put it online.
         */
        QUrl url(m_urlToBypassHash);
        QNetworkAccessManager *nam = new QNetworkAccessManager(this);
        QNetworkReply *reply = nam->get(QNetworkRequest(url));
        connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
    }
}