Пример #1
0
void DatabaseQuery::runQuery() {
    DatabaseQueryRequest *request = takeRequest();
    if (request) {
        QThread *thread = new QThread();
        connect(thread, SIGNAL(finished()), SLOT(threadFinished()));
        thread->start();
        request->moveToThread(thread);
        connect( request, SIGNAL(requestCompleted()), SLOT(finishQuery()) );
        connect( request, SIGNAL(resultsReady(DataStore)), SLOT(addResult(DataStore)) );
        connect( request, SIGNAL(errorMessageBox(QString,QString)), SIGNAL(errorMessageBox(QString,QString)) );
        QMetaObject::invokeMethod(request, "start", Qt::QueuedConnection);
    }
}
Пример #2
0
        void execute( HINSTANCE hInstance, dcx::dcxCPUFeatures* cpuFeatures ) {
            myMainWindow = createMainDialog( hInstance );

            dcx::dcxIniFileWriter ini_file_writer;
            DisplayModeList display_mode_list;
            {
              dcx::dcxIniFileReader ini_file_reader;
              ini_file_reader.read("config.ini");
              ini_file_writer.scan(&ini_file_reader);
              DWORD current_display_mode_index = 
                EnumDisplayModes(ini_file_reader.getSetting("Graphics", "ResolutionX", 0),
                                 ini_file_reader.getSetting("Graphics", "ResolutionY", 0),
                                 ini_file_reader.getSetting("Graphics", "ColorDepth", 0),
                                 ini_file_reader.getSetting("Graphics", "Fullscreen", 0) == 0, display_mode_list);

              { // re-sort
                DisplayMode current;
                if (current_display_mode_index < display_mode_list.size()) current = display_mode_list.at(current_display_mode_index);
                qsort(&display_mode_list.at(0), display_mode_list.size(), sizeof(DisplayModeList::value_type), CompareDisplayMode);
                DWORD index = 0;
                for (DisplayModeList::iterator i = display_mode_list.begin(); i != display_mode_list.end(); ++i, ++index) {
                  DisplayMode& dm = *i;
                  if (dm.width == current.width &&
                      dm.height == current.height &&
                      dm.windowed == current.windowed &&
                      (current.windowed == true || dm.bpp == current.bpp)) {
                    current_display_mode_index = index; break;
                  }
                }
              }


              HWND hDisplayModeCombo = getDisplayModeCombo();
              DWORD index = 0;
              for (DisplayModeList::iterator i = display_mode_list.begin(); i != display_mode_list.end(); ++i, ++index) {
                int k = ComboBox_AddString(hDisplayModeCombo, i->text.c_str());
                ComboBox_SetItemData(hDisplayModeCombo, k, index);
              }
              ComboBox_SetCurSel(hDisplayModeCombo, current_display_mode_index);
            }

            Evidyon::UpdateFile update_file;
            std::list<EvidyonUpdateFile> files_to_update;
            if (!Evidyon::DownloadUpdateFile(Evidyon::ONLINE_CLIENT_UPDATE_FILE, &update_file)) {
                errorMessageBox( "Couldn't contact the update server; please try again later" );
                goto EXIT;
            }

            if (update_file.major != MAJOR_VERSION) {
              // download the full installer
              MessageBox(myMainWindow, "The game has been significantly updated and you\n"
                                       "should re-download from www.unseenstudios.com", "Major Update!", MB_OK);
              goto EXIT;
            } else {
              ShowWindow( getEditboxStatus(), SW_SHOW);
              for (std::map<std::string, Evidyon::UpdateFileData>::const_iterator i = update_file.files.begin();
                   i != update_file.files.end(); ++i) {
                const std::string& filename = i->first;
                md5wrapper wrappy;
                std::string local_md5 = wrappy.getHashFromFile(filename);
                if (local_md5.compare(i->second.md5) != 0) {  // this file needs to be updated
                  EvidyonUpdateFile file;
                  file.file_name = filename;
                  file.file_size = i->second.file_bytes;
                  files_to_update.push_back(file);
                }
              }
            }
            // Update the client
            bool allowGameStart = false;
            if (files_to_update.size() > 0) {
              if (downloadUpdates(Evidyon::ONLINE_CLIENT_UPDATE_FOLDER, files_to_update)) {
                allowGameStart = true;
              } else {
                appendStatusLine( "ERROR!  Unable to download updates at this time.  If you are running Vista, this could "\
                                  "be due to the permissions for the directory in which Evidyon is installed being set to read-only." );
              }
            }
            else
                allowGameStart = true;

            // Add the update text to the output
            {
              //dc::dcFileStream fs;
              //if (fs.open("notes.txt", STREAM_TEXT)) {
              //  std::string notes;
              //  size_t len = fs.size();
              //  char text = new char[len+1];
              //  fs.read(text, len);
              //  text[len] = '\0';
              //  fs.close();
              //  appendStatusLine(text);
              //  delete[] text;
              //}
            }


            if (allowGameStart) {
                // Re-enable the "launch" button
                Button_Enable( getStartgameButton(), TRUE );
            }

            ShowWindow(getStartgameButton(), SW_SHOW);
            ShowWindow(getProgressBar(), SW_HIDE);

            // Wait for the user to do something
            myLaunchGameFlag = false;
            ComboBox_Enable(getDisplayModeCombo(), TRUE);
            while( dcx::dcxWin32StdMessagePump( myMainWindow ) && !myLaunchGameFlag );

            // Get the display mode selection
            int current_sel = ComboBox_GetCurSel(getDisplayModeCombo());
            current_sel = min(current_sel, display_mode_list.size() - 1);
            current_sel = max(current_sel, 0);
            DisplayMode& dm = display_mode_list.at(current_sel);
            ini_file_writer.setSetting("Graphics", "ResolutionX", dm.width),
            ini_file_writer.setSetting("Graphics", "ResolutionY", dm.height),
            ini_file_writer.setSetting("Graphics", "ColorDepth", dm.bpp),
            ini_file_writer.setSetting("Graphics", "Fullscreen", dm.windowed ? 0 : 1);
            {
              dc::dcFileStream ini_fs;
              ini_fs.open("config.ini", STREAM_OVERWRITE|STREAM_TEXT);
              ini_file_writer.write(&ini_fs);
              ini_fs.close();
            }

            // Close the window
            if( IsWindow( myMainWindow ) )
            {
                EndDialog( myMainWindow, 0 );
                DestroyWindow( myMainWindow );
                dcx::dcxWin32StdMessagePump( 0 );

                // Launch the client
                std::string exeFile = "evidyon";

                STARTUPINFO startupInfo;
                ZeroMemory( &startupInfo, sizeof(startupInfo) );

                PROCESS_INFORMATION processInfo;
                /*
                // Build the version to run based on the computer's capabilities
                if( cpuFeatures->sse2 ) {
                    exeFile.append( "_sse2" );
                }
                else if( cpuFeatures->sse ) {
                    exeFile.append( "_sse" );
                }*/

                exeFile.append( ".exe" );
                
                // Start the server
                if( !CreateProcessA( exeFile.c_str(), NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE|ABOVE_NORMAL_PRIORITY_CLASS,
                                     NULL, NULL, &startupInfo, &processInfo ) )
                {
                    DWORD error = GetLastError();
                    MessageBox( NULL, "Failed to launch Evidyon", "Error", MB_OK );
                    goto EXIT;
                }

                // Run the client
                WaitForSingleObject( processInfo.hProcess, INFINITE );

                // Free the process and exit
                CloseHandle( processInfo.hProcess );
                CloseHandle( processInfo.hThread );
            }

EXIT:
            DestroyWindow( myMainWindow );
        }