void vmsMediaConvertMgr::ConvertMediaFile_SetupDefaultOptions()
{
	vmsMediaFileConvertSettings stgs;
	GetDefaultSettings (stgs);
	CDlg_Convert dlg (&stgs);
	dlg.m_bCustomizingDefSettings = true;
	_DlgMgr.DoModal (&dlg);
}
void vmsMediaConvertMgr::ConvertMediaFile(vmsDownloadSmartPtr dld, vmsMediaConvertMgr_OptionsSource enOs)
{
	vmsConvertMediaFileContext *pcmfc = new vmsConvertMediaFileContext;

	if (enOs == MCM_OS_SEARCH_IN_MGR)
	{
		int nIndex = FindDownload (dld);
		if (nIndex == -1)
			return;

		vmsConvertMediaFileContext* ctx = (vmsConvertMediaFileContext*)m_vTasks [nIndex];
		if (ctx == 0)
			return;
		pcmfc->dld = ctx->dld;	
		pcmfc->stgs = ctx->stgs;
		
		
		m_vTasks.erase (m_vTasks.begin () + nIndex);
		setDirty();
		getPersistObjectChildren ()->removePersistObject (nIndex);
		
		
	}
	else
	{
		pcmfc->dld = dld;
		GetDefaultSettings (pcmfc->stgs);

		if (enOs == MCM_OS_SHOW_OPTIONS_UI)
		{
			CDlg_Convert dlg (&pcmfc->stgs);
			if (IDOK != _DlgMgr.DoModal (&dlg))
			{
				delete pcmfc;
				return;
			}
		}
	}

	CWaitDlg *dlg = new CWaitDlg;
	dlg->StartWaiting (LS (L_CONVERTING), _threadConvertMediaFile, TRUE, pcmfc, 
		(LPVOID)(enOs == MCM_OS_SHOW_OPTIONS_UI), 
		NULL, NULL, NULL, NULL, FALSE);
}
	void AssetsManager::OnInit() {

		string stringsPath = ofToDataPath(PATH_STRINGS);
		auto xmlDoc = LoadResourcesXml(stringsPath);

		if (xmlDoc) {
			for (auto stringNode : xmlDoc->child("resources").children("string")) {
				string key = stringNode.attribute("name").as_string();
				string value = stringNode.value();

				if (!key.empty() && !value.empty()) {
					strings[key] = value;
				}
			}
		}

		string dimensionsPath = ofToDataPath(PATH_DIMENSIONS);
		xmlDoc = LoadResourcesXml(dimensionsPath);
		if (xmlDoc) {
			for (auto dimenNode : xmlDoc->child("resources").children("string")) {
				string key = dimenNode.attribute("name").as_string();
				string value = dimenNode.value();

				if (!key.empty() && !value.empty()) {
					dimensions[key] = value;
				}
			}
		}

		string globalSettings = ofToDataPath(PATH_GLOBAL_SETTINGS);
		xmlDoc = LoadResourcesXml(globalSettings);
		if (xmlDoc) {
			auto resources = xmlDoc->child("resources");
			loadedGlobalSettings.LoadFromXml(resources);
		}

		string defaultSettings = ofToDataPath(PATH_DEFAULT_SETTINGS);
		xmlDoc = LoadResourcesXml(defaultSettings);
		if (xmlDoc) {
			auto resources = xmlDoc->child("resources");
			loadedDefaultSettings.LoadFromXml(resources);
		}

		string projectSettings = ofToDataPath(PATH_PROJECT_SETTINGS);
		xmlDoc = LoadResourcesXml(projectSettings);
		if (xmlDoc) {
			auto resources = xmlDoc->child("resources");
			loadedProjectSettings.LoadFromXml(resources);
		}

		string animationsPath = ofToDataPath(PATH_ANIMATIONS);
		xmlDoc = LoadResourcesXml(animationsPath);
		if (xmlDoc) {
			auto animLoader = AnimLoader();
			auto rootAnims = vector<spt<GeneralAnim>>();

			auto builder = [](void) {
				return new SheetAnim();
			};

			auto resources = xmlDoc->child("resources");
			animLoader.LoadAnimationsFromXml(resources, rootAnims, builder);


			// store animation
			for (spt<GeneralAnim> anim : rootAnims) {
				anim = static_pointer_cast<SheetAnim>(anim);
				StoreAnimation(anim);
			}
		}


		string attrAnimationsPath = ofToDataPath(PATH_ATTRANIMATIONS);
		xmlDoc = LoadResourcesXml(attrAnimationsPath);
		if (xmlDoc) {
			auto animLoader = AnimLoader();
			auto rootAnims = vector<spt<GeneralAnim>>();

			auto builder = [](void) {
				return new AttribAnim();
			};

			auto resources = xmlDoc->child("resources");
			animLoader.LoadAnimationsFromXml(resources, rootAnims, builder);

			// store animation
			for (spt<GeneralAnim> anim : rootAnims) {
				anim = static_pointer_cast<AttribAnim>(anim);
				StoreAnimation(anim);
			}
		}

		string transformsPath = ofToDataPath(PATH_TRANSFORMS);
		xmlDoc = LoadResourcesXml(transformsPath);
		if (xmlDoc) {
			auto resources = xmlDoc->child("resources");
			int indexCtr = 0;
			for (auto transNode : resources.children("transform")) {
				spt<TransformEnt> trans = spt<TransformEnt>(new TransformEnt());
				Setting defaultSet = GetDefaultSettings("transform");
				trans->LoadFromXml(transNode, defaultSet);

				COGASSERT(!trans->name.empty(), "Resources", "Transform entity on index %d in configuration file must have a name!", indexCtr);

				StoreEntity(trans->name, trans);
				indexCtr++;
			}
		}


		string behaviorsPath = ofToDataPath(PATH_BEHAVIORS);
		xmlDoc = LoadResourcesXml(behaviorsPath);
		if (xmlDoc) {
			auto resources = xmlDoc->child("resources");
			int indexCtr = 0;
			for (auto behNode : resources.children("behavior")) {
				spt<BehaviorEnt> ent = spt<BehaviorEnt>(new BehaviorEnt());

				auto dummySet = Setting();
				ent->LoadFromXml(behNode, dummySet);

				COGASSERT(!ent->name.empty(), "Resources", "Behavior entity on index %d in configuration file must have a name!", indexCtr);

				StoreEntity(ent->name, ent);
				indexCtr++;
			}
		}


		string spriteSheetsPath = ofToDataPath(PATH_SPRITESHEETS);
		xmlDoc = LoadResourcesXml(spriteSheetsPath);
		if (xmlDoc) {
			auto resources = xmlDoc->child("resources");

			for (auto sheetNode : resources.children("spriteatlas")) {

				string atlasName = sheetNode.attribute("name").as_string();
				string img = sheetNode.attribute("img").as_string();
				if (img.empty()) throw new IllegalArgumentException("Sprite atlas must have img specified!");

				auto spriteSheets = sheetNode.children("spritesheet");

				SpriteSheetBuilder bld;

				if (spriteSheets.begin() == spriteSheets.end()) {
					// no sprite sheet -> the sprite atlas itself is the only one sprite sheet 
					bld.LoadFromXml(sheetNode, img, atlasName);
					spt<SpriteSheet> spriteSheet = spt<SpriteSheet>(bld.Build());
					this->StoreSpriteSheet(spriteSheet);
				}
				else {
					for (auto spriteSheetDesc : spriteSheets) {
						bld.LoadFromXml(spriteSheetDesc, img, atlasName);
						spt<SpriteSheet> spriteSheet = spt<SpriteSheet>(bld.Build());
						this->StoreSpriteSheet(spriteSheet);
					}
				}
			}
		}
	}
