bool ConsoleExampleRunner::parseArgs(const CmdLineArgs &args) {
	unsigned int length = args.GetCount();
	for(unsigned int i = 0; i < length; ++i) {
		std::string arg = args.GetArg(i); 
		if (arg != "-r") {
			m_exampleName = arg;
		}
		else {
			if (i+1 < length) {
				++i;
				m_rendererName = args.GetArg(i);
			}
			else
			{
				showError("missing argument for parameter -r");
				return false;
			}
		}
		
	}

	if (m_rendererName.empty())
		m_rendererName = m_defaultRendererName;

	return true;
}
예제 #2
0
int main(int argc, char **argv)
{
    const QString errorstr = "Fatal error from the ALSA sequencer. "
        "This usually happens when the kernel doesn't have ALSA support, "
        "or the device node (/dev/snd/seq) doesn't exists, "
        "or the kernel module (snd_seq) is not loaded. "
        "Please check your ALSA/MIDI configuration.";

    CmdLineArgs args;
    args.setUsage("[port]");
    args.addOptionalArgument("port", "Source MIDI port");
    args.parse(argc, argv);
    try {
        test = new QDumpMIDI();
        signal(SIGINT, signalHandler);
        signal(SIGTERM, signalHandler);
        QVariant portName = args.getArgument("port");
        if (!portName.isNull())
            test->subscribe(portName.toString());
        test->run();
    } catch (const SequencerError& ex) {
        cerr << errorstr + " Returned error was: " + ex.qstrError() << endl;
    } catch (...) {
        cerr << errorstr << endl;
    }
    delete test;
    return 0;
}
예제 #3
0
TreeMapArgs TreeMapArgs::load(CmdLineArgs& argv) {
    TreeMapArgs tool_args;

    if (!argv.empty()) {
        tool_args.map_nameid = argv[0];
        argv = argv.subspan(1);
    }

    return tool_args;
}
예제 #4
0
static void InitVfs(const CmdLineArgs& args)
{
	TIMER(L"InitVfs");

	const Paths paths(args);

	OsPath logs(paths.Logs());
	CreateDirectories(logs, 0700);

	psSetLogDir(logs);
	// desired location for crashlog is now known. update AppHooks ASAP
	// (particularly before the following error-prone operations):
	AppHooks hooks = {0};
	hooks.bundle_logs = psBundleLogs;
	hooks.get_log_dir = psLogDir;
	hooks.display_error = psDisplayError;
	app_hooks_update(&hooks);

	const size_t cacheSize = ChooseCacheSize();
	g_VFS = CreateVfs(cacheSize);

	std::vector<CStr> mods = args.GetMultiple("mod");
	mods.insert(mods.begin(), "public");

	if (!args.Has("noUserMod"))
		mods.push_back("user");

	OsPath modPath = paths.RData()/"mods";
	OsPath modUserPath = paths.UserData()/"mods";
	for (size_t i = 0; i < mods.size(); ++i)
	{
		size_t priority = i+1;	// mods are higher priority than regular mountings, which default to priority 0
		size_t flags = VFS_MOUNT_WATCH|VFS_MOUNT_ARCHIVABLE|VFS_MOUNT_MUST_EXIST;
		OsPath modName(mods[i]);
		g_VFS->Mount(L"", modPath / modName/"", flags, priority);
		g_VFS->Mount(L"", modUserPath / modName/"", flags, priority);
	}

	// We mount these dirs last as otherwise writing could result in files being placed in a mod's dir.
	g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/"");
	g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH);
	const OsPath readonlyConfig = paths.RData()/"config"/"";
	// Mounting with highest priority, so that a mod supplied user.cfg is harmless
	g_VFS->Mount(L"config/", readonlyConfig, 0, (size_t)-1);
	if(readonlyConfig != paths.Config())
		g_VFS->Mount(L"config/", paths.Config(), 0, (size_t)-1);

	g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE);	// (adding XMBs to archive speeds up subsequent reads)

	// note: don't bother with g_VFS->TextRepresentation - directories
	// haven't yet been populated and are empty.
}
예제 #5
0
static std::vector<CStr> GetMods(const CmdLineArgs& args, bool dev)
{
	std::vector<CStr> mods = args.GetMultiple("mod");
	// TODO: It would be nice to remove this hard-coding
	mods.insert(mods.begin(), "public");

	// Add the user mod if not explicitly disabled or we have a dev copy so
	// that saved files end up in version control and not in the user mod.
	if (!dev && !args.Has("noUserMod"))
		mods.push_back("user");

	return mods;
}
예제 #6
0
파일: execjava.cpp 프로젝트: mwaghmar/try
int main()
{
		CmdLineArgs javaArgs;
		javaArgs.push_back("checkSignature");
		javaArgs.push_back(std::string(pk));
		javaArgs.push_back(std::string(msg));
		javaArgs.push_back(std::string(res));

		std::string signVerificationMsg = 
				getCommandOutPut("/usr/bin/java", javaArgs, NULL, 0);

		std::cout << signVerificationMsg << std::endl;
		return 0;
}
예제 #7
0
파일: showWin.cpp 프로젝트: hjgode/showwin
int getString(CmdLineArgs a, int idx, TCHAR* str){
	int iRet=0;
	if(a.size()<idx+1)
		return 0;
	wcscpy(a[idx+1], str);
	return wcslen(str);
}
예제 #8
0
int main(int argc, char **argv)
{
    const QString errorstr = "Fatal error from the ALSA sequencer. "
        "This usually happens when the kernel doesn't have ALSA support, "
        "or the device node (/dev/snd/seq) doesn't exists, "
        "or the kernel module (snd_seq) is not loaded. "
        "Please check your ALSA/MIDI configuration.";

    CmdLineArgs args;
    signal(SIGINT, signalHandler);
    signal(SIGTERM, signalHandler);

    args.setUsage("[options] port [bpm]");
    args.addRequiredArgument("port", "Destination, MIDI port identifier");
    args.addOptionalArgument("bpm", "Tempo, in beats per minute (default=120)");
    args.parse(argc, argv);

    try {
        metronome = new Metronome();
        QVariant port = args.getArgument("port");
        if (!port.isNull())
            metronome->subscribe(port.toString());
        QVariant bpm = args.getArgument("bpm");
        metronome->play(bpm.toString());
    } catch (const SequencerError& ex) {
        cerr << errorstr + " Returned error was: " + ex.qstrError() << endl;
    } catch (...) {
        cerr << errorstr << endl;
    }
    delete metronome;
    return 0;
}
예제 #9
0
파일: Atlas.cpp 프로젝트: Marlinc/0ad
// starts the Atlas UI if an "-editor" switch is found on the command line.
// this is the alternative to starting the main menu and clicking on
// the editor button; it is much faster because it's called during early
// init and therefore skips GUI setup.
// notes:
// - GUI init still runs, but some GUI setup will be skipped since
//   ATLAS_IsRunning() will return true.
bool ATLAS_RunIfOnCmdLine(const CmdLineArgs& args, bool force)
{
	if (force || args.Has("editor"))
	{
		ATLAS_Run(args, ATLAS_NO_GUI);
		return true;
	}

	return false;
}
예제 #10
0
파일: Paths.cpp 프로젝트: Marlinc/0ad
Paths::Paths(const CmdLineArgs& args)
{
	m_root = Root(args.GetArg0());

#ifdef INSTALLED_DATADIR
	m_rdata = OsPath(STRINGIZE(INSTALLED_DATADIR))/"";
#else
	m_rdata = m_root/"data"/"";
#endif

	const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad";

	// everything is a subdirectory of the root
	if(!subdirectoryName)
	{
		m_data = m_rdata;
		m_config = m_data/"config"/"";
		m_cache = m_data/"cache"/"";
		m_logs = m_root/"logs"/"";
	}
	else
	{
#if OS_WIN
		const OsPath appdata = wutil_AppdataPath() / subdirectoryName/"";
		m_data = appdata/"data"/"";
		m_config = appdata/"config"/"";
		m_cache = appdata/"cache"/"";
		m_logs = appdata/"logs"/"";
#else
		const char* envHome = getenv("HOME");
		ENSURE(envHome);
		const OsPath home(envHome);
		const OsPath xdgData   = XDG_Path("XDG_DATA_HOME",   home, home/".local/share/") / subdirectoryName;
		const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/"     ) / subdirectoryName;
		const OsPath xdgCache  = XDG_Path("XDG_CACHE_HOME",  home, home/".cache/"      ) / subdirectoryName;
		m_data   = xdgData/"";
		m_cache  = xdgCache/"";
		m_config = xdgConfig/"config"/"";
		m_logs   = xdgConfig/"logs"/"";
#endif
	}
}
예제 #11
0
int main(int argc, char *argv[])
{
  int rc = 0;
  CmdLineArgs check;
  DbMigrat dbMigrat;
  Db db;

  // check the command line arguments
  rc = check.CmdLineArgsCheck1(argc, argv, db);
  if (rc != 0)
  {
    return rc;
  }

  cout << "\nTHIS SAMPLE SHOWS HOW TO MIGRATE A DATABASE." << endl;

  dbMigrat.Migrate(db);

  return 0;
} // main
예제 #12
0
int main(int argc, char *argv[])
{
    QSpyWrk spy;
    CmdLineArgs args;
    args.setUsage("[options] file");
    args.addOption('v', "verbose", "Verbose output");
    args.addRequiredArgument("file", "Input WRK file name");
    args.parse(argc, argv);

    QVariant verbose = args.getOption("verbose");
    if (!verbose.isNull())
        spy.setVerbosity(true);

    QVariantList files = args.getArguments("file");
    QStringList fileNames;
    foreach(const QVariant& a, files) {
        QFileInfo f(a.toString());
        if (f.exists())
            fileNames += f.canonicalFilePath();
        else
            cout << "File not found: " << a.toString() << endl;
    }
예제 #13
0
bool Init(const CmdLineArgs& args, int flags)
{
	h_mgr_init();

	// Do this as soon as possible, because it chdirs
	// and will mess up the error reporting if anything
	// crashes before the working directory is set.
	InitVfs(args, flags);

	// This must come after VFS init, which sets the current directory
	// (required for finding our output log files).
	g_Logger = new CLogger;

	new CProfileViewer;
	new CProfileManager;	// before any script code

	g_ScriptStatsTable = new CScriptStatsTable;
	g_ProfileViewer.AddRootTable(g_ScriptStatsTable);

	// Set up the console early, so that debugging
	// messages can be logged to it. (The console's size
	// and fonts are set later in InitPs())
	g_Console = new CConsole();

	// g_ConfigDB, command line args, globals
	CONFIG_Init(args);
	
	// Using a global object for the runtime is a workaround until Simulation and AI use 
	// their own threads and also their own runtimes.
	const int runtimeSize = 384 * 1024 * 1024;
	const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
	g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger);

	// Special command-line mode to dump the entity schemas instead of running the game.
	// (This must be done after loading VFS etc, but should be done before wasting time
	// on anything else.)
	if (args.Has("dumpSchema"))
	{
		CSimulation2 sim(NULL, g_ScriptRuntime, NULL);
		sim.LoadDefaultScripts();
		std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc);
		f << sim.GenerateSchema();
		std::cout << "Generated entity.rng\n";
		exit(0);
	}

	// override ah_translate with our i18n code.
	AppHooks hooks = {0};
	hooks.translate = psTranslate;
	hooks.translate_free = psTranslateFree;
	app_hooks_update(&hooks);

	CNetHost::Initialize();

