Пример #1
0
int
mmi_setup_wifi_survey_dispatch(struct mmi_desc *parent)
{
	switch(parent->response) {
	case 0: // <-- back
		parent->level--;
		parent->show	= mmi_setup_wifi_show;
		parent->dispatch= mmi_setup_wifi_dispatch;
		break;
	default:
		if (parent->response < wifi_networks_size) {
			wifi_network_t *network = &wifi_networks[(parent->response)-1];
			
			parse_ini_file("wifi:ssid", 0, network->ssid, 0);
			if (strstr(network->security,"WPA2PSK")) {
				parse_ini_file("wifi:authmode", 0, "WPA2PSK", 0);
				if (strstr(network->security,"AES")) {
					parse_ini_file("wifi:encryptype", 0, "AES", 0);
				}
			}
			break;
		}
	}
	parent->response = -1;
}
Пример #2
0
int main(int argc, char * argv[])
{
	int		status ;

	if (argc<2) {
		create_example_ini_file();
		status = parse_ini_file("example.ini");
	} else {
		status = parse_ini_file(argv[1]);
	}
	return status ;
}
Пример #3
0
int main(void)
{
	struct AATree aatree;
	struct CBTree *cbtree;
	struct md5_ctx md5;
	struct Heap *heap;
	char buf[128];

	static_assert(sizeof(int) >= 4, "unsupported int size");

	heap = heap_create(heap_is_better, NULL, NULL);
	heap_top(heap);
	aatree_init(&aatree, NULL, NULL);
	cbtree = cbtree_create(NULL, NULL, NULL, NULL);
	cbtree_destroy(cbtree);
	daemonize(NULL, false);
	hash_lookup3("foo", 3);
	if (!event_init())
		log_debug("test");
	if (!parse_ini_file("foo", NULL, NULL))
		log_debug("test");
	log_stats("1");
	file_size("foo");
	md5_reset(&md5);
	strlcpy(buf, "foo", sizeof(buf));
	printf("xmalloc: %p\n", xmalloc(128));
	if (0) die("0");
	csrandom();
	tls_init();
	return 0;
}
Пример #4
0
bool cf_load_file(const struct CfContext *cf, const char *fn)
{
	struct LoaderCtx ctx = {
		.cf = cf,
		.cur_sect = NULL,
	};

	bool ok = parse_ini_file(fn, load_handler, &ctx);
	if (ctx.cur_sect)
		free(ctx.cur_sect);
	return ok;
}
Пример #5
0
int
mmi_setup_wifi_show(struct mmi_desc *parent)
{
	char item[256] = {0};
	char ssid[128] = {0};

	parse_ini_file("wifi:ssid", NULL, NULL, ssid);
	snprintf(item,sizeof(item),"Easy Mode:%s",ssid);

	mmi_reset();
	mmi_add_item(2, "MCA/Setup/.../Wireless");
	mmi_add_item(3, "Wireless");
	mmi_add_item(4, "Please select");
	mmi_add_item(5, item);
	mmi_add_item(5, "Advanced Mode");
	mmi_show();
	parent->level++;
	parent->waiting_for_response = 1;
}
Пример #6
0
int
main(int argc, char *argv[])
{
    int ret, opt, option_index;
    vrouter_ops req;

    parse_ini_file();
    platform = get_platform();

    if (argc == 1) {
        Usage();
    }

    while ((opt = getopt_long(argc, argv, "",
                    long_options, &option_index)) >= 0) {
        switch (opt) {
        case 0:
            parse_long_opts(option_index, optarg);
            break;

        case '?':
        default:
            Usage();
            break;
        }
    }


    validate_options();

    cl = vr_get_nl_client(VR_NETLINK_PROTO_DEFAULT);
    if (!cl) {
        exit(1);
    }

    vr_vrouter_op(cl);

    return 0;
}
Пример #7
0
int init(void){
    int i;
    if(parse_ini_file(arg_ini) == -1){
        return -1;
    }
    firmata = firmata_new(serial_port); //init Firmata
    if (firmata == NULL){
        return -1;
    }
    while(!firmata->isReady) //Wait until device is up
    firmata_pull(firmata);
	
	firmata_pinMode(firmata, ledg, MODE_OUTPUT);
	firmata_pinMode(firmata, ledb, MODE_OUTPUT);
	firmata_pinMode(firmata, ledr, MODE_OUTPUT);

    for(i=0; i<NUM_REL; i++) {
        firmata_pinMode(firmata, rel[i], MODE_OUTPUT);
        firmata_digitalWrite(firmata, rel[i], inv[i]);
    }
    return 0;
}
Пример #8
0
bool emu_options::parse_one_ini(const char *basename, int priority, astring *error_string)
{
	// don't parse if it has been disabled
	if (!read_config())
		return false;

	// open the file; if we fail, that's ok
	emu_file file(ini_path(), OPEN_FLAG_READ);
	file_error filerr = file.open(basename, ".ini");
	if (filerr != FILERR_NONE)
		return false;

	// parse the file
	osd_printf_verbose("Parsing %s.ini\n", basename);
	astring error;
	bool result = parse_ini_file(file, priority, OPTION_PRIORITY_DRIVER_INI, error);

	// append errors if requested
	if (!error.empty() && error_string != NULL)
		error_string->catprintf("While parsing %s:\n%s\n", file.fullpath(), error.c_str());

	return result;
}
Пример #9
0
bool emu_options::parse_one_ini(const char *basename, int priority, std::string *error_string)
{
	// don't parse if it has been disabled
	if (!read_config())
		return false;

	// open the file; if we fail, that's ok
	emu_file file(ini_path(), OPEN_FLAG_READ);
	osd_file::error filerr = file.open(basename, ".ini");
	if (filerr != osd_file::error::NONE)
		return false;

	// parse the file
	osd_printf_verbose("Parsing %s.ini\n", basename);
	std::string error;
	bool result = parse_ini_file((util::core_file&)file, priority, OPTION_PRIORITY_DRIVER_INI, error);

	// append errors if requested
	if (!error.empty() && error_string)
		error_string->append(string_format("While parsing %s:\n%s\n", file.fullpath(), error));

	return result;
}
Пример #10
0
int main(void)
{
	struct AATree aatree;
	struct CBTree *cbtree;
	struct md5_ctx md5;
	char buf[128];

	aatree_init(&aatree, NULL, NULL);
	cbtree = cbtree_create(NULL, NULL, NULL, USUAL_ALLOC);
	daemonize(NULL, NULL);
	hash_lookup3("foo", 3);
	if (!event_init())
		log_debug("test");
	if (!parse_ini_file("foo", NULL, NULL))
		log_debug("test");
	log_stats("1");
	file_size("foo");
	md5_reset(&md5);
	strlcpy(buf, "foo", sizeof(buf));
	printf("xmalloc: %p\n", xmalloc(128));
	if (0) die("0");
	return 0;
}
Пример #11
0
struct nl_client *
vr_get_nl_client(unsigned int proto)
{
    int ret;
    unsigned int sock_proto = proto;
    struct nl_client *cl;

    cl = nl_register_client();
    if (!cl)
        return NULL;

    parse_ini_file();

    if (proto == VR_NETLINK_PROTO_DEFAULT)
        sock_proto = get_protocol();

    ret = nl_socket(cl, get_domain(), get_type(), sock_proto);
    if (ret <= 0)
        goto fail;

    ret = nl_connect(cl, get_ip(), get_port());
    if (ret < 0)
        goto fail;

    if ((proto == VR_NETLINK_PROTO_DEFAULT) &&
            (vrouter_get_family_id(cl) <= 0))
        goto fail;

    return cl;

fail:
    if (cl)
        nl_free_client(cl);

    return NULL;
}
Пример #12
0
int parse_ini_cfg_file(const char* filePath)
{
    const int MaxFileSz = OPTIMUS_DOWNLOAD_SLOT_SZ;
    u8* CfgFileLoadAddr = (u8*)OPTIMUS_DOWNLOAD_TRANSFER_BUF_ADDR;
    int rcode = 0;
   
    init_config_para(&g_sdcBurnPara);

    rcode = parse_ini_file(filePath, CfgFileLoadAddr, MaxFileSz);
    if(rcode){
        err("error in parse ini file\n");
        return __LINE__;
    }

    rcode = check_cfg_burn_parts(&g_sdcBurnPara);
    if(rcode){
        err("Fail in check burn parts.\n");
        return __LINE__;
    }

    print_sdc_burn_para(&g_sdcBurnPara);

    return 0;
}
Пример #13
0
static void 
#if defined(_WIN32)
	WINAPI