Beispiel #4
0
    void LootState::Init(const std::string& cmdLineGame) {
        // Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it.
        //Boost.Locale initialisation: Specify location of language dictionaries.
        boost::locale::generator gen;
        gen.add_messages_path(g_path_l10n.string());
        gen.add_messages_domain("loot");

        //Boost.Locale initialisation: Generate and imbue locales.
        locale::global(gen(Language(Language::english).Locale() + ".UTF-8"));
        boost::filesystem::path::imbue(locale());

        // Check if the LOOT local app data folder exists, and create it if not.
        if (!fs::exists(g_path_local)) {
            BOOST_LOG_TRIVIAL(info) << "Local app data LOOT folder doesn't exist, creating it.";
            try {
                fs::create_directory(g_path_local);
            }
            catch (exception& e) {
                _initErrors.push_back((format(translate("Error: Could not create LOOT settings file. %1%")) % e.what()).str());
            }
        }
        if (fs::exists(g_path_settings)) {
            try {
                loot::ifstream in(g_path_settings);
                _settings = YAML::Load(in);
                in.close();
            }
            catch (exception& e) {
                _initErrors.push_back((format(translate("Error: Settings parsing failed. %1%")) % e.what()).str());
            }
        }
        // Check if the settings are valid (or if they don't exist).
        if (!AreSettingsValid()) {
            _settings = GetDefaultSettings();
        }

        //Set up logging.
        boost::log::add_file_log(
            boost::log::keywords::file_name = g_path_log.string().c_str(),
            boost::log::keywords::auto_flush = true,
            boost::log::keywords::format = (
            boost::log::expressions::stream
            << "[" << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%H:%M:%S") << "]"
            << " [" << boost::log::trivial::severity << "]: "
            << boost::log::expressions::smessage
            )
            );
        boost::log::add_common_attributes();
        bool enableDebugLogging = false;
        if (_settings["enableDebugLogging"]) {
            enableDebugLogging = _settings["enableDebugLogging"].as<bool>();
        }
        if (enableDebugLogging)
            boost::log::core::get()->set_logging_enabled(true);
        else
            boost::log::core::get()->set_logging_enabled(false);

        // Log some useful info.
        BOOST_LOG_TRIVIAL(info) << "LOOT Version: " << g_version_major << "." << g_version_minor << "." << g_version_patch;
        BOOST_LOG_TRIVIAL(info) << "LOOT Build Revision: " << g_build_revision;