#if CONFIG2_AUDIO
	ISoundManager::CreateSoundManager();
#endif

	// Check if there are mods specified on the command line,
	// or if we already set the mods (~INIT_MODS),
	// else check if there are mods that should be loaded specified
	// in the config and load those (by aborting init and restarting
	// the engine).
	if (!args.Has("mod") && (flags & INIT_MODS) == INIT_MODS)
	{
		CStr modstring;
		CFG_GET_VAL("mod.enabledmods", modstring);
		if (!modstring.empty())
		{
			std::vector<CStr> mods;
			boost::split(mods, modstring, boost::is_any_of(" "), boost::token_compress_on);
			std::swap(g_modsLoaded, mods);

			// Abort init and restart
			restart_engine();
			return false;
		}
	}

	new L10n;

	// before scripting 
	// JS debugger temporarily disabled during the SpiderMonkey upgrade (check trac ticket #2348 for details)
	//if (g_JSDebuggerEnabled)
	//	g_DebuggingServer = new CDebuggingServer();

	// Optionally start profiler HTTP output automatically
	// (By default it's only enabled by a hotkey, for security/performance)
	bool profilerHTTPEnable = false;
	CFG_GET_VAL("profiler2.autoenable", profilerHTTPEnable);
	if (profilerHTTPEnable)
		g_Profiler2.EnableHTTP();

	if (!g_Quickstart)
		g_UserReporter.Initialize(); // after config

	PROFILE2_EVENT("Init finished");
	return true;
}
예제 #14
0
/*
 * Command line options for autostart (keep synchronized with binaries/system/readme.txt):
 *
 * -autostart="TYPEDIR/MAPNAME"         enables autostart and sets MAPNAME; TYPEDIR is skirmishes, scenarios, or random
 * -autostart-ai=PLAYER:AI              sets the AI for PLAYER (e.g. 2:petra)
 * -autostart-aidiff=PLAYER:DIFF        sets the DIFFiculty of PLAYER's AI (0: sandbox, 5: very hard)
 * -autostart-civ=PLAYER:CIV            sets PLAYER's civilisation to CIV (skirmish and random maps only)
 * -autostart-aiseed=AISEED             sets the seed used for the AI random generator (default 0, use -1 for random)
 * Multiplayer:
 * -autostart-playername=NAME		sets local player NAME (default 'anonymous')
 * -autostart-host                      sets multiplayer host mode
 * -autostart-host-players=NUMBER       sets NUMBER of human players for multiplayer game (default 2)
 * -autostart-client=IP                 sets multiplayer client to join host at given IP address
 * Random maps only:
 * -autostart-seed=SEED                 sets random map SEED value (default 0, use -1 for random)
 * -autostart-size=TILES                sets random map size in TILES (default 192)
 * -autostart-players=NUMBER            sets NUMBER of players on random map (default 2)
 *
 * Examples:
 * 1) "Bob" will host a 2 player game on the Arcadia map:
 * -autostart="scenarios/Arcadia 02" -autostart-host -autostart-host-players=2 -autostart-playername="Bob"
 * 2) Load Alpine Lakes random map with random seed, 2 players (Athens and Britons), and player 2 is PetraBot:
 * -autostart="random/alpine_lakes" -autostart-seed=-1 -autostart-players=2 -autostart-civ=1:athen -autostart-civ=2:brit -autostart-ai=2:petra
*/
bool Autostart(const CmdLineArgs& args)
{
	CStr autoStartName = args.Get("autostart");

	if (autoStartName.empty())
		return false;

	g_Game = new CGame();

	ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
	JSContext* cx = scriptInterface.GetContext();
	JSAutoRequest rq(cx);

	JS::RootedValue attrs(cx);
	scriptInterface.Eval("({})", &attrs);
	JS::RootedValue settings(cx);
	scriptInterface.Eval("({})", &settings);
	JS::RootedValue playerData(cx);
	scriptInterface.Eval("([])", &playerData);

	// The directory in front of the actual map name indicates which type
	// of map is being loaded. Drawback of this approach is the association
	// of map types and folders is hard-coded, but benefits are:
	// - No need to pass the map type via command line separately
	// - Prevents mixing up of scenarios and skirmish maps to some degree
	Path mapPath = Path(autoStartName);
	std::wstring mapDirectory = mapPath.Parent().Filename().string();
	std::string mapType;

	if (mapDirectory == L"random")
	{
		// Default seed is 0
		u32 seed = 0;
		CStr seedArg = args.Get("autostart-seed");

		if (!seedArg.empty())
		{
			// Random seed value
			if (seedArg == "-1")
				seed = rand();
			else
				seed = seedArg.ToULong();
		}
		
		// Random map definition will be loaded from JSON file, so we need to parse it
		std::wstring scriptPath = L"maps/" + autoStartName.FromUTF8() + L".json";
		JS::RootedValue scriptData(cx);
		scriptInterface.ReadJSONFile(scriptPath, &scriptData);
		if (!scriptData.isUndefined() && scriptInterface.GetProperty(scriptData, "settings", &settings))
		{
			// JSON loaded ok - copy script name over to game attributes
			std::wstring scriptFile;
			scriptInterface.GetProperty(settings, "Script", scriptFile);
			scriptInterface.SetProperty(attrs, "script", scriptFile);				// RMS filename
		}
		else
		{
			// Problem with JSON file
			LOGERROR("Autostart: Error reading random map script '%s'", utf8_from_wstring(scriptPath));
			throw PSERROR_Game_World_MapLoadFailed("Error reading random map script.\nCheck application log for details.");
		}

		// Get optional map size argument (default 192)
		uint mapSize = 192;
		if (args.Has("autostart-size"))
		{
			CStr size = args.Get("autostart-size");
			mapSize = size.ToUInt();
		}

		scriptInterface.SetProperty(settings, "Seed", seed);		// Random seed
		scriptInterface.SetProperty(settings, "Size", mapSize);		// Random map size (in patches)

		// Get optional number of players (default 2)
		size_t numPlayers = 2;
		if (args.Has("autostart-players"))
		{
			CStr num = args.Get("autostart-players");
			numPlayers = num.ToUInt();
		}

		// Set up player data
		for (size_t i = 0; i < numPlayers; ++i)
		{
			JS::RootedValue player(cx);
			scriptInterface.Eval("({})", &player);

			// We could load player_defaults.json here, but that would complicate the logic
			// even more and autostart is only intended for developers anyway
			scriptInterface.SetProperty(player, "Civ", std::string("athen"));
			scriptInterface.SetPropertyInt(playerData, i, player);
		}
		mapType = "random";
	}
	else if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes")
	{
		// Initialize general settings from the map data so some values
		// (e.g. name of map) are always present, even when autostart is
		// partially configured
		CStr8 mapSettingsJSON = LoadSettingsOfScenarioMap("maps/" + autoStartName + ".xml");
		scriptInterface.ParseJSON(mapSettingsJSON, &settings);
		
		// Initialize the playerData array being modified by autostart
		// with the real map data, so sensible values are present:
		scriptInterface.GetProperty(settings, "PlayerData", &playerData);

		if (mapDirectory == L"scenarios")
			mapType = "scenario";
		else
			mapType = "skirmish";
	}
	else
	{
		LOGERROR("Autostart: Unrecognized map type '%s'", utf8_from_wstring(mapDirectory));
		throw PSERROR_Game_World_MapLoadFailed("Unrecognized map type.\nConsult readme.txt for the currently supported types.");
	}
	scriptInterface.SetProperty(attrs, "mapType", mapType);
	scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName));
	scriptInterface.SetProperty(settings, "mapType", mapType);

	// Set seed for AIs
	u32 aiseed = 0;
	if (args.Has("autostart-aiseed"))
	{
		CStr seedArg = args.Get("autostart-aiseed");
		if (seedArg == "-1")
			aiseed = rand();
		else
			aiseed = seedArg.ToULong();
	}
	scriptInterface.SetProperty(settings, "AISeed", aiseed);

	// Set player data for AIs
	//		attrs.settings = { PlayerData: [ { AI: ... }, ... ] }:
	if (args.Has("autostart-ai"))
	{
		std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai");
		for (size_t i = 0; i < aiArgs.size(); ++i)
		{
			int playerID = aiArgs[i].BeforeFirst(":").ToInt();

			// Instead of overwriting existing player data, modify the array
			JS::RootedValue player(cx);
			if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined())
			{
				if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes")
				{
					// playerID is certainly bigger than this map player number
					LOGWARNING("Autostart: Invalid player %d in autostart-ai option", playerID);
					continue;
				}
				scriptInterface.Eval("({})", &player);
			}

			CStr name = aiArgs[i].AfterFirst(":");
			scriptInterface.SetProperty(player, "AI", std::string(name));
			scriptInterface.SetProperty(player, "AIDiff", 3);
			scriptInterface.SetPropertyInt(playerData, playerID-1, player);
		}
	}
	// Set AI difficulty
	if (args.Has("autostart-aidiff"))
	{
		std::vector<CStr> civArgs = args.GetMultiple("autostart-aidiff");
		for (size_t i = 0; i < civArgs.size(); ++i)
		{
			int playerID = civArgs[i].BeforeFirst(":").ToInt();

			// Instead of overwriting existing player data, modify the array
			JS::RootedValue player(cx);
			if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined())
			{
				if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes")
				{
					// playerID is certainly bigger than this map player number
					LOGWARNING("Autostart: Invalid player %d in autostart-aidiff option", playerID);
					continue;
				}
				scriptInterface.Eval("({})", &player);
			}

			int difficulty = civArgs[i].AfterFirst(":").ToInt();			
			scriptInterface.SetProperty(player, "AIDiff", difficulty);
			scriptInterface.SetPropertyInt(playerData, playerID-1, player);
		}
	}
	// Set player data for Civs
	if (args.Has("autostart-civ"))
	{
		if (mapDirectory != L"scenarios")
		{
			std::vector<CStr> civArgs = args.GetMultiple("autostart-civ");
			for (size_t i = 0; i < civArgs.size(); ++i)
			{
				int playerID = civArgs[i].BeforeFirst(":").ToInt();

				// Instead of overwriting existing player data, modify the array
				JS::RootedValue player(cx);
				if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined())
				{
					if (mapDirectory == L"skirmishes")
					{
						// playerID is certainly bigger than this map player number
						LOGWARNING("Autostart: Invalid player %d in autostart-civ option", playerID);
						continue;
					}
					scriptInterface.Eval("({})", &player);
				}
			
				CStr name = civArgs[i].AfterFirst(":");			
				scriptInterface.SetProperty(player, "Civ", std::string(name));
				scriptInterface.SetPropertyInt(playerData, playerID-1, player);
			}
		}
		else
			LOGWARNING("Autostart: Option 'autostart-civ' is invalid for scenarios");
	}

	// Add player data to map settings
	scriptInterface.SetProperty(settings, "PlayerData", playerData);

	// Add map settings to game attributes
	scriptInterface.SetProperty(attrs, "settings", settings);

	JS::RootedValue mpInitData(cx);
	scriptInterface.Eval("({isNetworked:true, playerAssignments:{}})", &mpInitData);
	scriptInterface.SetProperty(mpInitData, "attribs", attrs);

	// Get optional playername
	CStrW userName = L"anonymous";
	if (args.Has("autostart-playername"))
	{
		userName = args.Get("autostart-playername").FromUTF8();
	}

	if (args.Has("autostart-host"))
	{
		InitPs(true, L"page_loading.xml", &scriptInterface, mpInitData);

		size_t maxPlayers = 2;
		if (args.Has("autostart-host-players"))
			maxPlayers = args.Get("autostart-host-players").ToUInt();

		g_NetServer = new CNetServer(maxPlayers);

		g_NetServer->UpdateGameAttributes(&attrs, scriptInterface);

		bool ok = g_NetServer->SetupConnection();
		ENSURE(ok);

		g_NetClient = new CNetClient(g_Game);
		g_NetClient->SetUserName(userName);
		g_NetClient->SetupConnection("127.0.0.1");
	}
	else if (args.Has("autostart-client"))
	{
		InitPs(true, L"page_loading.xml", &scriptInterface, mpInitData);

		g_NetClient = new CNetClient(g_Game);
		g_NetClient->SetUserName(userName);

		CStr ip = args.Get("autostart-client");
		if (ip.empty())
			ip = "127.0.0.1";

		bool ok = g_NetClient->SetupConnection(ip);
		ENSURE(ok);
	}
	else
	{
		g_Game->SetPlayerID(1);
		g_Game->StartGame(&attrs, "");

		LDR_NonprogressiveLoad();

		PSRETURN ret = g_Game->ReallyStartGame();
		ENSURE(ret == PSRETURN_OK);

		InitPs(true, L"page_session.xml", NULL, JS::UndefinedHandleValue);
	}

	return true;
}
예제 #15
0
파일: Config.cpp 프로젝트: righnatios/0ad
static void ProcessCommandLineArgs(const CmdLineArgs& args)
{
    // TODO: all these options (and the ones processed elsewhere) should
    // be documented somewhere for users.

    // Handle "-conf=key:value" (potentially multiple times)
    std::vector<CStr> conf = args.GetMultiple("conf");
    for (size_t i = 0; i < conf.size(); ++i)
    {
        CStr name_value = conf[i];
        if (name_value.Find(':') != -1)
        {
            CStr name = name_value.BeforeFirst(":");
            CStr value = name_value.AfterFirst(":");
            g_ConfigDB.SetValueString(CFG_COMMAND, name, value);
        }
    }

    if (args.Has("g"))
    {
        g_Gamma = args.Get("g").ToFloat();
        if (g_Gamma == 0.0f)
            g_Gamma = 1.0f;
    }

//	if (args.Has("listfiles"))
//		trace_enable(true);

    if (args.Has("profile"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "profile", args.Get("profile"));

    if (args.Has("quickstart"))
    {
        g_Quickstart = true;
        g_DisableAudio = true; // do this for backward-compatibility with user expectations
    }

    if (args.Has("nosound"))
        g_DisableAudio = true;

    if (args.Has("shadows"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "shadows", "true");

    if (args.Has("xres"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "xres", args.Get("xres"));

    if (args.Has("yres"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "yres", args.Get("yres"));

    if (args.Has("vsync"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "vsync", "true");

    if (args.Has("ooslog"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "ooslog", "true");

    if (args.Has("serializationtest"))
        g_ConfigDB.SetValueString(CFG_COMMAND, "serializationtest", "true");
}
예제 #16
0
파일: execjava.cpp 프로젝트: mwaghmar/try
std::string getCommandOutPut(const std::string& cmd, CmdLineArgs& cmdArgs, 
								unsigned char* stdinput, const unsigned stdinputlength)
{
	int outfd[2];
	int infd[2];
	int oldstdin, oldstdout;

	pipe(outfd); // Where the parent is going to write to
	pipe(infd); // From where parent is going to read

	oldstdin = dup(0); // Save current stdin
	oldstdout = dup(1); // Save stdout

	close(0);
	close(1);

	dup2(outfd[0], 0); // Make the read end of outfd pipe as stdin
	dup2(infd[1], 1); // Make the write end of infd as stdout

	if(!fork()) {

		//std::cerr<< "No. of cmd args : " << cmdArgs.size() << std::endl;
		char **argv = new char*[2 + cmdArgs.size()];
		argv[0] =  (char*) cmd.c_str();
		int i = 1;
		for(CmdLineArgs::iterator itr = cmdArgs.begin(); itr != cmdArgs.end(); ++itr) { 
			argv[i++] = (char*) itr->c_str();
			std::cerr << "Arg : \n"  << itr->c_str() << "\n";
		}
		argv[i] = 0;

		close(outfd[0]); // Not required for the child
		close(outfd[1]);
		close(infd[0]);
		close(infd[1]);

		execv(argv[0],argv);
	}
	else {
		close(0); close(1);
		dup2(oldstdin, 0);
		dup2(oldstdout, 1);

		close(outfd[0]); // These are being used by the child
		close(infd[1]);

		if( stdinput && stdinputlength ) {
			write(outfd[1],stdinput, stdinputlength ); // Write to child’s stdin
			close(outfd[1]);
		}
		
		char input[1024] = { 0 };
		int bytesRead = 0;
		std::string retVal;
		while( bytesRead = read(infd[0], input, 1024) ) {
			retVal += std::string(input);
			memset(input, 0, sizeof(input));
		}

		//char input[1024] = { 0 };
		//input[read(infd[0], input, 1024)] = 0; // Read from child’s stdout
		//std::string retVal(input);
		
		return retVal;
	}
}
예제 #17
0
void Init(const CmdLineArgs& args, int UNUSED(flags))
{
	h_mgr_init();

	// Do this as soon as possible, because it chdirs
	// and will mess up the error reporting if anything
	// crashes before the working directory is set.
	InitVfs(args);

	// This must come after VFS init, which sets the current directory
	// (required for finding our output log files).
	g_Logger = new CLogger;

	// Special command-line mode to dump the entity schemas instead of running the game.
	// (This must be done after loading VFS etc, but should be done before wasting time
	// on anything else.)
	if (args.Has("dumpSchema"))
	{
		CSimulation2 sim(NULL, NULL);
		sim.LoadDefaultScripts();
		std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc);
		f << sim.GenerateSchema();
		std::cout << "Generated entity.rng\n";
		exit(0);
	}

	// override ah_translate with our i18n code.
	AppHooks hooks = {0};
	hooks.translate = psTranslate;
	hooks.translate_free = psTranslateFree;
	app_hooks_update(&hooks);

	// Set up the console early, so that debugging
	// messages can be logged to it. (The console's size
	// and fonts are set later in InitPs())
	g_Console = new CConsole();

	CNetHost::Initialize();

	new CProfileViewer;
	new CProfileManager;	// before any script code

	g_ScriptStatsTable = new CScriptStatsTable;
	g_ProfileViewer.AddRootTable(g_ScriptStatsTable);


#if CONFIG2_AUDIO
	CSoundManager::CreateSoundManager();
#endif

	InitScripting();	// before GUI

	// g_ConfigDB, command line args, globals
	CONFIG_Init(args);

	// Optionally start profiler HTTP output automatically
	// (By default it's only enabled by a hotkey, for security/performance)
	bool profilerHTTPEnable = false;
	CFG_GET_VAL("profiler2.http.autoenable", Bool, profilerHTTPEnable);
	if (profilerHTTPEnable)
		g_Profiler2.EnableHTTP();

	if (!g_Quickstart)
		g_UserReporter.Initialize(); // after config

	PROFILE2_EVENT("Init finished");
}
예제 #18
0
bool Autostart(const CmdLineArgs& args)
{
	/*
	 * Handle various command-line options, for quick testing of various features:
	 * -autostart=name					-- map name for scenario, or rms name for random map
	 * -autostart-ai=1:dummybot			-- adds the dummybot AI to player 1
	 * -autostart-playername=name		-- multiplayer player name
	 * -autostart-host					-- multiplayer host mode
	 * -autostart-players=2				-- number of players
	 * -autostart-client				-- multiplayer client mode
	 * -autostart-ip=127.0.0.1			-- multiplayer connect to 127.0.0.1
	 * -autostart-random=104			-- random map, optional seed value = 104 (default is 0, random is -1)
	 * -autostart-size=192				-- random map size in tiles = 192 (default is 192)
	 *
	 * Examples:
	 * -autostart=Acropolis -autostart-host -autostart-players=2		-- Host game on Acropolis map, 2 players
	 * -autostart=latium -autostart-random=-1							-- Start single player game on latium random map, random rng seed
	 */

	CStr autoStartName = args.Get("autostart");

#if OS_ANDROID
	// HACK: currently the most convenient way to test maps on Android;
	// should find a better solution
	autoStartName = "Oasis";
#endif

	if (autoStartName.empty())
	{
		return false;
	}

	g_Game = new CGame();

	ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();

	CScriptValRooted attrs;
	scriptInterface.Eval("({})", attrs);
	CScriptVal settings;
	scriptInterface.Eval("({})", settings);
	CScriptVal playerData;
	scriptInterface.Eval("([])", playerData);

	// Set different attributes for random or scenario game
	if (args.Has("autostart-random"))
	{
		CStr seedArg = args.Get("autostart-random");

		// Default seed is 0
		uint32 seed = 0;
		if (!seedArg.empty())
		{
			if (seedArg.compare("-1") == 0)
			{	// Random seed value
				seed = rand();
			}
			else
			{
				seed = seedArg.ToULong();
			}
		}
		
		// Random map definition will be loaded from JSON file, so we need to parse it
		std::wstring mapPath = L"maps/random/";
		std::wstring scriptPath = mapPath + autoStartName.FromUTF8() + L".json";
		CScriptValRooted scriptData = scriptInterface.ReadJSONFile(scriptPath);
		if (!scriptData.undefined() && scriptInterface.GetProperty(scriptData.get(), "settings", settings))
		{
			// JSON loaded ok - copy script name over to game attributes
			std::wstring scriptFile;
			scriptInterface.GetProperty(settings.get(), "Script", scriptFile);
			scriptInterface.SetProperty(attrs.get(), "script", scriptFile);				// RMS filename
		}
		else
		{
			// Problem with JSON file
			LOGERROR(L"Error reading random map script '%ls'", scriptPath.c_str());
			throw PSERROR_Game_World_MapLoadFailed("Error reading random map script.\nCheck application log for details.");
		}

		// Get optional map size argument (default 192)
		uint mapSize = 192;
		if (args.Has("autostart-size"))
		{
			CStr size = args.Get("autostart-size");
			mapSize = size.ToUInt();
		}

		scriptInterface.SetProperty(attrs.get(), "map", std::string(autoStartName));
		scriptInterface.SetProperty(attrs.get(), "mapPath", mapPath);
		scriptInterface.SetProperty(attrs.get(), "mapType", std::string("random"));
		scriptInterface.SetProperty(settings.get(), "Seed", seed);									// Random seed
		scriptInterface.SetProperty(settings.get(), "Size", mapSize);								// Random map size (in patches)

		// Get optional number of players (default 2)
		size_t numPlayers = 2;
		if (args.Has("autostart-players"))
		{
			CStr num = args.Get("autostart-players");
			numPlayers = num.ToUInt();
		}

		// Set up player data
		for (size_t i = 0; i < numPlayers; ++i)
		{
			CScriptVal player;
			scriptInterface.Eval("({})", player);

			// We could load player_defaults.json here, but that would complicate the logic
			//	even more and autostart is only intended for developers anyway
			scriptInterface.SetProperty(player.get(), "Civ", std::string("athen"));
			scriptInterface.SetPropertyInt(playerData.get(), i, player);
		}
	}
	else
	{
		scriptInterface.SetProperty(attrs.get(), "map", std::string(autoStartName));
		scriptInterface.SetProperty(attrs.get(), "mapType", std::string("scenario"));
	}

	// Set player data for AIs
	//		attrs.settings = { PlayerData: [ { AI: ... }, ... ] }:
	if (args.Has("autostart-ai"))
	{
		std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai");
		for (size_t i = 0; i < aiArgs.size(); ++i)
		{
			// Instead of overwriting existing player data, modify the array
			CScriptVal player;
			if (!scriptInterface.GetPropertyInt(playerData.get(), i, player) || player.undefined())
			{
				scriptInterface.Eval("({})", player);
			}

			int playerID = aiArgs[i].BeforeFirst(":").ToInt();
			CStr name = aiArgs[i].AfterFirst(":");

			scriptInterface.SetProperty(player.get(), "AI", std::string(name));
			scriptInterface.SetPropertyInt(playerData.get(), playerID-1, player);
		}
	}

	// Add player data to map settings
	scriptInterface.SetProperty(settings.get(), "PlayerData", playerData);

	// Add map settings to game attributes
	scriptInterface.SetProperty(attrs.get(), "settings", settings);

	CScriptVal mpInitData;
	g_GUI->GetScriptInterface().Eval("({isNetworked:true, playerAssignments:{}})", mpInitData);
	g_GUI->GetScriptInterface().SetProperty(mpInitData.get(), "attribs",
			CScriptVal(g_GUI->GetScriptInterface().CloneValueFromOtherContext(scriptInterface, attrs.get())));

	// Get optional playername
	CStrW userName = L"anonymous";
	if (args.Has("autostart-playername"))
	{
		userName = args.Get("autostart-playername").FromUTF8();
	}

	if (args.Has("autostart-host"))
	{
		InitPs(true, L"page_loading.xml", mpInitData.get());

		size_t maxPlayers = 2;
		if (args.Has("autostart-players"))
		{
			maxPlayers = args.Get("autostart-players").ToUInt();
		}

		g_NetServer = new CNetServer(maxPlayers);

		g_NetServer->UpdateGameAttributes(attrs.get(), scriptInterface);

		bool ok = g_NetServer->SetupConnection();
		ENSURE(ok);

		g_NetClient = new CNetClient(g_Game);
		g_NetClient->SetUserName(userName);
		g_NetClient->SetupConnection("127.0.0.1");
	}
	else if (args.Has("autostart-client"))
	{
		InitPs(true, L"page_loading.xml", mpInitData.get());

		g_NetClient = new CNetClient(g_Game);
		g_NetClient->SetUserName(userName);

		CStr ip = "127.0.0.1";
		if (args.Has("autostart-ip"))
		{
			ip = args.Get("autostart-ip");
		}

		bool ok = g_NetClient->SetupConnection(ip);
		ENSURE(ok);
	}
	else
	{
		g_Game->SetPlayerID(1);
		g_Game->StartGame(attrs, "");

		LDR_NonprogressiveLoad();

		PSRETURN ret = g_Game->ReallyStartGame();
		ENSURE(ret == PSRETURN_OK);

		InitPs(true, L"page_session.xml", JSVAL_VOID);
	}

	return true;
}
예제 #19
0
void CNWNX2App::parseNWNCmdLine()
{
	CmdLineArgs args;

	for (int i = 0; i < args.size(); i++)
	{
		if (stricmp(args[i], "-port") == 0)
		{
			dlg.m_intServerPort = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-module") == 0)
		{
			dlg.m_strModuleName = args[i+1];
			i++;
		}
		else if (stricmp(args[i], "-processwatchdog") == 0)
		{
			if (atoi(args[i+1]) == 0)
				dlg.m_boolWatchdogProcess = false;
			else
				dlg.m_boolWatchdogProcess = true;
			i++;
		}
		else if (stricmp(args[i], "-processinterval") == 0)
		{
			dlg.m_intUpdateIntervalProcess = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-gamespywatchdog") == 0)
		{
			if (atoi(args[i+1]) == 0)
				dlg.m_boolWatchdogGamespy = false;
			else
				dlg.m_boolWatchdogGamespy = true;
			i++;
		}
		else if (stricmp(args[i], "-gamespyinterval") == 0)
		{
			dlg.m_intUpdateIntervalGamespy = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-gamespyretries") == 0)
		{
			dlg.m_intGamespyRetries = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-oldgamespyprotocol") == 0)
		{
			if (atoi(args[i+1]) == 1)
				dlg.m_boolOldGamespyProtocol = true;
			i++;
		}
		else if (stricmp(args[i], "-publicserver") == 0)
		{
			if (atoi(args[i+1]) == 0)
				dlg.m_boolWatchdogGamespy = false;
			strcat(cmdline, args[i]);
			strcat(cmdline, " ");
		}
		else if (stricmp(args[i], "-restartdelay") == 0)
		{
			dlg.m_intRestartDelay = atoi(args[i+1]);
			i++;
		}
		else
		{
			strcat(cmdline, args[i]);
			strcat(cmdline, " ");
		}
	}

	char port[6];
	itoa(dlg.m_intServerPort, port, 10);
	strcat(cmdline, "-port ");
	strcat(cmdline, port);

	if (dlg.m_strModuleName != "")
	{
		strcat(cmdline, " -module ");
		strcat(cmdline, dlg.m_strModuleName);
	}
}
예제 #20
0
int main(int argc, char* argv[])
{
  int NoProtect = 0;
  AllowLinear = true;
  double MaxMSE = 4.0;

	CmdLineArgs args;

	if (args.size() == 1)
	{
		Usage();
		return 1;
	}

	const char* InputDir = NULL;
	const char* OutputFilename = "Textures.xpr";

	for (unsigned int i = 1; i < args.size(); ++i)
	{
		if (!stricmp(args[i], "-help") || !stricmp(args[i], "-h") || !stricmp(args[i], "-?"))
		{
			Usage();
			return 1;
		}
		else if (!stricmp(args[i], "-input") || !stricmp(args[i], "-i"))
		{
			InputDir = args[++i];
		}
		else if (!stricmp(args[i], "-output") || !stricmp(args[i], "-o"))
		{
			OutputFilename = args[++i];
		}
    else if (!stricmp(args[i], "-noprotect") || !stricmp(args[i], "-p"))
    {
      NoProtect = 1;
    }
    else if (!stricmp(args[i], "-onlyswizzled") || !stricmp(args[i], "-s"))
    {
      AllowLinear = false;
    }
    else if (!stricmp(args[i], "-quality") || !stricmp(args[i], "-q"))
		{
			++i;
			if (!stricmp(args[i], "min"))
			{
				MaxMSE = DBL_MAX;
			}
			else if (!stricmp(args[i], "low"))
			{
				MaxMSE = 20.0;
			}
			else if (!stricmp(args[i], "normal"))
			{
				MaxMSE = 4.0;
			}
			else if (!stricmp(args[i], "high"))
			{
				MaxMSE = 1.5;
			}
			else if (!stricmp(args[i], "max"))
			{
				MaxMSE = 0.0;
			}
			else
			{
				printf("Unrecognised quality setting: %s\n", args[i]);
			}
		}
		else
		{
			printf("Unrecognised command line flag: %s\n", args[i]);
		}
	}

	// Initialize DirectDraw
	pD3D = Direct3DCreate8(D3D_SDK_VERSION);
	if (pD3D == NULL)
	{
		puts("Cannot init D3D");
		return 1;
	}

	HRESULT hr;
	D3DDISPLAYMODE dispMode;
	D3DPRESENT_PARAMETERS presentParams;

	pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dispMode);

	ZeroMemory(&presentParams, sizeof(presentParams));
	presentParams.Windowed = TRUE;
	presentParams.hDeviceWindow = GetConsoleWindow();
	presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
	presentParams.BackBufferWidth = 8;
	presentParams.BackBufferHeight = 8;
	presentParams.BackBufferFormat = dispMode.Format;

	hr = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &pD3DDevice);
	if (FAILED(hr))
	{
		printf("Cannot init D3D device: %08x\n", hr);
		pD3D->Release();
		return 1;
	}

	char HomeDir[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, HomeDir);

	XPRFile.OutputBuf = (char*)VirtualAlloc(0, 64 * 1024 * 1024, MEM_RESERVE, PAGE_NOACCESS);
	if (!XPRFile.OutputBuf)
	{
		printf("Memory allocation failure: %08x\n", GetLastError());
		pD3DDevice->Release();
		pD3D->Release();
		return 1;
	}

	Bundler.StartBundle();

	// Scan the input directory (or current dir if false) for media files
	ConvertDirectory(InputDir, NULL, MaxMSE);

	VirtualFree(XPRFile.OutputBuf, 0, MEM_RELEASE);

	pD3DDevice->Release();
	pD3D->Release();

	SetCurrentDirectory(HomeDir);
	DWORD attr = GetFileAttributes(OutputFilename);
	if (attr != -1 && (attr & FILE_ATTRIBUTE_DIRECTORY))
	{
		SetCurrentDirectory(OutputFilename);
		OutputFilename = "Textures.xpr";
	}

	printf("\nWriting bundle: %s", OutputFilename);
  int BundleSize = Bundler.WriteBundle(OutputFilename, NoProtect);
	if (BundleSize == -1)
	{
		printf("\nERROR: %08x\n", GetLastError());
		return 1;
	}

	printf("\nUncompressed texture size: %6dkB\nCompressed texture size: %8dkB\nBundle size:             %8dkB\n\nWasted Pixels: %u/%u (%5.2f%%)\n",
		(UncompressedSize + 1023) / 1024, (((CompressedSize + 1023) / 1024) + 3) & ~3, (BundleSize + 1023) / 1024,
		TotalDstPixels - TotalSrcPixels, TotalDstPixels, 100.f * (float)(TotalDstPixels - TotalSrcPixels) / (float)TotalDstPixels);

	return 0;
}
예제 #21
0
Paths::Paths(const CmdLineArgs& args)
{
	m_root = Root(args.GetArg0());

	m_rdata = RootData(args.GetArg0());

	const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad";

	if(!subdirectoryName)
	{
		// Note: if writableRoot option is passed to the game, then
		//	all the data is a subdirectory of the root
		m_gameData = m_rdata;
		m_userData = m_gameData;
		m_config = m_gameData / "config"/"";
		m_cache = m_gameData / "cache"/"";
		m_logs = m_root / "logs"/"";
	}
	else // OS-specific path handling
	{

#if OS_ANDROID

		const OsPath appdata = OsPath("/sdcard/0ad/appdata");

		// We don't make the game vs. user data distinction on Android
		m_gameData = appdata/"data"/"";
		m_userData = m_gameData;
		m_config = appdata/"config"/"";
		m_cache = appdata/"cache"/"";
		m_logs = appdata/"logs"/"";

#elif OS_WIN

		/* For reasoning behind our Windows paths, see the discussion here:
		 * http://www.wildfiregames.com/forum/index.php?showtopic=14759
		 * 
		 * Summary:
		 *	1. Local appdata: for bulky unfriendly data like the cache,
		 *      which can be recreated if deleted; doesn't need backing up.
		 *  2. Roaming appdata: for slightly less unfriendly data like config
		 *      files that might theoretically be shared between different
		 *      machines on a domain.
		 *  3. Personal / My Documents: for data explicitly created by the user,
		 *      and which should be visible and easily accessed. We use a non-
		 *      localized My Games subfolder for improved organization.
		 */

		// %localappdata%/0ad/
		const OsPath localAppdata = wutil_LocalAppdataPath() / subdirectoryName/"";
		// %appdata%/0ad/
		const OsPath roamingAppData = wutil_RoamingAppdataPath() / subdirectoryName/"";
		// My Documents/My Games/0ad/
		const OsPath personalData = wutil_PersonalPath() / "My Games" / subdirectoryName/"";

		m_cache = localAppdata / "cache"/"";
		m_gameData = roamingAppData / "data"/"";
		m_userData = personalData/"";
		m_config = roamingAppData / "config"/"";
		m_logs = localAppdata / "logs"/"";

#elif OS_MACOSX

		/* For reasoning behind our OS X paths, see the discussion here:
		 * http://www.wildfiregames.com/forum/index.php?showtopic=15511
		 *
		 * Summary:
		 *  1. Application Support: most data associated with the app
		 *		should be stored here, with few exceptions (e.g. temporary
		 *		data, cached data, and managed media files).
		 *  2. Caches: used for non-critial app data that can be easily
		 *		regenerated if this directory is deleted. It is not
		 *		included in backups by default.
		 *
		 * Note: the paths returned by osx_Get*Path are not guaranteed to exist,
		 *     but that's OK since we always create them on demand.
		 */

		// We probably want to use the same subdirectoryName regardless
		//	of whether running a bundle or from SVN. Apple recommends using
		//	company name, bundle name or bundle identifier.
		OsPath appSupportPath;  // ~/Library/Application Support/0ad
		OsPath cachePath;       // ~/Library/Caches/0ad

		{
			std::string path = osx_GetAppSupportPath();
			ENSURE(!path.empty());
			appSupportPath = OsPath(path) / subdirectoryName;
		}
		{
			std::string path = osx_GetCachesPath();
			ENSURE(!path.empty());
			cachePath = OsPath(path) / subdirectoryName;
		}

		// We don't make the game vs. user data distinction on OS X
		m_gameData = appSupportPath /"";
		m_userData = m_gameData;
		m_cache = cachePath/"";
		m_config = appSupportPath / "config"/"";
		m_logs = appSupportPath / "logs"/"";

#else // OS_UNIX

		const char* envHome = getenv("HOME");
		ENSURE(envHome);
		const OsPath home(envHome);
		const OsPath xdgData   = XDG_Path("XDG_DATA_HOME",   home, home/".local/share/") / subdirectoryName;
		const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/"     ) / subdirectoryName;
		const OsPath xdgCache  = XDG_Path("XDG_CACHE_HOME",  home, home/".cache/"      ) / subdirectoryName;

		// We don't make the game vs. user data distinction on Unix
		m_gameData = xdgData/"";
		m_userData = m_gameData;
		m_cache  = xdgCache/"";
		m_config = xdgConfig / "config"/"";
		m_logs   = xdgConfig / "logs"/"";

#endif
	}
}
예제 #22
0
파일: showWin.cpp 프로젝트: hjgode/showwin
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
    LoadString(hInstance, IDC_SHOWWIN, szWindowClass, MAX_LOADSTRING);

	HWND hwndOld=FindWindow(szWindowClass,NULL);
	// kill request?
	if(hwndOld!=NULL){
		if(wcsicmp(lpCmdLine, L"-kill")==0){
			PostMessage(hwndOld, WM_QUIT, 0, 0);
			return 11;
		}
	}

	DEBUGMSG(1, (L"CmdLine parsing #1: \r\n"));
	//command parsing
	struct cmdList *Liste;
	Liste=NULL;
	CmdLineArgs args;
	for (UINT i = 0; i < args.size(); i++){
		DEBUGMSG(1, (L"%20i: '%s'\r\n", i, args[i]));
		append(&Liste, args[i]);
	}
	getOptions(Liste);
	args.~CmdLineArgs();
	//end of parsing

	// already running?
	if(hwndOld!=NULL){
		//check if new message text?
		if(wcslen(szMessageTextNew) > 0){
			myMsg _mymsg;
			memset(&_mymsg,0,sizeof(myMsg));
			wsprintf( _mymsg.szText, L"%s", szMessageTextNew );
			_mymsg.iVal=0;	//the text message identifier
			//prepare WM_COPYDATA
			COPYDATASTRUCT copyData;
			copyData.dwData=1234;
			copyData.cbData=sizeof(myMsg);
			copyData.lpData=&_mymsg;
			SendMessage(hwndOld, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&copyData);
		}
		if(iProgressValNew!=-1){
			myMsg _mymsg;
			memset(&_mymsg,0,sizeof(myMsg));
			wsprintf( _mymsg.szText, L"%i", iProgressValNew );
			_mymsg.iVal=1;	//the progress message identifier
			//prepare WM_COPYDATA
			COPYDATASTRUCT copyData;
			copyData.dwData=1234;
			copyData.cbData=sizeof(myMsg);
			copyData.lpData=&_mymsg;
			SendMessage(hwndOld, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&copyData);
		}
		ShowWindow(hwndOld, SW_SHOWNORMAL);
		return -1;
	}
	
	//client size
	int maxX = GetSystemMetrics(SM_CXSCREEN);
	int maxY = GetSystemMetrics(SM_CYSCREEN);		//640 ??
	int borderSize = GetSystemMetrics(SM_CXBORDER);
	int minSize = GetSystemMetrics(SM_CYMENU);
	//int yFull = GetSystemMetrics(SM_CYFULLSCREEN);	//554 ??
	RECT rectMax;
	GetWindowRect(GetDesktopWindow(), &rectMax);
	if(xWidth<100 || xWidth>maxX)	// secure width setting
		xWidth=maxX-2*borderSize;
	if(yHeight<minSize)
		yHeight=minSize+2*borderSize;

	if(xPos<borderSize)	//secure x pos
		xPos=borderSize;
	if(yPos<rectMax.top)	//secure y pos
		yPos=rectMax.top;

	//progressBar is attached to bottom of window
	if(bUseProgress){
		//extend window
		xProgressWidth=xWidth;
		yHeight+=yProgressHeight;
		yProgress=yHeight-yProgressHeight;

	}
	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	HACCEL hAccelTable;
	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SHOWWIN));

	// Main message loop:
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}
예제 #23
0
파일: main.cpp 프로젝트: dquam/Bak3d
//------------------------------------------------------------------------------
int WINAPI WinMain(    HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                    int       nCmdShow )
{
    //initNSight();
#ifdef MEMORY_LEAKS_CHECK
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 
    _CrtSetReportMode ( _CRT_ERROR, _CRTDBG_MODE_DEBUG|_CRTDBG_MODE_WNDW);
#endif

    WNDCLASSEX winClass;
    MSG        uMsg;

    main::g_hInstance = hInstance;

    memset(&uMsg,0,sizeof(uMsg));

    winClass.lpszClassName = "MY_WINDOWS_CLASS";
    winClass.cbSize        = sizeof(WNDCLASSEX);
    winClass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
    winClass.lpfnWndProc   = main::WindowProc;
    winClass.hInstance     = hInstance;
    winClass.hIcon           = LoadIcon(hInstance, (LPCTSTR)IDI_OPENGL_ICON);
    winClass.hIconSm       = LoadIcon(hInstance, (LPCTSTR)IDI_OPENGL_ICON);
    winClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    winClass.lpszMenuName  = NULL;
    winClass.cbClsExtra    = 0;
    winClass.cbWndExtra    = 0;
    
    if(!RegisterClassEx(&winClass) )
        return E_FAIL;

    main::g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS",
                             "Viewer",
                             WS_OVERLAPPEDWINDOW, 0, 0, main::g_winSz[0], main::g_winSz[1], NULL, NULL, 
                             hInstance, NULL );

    if( main::g_hWnd == NULL )
        return E_FAIL;

    ShowWindow( main::g_hWnd, nCmdShow );
    UpdateWindow( main::g_hWnd );

#if defined(USESVCUI) || defined(USEANTTWEAKBAR)
    main::initUIBase();
#endif
    // Initialize the very base of OpenGL
    if(main::initGLBase())
    {
        // Initialize more general stuff... typically what can be declared when using GLUT
        // TODO: replace the lpCmdLine by proper C-style arguments
        CmdLineArgs args;

        std::string exe = args[0];
        //std::replace(exe.begin(),exe.end(),'\\','/');
        //size_t last = exe.rfind('/');
        //if (last != std::string::npos){
        //  g_path = exe.substr(0,last) + std::string("/");
        //}

        main::initGL((int)args.size(), (const char**)&args[0]);

        //---------------------------------------------------------------------------
        // Message pump
        while( uMsg.message != WM_QUIT )
        {
            if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
            { 
                TranslateMessage( &uMsg );
                DispatchMessage( &uMsg );
            }
            else 
            {
                main::idle();
                if(main::g_renderCnt > 0)
                {
                    main::g_renderCnt--;
                    main::display();
                    Sleep(1);
                } else
                    Sleep(10);
            }
        }
    }
    main::shutdown();
    if( main::g_hRC != NULL )
    {
        ReleaseDC( main::g_hWnd, main::g_hDC );
        main::g_hDC = NULL;
    }
    main::shutdownBase();
    UnregisterClass( "MY_WINDOWS_CLASS", hInstance );

#ifdef MEMORY_LEAKS_CHECK
    _CrtDumpMemoryLeaks();
#endif

    return (int)uMsg.wParam;
}
예제 #24
0
int main(int argc, char **argv)
{
    QApplication* app=NULL;
    initAppPaths(argc,argv);
    CmdLineArgs args;
    if(!args.preparse(argc,argv)) { // searches only for the -cfg parameter
        qCritical(CSTR(args.error()));
        return 1;
    }

    //Load Config
    QString IniFilename;
    if(args.configLocation().isEmpty()) {
        if(!QDir(HomeDir).exists()) {
            QDir conf(QDir::homePath());
            if(!QDir().mkpath(HomeDir))
                qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir));
        }
        IniFilename=HomeDir+"/config";
    }
    else
        IniFilename=args.configLocation();

    config = new KpxConfig(IniFilename);
    fileDlgHistory.load();

    // PlugIns

    if(config->integrPlugin()!=KpxConfig::NoIntegr) {
        QString LibName="libkeepassx-";
        if(config->integrPlugin()==KpxConfig::KDE)
            LibName+="kde.so";
        else if(config->integrPlugin()==KpxConfig::Gnome)
            LibName+="gnome.so";
        QString filename=findPlugin(LibName);
        if(filename!=QString()) {
            QPluginLoader plugin(filename);
            if(!plugin.load()) {
                PluginLoadError=plugin.errorString();
                qWarning("Could not load desktop integration plugin:");
                qWarning(CSTR(PluginLoadError));
            }
            else {
                QObject *plugininstance=plugin.instance();
                IFileDialog* fdlg=qobject_cast<IFileDialog*>(plugininstance);
                IconLoader=qobject_cast<IIconTheme*>(plugininstance);
                if(IconLoader==NULL) {
                    qWarning("Error: Integration Plugin: Could not initialize IconTheme interface.");
                }
                KpxFileDialogs::setPlugin(fdlg);
                if(config->integrPlugin()==KpxConfig::KDE) {
                    IKdeInit* kdeinit=qobject_cast<IKdeInit*>(plugin.instance());
                    app=kdeinit->getMainAppObject(argc,argv);
                    if(!app)PluginLoadError=QObject::tr("Initialization failed.");
                }
                if(config->integrPlugin()==KpxConfig::Gnome) {
                    IGnomeInit* ginit=qobject_cast<IGnomeInit*>(plugin.instance());
                    if(!ginit->init(argc,argv)) {
                        KpxFileDialogs::setPlugin(NULL);
                        qWarning("GtkIntegrPlugin: Gtk init failed.");
                        PluginLoadError=QObject::tr("Initialization failed.");
                    }
                }
            }
        }
        else {
            qWarning(CSTR(QString("Could not load desktop integration plugin: File '%1' not found.").arg(LibName)));
            PluginLoadError=QObject::tr("Could not locate library file.");
        }
    }
    if(!app) {
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
        app = new KeepassApplication(argc,argv);
#else
        app = new QApplication(argc,argv);
#endif
    }
    args.parse(QApplication::arguments());


    //Internationalization
    QLocale loc;
    if(!args.language().size())
        loc=QLocale::system();
    else
        loc=QLocale(args.language());

    QTranslator* translator = NULL;
    QTranslator* qtTranslator=NULL;
    translator=new QTranslator;
    qtTranslator=new QTranslator;

    if(loadTranslation(translator,"keepass-",loc.name(),QStringList()
                       << DataDir+"/i18n/"
                       << HomeDir))
    {
        app->installTranslator(translator);
        TrActive=true;
    }
    else {
        if(loc.name()!="en_US")
            qWarning(QString("Kpx: No Translation found for '%1 (%2)' using 'English (UnitedStates)'")
                     .arg(QLocale::languageToString(loc.language()))
                     .arg(QLocale::countryToString(loc.country())).toAscii());
        delete translator;
        TrActive=false;
    }

    if(TrActive) {
        if(loadTranslation(qtTranslator,"qt_",loc.name(),QStringList()
                           << QLibraryInfo::location(QLibraryInfo::TranslationsPath)
                           << DataDir+"/i18n/"
                           << HomeDir))
            app->installTranslator(qtTranslator);
        else {
            if(loc.name()!="en_US")
                qWarning(QString("Qt: No Translation found for '%1 (%2)' using 'English (UnitedStates)'")
                         .arg(QLocale::languageToString(loc.language()))
                         .arg(QLocale::countryToString(loc.country())).toAscii());
            delete qtTranslator;
        }
    }

    DetailViewTemplate=config->detailViewTemplate();

    loadImages();
    KpxBookmarks::load();
    initYarrow(); //init random number generator
    SecString::generateSessionKey();

    eventListener = new EventListener();
    app->installEventFilter(eventListener);

    QApplication::setQuitOnLastWindowClosed(false);
    KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked());
    int r=app->exec();
    delete mainWin;
    delete eventListener;

    fileDlgHistory.save();
    delete app;
    delete config;
    return r;
}
예제 #25
0
int main(int argc, char **argv)
{
#ifdef Q_WS_WIN
	// Make sure Windows doesn't load DLLs from the current working directory
	SetDllDirectoryA("");
	SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
#endif

	setlocale(LC_CTYPE, "");
	
#if defined(Q_WS_X11) && defined(AUTOTYPE)
	QApplication* app = new KeepassApplication(argc,argv);
#else
	QApplication* app = new QApplication(argc,argv);
#endif
	EventListener* eventListener = new EventListener();
	app->installEventFilter(eventListener);
	
	QApplication::setQuitOnLastWindowClosed(false);
	
	AppDir = QApplication::applicationFilePath();
	AppDir.truncate(AppDir.lastIndexOf("/"));
#if defined(Q_WS_X11)
	DataDir = AppDir+"/../share/keepassx";
	if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
		DataDir = AppDir+"/share";
	const char* env = getenv("XDG_CONFIG_HOME");
	if (!env) {
		HomeDir = QDir::homePath() + "/.config";
	}
	else {
		QString qenv = QTextCodec::codecForLocale()->toUnicode(env);
		if (qenv[0] == '/')
			HomeDir = qenv;
		else
			HomeDir = QDir::homePath() + '/' + qenv;
	}
	HomeDir += "/keepassx";
#elif defined(Q_WS_MAC)
	HomeDir = QDir::homePath()+"/.keepassx";
	DataDir = AppDir+"/../Resources/keepassx";
#else //Q_WS_WIN
	HomeDir = qtWindowsConfigPath(CSIDL_APPDATA);
	if(!HomeDir.isEmpty() && QFile::exists(HomeDir))
		HomeDir = QDir::fromNativeSeparators(HomeDir)+"/KeePassX";
	else
		HomeDir = QDir::homePath()+"/KeePassX";
	
	DataDir = AppDir+"/share";
#endif
	DataDir = QDir::cleanPath(DataDir);
	
	CmdLineArgs args;
	if ( !args.parse(QApplication::arguments()) ){
		qCritical("%s\n", CSTR( args.error() ));
		args.printHelp();
		return 1;
	}
	if (args.help()){
		args.printHelp();
		return 1;
	}

	//Load Config
	QString IniFilename;
	if(args.configLocation().isEmpty()){
		if(!QDir(HomeDir).exists()){
			QDir conf(QDir::homePath());
			if(!QDir().mkpath(HomeDir))
				qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir));
		}
		IniFilename=HomeDir+"/config.ini";
	}
	else
		IniFilename=args.configLocation();

