Status CatalogManagerReplicaSet::checkAndUpgrade(bool checkOnly) {
    auto versionStatus = _getConfigVersion();
    if (!versionStatus.isOK()) {
        return versionStatus.getStatus();
    }

    auto versionInfo = versionStatus.getValue();
    if (versionInfo.getMinCompatibleVersion() > CURRENT_CONFIG_VERSION) {
        return {ErrorCodes::IncompatibleShardingConfigVersion,
                str::stream() << "current version v" << CURRENT_CONFIG_VERSION
                              << " is older than the cluster min compatible v"
                              << versionInfo.getMinCompatibleVersion()};
    }

    if (versionInfo.getCurrentVersion() == UpgradeHistory_EmptyVersion) {
        VersionType newVersion;
        newVersion.setClusterId(OID::gen());

        // For v3.2, only v3.2 binaries can talk to RS Config servers.
        newVersion.setMinCompatibleVersion(CURRENT_CONFIG_VERSION);
        newVersion.setCurrentVersion(CURRENT_CONFIG_VERSION);

        BSONObj versionObj(newVersion.toBSON());

        return update(VersionType::ConfigNS,
                      versionObj,
                      versionObj,
                      true /* upsert*/,
                      false /* multi */,
                      nullptr);
    }

    if (versionInfo.getCurrentVersion() == UpgradeHistory_UnreportedVersion) {
        return {ErrorCodes::IncompatibleShardingConfigVersion,
                "Assuming config data is old since the version document cannot be found in the"
                "config server and it contains databases aside 'local' and 'admin'. "
                "Please upgrade if this is the case. Otherwise, make sure that the config "
                "server is clean."};
    }

    if (versionInfo.getCurrentVersion() < CURRENT_CONFIG_VERSION) {
        return {ErrorCodes::IncompatibleShardingConfigVersion,
                str::stream() << "need to upgrade current cluster version to v"
                              << CURRENT_CONFIG_VERSION << "; currently at v"
                              << versionInfo.getCurrentVersion()};
    }

    return Status::OK();
}
 int64_t IndexReader::getCurrentVersion(const char* directory){
    Directory* dir = FSDirectory::getDirectory(directory);
    int64_t version = getCurrentVersion(dir);
    dir->close();
    _CLDECDELETE(dir);
    return version;
 }
