예제 #1
0
bool Installer::Install(const QString& appName, const QString& appVersion, eAppType type) {
    Logger::GetInstance()->AddLog(tr("Installing %1").arg(appName));

    const AppsConfig::AppMap* apps = GetAppMap(type);
    if (!apps)
        return false;

    AppsConfig::AppMap::const_iterator appIter = apps->find(appName);
    if (appIter == apps->end())
        return false;

    AppsConfig::AppVersion::const_iterator iter = appIter.value().find(appVersion);
    if (iter == appIter->end())
        return false;

    const AppConfig& config = iter.value();

    m_pReply = m_pNetworkManager->get(QNetworkRequest(config.m_Url));
    connect(m_pReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(OnDownloadProgress(qint64, qint64)));
    connect(m_pReply, SIGNAL(finished()), this, SLOT(OnAppDownloaded()));
    m_pReply->setProperty(INSTALL_TYPE, type);
    m_pReply->setProperty(INSTALL_NAME, appName);
    m_pReply->setProperty(INSTALL_VERISON, appVersion);

    emit StartDownload();

    return true;
}
예제 #2
0
QString Settings::GetInstalledAppVersion(const QString& appName, eAppType type) {
    AppsConfig::AppMap* appMap = m_Config.GetAppMap(type);
    AppsConfig::AppMap::const_iterator appIter = appMap->find(appName);
    if (appIter == appMap->end())
        return "";

    AppsConfig::AppVersion::const_iterator iter = appIter.value().begin();
    if (iter == appIter.value().end())
        return "";

    return iter.value().m_Version;
}
예제 #3
0
void Installer::FormatFromSetting(AvailableSoftWare::SoftWareMap& softMap, const AppsConfig::AppMap& setting) {
    for (AppsConfig::AppMap::const_iterator appIter = setting.begin(); appIter != setting.end(); ++appIter) {
        AppsConfig::AppVersion::const_iterator iter = appIter.value().begin();
        if (iter == appIter.value().end())
            continue;

        const AppConfig& appConfig = iter.value();

        SoftWare soft;
        soft.m_CurVersion = appConfig.m_Version;
        soft.m_RunPath = appConfig.m_RunPath;
        softMap[appConfig.m_Name] = soft;
    }
}
예제 #4
0
QString Installer::GetRunPath(const QString& appName, eAppType type) {
    AppsConfig appsConfig = Settings::GetInstance()->GetCurrentConfig();
    AppsConfig::AppMap* appMap = appsConfig.GetAppMap(type);
    if (!appMap) {
        return "";
    }

    AppsConfig::AppMap::const_iterator appIter = appMap->find(appName);
    if (appIter == appMap->end())
        return "";

    AppsConfig::AppVersion::const_iterator iter = appIter.value().begin();
    if (iter == appIter.value().end())
        return "";

    const AppConfig& config = iter.value();
    return GetInstallPath(type) + config.m_RunPath;
}
예제 #5
0
void Installer::FormatFromUpdate(AvailableSoftWare::SoftWareMap& softMap, const AppsConfig::AppMap& update) {
    for (AppsConfig::AppMap::const_iterator appIter = update.begin(); appIter != update.end(); ++appIter) {
        for (AppsConfig::AppVersion::const_iterator iter = appIter.value().begin();
             iter != appIter.value().end();
             ++iter) {
            const AppConfig& appConfig = iter.value();

            if (softMap.contains(appConfig.m_Name)) {
                softMap[appConfig.m_Name].m_AvailableVersion.insert(appConfig.m_Version);
            } else {
                SoftWare soft;
                soft.m_AvailableVersion.insert(appConfig.m_Version);
                softMap[appConfig.m_Name] = soft;
            }
            if (Settings::GetVersion(softMap[appConfig.m_Name].m_NewVersion) != Settings::GetVersion(appConfig.m_Version))
                softMap[appConfig.m_Name].m_NewVersion = appConfig.m_Version;
        }
    }
}
예제 #6
0
void Settings::EmitAppConfig(YAML::Emitter& emitter, const char* appType, const AppsConfig::AppMap& appsMap) {
    if (appsMap.size()) {
        emitter << YAML::Key << appType;
        emitter << YAML::Value;
        emitter << YAML::BeginMap;
        for (AppsConfig::AppMap::const_iterator appIter = appsMap.begin(); appIter != appsMap.end(); ++appIter) {
            AppsConfig::AppVersion::const_iterator iter = appIter.value().begin();
            if (iter == appIter.value().end())
                continue;

            const AppConfig& config = iter.value();
            emitter << YAML::Key << config.m_Name.toStdString();
            emitter << YAML::Value;
            emitter << YAML::BeginMap;
            emitter << YAML::Key << VERSION;
            emitter << YAML::Value << config.m_Version.toStdString();
            emitter << YAML::Key << RUN_PATH;
            emitter << YAML::Value << config.m_RunPath.toStdString();
            emitter << YAML::Key << INSTALL_CMD;
            emitter << YAML::Value << config.m_InstallCmd.toStdString();
            emitter << YAML::Key << UNINSTALL_CMD;
            emitter << YAML::Value << config.m_UninstallCmd.toStdString();
            emitter << YAML::Key << INSTALL_PARAMS;
            emitter << YAML::Value << config.m_InstallParams.toStdString();
            emitter << YAML::Key << UNINSTALL_PARAMS;
            emitter << YAML::Value << config.m_UninstallParams.toStdString();

            if (config.m_InstalledFiles.size()) {
                emitter << YAML::Key << INSTALLED_FILES;
                emitter << YAML::Value;
                emitter << YAML::BeginSeq;
                for (int i = 0; i < config.m_InstalledFiles.size(); i++) {
                    emitter << config.m_InstalledFiles.at(i).toStdString();
                }
                emitter << YAML::EndSeq;
            }
            emitter << YAML::EndMap;
        }
        emitter << YAML::EndMap;
    }
}
예제 #7
0
bool Installer::Delete(const QString& appName, eAppType type, bool force) {
    Logger::GetInstance()->AddLog(tr("Deleting %1").arg(appName));
    AppsConfig appsConfig = Settings::GetInstance()->GetCurrentConfig();
    AppsConfig::AppMap* appMap = appsConfig.GetAppMap(type);

    AppsConfig::AppMap::const_iterator appIter = appMap->find(appName);
    if (appIter == appMap->end())
        return "";

    AppsConfig::AppVersion::const_iterator iter = appIter.value().begin();
    if (iter == appIter.value().end())
        return "";

    const AppConfig& config = iter.value();

    QString installPath = GetInstallPath(type);
    if (!config.m_RunPath.isEmpty()){
        while (ProcessHelper::IsProcessRuning(installPath + config.m_RunPath)) {
            Logger::GetInstance()->AddLog(tr("%1 app is running.").arg(appName));
            if(force)
            {
                if (1 == QMessageBox::information(NULL,//this,
                                                 tr("Error"),
                                                 tr("%1 app is running please close it.").arg(appName),
                                                 tr("Retry"))) {
                    Logger::GetInstance()->AddLog(tr("Deleting %1 canceled").arg(appName));
                    return false;
                }
            }
            else
            {
                if (1 == QMessageBox::information(NULL,//this,
                                                 tr("Error"),
                                                 tr("%1 app is running please close it.").arg(appName),
                                                 tr("Retry"),
                                                 tr("Cancel"))) {
                    Logger::GetInstance()->AddLog(tr("Deleting %1 canceled").arg(appName));
                    return false;
                }
            }
        }
    }

    bool result = false;
#ifdef Q_OS_WIN
    if (!config.m_InstallCmd.isEmpty() || !config.m_UninstallCmd.isEmpty()) {
        QString path = GetInstallPath(type) + APP_INSTALLER_DIR + "/" + appName + "/";
        if (!config.m_UninstallCmd.isEmpty())
            path += config.m_UninstallCmd;
        else
            path += config.m_InstallCmd;

        QString params = config.m_UninstallParams;

        int nExitCode = RunAndWaitForFinish(path, params);
        if (nExitCode == config.m_nSuccessInstallCode)
            result = true;
    } else {
#endif
        result = true;
        for (int i = 0; i < config.m_InstalledFiles.size(); ++i) {
            QString path = installPath + config.m_InstalledFiles.at(i);

            QFile file(path);
            if (file.exists()) {
                QFileInfo info(file);
                if (info.isDir()) {
                    result &= DirectoryManager::DeleteDir(path);
                } else {
                    result &= QFile().remove(path);
                }
            }
        }
#ifdef Q_OS_WIN
    }
#endif

    if (!result) {
        Logger::GetInstance()->AddLog(tr("Error delete app"));
        return false;
    }

    Logger::GetInstance()->AddLog(tr("%1 deleted").arg(appName));
    appMap->remove(appName);
    Settings::GetInstance()->UpdateConfig(appsConfig);

    UpdateAvailableSoftware();
    return true;
}
예제 #8
0
void Installer::OnAppDownloaded() {
    emit DownloadFinished();

    if (!m_pReply)
        return;

    eAppType type = (eAppType)m_pReply->property(INSTALL_TYPE).toInt();
    QString appName = m_pReply->property(INSTALL_NAME).toString();
    QString appVersion = m_pReply->property(INSTALL_VERISON).toString();
    const AppsConfig::AppMap* pUpdateMap = m_AppsConfig.GetAppMap(type);
    if (!pUpdateMap)
        return;

    AppsConfig::AppMap::const_iterator appIter = pUpdateMap->find(appName);
    if (appIter == pUpdateMap->end())
        return;

    AppsConfig::AppVersion::const_iterator iter = appIter.value().find(appVersion);
    if (iter == appIter.value().end())
        return;

    const AppConfig& updateConfig = iter.value();

    QByteArray data = m_pReply->readAll();
    if (!data.size()) {
        Logger::GetInstance()->AddLog(tr("Error download app"));
        return;
    }

    //save archive
    QString tempFilePath = DirectoryManager::GetInstance()->GetDownloadDir() + APP_DOWNLOAD;
    QFile tempFile(tempFilePath);
    if (!tempFile.open(QFile::WriteOnly | QFile::Truncate)) {
        Logger::GetInstance()->AddLog(tr("Error save archive"));
        return;
    }
    tempFile.write(data);
    tempFile.close();

    //unpack archive
    QString tempDir = DirectoryManager::GetInstance()->GetDownloadDir() + APP_TEMP_DIR;
    if (!DirectoryManager::DeleteDir(tempDir)) {
        Logger::GetInstance()->AddLog(tr("Error delete old directory"));
        return;
    }
    if (!QDir().mkdir(tempDir)) {
        Logger::GetInstance()->AddLog(tr("Error create temp directory"));
        return;
    }

    //if file is a zip-archive - unpack, otherwise - just move to the tempDir
    //check is performed by server's file extension
    QFileInfo serverFileInfo(updateConfig.m_Url.toString());
    QString serverFileName = serverFileInfo.fileName();

    if (DirectoryManager::IsFilePacked(serverFileName)) {
        if (!zipHelper::unZipFile(tempFilePath, tempDir)) {
            Logger::GetInstance()->AddLog(tr("Error unpack archive"));
            return;
        }
    } else {
        if (!DirectoryManager::MoveFileToDir(tempFilePath, tempDir, serverFileName)) {
            Logger::GetInstance()->AddLog(tr("Error move file to the temp directory"));
            return;
        }
    }

    //copy to destination
    QString installPath = GetInstallPath(type);

    //no install just copy file to new folder
    QStringList installedFiles = DirectoryManager::GetDirectoryStructure(tempDir);

    bool bInstalled = false;
#ifdef Q_OS_WIN
    if (updateConfig.m_InstallCmd.isEmpty()) {
#endif
        bInstalled = DirectoryManager::CopyAllFromDir(tempDir, installPath);
        if (!bInstalled) {
            Logger::GetInstance()->AddLog(tr("Error copy apps to destination"));
        }
#ifdef Q_OS_WIN
    }else {
        QString InstallerPath;
        do {
            //copy installer
            //create path for save installer
            QString InstallersPath = installPath + APP_INSTALLER_DIR;
            if (!QDir().exists(InstallersPath) &&
                !QDir().mkdir(InstallersPath)) {
                Logger::GetInstance()->AddLog(tr("Error create installers path"));
                break;
            }
            //create app installer path
            InstallerPath = InstallersPath + "/" + appName;
            DirectoryManager::DeleteDir(InstallerPath);
            if (!QDir().mkdir(InstallerPath)) {
                Logger::GetInstance()->AddLog(tr("Error create installer path"));
                break;
            }
            //copy installer
            if (!DirectoryManager::CopyAllFromDir(tempDir, InstallerPath)) {
                Logger::GetInstance()->AddLog(tr("Error copy installer"));
                break;
            }
            QString installer = InstallerPath + "/" + updateConfig.m_InstallCmd;

            QFile aFile(installer);
            if (!aFile.exists()) {
                Logger::GetInstance()->AddLog(tr("Error running installer - file not found"));
                break;
            }

            QString params = updateConfig.m_InstallParams;
            int nExitCode = RunAndWaitForFinish(installer, params);

            if (updateConfig.m_nSuccessInstallCode == nExitCode)
                bInstalled = true;
        } while(false);

        if (!bInstalled) {
            //hack after cancel install directory can't be delete at once
            //so we rename it and then delete
            QString temp = InstallerPath + QString::number(QDateTime().currentMSecsSinceEpoch());
            DirectoryManager::DeleteDir(QDir().rename(InstallerPath, temp) ? temp : InstallerPath);
        }
    }
#endif

    if (bInstalled) {
        AppConfig config;

        //const AppConfig installedConfig = installedApp.value(name);
        config.m_Name = appName;
        if (!updateConfig.m_RunPath.isEmpty())
            config.m_RunPath = updateConfig.m_RunPath;
        config.m_InstalledFiles = installedFiles;
        config.m_Version = updateConfig.m_Version;
        config.m_InstallCmd = updateConfig.m_InstallCmd;
        config.m_UninstallCmd = updateConfig.m_UninstallCmd;
        config.m_InstallParams = updateConfig.m_InstallParams;
        config.m_UninstallParams = updateConfig.m_UninstallParams;

        AppsConfig setting = Settings::GetInstance()->GetCurrentConfig();
        AppsConfig::AppMap* pSettingMap = setting.GetAppMap(type);
        if (pSettingMap) {
            pSettingMap->remove(config.m_Name);
            //pSettingMap->insert(appName, config);
            (*pSettingMap)[config.m_Name][config.m_Version] = config;
        }
        Settings::GetInstance()->UpdateConfig(setting);
    }

    //delete temp files
    DirectoryManager::DeleteDir(tempDir);
    QFile().remove(tempFilePath);

    UpdateAvailableSoftware();
    if (bInstalled) {
        Logger::GetInstance()->AddLog(tr("%1 installed.").arg(appName));
        CheckForUpdate();
    }
}