#ifdef Q_WS_X11
	{
		QString OldHomeDir = QDir::homePath()+"/.keepassx";
		if (args.configLocation().isEmpty() && QFile::exists(OldHomeDir+"/config") && !QFile::exists(HomeDir+"/config")) {
			QFile::rename(OldHomeDir+"/config", HomeDir+"/config.ini");
			if (QDir(OldHomeDir).entryList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System).count()==0)
				QDir().rmdir(OldHomeDir);
		}
	}
#else
	if (args.configLocation().isEmpty() && QFile::exists(HomeDir+"/config") && !QFile::exists(HomeDir+"/config.ini"))
		QFile::rename(HomeDir+"/config", HomeDir+"/config.ini");
#endif
	config = new KpxConfig(IniFilename);
	fileDlgHistory.load();
	
	// PlugIns
	/*
#ifdef Q_WS_X11
	if(config->integrPlugin()!=KpxConfig::NoIntegr){
		QString LibName="libkeepassx-";
		if(config->integrPlugin()==KpxConfig::KDE)
			LibName+="kde.so";
		else if(config->integrPlugin()==KpxConfig::Gnome)
			LibName+="gnome.so";
		QString filename=findPlugin(LibName);
		if(filename!=QString()){
			QPluginLoader plugin(filename);
			if(!plugin.load()){
				PluginLoadError=plugin.errorString();
				qWarning("Could not load desktop integration plugin:");
				qWarning("%s", CSTR(PluginLoadError));
			}
			else{
				QObject *plugininstance=plugin.instance();
				IFileDialog* fdlg=qobject_cast<IFileDialog*>(plugininstance);
				IconLoader=qobject_cast<IIconTheme*>(plugininstance);
				if(IconLoader==NULL){
					qWarning("Error: Integration Plugin: Could not initialize IconTheme interface.");
				}
				KpxFileDialogs::setPlugin(fdlg);
				if(config->integrPlugin()==KpxConfig::KDE){
					IKdeInit* kdeinit=qobject_cast<IKdeInit*>(plugin.instance());
					app=kdeinit->getMainAppObject(argc,argv);
					if(!app) PluginLoadError = "Initialization failed.";
				}
				if(config->integrPlugin()==KpxConfig::Gnome){
					IGnomeInit* ginit=qobject_cast<IGnomeInit*>(plugin.instance());
					if(!ginit->init(argc,argv)){
						KpxFileDialogs::setPlugin(NULL);
						qWarning("GtkIntegrPlugin: Gtk init failed.");
						PluginLoadError = "Initialization failed.";
					}
				}
			}
		}
		else{
			qWarning(CSTR(QString("Could not load desktop integration plugin: File '%1' not found.").arg(LibName)));
			PluginLoadError=QApplication::translate("Main", "Could not locate library file.");
		}
	}
#endif
	*/
	
	DetailViewTemplate=config->detailViewTemplate();

	loadImages();
	KpxBookmarks::load();
	initYarrow(); //init random number generator
	SecString::generateSessionKey();
	
	installTranslator();