#ifdef _WIN32
        // Check if LOOT is being run through Mod Organiser.
        bool runFromMO = GetModuleHandle(ToWinWide("hook.dll").c_str()) != NULL;
        if (runFromMO) {
            BOOST_LOG_TRIVIAL(info) << "LOOT is being run through Mod Organiser.";
        }
#endif

        // The CEF debug log is appended to, not overwritten, so it gets really long.
        // Delete the current CEF debug log.
        fs::remove(g_path_local / "CEFDebugLog.txt");

        // Now that settings have been loaded, set the locale again to handle translations.
        if (_settings["language"] && _settings["language"].as<string>() != Language(Language::english).Locale()) {
            BOOST_LOG_TRIVIAL(debug) << "Initialising language settings.";
            loot::Language lang(_settings["language"].as<string>());
            BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.Name();

            //Boost.Locale initialisation: Generate and imbue locales.
            locale::global(gen(lang.Locale() + ".UTF-8"));
            boost::filesystem::path::imbue(locale());
        }

        // Detect games & select startup game
        //-----------------------------------

        //Detect installed games.
        BOOST_LOG_TRIVIAL(debug) << "Detecting installed games.";
        try {
            _games = ToGames(GetGameSettings(_settings));
        }
        catch (YAML::Exception& e) {
            BOOST_LOG_TRIVIAL(error) << "Games' settings parsing failed. " << e.what();
            _initErrors.push_back((format(translate("Error: Games' settings parsing failed. %1%")) % e.what()).str());
            // Now redo, but with no games settings, so only the hardcoded defaults get loaded. It means the user can
            // at least still then edit them.
            _games = ToGames(GetGameSettings(YAML::Node()));
        }

        try {
            BOOST_LOG_TRIVIAL(debug) << "Selecting game.";
            SelectGame(cmdLineGame);
            BOOST_LOG_TRIVIAL(debug) << "Initialising game-specific settings.";
            _currentGame->Init(true);
            // Update game path in settings object.
            _settings["games"] = ToGameSettings(_games);
        }
        catch (loot::error &e) {
            if (e.code() == loot::error::no_game_detected) {
                _initErrors.push_back(e.what());
            }
            else {
                BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what();
                _initErrors.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str());
            }
        }
        BOOST_LOG_TRIVIAL(debug) << "Game selected is " << _currentGame->Name();
    }