示例#1
0
void MainWindow::Start()
{
    _ModuleManager = new ModuleManager(this);

    NeedRestart = false;
    BrowserFactory = 0;
    AlreadyShowsMessage = false;

    TranslateEngine.SetDirectory(":/engine/translate");
    TranslateFastExecuteScript.SetDirectory(":/fastexecutescript/translate");
    qDebug()<<"Start 020";
    bool DataBaseConnectorPreserved = _DataBaseConnector;
    qDebug()<<"Start 021";
    if(!DataBaseConnectorPreserved)
    {
        qDebug()<<"Start 022";
        _DataBaseConnector = new MongoDatabaseConnector(this);
        qDebug()<<"Start 023";
        _CsvHelper = new CsvHelper(_DataBaseConnector);
        qDebug()<<"Start 024";
        _DataBaseConnector->SetCsvHelper(_CsvHelper);
        qDebug()<<"Start 025";

        _DataBaseState = new DatabaseState(this);
        qDebug()<<"Start 026";
        _DataBaseConnector2 = new MongoDatabaseConnector(_DataBaseState);
        qDebug()<<"Start 027";
        _DataBaseState->SetDatabaseConnector(_DataBaseConnector2);
        qDebug()<<"Start 028";
        connect(_DataBaseConnector,SIGNAL(GroupManipulated()),_DataBaseState,SLOT(Reload()));
        qDebug()<<"Start 029";
        _DataBaseConnector3 = new MongoDatabaseConnector(this);
        qDebug()<<"Start 030";
    }

    qDebug()<<"Start 031";
    LangModel = new LanguageModel(this);
    TrayNotifier = new SystemTrayNotifier(this);
    TrayNotifier->Init();
    qDebug()<<"Start 032";

    Settings = new QSettings("settings.ini",QSettings::IniFormat,this);
    LogLocation = Settings->value("LogLocation","../../logs").toString();
    qDebug()<<"Start 033";

    SkinController * skin = new SkinController();
    skin->ApplyTheme(Settings->value("Theme","DarkFusion").toString());
    skin->deleteLater();
    qDebug()<<"Start 034";

    Language = Settings->value("DefaultLanguageScript","").toString().toLower();
    qDebug()<<"Start 035";
    if(Language.isEmpty())
    {
        ScriptLanguageChooserDialog LangDialog;
        LangDialog.SetLanguageModel(LangModel);
        if(!LangDialog.exec())
        {
            QTimer::singleShot(50,this,SLOT(Close()));
            return;
        }
        Language = LangDialog.GetLang();

        Settings->setValue("DefaultLanguageScript",Language);
    }
    qDebug()<<"Start 036";
    if(!DataBaseConnectorPreserved)
    {
        qDebug()<<"Start 037";
        _DataBaseConnector->Init(Language);
        if(!_DataBaseConnector->Start())
        {
            QEventLoop loop;
            connect(_DataBaseConnector, SIGNAL(Started()), &loop, SLOT(quit()));
            loop.exec();
        }
        qDebug()<<"Start 038";
        if(_DataBaseConnector->HasDatabase())
        {
            qDebug()<<"Start 039";
            if(_DataBaseConnector->WasError())
            {
                QMessageBox::information(0, tr("Database Error"), _DataBaseConnector->GetError());
                QTimer::singleShot(50,this,SLOT(Close()));
                return;
            }
            qDebug()<<"Start 040";

            if(!_DataBaseConnector2->Start())
            {
                QEventLoop loop;
                connect(_DataBaseConnector2, SIGNAL(Started()), &loop, SLOT(quit()));
                loop.exec();
            }
            qDebug()<<"Start 041";
            if(_DataBaseConnector2->WasError())
            {
                QMessageBox::information(0, tr("Database Error"), _DataBaseConnector2->GetError());
                QTimer::singleShot(50,this,SLOT(Close()));
                return;
            }
            qDebug()<<"Start 042";

            if(!_DataBaseConnector3->Start())
            {
                QEventLoop loop;
                connect(_DataBaseConnector3, SIGNAL(Started()), &loop, SLOT(quit()));
                loop.exec();
            }
            qDebug()<<"Start 043";
            if(_DataBaseConnector3->WasError())
            {
                QMessageBox::information(0, tr("Database Error"), _DataBaseConnector3->GetError());
                QTimer::singleShot(50,this,SLOT(Close()));
                return;
            }
            qDebug()<<"Start 044";
            _DataBaseState->Reload();
        }else
        {
            qDebug()<<"Start 045";
            ui->actionData->setVisible(false);
        }
    }else
    {
        qDebug()<<"Start 046";
        if(!_DataBaseConnector->HasDatabase())
        {
            ui->actionData->setVisible(false);
        }
    }

    qDebug()<<"Start 047";
    TranslateEngine.Translate(Language);
    TranslateFastExecuteScript.Translate(Language);
    LangModel->SetScriptAvailableLanguagesString(Language);
    qDebug()<<"Start 048";

    LabelAllLog = new QPushButton(tr("Show all log"),ui->tab_2);
    TopRightPositioner * AllButtonPositioner = new TopRightPositioner(this);
    AllButtonPositioner->SetChild(LabelAllLog);
    AllButtonPositioner->SetParent(ui->tab_2);
    AllButtonPositioner->Start();
    connect(LabelAllLog,SIGNAL(clicked()),this,SLOT(LabelAllLog_Click()));
    qDebug()<<"Start 049";

    movie = new QMovie(":/fastexecutescript/images/loading.gif");
    movie->setParent(this);
    ui->LabelGif->setMovie(movie);
    movie->start();


    qDebug()<<"Start 050";


    InitRecources();
    qDebug()<<"Start 051";
    InitWidgets();
    qDebug()<<"Start 052";

    IPreprocessor * _Preprocessor = new Preprocessor(this);
    _Preprocessor->SetEncryptor(new NoneEncryptor(_Preprocessor));
    qDebug()<<"Start 053";

    XmlResourceController loader;

    //Load from file
    loader.SetFileName("project.xml");

    qDebug()<<"Start 063";
    //Find actual and default files location
    QDir dir(QCoreApplication::applicationDirPath());
    QString ActualFilePath = dir.absoluteFilePath(QString("./Actual") + QString(".xml"));
    QString DefaultFilePath = ActualFilePath + ".default.xml";
    qDebug()<<"Start 065";

    //Delete actual if defaults not exists
    if(!QFile::exists(DefaultFilePath) && QFile::exists(ActualFilePath))
    {
        QFile(ActualFilePath).remove();
    }

    qDebug()<<"Start 066";
    Res->FromViewToModel(&loader);

    this->setWindowTitle(QString("%1(%2)").arg(loader.GetScriptName()).arg(loader.GetScriptVersion()));

    bool NeedToUseAdditionalSettings = Settings->value("RenderMethodVisible","false").toString().toLower() == "true";
    qDebug()<<"Start 067";

    AdditionalSettingsWidgets AdditionalSettingsStatic;
    AdditionalSettings = &AdditionalSettingsStatic;
    qDebug()<<"Start 068";

    if(NeedToUseAdditionalSettings)
        AdditionalSettings->SetDefault(Settings->value("DefaultWorker").toString());

    qDebug()<<"Start 069";
    XmlResourceController XmlActualStatic;
    XmlResourceController *XmlActual = &XmlActualStatic;
    qDebug()<<"Start 070";

    //Load From File

    XmlActual->SetFileName(ActualFilePath);
    qDebug()<<"Start 071";

    if(true/*Res->NeedToFillByUser()*/)
    {
        //Create dialog
        AskUserForResourcesDialog ask;
        Ask = &ask;


        
        if(Settings->value("HideLanguageChooser",false).toBool())
        {
            Ask->RemoveLanguageChooser();
        }
        Ask->setWindowTitle(QString("%1(%2)").arg(loader.GetScriptName()).arg(loader.GetScriptVersion()));
        ask.setModal(true);



        //Update with actual settings
        {
            Resources ResActual;
            ResActual.FromViewToModel(XmlActual);

            Resources ResDefault;
            XmlResourceController XmlDefaults;
            XmlDefaults.SetFileName(DefaultFilePath);
            ResDefault.FromViewToModel(&XmlDefaults);


            CopyResourceController Copy;
            Copy.SetResources(&ResActual);
            Copy.SetDefaults(&ResDefault);
            Res->FromViewToModel(&Copy);
        }


        ShowData();
        connect(Ask,SIGNAL(Default()),this,SLOT(SetDefault()));
        connect(Ask,SIGNAL(Save(QString)),this,SLOT(SaveActual(QString)));
        connect(Ask,SIGNAL(Load(QString)),this,SLOT(LoadActual(QString)));
        connect(Ask,SIGNAL(Reset()),this,SLOT(Restart()));
        connect(Ask,SIGNAL(ShowLanguage()),this,SLOT(ChooseLanguage()));
        connect(Ask,SIGNAL(ShowLogLocation()),this,SLOT(ChooseLogLocation()));
        connect(Ask,SIGNAL(ShowDatabase()),this,SLOT(ShowDatabase()));

        if(!_DataBaseConnector->HasDatabase())
        {
            Ask->HideDatabaseButton();
        }

        //Ask user for input
        if(!IsSilent && !ask.exec())
        {
            QTimer::singleShot(50,this,SLOT(Close()));
            delete UserWidgetControllerPointer;
            UserWidgetControllerPointer = 0;
            return;
        }

        //Save defaults
        {
            Resources ResDefaults;

            ResDefaults.FromViewToModel(&loader);
            XmlResourceController XmlDefaults;
            XmlDefaults.SetFileName(DefaultFilePath);
            ResDefaults.FromModelToView(&XmlDefaults);
        }


        if(NeedToUseAdditionalSettings)
        {
            Settings->setValue("DefaultWorker",AdditionalSettings->ParseWidget());
            InitBrowserList(AdditionalSettings->ParseWidget());
        }else
        {
            InitBrowserList(Settings->value("DefaultWorker", "MultiProcessQt5").toString());
        }

        //Load data to new model and then to engine resources
        Resources UserRes;
        UserRes.FromViewToModel(UserWidgetControllerPointer);
        UserRes.FromModelToView(XmlActual);
        UserRes.FromModelToView(EngineResController);

        //Clean memory
        delete UserWidgetControllerPointer;
        UserWidgetControllerPointer = 0;
        Ask = 0;
    }



    //Prepare Worker
    ScriptMultiWorker* worker = new ScriptMultiWorker(this);
    worker->SetModuleManager(_ModuleManager);
    worker->SetAdditionEngineScripts(_ModuleManager->GetModuleEngineCode());
    worker->SetPreprocessor(_Preprocessor);

    worker->SetBrowserFactory(BrowserFactory);


    Output->Clear();
    Output->disconnect();
    ReportData = new ScriptMultiWorkerReportData(this);
    ResVisualizer = new ResourcesVisualizer(this);
    connect(ResVisualizer,SIGNAL(ChangedState(bool)),this,SLOT(ResourcesReportStateChanged(bool)));
    ResVisualizer->SetReportData(EngineResController->GetWatcherList());
    DataVisualizer = new ReportDataVisualizer(this);
    DataVisualizer->SetReportData(ReportData);
    connect(ui->actionShow_Report,SIGNAL(triggered()),DataVisualizer,SLOT(ShowReport()));
    connect(FactorySolver,SIGNAL(UsedSolver(QString)),ReportData,SLOT(CaptchaUsed(QString)));
    connect(FactorySolver,SIGNAL(FailedSolver(QString)),ReportData,SLOT(CaptchaFailed(QString)));

    connect(ui->actionShow,SIGNAL(triggered()),this,SLOT(show()));
    connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(Close()));
    connect(ui->actionRestart,SIGNAL(triggered()),this,SLOT(Restart()));
    connect(ui->actionRestart,SIGNAL(triggered()),this,SLOT(Close()));
    connect(ui->actionData,SIGNAL(triggered()),this,SLOT(ShowDatabase()));
    connect(TrayNotifier,SIGNAL(Show()),this,SLOT(show()));

    QMenu *Menu = new QMenu(this);
    Menu->addAction(ui->actionShow);
    Menu->addSeparator();
    Menu->addAction(ui->actionExit);
    TrayNotifier->SetContextmenu(Menu);



    connect(worker,SIGNAL(Success()),Output,SLOT(Success()));
    connect(worker,SIGNAL(Failed()),Output,SLOT(Failed()));
    connect(worker,SIGNAL(ProgressMaximum(int)),Output,SLOT(ProgressMaximum(int)));
    connect(worker,SIGNAL(ProgressValue(int)),Output,SLOT(ProgressValue(int)));
    connect(worker,SIGNAL(Finished()),Output,SLOT(Finished()));



    //Set Loggers
    QDateTime CurrentDateTime = QDateTime::currentDateTime();
    QString datestringfile = CurrentDateTime.toString("yyyy.MM.dd.hh.mm.ss");

    Output->SetOutputTitle1(loader.GetOutputTitle1());
    Output->SetOutputTitle2(loader.GetOutputTitle2());
    Output->SetOutputTitle3(loader.GetOutputTitle3());
    Output->SetOutputTitle4(loader.GetOutputTitle4());
    Output->SetOutputTitle5(loader.GetOutputTitle5());
    Output->SetOutputTitle6(loader.GetOutputTitle6());
    Output->SetOutputTitle7(loader.GetOutputTitle7());
    Output->SetOutputTitle8(loader.GetOutputTitle8());
    Output->SetOutputTitle9(loader.GetOutputTitle9());

    ComplexLogger *ComplexLoggerResults1 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults1 = new FileLogger(ComplexLoggerResults1);
    QString FileName1 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle1().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName1(FileName1);
    FileLoggerResults1->SetFileName(FileName1);
    PlainTextLogger * PlainTextLoggerResults1 = new PlainTextLogger(ComplexLoggerResults1);
    PlainTextLoggerResults1->SetPlainTextElement(Output->GetOutput(0));
    ComplexLoggerResults1->AddLogger(FileLoggerResults1);
    ComplexLoggerResults1->AddLogger(PlainTextLoggerResults1);
    connect(ComplexLoggerResults1, SIGNAL(NewLine()), this, SLOT(AddedOutput1()));

    ComplexLogger *ComplexLoggerResults2 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults2 = new FileLogger(ComplexLoggerResults2);
    QString FileName2 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle2().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName2(FileName2);
    FileLoggerResults2->SetFileName(FileName2);
    PlainTextLogger * PlainTextLoggerResults2 = new PlainTextLogger(ComplexLoggerResults2);
    PlainTextLoggerResults2->SetPlainTextElement(Output->GetOutput(1));
    ComplexLoggerResults2->AddLogger(FileLoggerResults2);
    ComplexLoggerResults2->AddLogger(PlainTextLoggerResults2);
    connect(ComplexLoggerResults2, SIGNAL(NewLine()), this, SLOT(AddedOutput2()));

    ComplexLogger *ComplexLoggerResults3 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults3 = new FileLogger(ComplexLoggerResults3);
    QString FileName3 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle3().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName3(FileName3);
    FileLoggerResults3->SetFileName(FileName3);
    PlainTextLogger * PlainTextLoggerResults3 = new PlainTextLogger(ComplexLoggerResults3);
    PlainTextLoggerResults3->SetPlainTextElement(Output->GetOutput(2));
    ComplexLoggerResults3->AddLogger(FileLoggerResults3);
    ComplexLoggerResults3->AddLogger(PlainTextLoggerResults3);
    connect(ComplexLoggerResults3, SIGNAL(NewLine()), this, SLOT(AddedOutput3()));

    ComplexLogger *ComplexLoggerResults4 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults4 = new FileLogger(ComplexLoggerResults4);
    QString FileName4 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle4().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName4(FileName4);
    FileLoggerResults4->SetFileName(FileName4);
    PlainTextLogger * PlainTextLoggerResults4 = new PlainTextLogger(ComplexLoggerResults4);
    PlainTextLoggerResults4->SetPlainTextElement(Output->GetOutput(3));
    ComplexLoggerResults4->AddLogger(FileLoggerResults4);
    ComplexLoggerResults4->AddLogger(PlainTextLoggerResults4);
    connect(ComplexLoggerResults4, SIGNAL(NewLine()), this, SLOT(AddedOutput4()));

    ComplexLogger *ComplexLoggerResults5 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults5 = new FileLogger(ComplexLoggerResults5);
    QString FileName5 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle5().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName5(FileName5);
    FileLoggerResults5->SetFileName(FileName5);
    PlainTextLogger * PlainTextLoggerResults5 = new PlainTextLogger(ComplexLoggerResults5);
    PlainTextLoggerResults5->SetPlainTextElement(Output->GetOutput(4));
    ComplexLoggerResults5->AddLogger(FileLoggerResults5);
    ComplexLoggerResults5->AddLogger(PlainTextLoggerResults5);
    connect(ComplexLoggerResults5, SIGNAL(NewLine()), this, SLOT(AddedOutput5()));

    ComplexLogger *ComplexLoggerResults6 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults6 = new FileLogger(ComplexLoggerResults6);
    QString FileName6 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle6().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName6(FileName6);
    FileLoggerResults6->SetFileName(FileName6);
    PlainTextLogger * PlainTextLoggerResults6 = new PlainTextLogger(ComplexLoggerResults6);
    PlainTextLoggerResults6->SetPlainTextElement(Output->GetOutput(5));
    ComplexLoggerResults6->AddLogger(FileLoggerResults6);
    ComplexLoggerResults6->AddLogger(PlainTextLoggerResults6);
    connect(ComplexLoggerResults6, SIGNAL(NewLine()), this, SLOT(AddedOutput6()));

    ComplexLogger *ComplexLoggerResults7 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults7 = new FileLogger(ComplexLoggerResults7);
    QString FileName7 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle7().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName7(FileName7);
    FileLoggerResults7->SetFileName(FileName7);
    PlainTextLogger * PlainTextLoggerResults7 = new PlainTextLogger(ComplexLoggerResults7);
    PlainTextLoggerResults7->SetPlainTextElement(Output->GetOutput(6));
    ComplexLoggerResults7->AddLogger(FileLoggerResults7);
    ComplexLoggerResults7->AddLogger(PlainTextLoggerResults7);
    connect(ComplexLoggerResults7, SIGNAL(NewLine()), this, SLOT(AddedOutput7()));

    ComplexLogger *ComplexLoggerResults8 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults8 = new FileLogger(ComplexLoggerResults8);
    QString FileName8 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle8().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName8(FileName8);
    FileLoggerResults8->SetFileName(FileName8);
    PlainTextLogger * PlainTextLoggerResults8 = new PlainTextLogger(ComplexLoggerResults8);
    PlainTextLoggerResults8->SetPlainTextElement(Output->GetOutput(7));
    ComplexLoggerResults8->AddLogger(FileLoggerResults8);
    ComplexLoggerResults8->AddLogger(PlainTextLoggerResults8);
    connect(ComplexLoggerResults8, SIGNAL(NewLine()), this, SLOT(AddedOutput8()));

    ComplexLogger *ComplexLoggerResults9 = new ComplexLogger(worker);
    FileLogger *FileLoggerResults9 = new FileLogger(ComplexLoggerResults9);
    QString FileName9 = QDir::cleanPath(LogLocation + QDir::separator() + QString("%2/%1.txt").arg(datestringfile).arg(Output->GetOutputTitle9().GetTranslation("en").replace(QRegExp("\\s"),".").replace(QRegExp("[^a-zA-Z1-9]"),"")));
    Output->SetFileName9(FileName9);
    FileLoggerResults9->SetFileName(FileName9);
    PlainTextLogger * PlainTextLoggerResults9 = new PlainTextLogger(ComplexLoggerResults9);
    PlainTextLoggerResults9->SetPlainTextElement(Output->GetOutput(8));
    ComplexLoggerResults9->AddLogger(FileLoggerResults9);
    ComplexLoggerResults9->AddLogger(PlainTextLoggerResults9);
    connect(ComplexLoggerResults9, SIGNAL(NewLine()), this, SLOT(AddedOutput9()));




    Output->SetOutputVisible1(loader.GetOutputVisible1());
    Output->SetOutputVisible2(loader.GetOutputVisible2());
    Output->SetOutputVisible3(loader.GetOutputVisible3());
    Output->SetOutputVisible4(loader.GetOutputVisible4());
    Output->SetOutputVisible5(loader.GetOutputVisible5());
    Output->SetOutputVisible6(loader.GetOutputVisible6());
    Output->SetOutputVisible7(loader.GetOutputVisible7());
    Output->SetOutputVisible8(loader.GetOutputVisible8());
    Output->SetOutputVisible9(loader.GetOutputVisible9());


    Output->SetConfiguratorVisible(false);


    worker->SetResults1(ComplexLoggerResults1);
    worker->SetResults2(ComplexLoggerResults2);
    worker->SetResults3(ComplexLoggerResults3);
    worker->SetResults4(ComplexLoggerResults4);
    worker->SetResults5(ComplexLoggerResults5);
    worker->SetResults6(ComplexLoggerResults6);
    worker->SetResults7(ComplexLoggerResults7);
    worker->SetResults8(ComplexLoggerResults8);
    worker->SetResults9(ComplexLoggerResults9);



    ui->Results->clear();

    ComplexLogger *ComplexLoggerLog = new ComplexLogger(worker);
    FileLogger *FileLoggerLog = new FileLogger(ComplexLoggerLog);
    LogFileName = QDir::cleanPath(LogLocation + QDir::separator() + QString("log/%1.txt").arg(datestringfile));
    FileLoggerLog->SetFileName(LogFileName);
    PlainTextLogger * PlainTextLoggerLog = new PlainTextLogger(ComplexLoggerLog);
    PlainTextLoggerLog->SetPlainTextElement(ui->Results);
    ComplexLoggerLog->AddLogger(FileLoggerLog);
    ComplexLoggerLog->AddLogger(PlainTextLoggerLog);



    worker->SetLogger(ComplexLoggerLog);

    worker->SetScript(_Preprocessor->Preprocess(loader.GetScript(),0));

    worker->SetScriptResources(ScriptResources);

    TimeoutWaiterFactory *WaiterFactory = new TimeoutWaiterFactory(worker);
    WaiterFactory->SetMultiWorker(_MultiTimer);
    worker->SetWaiterFactory(WaiterFactory);

    worker->SetSolverFactory(FactorySolver);

    worker->SetEngineResources(EngineRes);

    worker->SetResourceHandlersFactory(new ResourceHandlersFactory(worker));
    worker->SetHttpClientFactory(_HttpClientFactory);
    worker->SetPop3ClientFactory(_Pop3ClientFactory);
    worker->SetImapClientFactory(_ImapClientFactory);
    worker->SetCsvHelper(_CsvHelper);
    worker->SetDatabaseConnector(_DataBaseConnector3);


    worker->SetScriptSuspender(new ScriptSuspender(worker));
    worker->SetWorkerFactory(new ScriptWorkerFactory(worker));

    connect(worker,SIGNAL(Finished()),this,SLOT(Finished()));
    worker->SetReportData(ReportData);
    Worker = worker;

    Worker->SetDoTrace(false);

    //Modules

    Worker->SetHtmlParserFactory(_HtmlParserFactory);
    Worker->SetHelperFactory(_HelperFactory);

    Worker->AddModule(new MemoryInfo(worker),"MemoryInfo",true,true);
    /*PeriodicalHttpRequest * SmsRegPeriodicalHttpRequest = new PeriodicalHttpRequest(this);
    SmsRegPeriodicalHttpRequest->SetHttpClientFactory(_HttpClientFactory);
    worker->AddModule(SmsRegPeriodicalHttpRequest,"SmsRegPeriodicalHttpRequest",false,true);*/

    connect(ui->actionStop,SIGNAL(triggered()),worker,SLOT(Abort()));
    connect(ui->actionResources_Report,SIGNAL(triggered()),this,SLOT(ResourcesReport()));

    TrayNotifier->Start();


    ui->actionResources_Report->setEnabled(true);
    ui->actionResources_Report->setIcon(QIcon(":/fastexecutescript/images/resources_ok.png"));
    ResVisualizer->SetEnabled();
    //Run Worker

    worker->SetProperties(new Properties(worker));


    #ifdef ONLY_REMOTE
       CheckLicense * Checker = new CheckLicense(worker);
       Checker->Preprocessor = _Preprocessor;
       Checker->Data = ContentLoader.GetData();
       Checker->MultiWorker = worker;
       Checker->MachineIdObtainer = MachineIdObtainer;
       Checker->Salt = ContentLoader.GetSalt();
       Checker->Start();
    #endif

    _ModuleManager->StartAllDlls();

    QTimer::singleShot(50,worker,SLOT(Run()));
    //worker->Run();

    if(!IsSilent)
        this->show();

}
示例#2
0
BipedManager::PreSkin* BipedManager::LoadSkinController(
    std::string const& rootPath, std::string const& name,
    SkinController::Updater const& postUpdate)
{
    std::string filename = rootPath + "Skins/" + name + ".skinctrl.raw";
    std::ifstream input(filename, std::ios::in | std::ios::binary);

    int repeatType, active;
    double minTime, maxTime, phase, frequency;
    input.read((char*)&repeatType, sizeof(repeatType));
    input.read((char*)&minTime, sizeof(minTime));
    input.read((char*)&maxTime, sizeof(maxTime));
    input.read((char*)&phase, sizeof(phase));
    input.read((char*)&frequency, sizeof(frequency));
    input.read((char*)&active, sizeof(active));

    int numVertices, numBones;
    input.read((char*)&numVertices, sizeof(numVertices));
    input.read((char*)&numBones, sizeof(numBones));

    SkinController* ctrl = new SkinController(numVertices, numBones, postUpdate);
    ctrl->name = name;
    PreSkin* preSkin = new PreSkin();
    preSkin->Associate = ctrl;

    ctrl->repeat = static_cast<Controller::RepeatType>(repeatType);
    ctrl->minTime = minTime;
    ctrl->maxTime = maxTime;
    ctrl->phase = phase;
    ctrl->frequency = frequency;
    ctrl->active = (active > 0);

    int b, v;
    for (b = 0; b < numBones; ++b)
    {
        int length;
        input.read((char*)&length, sizeof(length));
        char* text = new char[length + 1];
        input.read(text, sizeof(char) * length);
        text[length] = 0;
        preSkin->BoneNames.push_back(std::string(text));
        delete[] text;
    }

    float** weights = ctrl->GetWeights();
    Vector4<float>** offsets = ctrl->GetOffsets();

    for (v = 0; v < numVertices; ++v)
    {
        for (b = 0; b < numBones; ++b)
        {
            float weight;
            input.read((char*)&weight, sizeof(weight));
            weights[v][b] = weight;
        }
    }

    Vector4<float> offset{ 0.0f, 0.0f, 0.0f, 1.0f };
    for (v = 0; v < numVertices; ++v)
    {
        for (b = 0; b < numBones; ++b)
        {
            input.read((char*)&offset[0], 3 * sizeof(offset[0]));
            offsets[v][b] = offset;
        }
    }

    input.close();
    return preSkin;
}
示例#3
0
//----------------------------------------------------------------------------
TriMesh* SkinnedBiped::GetMesh (const std::string& name, Node* biped)
{
    // Load the triangle indices and material.
    std::string filename = name + ".triangle.raw";
    std::string path = Environment::GetPathR(filename);
    FileIO inFile(path, FileIO::FM_DEFAULT_READ);

    int numTriangles;
    inFile.Read(sizeof(int), &numTriangles);
    int numIndices = 3*numTriangles;
    IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int));
    int* indices = (int*)ibuffer->GetData();
    inFile.Read(sizeof(int), numIndices, indices);

    Material* material = new0 Material();
    Float4 emissive, ambient, diffuse, specular;
    inFile.Read(sizeof(float), 3, &material->Emissive);
    material->Emissive[3] = 1.0f;
    inFile.Read(sizeof(float), 3, &material->Ambient);
    material->Ambient[3] = 1.0f;
    inFile.Read(sizeof(float), 3, &material->Diffuse);
    material->Diffuse[3] = 1.0f;
    inFile.Read(sizeof(float), 3, &material->Specular);
    material->Specular[3] = 0.0f;

    inFile.Close();

    // Load the skin controller.
    filename = name + ".skin.raw";
    path = Environment::GetPathR(filename);
    inFile.Open(path, FileIO::FM_DEFAULT_READ);

    int repeat;
    float minTime, maxTime, phase, frequency;
    inFile.Read(sizeof(float), &repeat);
    inFile.Read(sizeof(float), &minTime);
    inFile.Read(sizeof(float), &maxTime);
    inFile.Read(sizeof(float), &phase);
    inFile.Read(sizeof(float), &frequency);

    int numVertices, numBones;
    inFile.Read(sizeof(int), &numVertices);
    inFile.Read(sizeof(int), &numBones);

    SkinController* ctrl = new0 SkinController(numVertices, numBones);

    ctrl->Repeat = (Controller::RepeatType)repeat;
    ctrl->MinTime = (double)minTime;
    ctrl->MaxTime = (double)maxTime;
    ctrl->Phase = (double)phase;
    ctrl->Frequency = (double)frequency;

    Node** bones = ctrl->GetBones();
    int i;
    for (i = 0; i < numBones; ++i)
    {
        int length;
        inFile.Read(sizeof(int), &length);
        char* boneName = new1<char>(length + 1);
        inFile.Read(sizeof(char), length, boneName);
        boneName[length] = 0;

        bones[i] = (Node*)biped->GetObjectByName(boneName);
        assertion(bones[i] != 0, "Failed to find bone.\n");
        delete1(boneName);
    }

    float** weights = ctrl->GetWeights();
    APoint** offsets = ctrl->GetOffsets();
    for (int j = 0; j < numVertices; ++j)
    {
        for (i = 0; i < numBones; ++i)
        {
            inFile.Read(sizeof(float), &weights[j][i]);
            inFile.Read(sizeof(float), 3, &offsets[j][i]);
        }
    }

    inFile.Close();

    int vstride = mVFormat->GetStride();
    VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, vstride);

    // Set positions and normals to zero for now.  The controller update
    // will set the initial values.
    memset(vbuffer->GetData(), 0, numVertices*vstride);

    TriMesh* mesh = new0 TriMesh(mVFormat, vbuffer, ibuffer);
    mesh->SetName(name);
    mesh->AttachController(ctrl);
    mesh->SetEffectInstance(LightDirPerVerEffect::CreateUniqueInstance(
        mLight, material));

    return mesh;
}
示例#4
0
BipedManager::BipedManager(std::string const& rootPath,
    std::string const& bname, ProgramFactory& programFactory,
    SkinController::Updater const& postUpdate)
{
    // Vertex format shared by the two skins.
    VertexFormat vformat;
    vformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0);
    vformat.Bind(VA_NORMAL, DF_R32G32B32_FLOAT, 0);
    vformat.Bind(VA_TEXCOORD, DF_R32G32_FLOAT, 0);

    // Create the texture effects for the two skins.
    std::shared_ptr<Texture2> texture[2];
    std::shared_ptr<Texture2Effect> effect[2];
    for (int i = 0; i < 2; ++i)
    {
        std::string name = rootPath + "Skins/Skins" + std::to_string(i) + ".texture.png";
        texture[i].reset(WICFileIO::Load(name, true));
        texture[i]->AutogenerateMipmaps();
        effect[i] = std::make_shared<Texture2Effect>(programFactory,
            texture[i], SamplerState::MIN_L_MAG_L_MIP_L, SamplerState::WRAP,
            SamplerState::WRAP);
    }

    PreSpatialArray preSpatialArray;
    PreSkinArray preSkinArray;
    SpatialMap spatialMap;

    std::string filename = rootPath + bname + ".txt";
    std::ifstream inFile(filename);
    while (!inFile.eof())
    {
        std::string line;
        getline(inFile, line);
        if (line == "")
        {
            // The file contains no blank lines, except for the very last one.
            break;
        }

        // Strip off initial white space.
        std::string::size_type begin = line.find_first_not_of(" ");
        if (begin > 0)
        {
            line = line.substr(begin);
        }

        std::string::size_type end;
        std::string name;
        if (line.find("Node") == 0)
        {
            // Load the node.
            begin = line.find("<");
            end = line.find(">");
            name = line.substr(begin + 1, end - 1 - begin);
            if (name.back() == 'X')
            {
                // TODO: These nodes are not necessary.  Remove them from the
                // data sets.
                continue;
            }

            PreSpatial* preSpatial = LoadNode(rootPath, name);
            preSpatialArray.push_back(preSpatial);
            Node* node = reinterpret_cast<Node*>(preSpatial->Associate);
            spatialMap[name] = node;

            // Load the transform controllers.
            NodeCtrl nc;
            nc.first = node;

            nc.second.reset(LoadTransformController(rootPath, name, "Idle"));
            mIdleArray.push_back(nc);

            nc.second.reset(LoadTransformController(rootPath, name, "Walk"));
            mWalkArray.push_back(nc);

            nc.second.reset(LoadTransformController(rootPath, name, "Run"));
            mRunArray.push_back(nc);
        }
        else if (line.find("TriMesh") == 0)
        {
            // Load the mesh.
            begin = line.find("<");
            end = line.find(">");
            name = line.substr(begin + 1, end - 1 - begin);
            int suffix = name[name.length() - 1] - '0';
            PreSpatial* preSpatial = LoadMesh(rootPath, name, vformat, effect[suffix]);
            preSpatialArray.push_back(preSpatial);
            spatialMap[name] = preSpatial->Associate;

            // Load the skin controller.
            PreSkin* preSkin = LoadSkinController(rootPath, name, postUpdate);
            preSkinArray.push_back(preSkin);

            // Attach the skin controller to the mesh.
            preSpatial->Associate->AttachController(preSkin->Associate);
        }
    }

    // Resolve the bone links.
    for (auto preSkin : preSkinArray)
    {
        SkinController* ctrl = preSkin->Associate;
        Node** bones = ctrl->GetBones();
        int i = 0;
        for (auto const& boneName : preSkin->BoneNames)
        {
            auto iter = spatialMap.find(boneName);
            bones[i] = reinterpret_cast<Node*>(iter->second);
            ++i;
        }
    }

    // Assemble the biped hierarchy.
    for (auto preSpatial : preSpatialArray)
    {
        Node* node = dynamic_cast<Node*>(preSpatial->Associate);
        if (node)
        {
            for (auto const& childName : preSpatial->ChildNames)
            {
                if (childName.back() == 'X')
                {
                    // TODO: These nodes are not necessary.  Remove them from
                    // the data sets.
                    continue;
                }

                auto iter = spatialMap.find(childName);
                Visual* mesh = dynamic_cast<Visual*>(iter->second);
                if (mesh)
                {
                    std::shared_ptr<Visual> visual(mesh);
                    node->AttachChild(visual);
                    if (visual->GetEffect().get() == effect[0].get())
                    {
                        mSubscribers[0].first = visual;
                        mSubscribers[0].second = effect[0]->GetPVWMatrixConstant();
                    }
                    else
                    {
                        mSubscribers[1].first = visual;
                        mSubscribers[1].second = effect[1]->GetPVWMatrixConstant();
                    }
                }
                else
                {
                    node->AttachChild(std::shared_ptr<Spatial>(iter->second));
                }
            }
        }
    }

    mRoot.reset(reinterpret_cast<Node*>(preSpatialArray[0]->Associate));

    for (auto preSpatial : preSpatialArray)
    {
        delete preSpatial;
    }

    for (auto preSkin : preSkinArray)
    {
        delete preSkin;
    }

    // Create the blend controllers.
    int const numControllers = static_cast<int>(mIdleArray.size());
    mIdleWalkArray.resize(numControllers);
    mWalkRunArray.resize(numControllers);
    for (int i = 0; i < numControllers; ++i)
    {
        NodeCtrl const& nc0 = mIdleArray[i];
        NodeCtrl const& nc1 = mWalkArray[i];
        NodeCtrl const& nc2 = mRunArray[i];

        mIdleWalkArray[i].first = nc0.first;
        mIdleWalkArray[i].second = std::make_shared<BlendTransformController>(
            nc0.second, nc1.second, true, false);

        mWalkRunArray[i].first = nc0.first;
        mWalkRunArray[i].second = std::make_shared<BlendTransformController>(
            nc1.second, nc2.second, true, false);
    }
}