#ifdef Q_WS_MAC
	QApplication::processEvents();
	if (args.file().isEmpty() && !eventListener->file().isEmpty()) {
		args.setFile(eventListener->file());
	}
#endif

	KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked());
#ifdef Q_WS_MAC
	eventListener->setMainWin(mainWin);
#endif

	int r=app->exec();
	delete mainWin;
	delete eventListener;

	fileDlgHistory.save();
	SecString::deleteSessionKey();
	delete app;
	delete config;
	return r;
}
예제 #26
0
static void ProcessCommandLineArgs(const CmdLineArgs& args)
{
	// TODO: all these options (and the ones processed elsewhere) should
	// be documented somewhere for users.

	if (args.Has("buildarchive"))
	{
		// note: VFS init is sure to have been completed by now
		// (since CONFIG_Init reads from file); therefore,
		// it is safe to call this from here directly.
//		vfs_opt_rebuild_main_archive("mods/official/official1.zip", "../logs/trace.txt");
	}

	// Handle "-conf=key:value" (potentially multiple times)
	std::vector<CStr> conf = args.GetMultiple("conf");
	for (size_t i = 0; i < conf.size(); ++i)
	{
		CStr name_value = conf[i];
		if (name_value.Find(':') != -1)
		{
			CStr name = name_value.BeforeFirst(":");
			CStr value = name_value.AfterFirst(":");
			g_ConfigDB.CreateValue(CFG_COMMAND, name)->m_String = value;
		}
	}

	if (args.Has("g"))
	{
		g_Gamma = args.Get("g").ToFloat();
		if (g_Gamma == 0.0f)
			g_Gamma = 1.0f;
	}

//	if (args.Has("listfiles"))
//		trace_enable(true);

	if (args.Has("profile"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "profile")->m_String = args.Get("profile");

	if (args.Has("quickstart"))
	{
		g_Quickstart = true;
		g_DisableAudio = true; // do this for backward-compatibility with user expectations
	}

	if (args.Has("nosound"))
		g_DisableAudio = true;

	if (args.Has("shadows"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "shadows")->m_String = "true";

	if (args.Has("xres"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "xres")->m_String = args.Get("xres");

	if (args.Has("yres"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "yres")->m_String = args.Get("yres");

	if (args.Has("vsync"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "vsync")->m_String = "true";

	if (args.Has("ooslog"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "ooslog")->m_String = "true";

	if (args.Has("serializationtest"))
		g_ConfigDB.CreateValue(CFG_COMMAND, "serializationtest")->m_String = "true";
}
예제 #27
0
int _tmain(int argc, _TCHAR* argv[])
{
	// -class "IE6on6SoftKeyBar" -enable -list
	if(argc==1){	// no args
		nclog(L"showFullScreen utility v 1.0 * %s\n", logDateTime());
		printHelp();
		MessageBox(GetDesktopWindow(), L"showFullScreen needs some args. Please see 'showFullScreen.exe.log.txt'", L"showFullScreen", MB_SETFOREGROUND | MB_TOPMOST | MB_OK);
		return -3;
	}

	DEBUGMSG(1, (L"CmdLine parsing #1: \r\n"));
	//command parsing
	struct cmdList *Liste;
	Liste=NULL;
	CmdLineArgs args;
	for (UINT i = 0; i < args.size(); i++){
		DEBUGMSG(1, (L"%20i: '%s'\r\n", i, args[i]));
		append(&Liste, args[i]);
	}
	getOptions(Liste);
	args.~CmdLineArgs();
	//end of parsing

	if(bListWindows){
		nclog(L"showFullScreen utility v 1.0 * %s\n", logDateTime());
		
		ListWindows();
	}

	//look for window
	HWND hWnd=NULL;
	if(wcslen(szWindowClass) && wcslen(szWindowTitle)){
		//window title and class
		hWnd = FindWindow(szWindowClass, szWindowTitle);
	}
	else if(wcslen(szWindowClass)){
		//only window class, ie "WFIcaClient"
		hWnd = FindWindow(szWindowClass, NULL);
	}
	else if(wcslen(szWindowTitle)){
		//only window title
		hWnd = FindWindow(NULL, szWindowTitle);
	}

	HWND hWndTaskbar = FindWindow(L"HHTASKBAR", NULL);
	//sanity restore of HHTASKBAR?
	//ShowWindow(hWndTaskbar, SW_SHOWNORMAL);

	if(hWnd==NULL)
		return -1;	//no window found

	if(bChangeSize){	//change size?
		RECT rectDesktop;
		HRESULT hRes = GetWindowRect(GetDesktopWindow(), &rectDesktop);	//desktopwindow is only the taskbar window!
		// SM_CXFULLSCREEN , SM_CXMAXIMIZED , SM_CXSCREEN 
		int iCX;
		int iCY;
		BOOL bRes;
		if(bShowFullScreen){
			iCX = GetSystemMetrics(SM_CXSCREEN);	// 480
			iCY = GetSystemMetrics(SM_CYSCREEN);	// 640
			bRes = SetWindowPos(hWnd, GetDesktopWindow(), 0, 0, iCX, iCY, SWP_SHOWWINDOW);
			ShowWindow(hWndTaskbar, SW_HIDE);
		}
		else{
			RECT rcMaxScreen;
			SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMaxScreen, SPIF_SENDCHANGE);	// {top=36 bottom=640 left=0 right=480}
			bRes = SetWindowPos(hWnd, GetDesktopWindow(), rcMaxScreen.left, rcMaxScreen.top, rcMaxScreen.right, rcMaxScreen.bottom-rcMaxScreen.top, SWP_SHOWWINDOW);
			ShowWindow(hWndTaskbar, SW_SHOWNORMAL);
		}
	}
	if(iShowHide!=0){	//change show/hide
		switch(iShowHide){
			case 1:
				ShowWindow(hWnd, SW_SHOWNORMAL);
				break;
			case 2:
				ShowWindow(hWnd, SW_HIDE);
				break;
		}
	}
	if(iEnableDisable!=0){	//enable/disbale window
		switch(iEnableDisable){
			case 1:
				EnableWindow(hWnd, TRUE);
				break;
			case 2:
				EnableWindow(hWnd, FALSE);
				break;
		}
	}

	return 0;
}