#endif
service_loop(int argc, char** argv)
{
	int		argn;
	char*	arg;
	char	str[128];
	char	compiler[128];

	for(argn=1; argn<(int)argc; argn++) {
		arg=argv[argn];
		if(*arg!='-') {	/* .ini file specified */
			if(!fexist(arg)) {
				lprintf(LOG_ERR,"Initialization file does not exist: %s", arg);
				exit(usage(argv[0]));
			}
			parse_ini_file(arg);
			continue;
		}
		while(*arg=='-') 
			arg++;
		if(stricmp(arg,"null")==0)
			mdm_null=TRUE;
		else if(stricmp(arg,"com")==0 && argc > argn+1)
			SAFECOPY(com_dev, argv[++argn]);
		else if(stricmp(arg,"baud")==0 && argc > argn+1)
			com_baudrate = (ulong)strtol(argv[++argn],NULL,0);
		else if(stricmp(arg,"host")==0 && argc > argn+1)
			SAFECOPY(host, argv[++argn]);
		else if(stricmp(arg,"port")==0 && argc > argn+1)
			port = (ushort)strtol(argv[++argn], NULL, 0);
		else if(stricmp(arg,"live")==0) {
			if(argc > argn+1 &&
				(com_handle = (COM_HANDLE)strtol(argv[argn+1], NULL, 0)) != 0) {
				argn++;
				com_handle_passed=TRUE;
			}
			com_alreadyconnected=TRUE;
			terminate_after_one_call=TRUE;
			mdm_null=TRUE;
		}
		else if(stricmp(arg,"nohangup")==0) {
			com_hangup=FALSE;
		}
		else if(stricmp(arg,"debug")==0) {
			log_level=LOG_DEBUG;
		}
		else if(stricmp(arg,"help")==0 || *arg=='?')
			exit(usage(argv[0]));
		else {
			fprintf(stderr,"Invalid option: %s\n", arg);
			exit(usage(argv[0]));
		}
	}

#if defined(_WIN32)
	/* Convert "1" to "COM1" for Windows */
	{
		int i;

		if((i=atoi(com_dev)) != 0)
			SAFEPRINTF(com_dev, "COM%d", i);
	}

	if(daemonize) {

		if((svc_status_handle = RegisterServiceCtrlHandler(NAME, ServiceControlHandler))==0) {
			lprintf(LOG_ERR,"!ERROR %d registering service control handler",GetLastError());
			return;
		}

		svc_status.dwServiceType=SERVICE_WIN32_OWN_PROCESS;
		svc_status.dwControlsAccepted=SERVICE_ACCEPT_SHUTDOWN;
		svc_status.dwWaitHint=NTSVC_TIMEOUT_STARTUP;

		svc_status.dwCurrentState=SERVICE_START_PENDING;
		SetServiceStatus(svc_status_handle, &svc_status);
	}

#endif

	lprintf(LOG_INFO,"%s", comVersion(str,sizeof(str)));
	DESCRIBE_COMPILER(compiler);
	lprintf(LOG_INFO,"Build %s %s %s", __DATE__, __TIME__, compiler);

	/************************************/
	/* Inititalize WinSock and COM Port */
	/************************************/

	if(!winsock_startup())
		exit(1);

	/* Install clean-up callback */
	atexit(cleanup);

	lprintf(LOG_INFO,"TCP Host: %s", host);
	lprintf(LOG_INFO,"TCP Port: %u", port);
	
	if(!com_handle_passed) {
		lprintf(LOG_INFO,"Opening Communications Device (COM Port): %s", com_dev);
		if((com_handle=comOpen(com_dev)) == COM_HANDLE_INVALID) {
			lprintf(LOG_ERR,"ERROR %u opening communications device/port: '%s'", COM_ERROR_VALUE, com_dev);
			exit(1);
		}
	}
	lprintf(LOG_INFO,"COM Port device handle: %u", com_handle);

	if(com_baudrate!=0) {
		if(!comSetBaudRate(com_handle,com_baudrate))
			lprintf(LOG_ERR,"ERROR %u setting DTE rate to %lu bps"
				,COM_ERROR_VALUE, com_baudrate);
	}

	lprintf(LOG_INFO,"COM Port DTE rate: %ld bps", comGetBaudRate(com_handle));

	if(ident)
		_beginthread(ident_server_thread, 0, NULL);

#if defined(_WIN32)
	if(daemonize) {
		svc_status.dwCurrentState=SERVICE_RUNNING;
		svc_status.dwControlsAccepted|=SERVICE_ACCEPT_STOP;
		SetServiceStatus(svc_status_handle, &svc_status);
	}
#endif

	/***************************/
	/* Initialization Complete */
	/***************************/

	/* Main service loop: */
	while(!terminated && wait_for_call(com_handle)) {
		if(!carrier_detect(com_handle))	/* re-initialization timer time-out? */
			continue;
		comWriteByte(com_handle,'\r');
		comWriteString(com_handle, banner);
		comWriteString(com_handle, "\r\n");
		if((sock=connect_socket(host, port)) == INVALID_SOCKET) {
			comWriteString(com_handle,"\7\r\n!ERROR connecting to TCP port\r\n");
		} else {
			handle_call();
			close_socket(&sock);
			total_calls++;
			lprintf(LOG_INFO,"Call completed (%lu total)", total_calls);
		}
		if(com_hangup && !hangup_call(com_handle))
			break;
		if(terminate_after_one_call)
			break;
	}

	exit(0);
}
Пример #14
0
int main(int argc, char * argv[])
{
	int	status ;
	status =  parse_ini_file("robot.ini");
	return status ;
}
Пример #15
0
CQuotesProviderBase::CXMLFileInfo init_xml_info(LPCTSTR pszFileName, bool& rbSucceded)
{
	rbSucceded = false;
	tstring sIniFile = get_ini_file_name(pszFileName);
	return parse_ini_file(sIniFile, rbSucceded);
}
Пример #16
0
int main(int argc, char* args[])
{
	std::cout<<"GBE+ 1.3 [SDL]\n";

	core_emu* gbe_plus = NULL;

	//Start SDL from the main thread now, report specific init errors later in the core
	SDL_Init(SDL_INIT_VIDEO);

	//Grab command-line arguments
	for(int x = 0; x++ < argc - 1;) 
	{ 
		std::string temp_arg = args[x]; 
		config::cli_args.push_back(temp_arg);
		parse_filenames();
	}

	//Parse .ini options
	parse_ini_file();

	//Load OSD font
	load_osd_font();

	//Parse cheat file
	if(config::use_cheats) { parse_cheats_file(false); }

	if(config::mute) { config::volume = 0; }

	//Parse command-line arguments
	//These will override .ini options!
	if(!parse_cli_args()) { return 0; }

	//Get emulated system type from file
	config::gb_type = get_system_type_from_file(config::rom_file);

	//GBA core
	if(config::gb_type == 3)
	{
		gbe_plus = new AGB_core();
	}
	
	//DMG-GBC core
	else if((config::gb_type >= 0) && (config::gb_type <= 2))
	{
		gbe_plus = new DMG_core();
	}

	//Super Game Boy (SGB1 and SGB2)
	else if((config::gb_type == 5) || (config::gb_type == 6))
	{
		gbe_plus = new SGB_core();
	}

	//NDS core
	else
	{
		gbe_plus = new NTR_core();
	}
	
	//Read BIOS file optionally
	if(config::use_bios) 
	{
		//If no bios file was passed from the command-line arguments, defer to .ini options
		if(config::bios_file == "")
		{
			switch(config::gb_type)
			{
				case 0x1 : config::bios_file = config::dmg_bios_path; break;
				case 0x2 : config::bios_file = config::gbc_bios_path; break;
				case 0x3 : config::bios_file = config::agb_bios_path; break;
			}
		}

		if(!gbe_plus->read_bios(config::bios_file)) { return 0; } 
	}

	//Read specified ROM file
	if(!gbe_plus->read_file(config::rom_file)) { return 0; }

	//Read firmware optionally (NDS)
	if((config::use_firmware) && (config::gb_type == 4))
	{
		if(!gbe_plus->read_firmware(config::nds_firmware_path)) { return 0; }
	}

	//Engage the core
	gbe_plus->start();
	gbe_plus->db_unit.debug_mode = config::use_debugger;

	if(gbe_plus->db_unit.debug_mode) { SDL_CloseAudio(); }

	//Disbale mouse cursor in SDL, it's annoying
	SDL_ShowCursor(SDL_DISABLE);

	//Actually run the core
	gbe_plus->run_core();

	return 0;
}  
Пример #17
0
int main(int argc, char **argv)
{
    char *fnct_name = "main";
    pthread_attr_t thrd_attr;
    int counter;
    int ret;

    set_init_gbl_params();

    if (parse_main_args(argc, argv) != 0) {
        ERR(gbl.init_dbg, "Unable to parse arguments");
        return -1;
    }

    gbl.ini_file_ptr = fopen(gbl.ini_file_path, "r");
    if (gbl.ini_file_ptr == NULL) {
        ERR(gbl.init_dbg, "Unable to open INI file [%s]", gbl.ini_file_path);
        return -1;
    }

    if (parse_ini_file() != 0) {
        ERR(gbl.init_dbg, "Unable to parse INI file [%s]", gbl.ini_file_path);
        goto QUIT_CLEANUP;
    }
    OK(gbl.init_dbg, "parse_ini_file done OK");

    if (init_mb_links() != retOK) {
        ERR(gbl.init_dbg, "init_mb_links failed");
        goto QUIT_CLEANUP;
    }
    OK(gbl.init_dbg, "init_gbl.mb_link done OK");

    if (init_mb_tx() != retOK) {
        ERR(gbl.init_dbg, "init_mb_tx failed");
        goto QUIT_CLEANUP;
    }
    OK(gbl.init_dbg, "init_gbl.mb_tx done OK");

    gbl.hal_mod_id = hal_init(gbl.hal_mod_name);
    if (gbl.hal_mod_id < 0) {
        ERR(gbl.init_dbg, "Unable to initialize HAL component [%s]", gbl.hal_mod_name);
        goto QUIT_CLEANUP;
    }
    if (create_HAL_pins() != retOK) {
        ERR(gbl.init_dbg, "Unable to create HAL pins");
        goto QUIT_CLEANUP;
    }
    hal_ready(gbl.hal_mod_id);
    OK(gbl.init_dbg, "HAL components created OK");

    gbl.quit_flag = 0; //tell the threads to quit (SIGTERM o SIGQUIT) (unloadusr mb2hal).
    signal(SIGINT, quit_signal);
    //unloadusr and unload commands of halrun
    signal(SIGTERM, quit_signal);

    /* Each link has it's own thread */
    pthread_attr_init(&thrd_attr);
    pthread_attr_setdetachstate(&thrd_attr, PTHREAD_CREATE_DETACHED);
    for (counter = 0; counter < gbl.tot_mb_links; counter++) {
        ret = pthread_create(&gbl.mb_links[counter].thrd, &thrd_attr, link_loop_and_logic, (void *) &gbl.mb_links[counter].mb_link_num);
        if (ret != 0) {
            ERR(gbl.init_dbg, "Unable to start thread for link number %d", counter);
        }
        OK(gbl.init_dbg, "Link thread loop and logic %d created OK", counter);
    }

    OK(gbl.init_dbg, "%s is running", gbl.hal_mod_name);
    while (gbl.quit_flag == 0) {
        sleep(1);
    }

QUIT_CLEANUP:
    quit_cleanup();
    OK(gbl.init_dbg, "going to exit!");
    return 0;
}
Пример #18
0
int main(int argc, char** argv)
{
	int		argn;
	char*	arg;
	char*	p;
	char	path[MAX_PATH+1];
	char	fname[MAX_PATH+1];
	char	ini_fname[MAX_PATH+1];

	/*******************************/
	/* Generate and display banner */
	/*******************************/
	sscanf("$Revision$", "%*s %s", revision);

	sprintf(banner,"\n%s v%s-%s"
		" Copyright %s Rob Swindell"
		,TITLE
		,revision
		,PLATFORM_DESC
		,__DATE__+7
		);

	fprintf(stdout,"%s\n\n", banner);

	/**********************/
	/* Parse command-line */
	/**********************/

	for(argn=1; argn<argc; argn++) {
		arg=argv[argn];
		while(*arg=='-') 
			arg++;
		if(stricmp(arg,"help")==0 || *arg=='?')
			return usage(argv[0]);
#ifdef _WIN32
		else if(stricmp(arg,"service")==0)
			daemonize=TRUE;
		else if(stricmp(arg,"install")==0)
			return install();
		else if(stricmp(arg,"remove")==0)
			return uninstall();
		else if(stricmp(arg,"disable")==0)
			return enable(FALSE);
		else if(stricmp(arg,"enable")==0)
			return enable(TRUE);
#endif
	}

	/******************/
	/* Read .ini file */
	/******************/
	/* Generate path/sexpots[.host].ini from path/sexpots[.exe] */
	SAFECOPY(path,argv[0]);
	p=getfname(path);
	SAFECOPY(fname,p);
	*p=0;
	if((p=getfext(fname))!=NULL) 
		*p=0;
	strcat(fname,".ini");

	iniFileName(ini_fname,sizeof(ini_fname),path,fname);
	parse_ini_file(ini_fname);

#if defined(_WIN32)
	if(daemonize) {

		SERVICE_TABLE_ENTRY  ServiceDispatchTable[] = 
		{ 
			{ NAME,	(void(WINAPI*)(DWORD, char**))service_loop	}, 
			{ NULL,			NULL										}	/* Terminator */
		};

		printf("Starting service control dispatcher.\n" );
		printf("This may take several seconds.  Please wait.\n" );

		if(!StartServiceCtrlDispatcher(ServiceDispatchTable)) {
			lprintf(LOG_ERR,"StartServiceCtrlDispatcher ERROR %d",GetLastError());
			return -1;
		}
		return 0;
	}
	SetConsoleCtrlHandler(ControlHandler, TRUE /* Add */);

#endif

	service_loop(argc,argv);

	return 0;
}
Пример #19
0
/****** Main menu constructor ******/
main_menu::main_menu(QWidget *parent) : QWidget(parent)
{
	//Setup actions
	QAction* open = new QAction("Open", this);
	QAction* quit = new QAction ("Quit", this);

	QAction* pause = new QAction("Pause", this);
	QAction* reset = new QAction("Reset", this);
	QAction* fullscreen = new QAction("Fullscreen", this);
	QAction* screenshot = new QAction("Screenshot", this);
	QAction* nplay_start = new QAction("Start Netplay", this);
	QAction* nplay_stop = new QAction("Stop Netplay", this);

	QAction* general = new QAction("General Settings...", this);
	QAction* display = new QAction("Display", this);
	QAction* sound = new QAction("Sound", this);
	QAction* controls = new QAction("Controls", this);
	QAction* netplay = new QAction("Netplay", this);
	QAction* paths = new QAction("Paths", this);

	QAction* custom_gfx = new QAction("Custom Graphics...", this);
	QAction* debugging = new QAction("Debugger", this);

	QAction* about = new QAction("About", this);

	//Set shortcuts for actions
	open->setShortcut(tr("CTRL+O"));
	quit->setShortcut(tr("CTRL+Q"));

	pause->setShortcut(tr("CTRL+P"));
	reset->setShortcut(tr("F8"));
	fullscreen->setShortcut(tr("F12"));
	screenshot->setShortcut(tr("F9"));
	nplay_start->setShortcut(tr("F5"));
	nplay_stop->setShortcut(tr("F6"));

	pause->setCheckable(true);
	pause->setObjectName("pause_action");
	fullscreen->setCheckable(true);
	fullscreen->setObjectName("fullscreen_action");

	menu_bar = new QMenuBar(this);

	//Setup File menu
	QMenu* file;

	file = new QMenu(tr("File"), this);
	file->addAction(open);
	recent_list = file->addMenu(tr("Recent Files"));
	file->addSeparator();
	state_save_list = file->addMenu(tr("Save State"));
	state_load_list = file->addMenu(tr("Load State"));
	file->addSeparator();
	file->addAction(quit);
	menu_bar->addMenu(file);

	//Setup Emulation menu
	QMenu* emulation;

	emulation = new QMenu(tr("Emulation"), this);
	emulation->addAction(pause);
	emulation->addAction(reset);
	emulation->addSeparator();
	emulation->addAction(fullscreen);
	emulation->addAction(screenshot);
	emulation->addSeparator();
	emulation->addAction(nplay_start);
	emulation->addAction(nplay_stop);
	menu_bar->addMenu(emulation);

	//Setup Options menu
	QMenu* options;
	
	options = new QMenu(tr("Options"), this);
	options->addAction(general);
	options->addSeparator();
	options->addAction(display);
	options->addAction(sound);
	options->addAction(controls);
	options->addAction(netplay);
	options->addAction(paths);
	menu_bar->addMenu(options);

	//Advanced menu
	QMenu* advanced;

	advanced = new QMenu(tr("Advanced"), this);
	advanced->addAction(custom_gfx);
	advanced->addAction(debugging);
	menu_bar->addMenu(advanced);

	//Setup Help menu
	QMenu* help;

	help = new QMenu(tr("Help"), this);
	help->addAction(about);
	menu_bar->addMenu(help);

	//Setup signals
	connect(quit, SIGNAL(triggered()), this, SLOT(quit()));
	connect(open, SIGNAL(triggered()), this, SLOT(open_file()));
	connect(pause, SIGNAL(triggered()), this, SLOT(pause()));
	connect(fullscreen, SIGNAL(triggered()), this, SLOT(fullscreen()));
	connect(screenshot, SIGNAL(triggered()), this, SLOT(screenshot()));
	connect(nplay_start, SIGNAL(triggered()), this, SLOT(start_netplay()));
	connect(nplay_stop, SIGNAL(triggered()), this, SLOT(stop_netplay()));
	connect(reset, SIGNAL(triggered()), this, SLOT(reset()));
	connect(general, SIGNAL(triggered()), this, SLOT(show_settings()));
	connect(display, SIGNAL(triggered()), this, SLOT(show_display_settings()));
	connect(sound, SIGNAL(triggered()), this, SLOT(show_sound_settings()));
	connect(controls, SIGNAL(triggered()), this, SLOT(show_control_settings()));
	connect(netplay, SIGNAL(triggered()), this, SLOT(show_netplay_settings()));
	connect(paths, SIGNAL(triggered()), this, SLOT(show_paths_settings()));
	connect(custom_gfx, SIGNAL(triggered()), this, SLOT(show_cgfx()));
	connect(debugging, SIGNAL(triggered()), this, SLOT(show_debugger()));
	connect(about, SIGNAL(triggered()), this, SLOT(show_about()));

	sw_screen = new soft_screen();
	hw_screen = new hard_screen();

	QVBoxLayout* layout = new QVBoxLayout;
	layout->setContentsMargins(0, 0, 0, -1);
	layout->addWidget(sw_screen);
	layout->addWidget(hw_screen);
	layout->setMenuBar(menu_bar);
	setLayout(layout);

	config::scaling_factor = 2;

	hw_screen->hide();
	hw_screen->setEnabled(false);

	//Parse .ini options
	parse_ini_file();

	//Parse cheats file
	if(config::use_cheats) { parse_cheats_file(); }

	//Parse command-line arguments
	//These will override .ini options!
	if(!parse_cli_args()) { exit(0); }

	//Some command-line arguments are invalid for the Qt version
	config::use_debugger = false;

	//Setup Recent Files
	list_mapper = new QSignalMapper(this);

	for(int x = (config::recent_files.size() - 1); x >= 0; x--)
	{
		QString path = QString::fromStdString(config::recent_files[x]);
		QFileInfo file(path);
		path = file.fileName();

		QAction* temp = new QAction(path, this);
		recent_list->addAction(temp);

		connect(temp, SIGNAL(triggered()), list_mapper, SLOT(map()));
		list_mapper->setMapping(temp, x);
	}

	connect(list_mapper, SIGNAL(mapped(int)), this, SLOT(load_recent(int)));

	//Setup Save States
	QSignalMapper* save_mapper = new QSignalMapper(this);

	for(int x = 0; x < 10; x++)
	{
		QAction* temp;

		if(x == 0) 
		{
			temp = new QAction(tr("Quick Save"), this);
			temp->setShortcut(tr("F1"));
		}
		
		else
		{
			std::string slot_id = "Slot " + util::to_str(x);
			QString slot_name = QString::fromStdString(slot_id);
			temp = new QAction(slot_name, this);
		}

		state_save_list->addAction(temp);

		connect(temp, SIGNAL(triggered()), save_mapper, SLOT(map()));
		save_mapper->setMapping(temp, x);
	}

	connect(save_mapper, SIGNAL(mapped(int)), this, SLOT(save_state(int)));

	//Setup Load States
	QSignalMapper* load_mapper = new QSignalMapper(this);

	for(int x = 0; x < 10; x++)
	{
		QAction* temp;

		if(x == 0)
		{
			temp = new QAction(tr("Quick Load"), this);
			temp->setShortcut(tr("F2"));
		}
		
		else
		{
			std::string slot_id = "Slot " + util::to_str(x);
			QString slot_name = QString::fromStdString(slot_id);
			temp = new QAction(slot_name, this);
		}

		state_load_list->addAction(temp);

		connect(temp, SIGNAL(triggered()), load_mapper, SLOT(map()));
		load_mapper->setMapping(temp, x);
	}

	connect(load_mapper, SIGNAL(mapped(int)), this, SLOT(load_state(int)));

	//Set up settings dialog
	settings = new gen_settings();
	settings->set_ini_options();

	//Set up custom graphics dialog
	cgfx = new gbe_cgfx();
	cgfx->hide();
	cgfx->advanced->setChecked(true);

	//Set up DMG-GBC debugger
	main_menu::dmg_debugger = new dmg_debug();
	main_menu::dmg_debugger->hide();

	//Setup About pop-up
	about_box = new QWidget();
	about_box->resize(300, 250);
	about_box->setWindowTitle("About GBE+");

	QDialogButtonBox* about_button = new QDialogButtonBox(QDialogButtonBox::Close);
	connect(about_button->button(QDialogButtonBox::Close), SIGNAL(clicked()), about_box, SLOT(close()));

	QLabel* emu_title = new QLabel("GBE+ 1.0");
	QFont font = emu_title->font();
	font.setPointSize(18);
	font.setBold(true);
	emu_title->setFont(font);

	QImage logo(QString::fromStdString(config::cfg_path + "data/icons/gbe_plus.png"));
	logo = logo.scaled(128, 128);
	QLabel* emu_desc = new QLabel("A GB/GBC/GBA emulator with enhancements");
	QLabel* emu_copyright = new QLabel("Copyright D.S. Baxter 2014-2016");
	QLabel* emu_proj_copyright = new QLabel("Copyright GBE+ Team 2014-2016");
	QLabel* emu_license = new QLabel("This program is licensed under the GNU GPLv2");
	QLabel* emu_site = new QLabel("<a href=\"https://github.com/shonumi/gbe-plus/\">GBE+ on GitHub</a>");
	emu_site->setOpenExternalLinks(true);
	QLabel* emu_logo = new QLabel;
	emu_logo->setPixmap(QPixmap::fromImage(logo));

	QVBoxLayout* about_layout = new QVBoxLayout;
	about_layout->addWidget(emu_title, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(emu_desc, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(emu_copyright, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(emu_proj_copyright, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(emu_license, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(emu_site, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(emu_logo, 0, Qt::AlignCenter | Qt::AlignTop);
	about_layout->addWidget(about_button);
	about_box->setLayout(about_layout);
	about_box->setWindowIcon(QIcon(QString::fromStdString(config::cfg_path + "data/icons/gbe_plus.png")));
	
	about_box->hide();

	//Setup warning message box
	warning_box = new QMessageBox;
	QPushButton* warning_box_ok = warning_box->addButton("OK", QMessageBox::AcceptRole);
	warning_box->setIcon(QMessageBox::Warning);
	warning_box->hide();

	display_width = QApplication::desktop()->screenGeometry().width();
	display_height = QApplication::desktop()->screenGeometry().height();

	fullscreen_mode = false;
}
Пример #20
0
int main(int argc, char **argv)
{
    //Получить адрес директории пользователя
    struct passwd *UserData = getpwuid(getuid());
    
    if((HomeDir = (char*)malloc(sizeof((*UserData).pw_dir))) == NULL)
    {   
        printf("Ошибка при распределении памяти!\n");
        exit(1);
    }

    strcpy(HomeDir, (*UserData).pw_dir);

    /*
     * Разбор строки параметров
     */
    //Имя конфигурационного файла
    char *ini_config = NULL;
    //Передаваймый параметр
    int c;

    opterr = 0;

    while ((c = getopt (argc, argv, "i:")) != -1)
    {
         switch (c)
        {
            case 'i':
                ini_config = optarg;
                break;
            case '?':
                if (optopt == 'i')
                    fprintf (stderr, "Option -%c requires an argument.\n", optopt);
                else if (isprint (optopt))
                    fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                else
                    fprintf (stderr,
                    "Unknown option character `\\x%x'.\n", optopt);
                return 1;
            default:
                abort ();
        }
    }
        
    //Отладка парсинга параметров ini файла
    #if DEBUG_INI_PARS

    printf ("ini_config = %s\n", ini_config);
    int index;
    for (index = optind; index < argc; index++)
        printf ("Non-option argument %s\n", argv[index]);

    #endif	

    //Ссылка на конфиг файл
    FILE *stream;
    int status ;

    

    //Проверить наличия ini файла
    if(ini_config == NULL)
    {
        

        if((Ini_File = (char*)malloc(sizeof(HomeDir))) == NULL)
            {   
                printf("Ошибка при распределении памяти!\n");
                exit(1);
            }
        
        strcpy(Ini_File, HomeDir);

        printf ("Ini File: %s\n", Ini_File);
        strcat(Ini_File, "/"NAME_PROGRAMM".ini");
        //Проверить наличия ini файла по умолчанию
        if((stream = fopen(Ini_File, "r"))==NULL)
        {
            //TODO : Журналируем любой сбой
            
            create_config_ini_file();
            printf ("Был создан конфигурационный файл по умолчанию: %s, отредактируйте его\n", NAME_PROGRAMM".ini");
            exit(1);
        }
        else
        {
            printf ("Обработать конфигурационный файл по умолчанию\n");
            status = parse_ini_file();
        }
    }
    else
    {
        //Проверить наличие переданного файла
        if((stream = fopen(ini_config, "r"))==NULL)
        {
            //TODO : Журналируем любой сбой
            fprintf (stderr, "Переданный конфигурационный файл %s не существует\n", ini_config);
            exit(1);
        }
        else
        {
            printf ("Обработать конфигурационный файл: %s\n", ini_config);
            status = parse_ini_file(ini_config);
        }
    }

    //Отладка парсинга параметров ini файла
    #if DEBUG_INI_PARS

    printf("Параметры ini файла из функции main\n");
    printf("Script: [%s]\n",  config_job.Script ? config_job.Script : "UNDEF");
    printf("time: [%d]\n",  config_job.Time);
    
    #endif

    //Проверим наличие заданного сценария
    if((stream = fopen(config_job.Script, "r"))==NULL)
    {
        //TODO : Журналируем любой сбой
        printf ("Указанный командный файл %s отсуствует.\n", config_job.Script);
        exit(1);
    }

    //Отключить процесс демонизации
    #if DEBUG_ON_DAEMON

    daemon_start();

    #endif

    // Заходим в функцию run  с главным циклом демона
    run(config_job.Time, config_job.Script);
    
    exit(EXIT_SUCCESS);
}
Configuration::Configuration( const std::string& ini_file_name /* = CONFIG_INI */ )
    : m_ini_file_name( ini_file_name )
{
    parse_ini_file( ini_file_name, m_section_map );
}