void SyncConnector::urlTested(QNetworkReply* reply)
{
  ignoreSslErrors(reply);
  if (reply->error() == QNetworkReply::TimeoutError ||
      reply->error() == QNetworkReply::ConnectionRefusedError)
  {
    shutdownINotifyProcess();
    mpConnectionAvailabilityTimer->start(1000);
  }
  else
  {
    ConnectionState connectionInfo =
      api::APIHandlerFactory<QNetworkReply>().getConnectionVersionInfo(reply);

    int versionNumber = getCurrentVersion(connectionInfo.first);
    if (mAPIHandler == nullptr || mAPIHandler->version != versionNumber)
    {
      mAPIHandler =
        std::unique_ptr<api::APIHandlerBase>(
          api::APIHandlerFactory<QNetworkReply>().getAPIForVersion(versionNumber));
    }

    mConnectionStateCallback(connectionInfo);
    mpConnectionAvailabilityTimer->stop();
    mpConnectionHealthTimer->start(mConnectionHealthTime);
    checkAndSpawnINotifyProcess(false);
  }
  reply->deleteLater();
}
Exemple #4
0
TEST(TBDv2, ReadFile2) {
  static const char tbd_v2_file2[] =
      "--- !tapi-tbd-v2\n"
      "archs: [ armv7, armv7s, armv7k, arm64 ]\n"
      "platform: ios\n"
      "flags: [ flat_namespace, not_app_extension_safe ]\n"
      "install-name: Test.dylib\n"
      "swift-version: 1.1\n"
      "exports:\n"
      "  - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
      "    symbols: [ _sym1, _sym2, _sym3, _sym4, $ld$hide$os9.0$_sym1 ]\n"
      "    objc-classes: [ _class1, _class2 ]\n"
      "    objc-ivars: [ _class1._ivar1, _class1._ivar2 ]\n"
      "    weak-def-symbols: [ _weak1, _weak2 ]\n"
      "    thread-local-symbols: [ _tlv1, _tlv2 ]\n"
      "  - archs: [ armv7, armv7s, armv7k ]\n"
      "    symbols: [ _sym5 ]\n"
      "    objc-classes: [ _class3 ]\n"
      "    objc-ivars: [ _class1._ivar3 ]\n"
      "    weak-def-symbols: [ _weak3 ]\n"
      "    thread-local-symbols: [ _tlv3 ]\n"
      "undefineds:\n"
      "  - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
      "    symbols: [ _undefSym1, _undefSym2, _undefSym3 ]\n"
      "    objc-classes: [ _undefClass1, _undefClass2 ]\n"
      "    objc-ivars: [ _undefClass1._ivar1, _undefClass1._ivar2 ]\n"
      "    weak-ref-symbols: [ _undefWeak1, _undefWeak2 ]\n"
      "...\n";

  auto Buffer = MemoryBuffer::getMemBuffer(tbd_v2_file2, "Test.tbd");
  auto Result = TextAPIReader::get(std::move(Buffer));
  EXPECT_TRUE(!!Result);
  auto File = std::move(Result.get());
  EXPECT_EQ(FileType::TBD_V2, File->getFileType());
  auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
  EXPECT_EQ(Archs, File->getArchitectures());
  EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
  EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
  EXPECT_EQ(PackedVersion(1, 0, 0), File->getCurrentVersion());
  EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
  EXPECT_EQ(2U, File->getSwiftABIVersion());
  EXPECT_EQ(ObjCConstraintType::Retain_Release, File->getObjCConstraint());
  EXPECT_FALSE(File->isTwoLevelNamespace());
  EXPECT_FALSE(File->isApplicationExtensionSafe());
  EXPECT_FALSE(File->isInstallAPI());
  EXPECT_EQ(0U, File->allowableClients().size());
  EXPECT_EQ(0U, File->reexportedLibraries().size());
}
Exemple #5
0
void RO6DTxn::commit(
        const ChopFinishRequest &req,
        ChopFinishResponse *res,
        rrr::DeferredReply *defer) {
    std::vector<i64> ids;
    Compressor::string_to_vector(req.read_only, &ids);

    // handle ro list, put ro ids into table
    // I assume one txn may query multiple rows on this node?
    for (auto &pair : row_col_map) {
        auto row = (RO6Row *) pair.first;
        int col_id = pair.second;
        // get current version of the cell this txn is going to update
        version_t current_version = row->getCurrentVersion(col_id);
        for (i64 &ro_id : ids) {
            row->rtxn_tracker.checkIfTxnIdBeenRecorded(col_id, ro_id, true, current_version);
        }
    }
    // We need to commit this txn after updating the table, because we need to know what the
    // old version number was before committing current version.
    RCCDTxn::commit(req, res, defer);
}
Exemple #6
0
void UpdateManager::downloadUpdater() {
    std::string fileName;
    std::string address;
    if (!_versionConfDownloaded) {
        fileName = string("version.conf");
        std::string currentVersion = getCurrentVersion();
        string userId(readConfValue("user-id", ""));
        address = "http://d-jon.com/downloads/version.php?version=" + currentVersion;// readConfValue("version-file", "");
        address = address.append("&userId=" + userId);
    }
    fileName = *getTempDir() + "/" + fileName;
    _file = new QFile(QString(fileName.c_str()));

    if (_file->exists()) {
        _file->remove();
    }
    QUrl url(address.c_str());

    _manager->get(QNetworkRequest(url));

    _downloading = true;
}
Exemple #7
0
void UpdateManager::checkVersion() {
    std::string tempFileName = *getTempDir() + "/version.conf";
    _isLastVersion = true;
    if (existFile(tempFileName.c_str())) {
        std::string versioncont = std::string(readFile(const_cast<char*>(tempFileName.c_str())));

        if (versioncont.find("version:") == -1) {
            versioncont = "version:" + versioncont + ";\nreleaseNotesURL:http://d-jon.com/downloads/releasenotes.php?version=" + VERSION + ";";
        }
        const char* cwebLastVersion = readValue(versioncont, "version");
        if (strlen(cwebLastVersion) > 0) {
            Version webVersion = getVersion(cwebLastVersion);
            Version currentVersion = getCurrentVersion();

            if (webVersion > currentVersion) {
                _isLastVersion = false;
            }
            if (!_isLastVersion) {
                QMessageBox box;
                box.setWindowTitle("d-jon update available");
                box.setTextFormat(Qt::RichText);
                std::stringstream ss;
                ss << "A new version of d-jon is available at <a href=\"http://d-jon.com/downloads.html\">http://d-jon.com/downloads.html</a><br/>";
                ss << "please take a look of the <a href=\"";
                std::string releaseNotesURL = readValue(versioncont, "releaseNotesURL");
                ss << releaseNotesURL << "\">release notes</a> to know what is new in this release.";
                std::string message = ss.str();
                box.setText(message.c_str());
                box.exec();
            }
        }
        _file->remove();
        delete(_file);
        _file = NULL;
    }
}
void CommonBlob::initialize()
{
    magic = magicNumber;

    this->blobVersion = getCurrentVersion();
}
Exemple #9
0
TEST(TBDv2, ReadFile) {
  static const char tbd_v2_file1[] =
      "--- !tapi-tbd-v2\n"
      "archs: [ armv7, armv7s, armv7k, arm64 ]\n"
      "platform: ios\n"
      "flags: [ installapi ]\n"
      "install-name: Test.dylib\n"
      "current-version: 2.3.4\n"
      "compatibility-version: 1.0\n"
      "swift-version: 1.1\n"
      "parent-umbrella: Umbrella.dylib\n"
      "exports:\n"
      "  - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
      "    allowable-clients: [ clientA ]\n"
      "    re-exports: [ /usr/lib/libfoo.dylib ]\n"
      "    symbols: [ _sym1, _sym2, _sym3, _sym4, $ld$hide$os9.0$_sym1 ]\n"
      "    objc-classes: [ _class1, _class2 ]\n"
      "    objc-ivars: [ _class1._ivar1, _class1._ivar2 ]\n"
      "    weak-def-symbols: [ _weak1, _weak2 ]\n"
      "    thread-local-symbols: [ _tlv1, _tlv2 ]\n"
      "  - archs: [ armv7, armv7s, armv7k ]\n"
      "    symbols: [ _sym5 ]\n"
      "    objc-classes: [ _class3 ]\n"
      "    objc-ivars: [ _class1._ivar3 ]\n"
      "    weak-def-symbols: [ _weak3 ]\n"
      "    thread-local-symbols: [ _tlv3 ]\n"
      "...\n";

  auto Buffer = MemoryBuffer::getMemBuffer(tbd_v2_file1, "Test.tbd");
  auto Result = TextAPIReader::get(std::move(Buffer));
  EXPECT_TRUE(!!Result);
  auto File = std::move(Result.get());
  EXPECT_EQ(FileType::TBD_V2, File->getFileType());
  auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
  EXPECT_EQ(Archs, File->getArchitectures());
  EXPECT_EQ(PlatformKind::iOS, File->getPlatform());
  EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
  EXPECT_EQ(PackedVersion(2, 3, 4), File->getCurrentVersion());
  EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
  EXPECT_EQ(2U, File->getSwiftABIVersion());
  EXPECT_EQ(ObjCConstraintType::Retain_Release, File->getObjCConstraint());
  EXPECT_TRUE(File->isTwoLevelNamespace());
  EXPECT_TRUE(File->isApplicationExtensionSafe());
  EXPECT_TRUE(File->isInstallAPI());
  InterfaceFileRef client("clientA", Archs);
  InterfaceFileRef reexport("/usr/lib/libfoo.dylib", Archs);
  EXPECT_EQ(1U, File->allowableClients().size());
  EXPECT_EQ(client, File->allowableClients().front());
  EXPECT_EQ(1U, File->reexportedLibraries().size());
  EXPECT_EQ(reexport, File->reexportedLibraries().front());

  ExportedSymbolSeq Exports;
  for (const auto *Sym : File->symbols()) {
    EXPECT_FALSE(Sym->isWeakReferenced());
    EXPECT_FALSE(Sym->isUndefined());
    Exports.emplace_back(ExportedSymbol{Sym->getKind(), Sym->getName(),
                                        Sym->isWeakDefined(),
                                        Sym->isThreadLocalValue()});
  }
  llvm::sort(Exports.begin(), Exports.end());

  EXPECT_EQ(sizeof(TBDv2Symbols) / sizeof(ExportedSymbol), Exports.size());
  EXPECT_TRUE(
      std::equal(Exports.begin(), Exports.end(), std::begin(TBDv2Symbols)));
}
Exemple #10
0
int runTheGame(int argc,
			   char** pp_argv)
{
	FileSystem& fs = FileSystem::inst();
	const std::string homeDirectory(fs.getAppHomeDirectory());
	const std::string versionInitialized(detectInitializedVersion());
	fs.createDirectory(homeDirectory);

	clearLog();
	printfLog("Blocks 5\n");
	printfLog("========\n");
	printfLog("Installed game version: %s\n", p_localVersion);
	printfLog("Last played:            %s\n", versionInitialized.c_str());

	if(versionInitialized != p_localVersion)
	{
		printfLog("Initializing/Updating ...\n");

		bool success = true;
		std::string errorMsg;
		bool severeError = false;
		bool quit = false;

		if(versionInitialized == "not_played" ||
		   versionInitialized == "<= 1.0.7")
		{
			// Verzeichnis initialisieren
			success &= fs.createDirectory(homeDirectory + "levels");
			success &= fs.createDirectory(homeDirectory + "levels/campaigns");
			success &= fs.createDirectory(homeDirectory + "levels/skins");
			success &= fs.createDirectory(homeDirectory + "screenshots");
			success &= fs.createDirectory(homeDirectory + "videos");
			if (fs.fileExists("config.xml")) success &= fs.copyFile("config.xml", homeDirectory + "config.xml");
			success &= fs.copyFile("videos/readme.txt", homeDirectory + "videos/readme.txt");
			if(versionInitialized == "<= 1.0.7") success &= fs.copyFile("progress.zip", homeDirectory + "progress.zip");
			success &= fs.copyFile("update_checker_disable.bat", homeDirectory + "update_checker_disable.bat");
			success &= fs.copyFile("update_checker_enable.bat", homeDirectory + "update_checker_enable.bat");
			if(fs.fileExists(".update_checker")) success &= fs.copyFile(".update_checker", homeDirectory + ".update_checker");

			std::list<std::string> fileList(fs.listDirectory("levels"));
			for(std::list<std::string>::const_iterator it = fileList.begin(); it != fileList.end(); ++it) success &= fs.copyFile(std::string("levels/") + *it, homeDirectory + "levels/" + *it);
			fileList = fs.listDirectory("levels/campaigns");
			for(std::list<std::string>::const_iterator it = fileList.begin(); it != fileList.end(); ++it) success &= fs.copyFile(std::string("levels/campaigns/") + *it, homeDirectory + "levels/campaigns/" + *it);
			fileList = fs.listDirectory("levels/skins");
			for(std::list<std::string>::const_iterator it = fileList.begin(); it != fileList.end(); ++it) success &= fs.copyFile(std::string("levels/skins/") + *it, homeDirectory + "levels/skins/" + *it);
			fileList = fs.listDirectory("screenshots");
			for(std::list<std::string>::const_iterator it = fileList.begin(); it != fileList.end(); ++it) success &= fs.copyFile(std::string("screenshots/") + *it, homeDirectory + "screenshots/" + *it);

			if(success)
			{
				if(versionInitialized != "not_played")
				{
#ifdef _WIN32
					int answer = MessageBoxA(0,
											 "In the new version, Blocks 5 stores the levels, campaigns and other data in a different folder. "
											 "These files are now in a folder called \"Blocks 5\" within your \"My Documents\" folder. "
											 "Please keep this in mind when installing new levels, campaigns or skins!\r\n\r\n"
											 "Do you want to open this folder now in Windows Explorer?",
											 "Important update information",
											 MB_YESNO | MB_ICONINFORMATION);
					if(answer == IDYES)
					{
						std::string temp(homeDirectory);
						for(std::string::iterator it = temp.begin(); it != temp.end(); ++it) if(*it == '/') *it = '\\';
						const std::string cmdLine = std::string("EXPLORER.EXE \"") + temp + "\"";
						WinExec(cmdLine.c_str(), SW_SHOWMAXIMIZED);
						Sleep(5000);
						MessageBoxA(0,
									"Windows Explorer has been started, you should now see the new folder. "
									"Click OK to continue.",
									"Continue",
									MB_OK | MB_ICONINFORMATION);
					}
				}
#endif
			}
			else
			{
				severeError = true;
				errorMsg = std::string("The program could not create and initialize the folder: \"") + homeDirectory + "\"";
			}
		}
		else if(versionInitialized == "1.0.71" ||
				versionInitialized == "1.0.72")
		{
			fs.deleteFile(homeDirectory + "updates.no");
			success &= fs.copyFile("update_checker_disable.bat", homeDirectory + "update_checker_disable.bat");
			success &= fs.copyFile("update_checker_enable.bat", homeDirectory + "update_checker_enable.bat");
			if(fs.fileExists(".update_checker")) success &= fs.copyFile(".update_checker", homeDirectory + ".update_checker");

			success &= fs.createDirectory(homeDirectory + "videos");
			success &= fs.copyFile("videos/readme.txt", homeDirectory + "videos/readme.txt");

			if(!success) errorMsg = "Could not migrate all settings!";
		}
		else if(versionInitialized == "1.0.73")
		{
			fs.deleteFile(homeDirectory + "updates.no");
			success &= fs.copyFile("update_checker_disable.bat", homeDirectory + "update_checker_disable.bat");
			success &= fs.copyFile("update_checker_enable.bat", homeDirectory + "update_checker_enable.bat");
			if (fs.fileExists(".update_checker")) success &= fs.copyFile(".update_checker", homeDirectory + ".update_checker");

			if(!success) errorMsg = "Could not migrate all settings!";
		}

		if(success)
		{
			fs.writeStringToFile(p_localVersion, homeDirectory + ".initialized");
			printfLog("Succeeded initializing/updating user directory!\n");

#ifdef _WIN32
			if(versionInitialized != "not_played")
			{
				int answer = MessageBoxA(0,
										 "Do you want to read the changelog (what's new in this version)? "
										 "If you click \"Yes\", the changelog will be opened in Notepad. "
										 "Once you close the window, the game will start.",
										 "Read changelog?",
										 MB_YESNO | MB_ICONQUESTION);
				if(answer == IDYES)
				{
					system("NOTEPAD.EXE readme.txt");
					Sleep(1000);
				}
			}
#endif
		}
		else
		{
#ifdef _WIN32
			MessageBoxA(0, errorMsg.c_str(), "Error!", MB_OK | MB_ICONERROR);
#else
			std::cerr << errorMsg.c_str() << std::endl;
#endif
			printfLog("%s\n", errorMsg.c_str());
			if(severeError) return 1;
		}

		if(quit) return 0;
	}

	if (!fs.fileExists(homeDirectory + ".update_checker")) fs.writeStringToFile("0", homeDirectory + ".update_checker");
	const std::string updateCheckerStatus(fs.readStringFromFile(homeDirectory + ".update_checker"));
	if(!updateCheckerStatus.empty() && updateCheckerStatus[0] == '1')
	{
		printfLog("Checking for update ...\n");

		// Neue Version da?
		std::string currentVersion = getCurrentVersion();
		if(currentVersion.empty()) printfLog("Could not detect current version!\n");
		else printfLog("Current game version:   %s\n", currentVersion.c_str());
		if(!currentVersion.empty() &&
		   isNewer(currentVersion, p_localVersion))
		{
			std::ostringstream str;
			str << "A new version of Blocks 5 is available.\r\n";
			str << "Installed version: " << p_localVersion << "\r\n";
			str << "New version: " << currentVersion << "\r\n\r\n";
			str << "Do you want to visit the Blocks 5 website now?" << "\r\n\r\n";

#ifdef _WIN32
			int answer = MessageBoxA(0, str.str().c_str(), "Update available!", MB_YESNO | MB_ICONINFORMATION);
			if(answer == IDYES)
			{
				// Seite öffnen
				ShellExecuteA(0, "open", "Blocks 5 Website.url", NULL, NULL, SW_SHOWNORMAL);
				return 0;
			}
		}
#else
#error NOT IMPLEMENTED
#endif
	}
	else
	{
		// Keine automatischen Updates!
		printfLog("Not checking for update!\n");
	}

	// Daten aus dem verschlüsselten Archiv lesen
	fs.pushCurrentDir("data.zip[3Cs18Ab0bV0Aat3Wf27le1ZM12kt0Xs05Aa4PX1EyI2V112Jr26v2GZO3dN0Ec91hk024P3cA32bc3GZ07Em4bf34st4320F7d13S00wd4Mg1ANn4SF2EO94Hz13Qq0LO18iY4Qy2C8r2XF28Bh]");
	
	// Alternativ: Daten aus dem lokalen Verzeichnis lesen
	// fs.pushCurrentDir("data");

	// Fortschritt laden
	ProgressDB::inst().load();

	bool fullScreen;
	bool useHQ2X = false;

#ifdef _DEBUG
	fullScreen = false;
#else
	fullScreen = true;
#endif

	// Argumente parsen
	for(int i = 0; i < argc; i++)
	{
		char* p_arg = pp_argv[i];
		if(!_stricmp(p_arg, "-windowed")) fullScreen = false;
		else if(!_stricmp(p_arg, "-fullScreen")) fullScreen = true;
		else if(!_stricmp(p_arg, "-hq2x")) useHQ2X = true;
	}

	printfLog("Initializing engine ...\n");
	Engine& engine = Engine::inst();

	// Spielaktionen festlegen
	Action* p_action = engine.registerAction("$A_LEFT", engine.getKeyboardVK(SDLK_LEFT), engine.getKeyboardVK(SDLK_KP4));
	p_action->resetsActions.push_back("$A_UP");
	p_action->resetsActions.push_back("$A_DOWN");
	p_action = engine.registerAction("$A_RIGHT", engine.getKeyboardVK(SDLK_RIGHT), engine.getKeyboardVK(SDLK_KP6));
	p_action->resetsActions.push_back("$A_UP");
	p_action->resetsActions.push_back("$A_DOWN");
	p_action = engine.registerAction("$A_UP", engine.getKeyboardVK(SDLK_UP), engine.getKeyboardVK(SDLK_KP8));
	p_action->resetsActions.push_back("$A_LEFT");
	p_action->resetsActions.push_back("$A_RIGHT");
	p_action = engine.registerAction("$A_DOWN", engine.getKeyboardVK(SDLK_DOWN), engine.getKeyboardVK(SDLK_KP2));
	p_action->resetsActions.push_back("$A_LEFT");
	p_action->resetsActions.push_back("$A_RIGHT");
	engine.registerAction("$A_PLANT_BOMB", engine.getKeyboardVK(SDLK_LSHIFT), engine.getKeyboardVK(SDLK_RSHIFT));
	engine.registerAction("$A_PUT_DOWN_BOMB", engine.getKeyboardVK(SDLK_LCTRL), engine.getKeyboardVK(SDLK_RCTRL));
	engine.registerAction("$A_SWITCH_CHARACTER", engine.getKeyboardVK(SDLK_TAB));
	engine.registerAction("$A_SAVE_IN_HOTEL", engine.getKeyboardVK(SDLK_RETURN), engine.getKeyboardVK(SDLK_KP_ENTER));
	p_action = engine.registerAction("$A_RESTART_LEVEL", engine.getKeyboardVK(SDLK_F5));
	p_action->delay = 1000;
	p_action->interval = 1000;
	p_action = engine.registerAction("$A_RESTART_FROM_HOTEL", engine.getKeyboardVK(SDLK_F10));
	p_action->delay = 1000;
	p_action->interval = 1000;
	p_action = engine.registerAction("$A_PAUSE", engine.getKeyboardVK(SDLK_PAUSE));
	p_action->delay = 200;
	p_action->interval = 500;

	// Engine-Aktionen festlegen
	p_action = engine.registerAction("$A_TOGGLE_MUTE", engine.getKeyboardVK(SDLK_F1));
	p_action->delay = INT_MAX;
	p_action = engine.registerAction("$A_CAPTURE_SCREENSHOT", engine.getKeyboardVK(SDLK_F11));
	p_action->delay = INT_MAX;
	p_action = engine.registerAction("$A_TOGGLE_CAPTURE_VIDEO", engine.getKeyboardVK(SDLK_F12));
	p_action->delay = INT_MAX;

	if(!engine.init("Blocks 5", "window.png", 640, 480, fullScreen, useHQ2X))
	{
		printfLog("Error while initializing the engine.\n");
		return 1;
	}

	// Lokalisierung laden
	engine.loadStringDB("languages.txt");

	// Instanzen der Spielzustandsklassen erzeugen
	GS_Menu menu;
	GS_SelectLevel selectLevel;
	GS_Game game;
	GS_LevelEditor levelEditor;
	GS_CampaignEditor campaignEditor;
	GS_Credits credits;
	GS_Loading loading;

	printfLog("Starting game ...\n");
	engine.setGameState("GS_Loading");

	printfLog("Entering main loop ...\n");
	engine.mainLoop();

	printfLog("Shutting down the engine ...\n");
	engine.exit();
	printfLog("Engine has been shut down.\n");

	return 0;
}
Status CatalogManagerReplicaSet::initConfigVersion(OperationContext* txn) {
    for (int x = 0; x < kMaxConfigVersionInitRetry; x++) {
        auto versionStatus = _getConfigVersion(txn);
        if (!versionStatus.isOK()) {
            return versionStatus.getStatus();
        }

        auto versionInfo = versionStatus.getValue();
        if (versionInfo.getMinCompatibleVersion() > CURRENT_CONFIG_VERSION) {
            return {ErrorCodes::IncompatibleShardingConfigVersion,
                    str::stream() << "current version v" << CURRENT_CONFIG_VERSION
                                  << " is older than the cluster min compatible v"
                                  << versionInfo.getMinCompatibleVersion()};
        }

        if (versionInfo.getCurrentVersion() == UpgradeHistory_EmptyVersion) {
            VersionType newVersion;
            newVersion.setClusterId(OID::gen());
            newVersion.setMinCompatibleVersion(MIN_COMPATIBLE_CONFIG_VERSION);
            newVersion.setCurrentVersion(CURRENT_CONFIG_VERSION);

            BSONObj versionObj(newVersion.toBSON());
            BatchedCommandResponse response;
            auto upsertStatus = update(txn,
                                       VersionType::ConfigNS,
                                       versionObj,
                                       versionObj,
                                       true /* upsert*/,
                                       false /* multi */,
                                       &response);

            if ((upsertStatus.isOK() && response.getN() < 1) ||
                upsertStatus == ErrorCodes::DuplicateKey) {
                // Do the check again as someone inserted a new config version document
                // and the upsert neither inserted nor updated a config version document.
                // Note: you can get duplicate key errors on upsert because of SERVER-14322.
                continue;
            }

            return upsertStatus;
        }

        if (versionInfo.getCurrentVersion() == UpgradeHistory_UnreportedVersion) {
            return {ErrorCodes::IncompatibleShardingConfigVersion,
                    "Assuming config data is old since the version document cannot be found in the "
                    "config server and it contains databases aside 'local' and 'admin'. "
                    "Please upgrade if this is the case. Otherwise, make sure that the config "
                    "server is clean."};
        }

        if (versionInfo.getCurrentVersion() < CURRENT_CONFIG_VERSION) {
            return {ErrorCodes::IncompatibleShardingConfigVersion,
                    str::stream() << "need to upgrade current cluster version to v"
                                  << CURRENT_CONFIG_VERSION << "; currently at v"
                                  << versionInfo.getCurrentVersion()};
        }

        return Status::OK();
    }

    return {ErrorCodes::IncompatibleShardingConfigVersion,
            str::stream() << "unable to create new config version document after "
                          << kMaxConfigVersionInitRetry << " retries"};
}
Exemple #12
0
int HolisticRecognizer::train(const string& trainingList, string& strModelDataHeaderInfoFile, string &comment, string &dataset, const string &inFileType)
{
	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entered HolisticRecognizer::train"  << endl;

	string path;							//	file path of a ink file

	string shapeId;							//	shape id of the ink file

	int shapeCount = 0;						//	count of the no. of shape samples read so far

	int prevShape = 0;						//	shape id of the previous shape

	int numStrokes = 0;						//	number of strokes in a particular character

	int numFeatures = 0;					//	number of features being used

	int	traceIndex;							//	variable to loop over all traces of the trace group

	bool firstFileFlag = true;				//	flag is used for writing the number of features in the dat file

	LTKCaptureDevice captureDevice;

	LTKScreenContext screenContext;

	int iMajor, iMinor, iBugFix;			// Version identifiers

	char versionInfo[VERSION_STR_LEN];					// Holds the version information.

    string version;	///, pca="PCA";


	//	opening the file containing the training list of each of the shapes	
	
	ifstream in(trainingList.c_str());

	//	throwing error if unable to open the training list file

	if(!in)
	{
		throw LTKException(ETRAINLIST_FILE_OPEN);
	}

	//	opening the output reference model file

	ofstream out(m_referenceModelFile.c_str(),ios::out);

	// throwing error if unable to open the reference model file

	if(!out)
	{
		throw LTKException(EMODEL_DATA_FILE_OPEN);
	}

	//	writing the header information into the reference model file

	out << m_numShapes << endl;

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "m_numShapes = " << m_numShapes << endl;

	//	reading the ink file paths from the training list file
	
	while(in)
	{
		
		getline(in, path, ' ');

		getline(in, shapeId);

		if(atoi(shapeId.c_str()) != prevShape)
		{
			++shapeCount;

			prevShape = atoi(shapeId.c_str()); 
		}

		// checking for end of training data

		if(shapeCount == m_numShapes)
		{
			break;
		}

		LTKTraceGroup traceGroup;

		float2DVector featureVector;

		cout << path ;

		// reading the ink files

		LTKInkFileReader::readUnipenInkFile(path, traceGroup, captureDevice, screenContext);

		numStrokes = traceGroup.getNumTraces();
		
		// extracting features from the traceGroup

		m_featureExtractorObj.extractFeatures(traceGroup, captureDevice, screenContext, ltkShapeRecPtr, featureVector);

		// writing the number of features in the dat file only the first time

		if (firstFileFlag==true)
		{
			numFeatures = featureVector.at(0).size();			

			out << numFeatures << endl;
		}

		firstFileFlag = false;

		// writing the shapeId and the corresponding features in the dat file

		out << shapeId << " ";

		out << numStrokes << " ";
		
		for(traceIndex = 0; traceIndex < numStrokes; ++traceIndex)
		{
			for(int loopIndex = 0; loopIndex < numFeatures; ++loopIndex)
			{
				out << featureVector.at(traceIndex).at(loopIndex) << " ";
			}
		}

		out << endl;
		
	}//while(in)

	//	closing the training list file and returning

	in.close();

	out.close();

	getCurrentVersion(&iMajor,&iMinor,&iBugFix);

	sprintf(versionInfo, "%d.%d.%d",iMajor, iMinor, iBugFix);

	version = versionInfo;

	headerInfo[RECVERSION] = version;
	string algoName = "holistic";
	headerInfo[RECNAME] = algoName;
	headerInfo[COMMENT]=comment;
	headerInfo[DATASET]=dataset;
	if(errorCode = cheSumGen.addHeaderInfo(strModelDataHeaderInfoFile, m_referenceModelFile, headerInfo))
	{
		return errorCode;
	}

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Holistic Engine Trained"  << endl;

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting HolisticRecognizer::train"  << endl;

	return SUCCESS;
}
Exemple #13
0
int HolisticRecognizer::loadModelData(void)
{
	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entered HolisticRecognizer::loadTrainingData"  << endl;

	int numShapes;					//	number of shapes in the problem set

	int shapeId;					//	temp variable for storing the shape ID of incoming tracegroup

	int numFeatures;				//	total number of features used

	int numStrokes;					//	number of strokes in the character

	HolisticShapeModel shapeModel;	//	a shape model variable

	string algoVersion;					//Algorithm version.

	char versionInfo[VERSION_STR_LEN];
	string version;
	int iMajor, iMinor, iBugfix;

	stringStringMap headerSequence;

	float2DVector::iterator strokeIter; //	Iterator to loop over number of strokes
	float2DVector::iterator strokeIterEnd;

	floatVector::iterator loopIter;		// Iterator to loop over all the features
	floatVector::iterator loopIterEnd;

	// load the training file for the mapping
	if(m_confMapFile != "")
	{
		m_confMapper.readConfigMapping(m_confMapFile);
	}
	else
	{
		LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Warning: Mapping file is not set in the config" << endl;
	}

	
	if((errorCode = cheSumGen.readMDTHeader(m_referenceModelFile,headerSequence)) != 0)
	{
		return errorCode;
		//throw LTKException("ModelData File has been corrupted" + m_referenceModelFile);
	}
	
	algoVersion = headerSequence[RECVERSION].c_str();

	getCurrentVersion(&iMajor, &iMinor, &iBugfix);

	sprintf(versionInfo, "%c", algoVersion[0]);

	int ver = atoi(versionInfo);
	if(ver != iMajor)

	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Incompatible algorithm version : " + version  << endl;

		LTKReturnError(EINCOMPATIBLE_VERSION);
	}

	// open the reference model file for loading the training data
	ifstream infile(m_referenceModelFile.c_str(),ios::in);

	if(!infile)
    {
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Unable to open model data file : " +  m_referenceModelFile  << endl;

		LTKReturnError(EMODEL_DATA_FILE_OPEN);
	}


	infile.seekg(atoi(headerSequence[HEADERLEN].c_str()),ios::beg);  
	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Reference model file read"  << endl;

	//	reading reference model file header

	infile >> numShapes;

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "number of shapes read from reference model file = " << numShapes << endl;

	if(m_numShapes != numShapes)
    {
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Invalid value for number of shapes"  << endl;
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "NumShapes from cofiguration file ( or default value ) : " << m_numShapes << endl;
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "NumShapes from model data file : " << numShapes << endl;

		LTKReturnError(EINVALID_NUM_OF_SHAPES);
    }

	infile >> numFeatures;

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "number of features read from reference model file = " << numFeatures << endl;
	
	floatVector tempFloatVector(numFeatures,0);	// temporary float vector

	// reading the prototype models

	while(infile)
	{
		infile >> shapeId;

		infile >> numStrokes;

		float2DVector featureVector(numStrokes,tempFloatVector);

		// reading from the dat file and populating the featureVector 

		strokeIterEnd = featureVector.end();
		
		for(strokeIter = featureVector.begin(); strokeIter != strokeIterEnd; ++strokeIter)
		{
			loopIterEnd = (*strokeIter).end();

			for(loopIter = (*strokeIter).begin(); loopIter != loopIterEnd; ++loopIter)
			{
				infile >> (*loopIter);
			}
		}

		shapeModel.setShapeId(shapeId);

		shapeModel.setModel(featureVector);

		m_referenceModels.push_back(shapeModel);	// populating the reference models

	}

	cout << "Total number of reference models read - " << m_referenceModels.size() << endl;

	infile.close();

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting HolisticRecognizer::loadTrainingData"  << endl;

	return SUCCESS;

}