コード例 #1
0
ファイル: File.c プロジェクト: 0x73/libCello
var File_New(var self, var_list vl) {
  FileData* fd = cast(self, File);
  const char* filename = as_str(var_list_get(vl));
  const char* access = as_str(var_list_get(vl));
  stream_open(self, filename, access);
  return self;
}
コード例 #2
0
	inline void ebox_code(DWORD err, PCWSTR line) {
		ustring	title(L"Error: ");
		title += as_str(err);
		::SetLastError(err);
		PCWSTR Msg[] = {title.c_str(), line, L"OK", };
		psi().Message(get_plugin_guid(), FMSG_WARNING | FMSG_ERRORTYPE, nullptr, Msg, sizeofa(Msg), 1);
	}
コード例 #3
0
ファイル: wr_coremap.c プロジェクト: hemantagr/pktgen-dpdk
static const char *
as_str(const char *line)
{
	if (*line != ':')
		return as_str(line + 1);
	return line + 1;
}
コード例 #4
0
ファイル: wr_coremap.c プロジェクト: hemantagr/pktgen-dpdk
static lcore_t *
set_model_name(const char *line, lcore_t *lc)
{
	if (!model_name)
		model_name = strdup(as_str(line));
	return lc;
}
コード例 #5
0
ファイル: String.c プロジェクト: EddieRingle/libCello
void String_Assign(var self, var obj) {
  StringData* s = cast(self, String);
  const char* value = as_str(obj);
  s->value = realloc(s->value, strlen(value) + 1);
  if (s->value == NULL) { throw(OutOfMemoryError, "Cannot allocate string, out of memory!"); }
  strcpy(s->value, value);
}
コード例 #6
0
ファイル: soa2xml.cpp プロジェクト: vadz/lmi.new
xml::node xml_for_aggregate_table(soa_actuarial_table const& t)
{
    xml::node n("aggregate");

    std::vector<double> const values =
        t.values(t.min_age(), t.max_age() - t.min_age() + 1);

    for(unsigned int i = 0; i < values.size(); i++)
        {
        xml::node v("value", as_str(values[i]));
        v.get_attributes().insert("age", as_str(t.min_age() + i));
        n.insert(v);
        }

    return n;
}
コード例 #7
0
ファイル: String.c プロジェクト: EddieRingle/libCello
var String_Eq(var self, var other) {
  StringData* fst = cast(self, String);
  if (type_implements(type_of(other), AsStr)) {
    return (var)(intptr_t)(strcmp(fst->value, as_str(other)) == 0);
  } else {
    return False;
  }
}
コード例 #8
0
ファイル: String.c プロジェクト: EddieRingle/libCello
void String_Append(var self, var obj) {
  StringData* s = cast(self, String);
  const char* os = as_str(obj);
  
  size_t newlen = strlen(s->value) + strlen(os);
  
  s->value = realloc(s->value, newlen + 1);
  if (s->value == NULL) { throw(OutOfMemoryError, "Cannot allocate string, out of memory!"); }
  
  strcat(s->value, os);
}
コード例 #9
0
ファイル: fe_config.cpp プロジェクト: Cucurbitace/attract
void FeInputSelMenu::get_options( FeConfigContext &ctx )
{
	ctx.set_style( FeConfigContext::EditList, "Configure / Controls" );
	ctx.fe_settings.get_input_mappings( m_mappings );

	std::vector < FeMapping >::iterator it;
	for ( it=m_mappings.begin(); it != m_mappings.end(); ++it )
	{
		std::string setstr, help, orstr;
		ctx.fe_settings.get_resource( "OR", orstr );
		std::string value;
		std::vector < std::string >::iterator iti;
		for ( iti=(*it).input_list.begin(); iti != (*it).input_list.end(); ++iti )
		{
			if ( iti > (*it).input_list.begin() )
			{
				value += " ";
				value += orstr;
				value += " ";
			}

			value += (*iti);
		}

		std::string help_msg( "_help_control_" );
		help_msg += FeInputMap::commandStrings[(*it).command];

		ctx.add_optl( Opt::SUBMENU,
			FeInputMap::commandDispStrings[(*it).command],
			value,
			help_msg );
	}

	// Add the joystick and mouse threshold settings to this menu as well
	std::vector<std::string> thresh(21);
	thresh[0]="99";
	for ( int i=0; i<19; i++ )
		thresh[i+1] = as_str( 95 - ( i * 5 ) );
	thresh[20]="1";
	std::string setstr, help;

	ctx.add_optl( Opt::LIST, "Joystick Threshold",
		ctx.fe_settings.get_info( FeSettings::JoystickThreshold ), "_help_joystick_threshold" );
	ctx.back_opt().append_vlist( thresh );
	ctx.back_opt().opaque = 1;

	ctx.add_optl( Opt::LIST, "Mouse Threshold",
		ctx.fe_settings.get_info( FeSettings::MouseThreshold ), "_help_mouse_threshold" );
	ctx.back_opt().append_vlist( thresh );
	ctx.back_opt().opaque = 1;

	FeBaseConfigMenu::get_options( ctx );
}
コード例 #10
0
ファイル: soa2xml.cpp プロジェクト: vadz/lmi.new
xml::node xml_for_duration_table(soa_actuarial_table const& t)
{
    xml::node n("duration");

    std::vector<double> const values =
        t.values(t.min_age(), t.max_age() - t.min_age() + 1);

    for(unsigned int i = 0; i < values.size(); i++)
        {
        xml::node v("value", as_str(values[i]));
        n.insert(v);
        }

    return n;
}
コード例 #11
0
ファイル: String.c プロジェクト: EddieRingle/libCello
var String_Lt(var self, var obj) {
  StringData* s = cast(self, String);
  if (not type_implements(type_of(obj), AsStr)) return false;
  
  const char* fst = s->value;
  const char* snd = as_str(obj);
  
  int fstlen = strlen(fst);
  int sndlen = strlen(snd);
  int minlen = fstlen > sndlen ? sndlen : fstlen; 
  
  for(int i = 0; i < minlen; i++) {
    if (fst[i] < snd[i]) return True;
  }
  
  if (fstlen < sndlen) return True;
  
  return False;
}
コード例 #12
0
ファイル: String.c プロジェクト: EddieRingle/libCello
void String_Discard(var self, var obj) {
  StringData* s = cast(self, String);
  
  if (type_implements(type_of(obj), AsStr)) {
    const char* ostr = as_str(obj);
    const char* pos = strstr(s->value, ostr);
    
    int bytecount = strlen(s->value) - strlen(pos) - strlen(ostr) + 1;
    memmove((char*)pos, pos + strlen(ostr), bytecount);
  }
  
  if (type_implements(type_of(obj), AsChar)) {
    char ochar = as_char(obj);
    const char* pos = strchr(s->value, ochar);
    while(pos != NULL) {
      pos = pos+1;
    }
  }
  
}
コード例 #13
0
ファイル: soa2xml.cpp プロジェクト: vadz/lmi.new
xml::node xml_for_select_and_ultimate_table(soa_actuarial_table const& t)
{
    xml::node n("select-and-ultimate");

    xml::node n_select("select");
    xml::node n_ultimate("ultimate");

    // Write the <select> portion:
    n_select.get_attributes().insert("period", as_str(t.select_period()));
    for(int age = t.min_age(); age <= t.max_select_age(); age++)
        {
            std::vector<double> data = t.values(age, t.select_period());
            xml::node n_row("row");
            n_row.get_attributes().insert("age", as_str(age));
            for (int s = 0; s < t.select_period(); s++)
                {
                xml::node v("value", as_str(data[s]));
                n_row.insert(v);
                }

            n_select.insert(n_row);
        }

    // Write the <ultimate> portion:
    for(int age = t.min_age(); age <= t.max_select_age(); age++)
        {
        std::vector<double> data = t.values(age, t.select_period() + 1);
        xml::node v("value", as_str(data.back()));
        v.get_attributes().insert("age", as_str(age + t.select_period()));
        n_ultimate.insert(v);
        }
    for(int age = t.max_select_age() + t.select_period() + 1; age <= t.max_age(); age++)
        {
        std::vector<double> data = t.values(age, 1);
        xml::node v("value", as_str(data.back()));
        v.get_attributes().insert("age", as_str(age));
        n_ultimate.insert(v);
        }

    n.insert(n_select);
    n.insert(n_ultimate);

    return n;
}
コード例 #14
0
ファイル: String.c プロジェクト: EddieRingle/libCello
var String_Contains(var self, var obj) {
  StringData* s = cast(self, String);
  
  if (type_implements(type_of(obj), AsStr)) {
    const char* ostr = as_str(obj);
    if ( strstr(s->value, ostr) ) {
      return True;
    } else {
      return False;
    }
  }
  
  if (type_implements(type_of(obj), AsChar)) {
    char ochar = as_char(obj);
    if (strchr(s->value, ochar)) {
      return True;
    } else {
     return False;
    }
  }
  
  return False;
}
コード例 #15
0
ssize_t tst::_registry()
{
    LogAlert();

    astring welln[] = {
        astring(".DEFAULT"),
//		astring("S-1-5-18"),
//		astring("S-1-5-19"),
//		astring("S-1-5-20"),
    };

    auto seq = registry::open(HKEY_USERS, "");
    if (seq) {
        for (auto it = seq->begin(), end = seq->end(); it != end; ++it) {
            if (simstd::find(simstd::begin(welln), simstd::end(welln), it->name()) == simstd::end(welln)) {
                LogReport("found name: '%s'", it->name().c_str());

                auto sid = windows::sid::open(it->name().c_str());
                if (sid) {
                    LogReport("\tgood sid: '%s', name: '%s'", sid->as_str().c_str(), sid->name().c_str());
                }

                // try open network
                auto key = registry::open(seq->system(), (it->name() + "\\Network").c_str());
                if (key) {
                    LogReport("\texist!");
                    for (auto it = key->begin(), end = key->end(); it != end; ++it) {
                        auto letter = registry::open(key->system(), it->name().c_str());
                        auto path = letter->get("RemotePath", "");
                        LogReport("letter: '%s' -> '%s'", it->name().c_str(), path.c_str());
                    }
                }
            }
        }
    }
    return 0;
}
コード例 #16
0
ファイル: fe_build.cpp プロジェクト: omegaman1/attract
bool FeSettings::scrape_artwork( const std::string &emu_name, UiUpdate uiu, void *uid, std::string &msg )
{
	FeEmulatorInfo *emu = m_rl.get_emulator( emu_name );
	if ( emu == NULL )
		return false;

	//
	// Put up the "scraping artwork" message at 0 percent while we get going...
	//
	if ( uiu )
		uiu( uid, 0 );

	std::cout << "*** Scraping artwork for: " << emu_name << std::endl;

	FeRomInfoListType romlist;

	std::string fn = get_config_dir() + FE_ROMLIST_SUBDIR + emu_name + FE_ROMLIST_FILE_EXTENSION;

	FeImporterContext ctx( *emu, romlist );
	ctx.uiupdate = uiu;
	ctx.uiupdatedata = uid;

	if ( file_exists( fn ) )
	{
		FeRomList loader( get_config_dir() );
		loader.load_from_file( fn, ";" );
		ctx.romlist.swap( loader.get_list() );
	}
	else
	{
		ctx.progress_range=33;
		build_basic_romlist( ctx );
		apply_xml_import( ctx );
		ctx.progress_past=33;
	}

	ctx.progress_range = ( 100-ctx.progress_past ) / 2;
	ctx.scrape_art = true;
	confirm_directory( get_config_dir(), FE_SCRAPER_SUBDIR );

	// do the mamedb scraper first (which only does anything for mame) followed
	// by the more general thegamesdb scraper.  these return false if the user
	// cancels...
	if ( mamedb_scraper( ctx ) )
	{
		ctx.progress_past = ctx.progress_past + ctx.progress_range;
		thegamesdb_scraper( ctx );
	}

	if ( uiu )
		uiu( uid, 100 );

	std::cout << "*** Scraping done." << std::endl;

	if ( ctx.user_message.empty() )
		get_resource( "Scraped $1 artwork file(s)", as_str( ctx.download_count ), msg );
	else
		msg = ctx.user_message;

	return true;
}
コード例 #17
0
ファイル: Format.c プロジェクト: eccstartup/libCello
int scan_from_va(var input, int pos, const char* fmt, va_list va) {

  char fmt_buf[strlen(fmt)+1];
  
  while(true) {
    
    if (*fmt == '\0') { break; }
    
    const char* start = fmt;
    
    /* Match String */
    while(!strchr("%\0", *fmt)) { fmt++; }
    
    if (start != fmt) {
      
      strncpy(fmt_buf, start, (fmt - start));
      fmt_buf[(fmt - start)+0] = '\0';
      fmt_buf[(fmt - start)+1] = '%';
      fmt_buf[(fmt - start)+2] = 'n';
      
      int off = 0;
      int err = format_from(input, pos, fmt_buf, &off);
      if (err < 0) { throw(FormatError, "Unable to input format!"); }
      
      pos += off;
      continue;
    }
    
    /* Match %% */
    if (*fmt == '%' && *(fmt+1) == '%') {
      
      int err = format_from(input, pos, "%%");
      if (err < 0) { throw(FormatError, "Unable to input '%%%%'!"); }
      
      pos += 2;
      fmt += 2;
      continue;
    }
    
    /* Match Format Specifier */
    while(!strchr("diuoxXfFeEgGaAxcsp$\0", *fmt)) { fmt++; }
    
    if (start != fmt) {
    
      strncpy(fmt_buf, start, (fmt - start)+1);
      fmt_buf[(fmt - start)+1] = '\0';
      
      var a = va_arg(va, var);
      
      if (*fmt == '$') { pos = look_from(a, input, pos); }
      
      fmt_buf[(fmt - start)+1] = '%';
      fmt_buf[(fmt - start)+2] = 'n';
      fmt_buf[(fmt - start)+3] = '\0';
      
      int off = 0;
      
      if (*fmt == 's') {      
        int err = format_from(input, pos, fmt_buf, as_str(a), &off);
        if (err < 1) { throw(FormatError, "Unable to input String!"); }
        pos += off;
      }
      
      if (strchr("diouxX", *fmt)) {
        long tmp = 0;
        int err = format_from(input, pos, fmt_buf, &tmp, &off);
        if (err < 1) { throw(FormatError, "Unable to input Int!"); }
        pos += off;
        assign(a, $(Int, tmp));
      }
      
      if (strchr("fFeEgGaA", *fmt)) {
        if (strchr(fmt_buf, 'l')) {
          double tmp = 0;
          int err = format_from(input, pos, fmt_buf, &tmp, &off);
          if (err < 1) { throw(FormatError, "Unable to input Real!"); }
          pos += off;
          assign(a, $(Real, tmp));
        } else {
          float tmp = 0;
          int err = format_from(input, pos, fmt_buf, &tmp, &off);
          if (err < 1) { throw(FormatError, "Unable to input Real!"); }
          pos += off;
          assign(a, $(Real, tmp));
        }
      }
      
      if (*fmt == 'c') {
        char tmp = '\0';
        int err = format_from(input, pos, fmt_buf, &tmp, &off);
        if (err < 1) { throw(FormatError, "Unable to input Char!"); }
        pos += off;
        assign(a, $(Char, tmp));
      }
      
      if (*fmt == 'p') {
        void* tmp = NULL;
        int err = format_from(input, pos, fmt_buf, &tmp, &off);
        if (err < 1) { throw(FormatError, "Unable to input Reference!"); }
        pos += off;
        assign(a, $(Reference, tmp));
      }

      fmt++;
      continue;
    }
    
    throw(FormatError, "Invalid Format String!");
  }
  
  return pos;

}
コード例 #18
0
ファイル: wr_coremap.c プロジェクト: hemantagr/pktgen-dpdk
static unsigned
as_int(const char *line)
{
	return atoi(as_str(line));
}
コード例 #19
0
ファイル: Format.c プロジェクト: eccstartup/libCello
int print_to_va(var out, int pos, const char* fmt, va_list va) {

  char fmt_buf[strlen(fmt)+1]; 
  
  while(true) {
    
    if (*fmt == '\0') { break; }
    
    const char* start = fmt;
    
    /* Match String */
    while(!strchr("%\0", *fmt)) { fmt++; }
    
    if (start != fmt) {
      strncpy(fmt_buf, start, (fmt - start));
      fmt_buf[(fmt - start)] = '\0';
      int off = format_to(out, pos, fmt_buf);
      if (off < 0) { throw(FormatError, "Unable to output format!"); }
      pos += off;
      continue;
    }
    
    /* Match %% */
    if (*fmt == '%' && *(fmt+1) == '%') {
      int off = format_to(out, pos, "%%");
      if (off < 0) { throw(FormatError, "Unable to output '%%%%'!"); }
      pos += off;
      fmt += 2;
      continue;
    }
    
    /* Match Format Specifier */
    while(!strchr("diuoxXfFeEgGaAxcsp$\0", *fmt)) { fmt++; }
    
    if (start != fmt) {
    
      strncpy(fmt_buf, start, (fmt - start)+1);
      fmt_buf[(fmt - start)+1] = '\0';
      
      var a = va_arg(va, var);
      
      if (*fmt == '$') { pos = show_to(a, out, pos); }
      
      if (*fmt == 's') {      
        int off = format_to(out, pos, fmt_buf, as_str(a));
        if (off < 0) { throw(FormatError, "Unable to output String!"); }
        pos += off;
      }
      
      if (strchr("diouxX", *fmt)) {
        int off = format_to(out, pos, fmt_buf, as_long(a));
        if (off < 0) { throw(FormatError, "Unable to output Int!"); }
        pos += off;
      }
      
      if (strchr("fFeEgGaA", *fmt)) { 
        int off = format_to(out, pos, fmt_buf, as_double(a));
        if (off < 0) { throw(FormatError, "Unable to output Real!"); }
        pos += off;
      }
      
      if (*fmt == 'c') {
        int off = format_to(out, pos, fmt_buf, as_char(a));
        if (off < 0) { throw(FormatError, "Unable to output Char!"); }
        pos += off;
      }
      
      if (*fmt == 'p') {
        int off = format_to(out, pos, fmt_buf, a);
        if (off < 0) { throw(FormatError, "Unable to output Object!"); }
        pos += off;
      }

      fmt++;
      continue;
    }
    
    throw(FormatError, "Invalid Format String!");
  }
  
  return pos;
  
}
コード例 #20
0
ファイル: fe_config.cpp プロジェクト: Cucurbitace/attract
void FeDisplayEditMenu::get_options( FeConfigContext &ctx )
{
	ctx.set_style( FeConfigContext::EditList, "Display Edit" );

	if ( m_display )
	{
		ctx.add_optl( Opt::EDIT, "Name",
				m_display->get_info( FeDisplayInfo::Name ), "_help_display_name" );

		ctx.add_optl( Opt::LIST, "Layout",
				m_display->get_info( FeDisplayInfo::Layout ), "_help_display_layout" );

		std::vector<std::string> layouts;
		ctx.fe_settings.get_layouts_list( layouts );
		ctx.back_opt().append_vlist( layouts );

		ctx.add_optl( Opt::LIST, "Collection/Rom List",
				m_display->get_info( FeDisplayInfo::Romlist ), "_help_display_romlist" );

		std::vector<std::string> romlists;
		ctx.fe_settings.get_romlists_list( romlists );
		ctx.back_opt().append_vlist( romlists );

		std::vector<std::string> bool_opts( 2 );
		ctx.fe_settings.get_resource( "Yes", bool_opts[0] );
		ctx.fe_settings.get_resource( "No", bool_opts[1] );

		ctx.add_optl( Opt::LIST, "Show in Cycle",
			m_display->show_in_cycle() ? bool_opts[0] : bool_opts[1],
			"_help_display_in_cycle" );

		ctx.back_opt().append_vlist( bool_opts );

		ctx.add_optl( Opt::LIST, "Show in Menu",
			m_display->show_in_menu() ? bool_opts[0] : bool_opts[1],
			"_help_display_in_menu" );
		ctx.back_opt().append_vlist( bool_opts );

		FeFilter *f = m_display->get_filter( -1 );

		std::string filter_desc;
		if ( f->get_rule_count() < 1 )
			ctx.fe_settings.get_resource( "Empty", filter_desc );
		else
			ctx.fe_settings.get_resource( "$1 Rule(s)",
					as_str(f->get_rule_count()), filter_desc );

		ctx.add_optl( Opt::SUBMENU, "Global Filter", filter_desc, "_help_display_global_filter" );
		ctx.back_opt().opaque = 9;

		std::vector<std::string> filters;
		m_display->get_filters_list( filters );
		int i=0;

		for ( std::vector<std::string>::iterator itr=filters.begin();
				itr != filters.end(); ++itr )
		{
			ctx.add_optl( Opt::SUBMENU, "Filter",
				(*itr), "_help_display_filter" );
			ctx.back_opt().opaque = 100 + i;
			i++;
		}

		ctx.add_optl( Opt::SUBMENU, "Add Filter", "", "_help_display_add_filter" );
		ctx.back_opt().opaque = 1;

		ctx.add_optl( Opt::SUBMENU, "Layout Options", "", "_help_display_layout_options" );
		ctx.back_opt().opaque = 2;

		ctx.add_optl( Opt::EXIT, "Delete this Display", "", "_help_display_delete" );
		ctx.back_opt().opaque = 3;
	}

	FeBaseConfigMenu::get_options( ctx );
}
コード例 #21
0
ファイル: fe_config.cpp プロジェクト: Cucurbitace/attract
void FeFilterEditMenu::get_options( FeConfigContext &ctx )
{
	ctx.set_style( FeConfigContext::EditList, "Filter Edit" );

	if ( m_display )
	{
		FeFilter *f = m_display->get_filter( m_index );

		if ( m_index < 0 )
		{
			std::string gf;
			ctx.fe_settings.get_resource( "Global Filter", gf );
			ctx.add_optl( Opt::INFO, "Filter Name", gf, "_help_filter_name" );
		}
		else
		{
			ctx.add_optl( Opt::EDIT, "Filter Name", f->get_name(),
				"_help_filter_name" );
		}

		int i=0;
		std::vector<FeRule> &rules = f->get_rules();

		for ( std::vector<FeRule>::const_iterator itr=rules.begin();
				itr != rules.end(); ++itr )
		{
			std::string rule_str;
			FeRomInfo::Index t = (*itr).get_target();

			if ( t != FeRomInfo::LAST_INDEX )
			{
				ctx.fe_settings.get_resource( FeRomInfo::indexStrings[t], rule_str );

				FeRule::FilterComp c = (*itr).get_comp();
				if ( c != FeRule::LAST_COMPARISON )
				{
					std::string comp_str;
					ctx.fe_settings.get_resource( FeRule::filterCompDisplayStrings[c], comp_str );

					rule_str += " ";
					rule_str += comp_str;
					rule_str += " ";
					rule_str += (*itr).get_what();
				}
			}

			if ( (*itr).is_exception() )
				ctx.add_optl( Opt::SUBMENU, "Exception", rule_str, "_help_filter_exception" );
			else
				ctx.add_optl( Opt::SUBMENU, "Rule", rule_str, "_help_filter_rule" );

			ctx.back_opt().opaque = 100 + i;
			i++;
		}

		ctx.add_optl(Opt::SUBMENU,"Add Rule","","_help_filter_add_rule");
		ctx.back_opt().opaque = 1;

		ctx.add_optl(Opt::SUBMENU,"Add Exception","","_help_filter_add_exception");
		ctx.back_opt().opaque = 2;

		if ( m_index >= 0 ) // don't add the following options for the global filter
		{
			std::string no_sort_str, sort_val;
			ctx.fe_settings.get_resource( "No Sort", no_sort_str );

			if ( f->get_sort_by() != FeRomInfo::LAST_INDEX )
				sort_val = FeRomInfo::indexStrings[f->get_sort_by()];
			else
				sort_val = no_sort_str;

			std::vector< std::string > targets;
			i=0;
			while ( FeRomInfo::indexStrings[i] != 0 )
			{
				targets.push_back( std::string() );
				ctx.fe_settings.get_resource( FeRomInfo::indexStrings[i], targets.back() );
				i++;
			}
			targets.push_back( no_sort_str );

			ctx.add_optl( Opt::LIST, "Sort By", sort_val, "_help_filter_sort_by" );
			ctx.back_opt().append_vlist( targets );

			ctx.add_optl( Opt::EDIT, "List Limit", as_str( f->get_list_limit() ),
				"_help_filter_list_limit" );

			ctx.add_optl(Opt::EXIT,"Delete this Filter","","_help_filter_delete");
			ctx.back_opt().opaque = 3;
		}
	}

	FeBaseConfigMenu::get_options( ctx );
}
コード例 #22
0
ファイル: fe_config.cpp プロジェクト: Cucurbitace/attract
void FeSoundMenu::get_options( FeConfigContext &ctx )
{
	ctx.set_style( FeConfigContext::EditList, "Configure / Sound" );

	std::vector<std::string> volumes(11);
	for ( int i=0; i<11; i++ )
		volumes[i] = as_str( 100 - ( i * 10 ) );

	std::string setstr, help;

	//
	// Sound, Ambient and Movie Volumes
	//
	for ( int i=0; i<3; i++ )
	{
		int v = ctx.fe_settings.get_set_volume( (FeSoundInfo::SoundType)i );
		ctx.add_optl( Opt::LIST, FeSoundInfo::settingDispStrings[i],
					as_str(v), "_help_volume" );
		ctx.back_opt().append_vlist( volumes );
	}

	//
	// Get the list of available sound files
	// Note the sound_list vector gets copied to each option!
	//
	std::vector<std::string> sound_list;
	ctx.fe_settings.get_sounds_list( sound_list );

#ifndef NO_MOVIE
	for ( std::vector<std::string>::iterator itr=sound_list.begin();
			itr != sound_list.end(); )
	{
		if ( !FeMedia::is_supported_media_file( *itr ) )
			itr = sound_list.erase( itr );
		else
			itr++;
	}
#endif

	sound_list.push_back( "" );

	//
	// Sounds that can be mapped to input commands.
	//
	for ( int i=0; i < FeInputMap::LAST_EVENT; i++ )
	{
		// there is a NULL in the middle of the commandStrings list
		if ( FeInputMap::commandDispStrings[i] != NULL )
		{
			std::string v;
			ctx.fe_settings.get_sound_file( (FeInputMap::Command)i, v, false );

			ctx.add_optl( Opt::LIST,
				FeInputMap::commandDispStrings[i], v, "_help_sound_sel" );

			ctx.back_opt().append_vlist( sound_list );
			ctx.back_opt().opaque = i;
		}
	}

	FeBaseConfigMenu::get_options( ctx );
}
コード例 #23
0
ファイル: world.cpp プロジェクト: BizarreCake/hCraft
		static void
		_handle_resize (player *pl, world *w, command_reader& reader)
		{
			if (!pl->has ("command.world.world.resize"))
    		{
    			pl->message (messages::not_allowed ());
    			return;
    		}
    	
			if (reader.arg_count () != 3)
				{
					pl->message ("§c * §7Usage§f: §e/world resize §cwidth depth");
					return;
				}
			
			int width = 0, depth = 0;
			
			auto a_width = reader.next ();
			auto a_depth = reader.next ();
			
			if (!a_width.is_int ())
				{
					if (sutils::iequals (a_width.as_str (), "inf"))
						width = 0;
					else
						{
							pl->message ("§c * §7Both width and depth must be non-zero positive integers§c.");
							return;
						}
				}
			else
				{
					width = a_width.as_int ();
					if (width <= 0)
						{
							pl->message ("§c * §7Both width and depth must be non-zero positive integers§c.");
							return;
						}
				}
			
			if (!a_depth.is_int ())
				{
					if (sutils::iequals (a_depth.as_str (), "inf"))
						depth = 0;
					else
						{
							pl->message ("§c * §7Both width and depth must be non-zero positive integers§c.");
							return;
						}
				}
			else
				{
					depth = a_depth.as_int ();
					if (depth <= 0)
						{
							pl->message ("§c * §7Both width and depth must be non-zero positive integers§c.");
							return;
						}
				}
			
			if (width == w->get_width () && depth == w->get_depth ())
				{
					pl->message ("§c * §7The world is already in that size§c.");
					return;
				}
			
			w->set_size (width, depth);
			w->get_players ().all (
				[] (player *pl)
					{
						pl->rejoin_world (false);
						pl->message ("§bWorld reloaded");
					});
		}
コード例 #24
0
ファイル: fe_xml.cpp プロジェクト: omegaman1/attract
void FeMameXMLParser::end_element( const char *element )
{
	if (( strcmp( element, "game" ) == 0 )
		|| ( strcmp( element, "machine" ) == 0 ))
	{
		if ( m_collect_data )
		{
			m_collect_data = false;

			if ( !m_keep_rom )
				m_discarded.push_back( m_itr );
			else
			{
				//
				// Construct the extra info now
				//
				std::string extra;
				if ( m_chd )
					extra += "chd";

				if ( m_mechanical )
				{
					if ( !extra.empty() )
						extra += ",";

					extra += "mechanical";
				}

				(*m_itr).set_info( FeRomInfo::Extra, extra );
				(*m_itr).set_info( FeRomInfo::DisplayCount, as_str( m_displays ) );
			}

			m_count++;

			int percent = m_ctx.progress_past + m_count * m_ctx.progress_range / m_ctx.romlist.size();
			if ( percent > m_percent )
			{
				m_percent = percent;
				std::cout << "\b\b\b\b" << std::setw(3)
					<< m_percent << '%' << std::flush;

				if ( m_ui_update )
				{
					if ( m_ui_update( m_ui_update_data, m_percent ) == false )
						set_continue_parse( false );
				}
			}
		}
	}

	if ( m_element_open )
	{
		if ( strcmp( element, "description" ) == 0 )
			(*m_itr).set_info( FeRomInfo::Title, m_current_data );
		else if ( strcmp( element, "year" ) == 0 )
			(*m_itr).set_info( FeRomInfo::Year, m_current_data );
		else if ( strcmp( element, "manufacturer" ) == 0 )
			(*m_itr).set_info( FeRomInfo::Manufacturer, m_current_data );

		m_current_data.clear();
		m_element_open=false;
	}
}
コード例 #25
0
ファイル: scraper_net.cpp プロジェクト: Cucurbitace/attract
bool FeSettings::thegamesdb_scraper( FeImporterContext &c )
{
#ifndef NO_NET
	const char *HOSTNAME = "http://thegamesdb.net";
	const char *PLATFORM_LIST_REQ = "api/GetPlatformsList.php";
	const char *PLAT_REQ = "api/GetPlatform.php?id=$1";
	const char *GAME_REQ = "api/GetGame.php?name=$1";
	const char *FLYER = "flyer/";
	const char *WHEEL = "wheel/";
	const char *MARQUEE = "marquee/";
	const char *SNAP = "snap/";
	const char *FANART = "fanart/";

	//
	// Get a list of valid platforms
	//
	FeNetQueue q;
	q.add_buffer_task( HOSTNAME, PLATFORM_LIST_REQ, 0 );
	sf::Http::Response::Status status;
	std::string err_req;

	q.do_next_task( status, err_req );

	if ( status != sf::Http::Response::Ok )
	{
		get_resource( "Error getting platform list from thegamesdb.net.  Code: $1",
			as_str( status ), c.user_message );

		std::cerr << " ! " << c.user_message << " (" << err_req << ")" << std::endl;
		return true;
	}

	int temp;
	std::string body;
	q.pop_completed_task( temp, body );

	FeGameDBPlatformListParser gdbplp;
	gdbplp.parse( body );

	std::vector<std::string> system_list;
	std::vector<int> system_ids;

	const std::vector<std::string> &sl_temp = c.emulator.get_systems();
	for ( std::vector<std::string>::const_iterator itr = sl_temp.begin();
			itr != sl_temp.end(); ++itr )
	{
		std::string comp_fuzz = get_fuzzy( *itr );

		for ( size_t i=0; i<gdbplp.m_names.size(); i++ )
		{
			ASSERT( gdbplp.m_names.size() == gdbplp.m_ids.size() );

			std::string &n = gdbplp.m_names[i];
			int id = ( i < gdbplp.m_ids.size() ) ? i : 0;

			if ( comp_fuzz.compare( get_fuzzy( n ) ) == 0 )
			{
				system_list.push_back( n );
				system_ids.push_back( id );
				break;
			}
			else
			{
				size_t pos = n.find_first_of( "(" );

				if (( pos != std::string::npos ) &&
					(( comp_fuzz.compare( get_fuzzy( n.substr(0,pos-1))) == 0 )
					|| ( comp_fuzz.compare(get_fuzzy( n.substr(pos+1,n.size()-pos-1 ))) == 0 )))
				{
					system_list.push_back( n );
					system_ids.push_back( id );
					break;
				}
			}
		}
	}

	if ( system_list.size() < 1 )
	{
		// Correct if we can based on the configured info source,
		// otherwise we error out
		switch( c.emulator.get_info_source() )
		{
		case FeEmulatorInfo::Listxml:
			system_list.push_back( "Arcade" ); break;
		case FeEmulatorInfo::Steam:
			system_list.push_back( "PC" ); break;
		default:
			get_resource( "Error: None of the configured system identifier(s) are recognized by thegamesdb.net.",
								c.user_message );

			std::cerr << " ! " << c.user_message << std::endl;
			return true;
		}
	}

	std::string emu_name = c.emulator.get_info( FeEmulatorInfo::Name );
	std::string base_path = get_config_dir() + FE_SCRAPER_SUBDIR;
	base_path += emu_name + "/";

	if ( c.scrape_art )
	{
		//
		// Get emulator-specific images
		//
		for ( std::vector<int>::iterator iti=system_ids.begin();
				iti != system_ids.end(); ++iti )
		{
			std::string plat_string = PLAT_REQ;
			perform_substitution( plat_string, "$1", as_str( *iti ) );

			q.add_buffer_task( HOSTNAME, plat_string, 0 );
			q.do_next_task( status, err_req );
			if ( status != sf::Http::Response::Ok )
			{
				std::cout << " * Unable to get platform information. Status code: "
					<< status << " (" << err_req << ")" << std::endl;
				continue;
			}

			body.clear();
			q.pop_completed_task( temp, body );

			FeGameDBArt my_art;
			FeGameDBPlatformParser gdbpp( my_art );
			gdbpp.parse( body );

			std::string hostn = HOSTNAME;
			std::string base_req = "banners/";
			get_url_components( my_art.base,
				hostn, base_req );

			std::string path = base_path + FLYER;
			if ( m_scrape_flyers && ( !my_art.flyer.empty() )
				&& ( !art_exists( path, emu_name ) ))
			{
				confirm_directory( base_path, FLYER );
				q.add_file_task( hostn, base_req + my_art.flyer,
					path + emu_name );
			}

			path = base_path + WHEEL;
			if ( m_scrape_wheels && ( !my_art.wheel.empty() )
				&& ( !art_exists( path, emu_name ) ))
			{
				confirm_directory( base_path, WHEEL );
				q.add_file_task( hostn, base_req + my_art.wheel,
					path + emu_name );
			}

			path = base_path + MARQUEE;
			if ( m_scrape_marquees && ( !my_art.marquee.empty() )
				&& ( !art_exists( path, emu_name ) ))
			{
				confirm_directory( base_path, MARQUEE );
				q.add_file_task( hostn, base_req + my_art.marquee,
					path + emu_name );
			}

			if ( m_scrape_fanart && !my_art.fanart.empty() )
			{
				std::string path_base = base_path + FANART + emu_name + "/";
				confirm_directory( base_path, "" );
				confirm_directory( base_path + FANART, emu_name );

				for ( std::vector<std::string>::iterator itr = my_art.fanart.begin();
							itr != my_art.fanart.end(); ++itr )
				{
					size_t start_pos = (*itr).find_last_of( "/\\" );
					size_t end_pos = (*itr).find_last_of( '.' );

					if (( start_pos != std::string::npos )
						&& ( !file_exists( path_base + (*itr).substr( start_pos+1 ) ) ))
					{
						if (( end_pos != std::string::npos ) && ( end_pos > start_pos ))
						{
							q.add_file_task( hostn,
								base_req + (*itr),
								path_base + (*itr).substr( start_pos+1,
											end_pos-start_pos-1 ) );
						}
					}
				}
			}
		}
	}

	bool prefer_alt_filename = c.emulator.is_mess();

	//
	// Build a map for looking up parents
	//
	ParentMapType parent_map;
	build_parent_map( parent_map, c.romlist, prefer_alt_filename );

	//
	// Build a worklist of the roms where we need to lookup
	//
	std::vector<FeRomInfo *> worklist;
	worklist.reserve( c.romlist.size() );
	for ( FeRomInfoListType::iterator itr=c.romlist.begin(); itr!=c.romlist.end(); ++itr )
	{
		(*itr).set_info( FeRomInfo::Emulator, emu_name );

		// Don't scrape for a clone if its parent has the same name
		//
		if ( has_same_name_as_parent( *itr, parent_map ) )
			continue;

		if ( !c.scrape_art || m_scrape_fanart
				|| ( m_scrape_flyers && (!has_artwork( *itr, "flyer" ) ) )
				|| ( m_scrape_wheels && (!has_artwork( *itr, "wheel" ) ) )
				|| ( m_scrape_snaps && (!has_image_artwork( *itr, "snap" ) ) )
				|| ( m_scrape_marquees && (!has_artwork( *itr, "marquee" ) ) ) )
			worklist.push_back( &(*itr) );
	}

	const int NUM_ARTS=5; // the number of scrape-able artwork types
	int done_count( 0 );

	//
	// Set up our initial queue of network tasks
	//
	for ( unsigned int i=0; i<worklist.size(); i++ )
	{
		std::string req_string = GAME_REQ;

		std::string game = url_escape(
				name_with_brackets_stripped( worklist[i]->get_info( FeRomInfo::Title ) ) );

		perform_substitution( req_string, "$1", game );

		//
		// If we don't need to scrape a wheel artwork, then add the specific platform to our request
		// If we are scraping a wheel, we want to be able to grab them where the game name (but
		// not the system) matches, so we don't limit ourselves by system...
		//
		if (( system_list.size() == 1 )
			&& ( !c.scrape_art || !m_scrape_wheels || has_artwork( *(worklist[i]), "wheel" ) ))
		{
			req_string += "&platform=";
			req_string += url_escape( system_list.front() );
		}

		q.add_buffer_task( HOSTNAME, req_string, i );
	}

	//
	// Create worker threads to process the queue, adding new tasks to download
	// artwork files where appropriate
	//
	FeNetWorker worker1( q ), worker2( q ), worker3( q ), worker4( q );
	std::string aux;

	//
	// Process the output queue from our worker threads
	//
	while ( !( q.input_done() && q.output_done() ) )
	{
		int id;
		std::string result;

		if ( q.pop_completed_task( id, result ) )
		{
			if ( id < 0 )
			{
				if (( id == FeNetTask::FileTask ) || ( id == FeNetTask::SpecialFileTask ))
				{
					std::cout << " + Downloaded: " << result << std::endl;
					c.download_count++;

					// find second last forward slash in filename
					// we assume that there will always be at least two
					size_t pos = result.find_last_of( "\\/" );
					if ( pos != std::string::npos )
					{
						pos = result.find_last_of( "\\/", pos-1 );
						if ( pos != std::string::npos )
							aux = result.substr( pos );
					}
				}

				if ( id == FeNetTask::FileTask ) // we don't increment if id = FeNetTask::SpecialFileTask
					done_count++;
			}
			else
			{
				FeGameDBArt my_art;
				FeGameDBParser gdbp( system_list, *(worklist[id]), ( c.scrape_art ? &my_art : NULL ) );
				gdbp.parse( result );

				if ( c.scrape_art && !my_art.base.empty() )
				{
					std::string hostn = HOSTNAME;
					std::string base_req = "banners/";
					get_url_components( my_art.base,
						hostn, base_req );

					const FeRomInfo &rom = *(worklist[id]);

					if ( m_scrape_flyers && ( !my_art.flyer.empty() ) && (!has_artwork( rom, "flyer" )) )
					{
						std::string fname = base_path + FLYER;

						const std::string &altname = rom.get_info( FeRomInfo::AltRomname );
						if ( prefer_alt_filename && !altname.empty() )
							fname += rom.get_info( FeRomInfo::AltRomname );
						else
							fname += rom.get_info( FeRomInfo::Romname );

						confirm_directory( base_path, FLYER );
						q.add_file_task( hostn, base_req + my_art.flyer, fname );
					}
					else
						done_count++;

					if ( m_scrape_wheels && ( !my_art.wheel.empty() ) && (!has_artwork( rom, "wheel" )) )
					{
						std::string fname = base_path + WHEEL;

						const std::string &altname = rom.get_info( FeRomInfo::AltRomname );
						if ( prefer_alt_filename && !altname.empty() )
							fname += rom.get_info( FeRomInfo::AltRomname );
						else
							fname += rom.get_info( FeRomInfo::Romname );

						confirm_directory( base_path, WHEEL );
						q.add_file_task( hostn, base_req + my_art.wheel, fname );
					}
					else
						done_count++;

					if ( m_scrape_marquees && (!my_art.marquee.empty() ) && (!has_artwork( rom, "marquee" )) )
					{
						std::string fname = base_path + MARQUEE;

						const std::string &altname = rom.get_info( FeRomInfo::AltRomname );
						if ( prefer_alt_filename && !altname.empty() )
							fname += rom.get_info( FeRomInfo::AltRomname );
						else
							fname += rom.get_info( FeRomInfo::Romname );

						confirm_directory( base_path, MARQUEE );
						q.add_file_task( hostn, base_req + my_art.marquee, fname );
					}
					else
						done_count++;

					if ( m_scrape_snaps && (!my_art.snap.empty() ) && (!has_image_artwork( rom, "snap" )) )
					{
						std::string fname = base_path + SNAP;

						const std::string &altname = rom.get_info( FeRomInfo::AltRomname );
						if ( prefer_alt_filename && !altname.empty() )
							fname += rom.get_info( FeRomInfo::AltRomname );
						else
							fname += rom.get_info( FeRomInfo::Romname );

						confirm_directory( base_path, SNAP );
						q.add_file_task( hostn, base_req + my_art.snap, fname );
					}
					else
						done_count++;

					if ( m_scrape_fanart && !my_art.fanart.empty() )
					{
						std::string fname_base = base_path + FANART;

						confirm_directory( base_path, "" );

						const std::string &altname = rom.get_info( FeRomInfo::AltRomname );
						if ( prefer_alt_filename && !altname.empty() )
						{
							fname_base += rom.get_info( FeRomInfo::AltRomname );
							confirm_directory( base_path + FANART,
								rom.get_info( FeRomInfo::AltRomname ) );
						}
						else
						{
							fname_base += rom.get_info( FeRomInfo::Romname );
							confirm_directory( base_path + FANART,
								rom.get_info( FeRomInfo::Romname ) );
						}

						fname_base += "/";

						bool done_first=false; // we only count the first fanart against our percentage completed...

						for ( std::vector<std::string>::iterator itr = my_art.fanart.begin();
								itr != my_art.fanart.end(); ++itr )
						{
							size_t start_pos = (*itr).find_last_of( "/\\" );
							size_t end_pos = (*itr).find_last_of( '.' );

							if (( start_pos != std::string::npos )
								&& ( !file_exists( fname_base + (*itr).substr( start_pos+1 ) ) ))
							{
								if (( end_pos != std::string::npos ) && ( end_pos > start_pos ))
								{
									q.add_file_task( hostn,
												base_req + (*itr),
												fname_base + (*itr).substr( start_pos+1, end_pos-start_pos-1 ),
												done_first );
									done_first=true;
								}
							}
						}
					}
					else
						done_count++;
				}
				else
				{
					aux = (worklist[id])->get_info( FeRomInfo::Title );
					done_count+=NUM_ARTS;
				}
			}

			if (( c.uiupdate ) && !worklist.empty() )
			{
				int p = c.progress_past + done_count * c.progress_range / ( NUM_ARTS * worklist.size() );
				if ( c.uiupdate( c.uiupdatedata, p, aux ) == false )
					return false;
			}
		}
		else if ( q.output_done() )
		{
			sf::Http::Response::Status status;
			std::string err_req;
			q.do_next_task( status, err_req );
			if ( status != sf::Http::Response::Ok )
			{
				std::cout << " * Error processing request. Status code: "
					<< status << " (" << err_req << ")" << std::endl;
			}
		}
		else
			sf::sleep( sf::milliseconds( 10 ) );
	}
#endif
	return true;
}
コード例 #26
0
ファイル: fe_build.cpp プロジェクト: omegaman1/attract
bool FeSettings::thegamesdb_scraper( FeImporterContext &c )
{
#ifndef NO_NET
	const char *HOSTNAME = "http://thegamesdb.net";
	const char *PLATFORM_REQ = "api/GetPlatformsList.php";
	const char *GAME_REQ = "api/GetGame.php?name=$1";

	//
	// Get a list of valid platforms
	//
	FeNetQueue q;
	q.add_buffer_task( HOSTNAME, PLATFORM_REQ, 0 );
	sf::Http::Response::Status status;
	q.do_next_task( status );

	if ( status != sf::Http::Response::Ok )
	{
		get_resource( "Error getting platform list from thegamesdb.net.  Code: $1",
							as_str( status ), c.user_message );

		std::cout << " * " << c.user_message << std::endl;
		return true;
	}

	int temp;
	std::string body;
	q.pop_completed_task( temp, body );

	FeGameDBPlatformParser gdbpp;
	gdbpp.parse( body );

	const std::vector<std::string> &sl_temp = c.emulator.get_systems();
	std::vector<std::string> system_list;
	for ( std::vector<std::string>::const_iterator itr = sl_temp.begin(); itr!=sl_temp.end(); ++itr )
	{
		if ( gdbpp.m_set.find( *itr ) != gdbpp.m_set.end() )
			system_list.push_back( *itr );
		else
			std::cout << " * System identifier '" << (*itr) << "' not recognized by "
				<< HOSTNAME << std::endl;
	}

	if ( system_list.size() < 1 )
	{
		// Correct if we can based on the configured info source,
		// otherwise we error out
		const std::string source = c.emulator.get_info( FeEmulatorInfo::Info_source );
		if ( source.compare( "mame" ) == 0 )
			system_list.push_back( "Arcade" );
		else if ( source.compare( "steam" ) == 0 )
			system_list.push_back( "PC" );
		else
		{
			get_resource( "Error: None of the configured system identifier(s) are recognized by thegamesdb.net.",
								c.user_message );

			std::cout << " * " << c.user_message << std::endl;
			return true;
		}
	}

	std::string emu_name = c.emulator.get_info( FeEmulatorInfo::Name );

	//
	// Build a map for looking up parents
	//
	std::map < std::string, FeRomInfo * > parent_map;
	build_parent_map( parent_map, c.romlist );

	//
	// Build a worklist of the roms where we need to lookup
	//
	std::vector<FeRomInfo *> worklist;
	worklist.reserve( c.romlist.size() );
	for ( FeRomInfoListType::iterator itr=c.romlist.begin(); itr!=c.romlist.end(); ++itr )
	{
		(*itr).set_info( FeRomInfo::Emulator, emu_name );

		// Don't scrape for a clone if its parent has the same name
		//
		if ( has_same_name_as_parent( *itr, parent_map ) )
			continue;

		if ( !c.scrape_art || m_scrape_fanart
				|| ( m_scrape_flyers && (!has_artwork( *itr, "flyer" ) ) )
				|| ( m_scrape_wheels && (!has_artwork( *itr, "wheel" ) ) )
				|| ( m_scrape_snaps && (!has_artwork( *itr, "snap" ) ) )
				|| ( m_scrape_marquees && (!has_artwork( *itr, "marquee" ) ) ) )
			worklist.push_back( &(*itr) );
	}

	const int NUM_ARTS=5; // the number of scrape-able artwork types
	int done_count( 0 );

	//
	// Set up our initial queue of network tasks
	//
	for ( unsigned int i=0; i<worklist.size(); i++ )
	{
		std::string req_string = GAME_REQ;

		std::string game = url_escape(
				name_with_brackets_stripped( worklist[i]->get_info( FeRomInfo::Title ) ) );

		perform_substitution( req_string, "$1", game );

		//
		// If we don't need to scrape a wheel artwork, then add the specific platform to our request
		// If we are scraping a wheel, we want to be able to grab them where the game name (but
		// not the system) matches, so we don't limit ourselves by system...
		//
		if (( system_list.size() == 1 )
			&& ( !c.scrape_art || !m_scrape_wheels || has_artwork( *(worklist[i]), "wheel" ) ))
		{
			req_string += "&platform=";
			req_string += url_escape( system_list.front() );
		}

		q.add_buffer_task( HOSTNAME, req_string, i );
	}

	std::string base_path = get_config_dir() + FE_SCRAPER_SUBDIR;
	base_path += emu_name + "/";

	//
	// Create worker threads to process the queue, adding new tasks to download
	// artwork files where appropriate
	//
	FeNetWorker worker1( q ), worker2( q ), worker3( q ), worker4( q );

	//
	// Process the output queue from our worker threads
	//
	while ( !q.input_done() || !q.output_done() )
	{
		int id;
		std::string result;
		if ( q.pop_completed_task( id, result ) )
		{
			if ( id < 0 )
			{
				if (( id == FeNetTask::FileTask ) || ( id == FeNetTask::SpecialFileTask ))
				{
					std::cout << " + Downloaded: " << result << std::endl;
					c.download_count++;
				}

				if ( id == FeNetTask::FileTask ) // we don't increment if id = FeNetTask::SpecialFileTask
					done_count++;
			}
			else
			{
				FeGameDBArt my_art;
				FeGameDBParser gdbp( system_list, *(worklist[id]), ( c.scrape_art ? &my_art : NULL ) );
				gdbp.parse( result );

				if ( c.scrape_art && !my_art.base.empty() )
				{
					std::string hostn = HOSTNAME;
					std::string base_req = "banners/";
					size_t pos=0;
					for ( int i=0; i<3 && ( pos != std::string::npos ); i++ )
						pos = my_art.base.find_first_of( '/', pos+1 );

					if (( pos != std::string::npos ) && ( pos < my_art.base.size()-1 ) )
					{
						hostn = my_art.base.substr( 0, pos+1 );
						base_req = my_art.base.substr( pos+1 );
					}

					FeRomInfo &rom = *(worklist[id]);

					if ( m_scrape_flyers && ( !my_art.flyer.empty() ) && (!has_artwork( rom, "flyer" )) )
					{
						const char *FLYER = "flyer/";
						std::string fname = base_path + FLYER + rom.get_info( FeRomInfo::Romname );
						confirm_directory( base_path, FLYER );
						q.add_file_task( hostn, base_req + my_art.flyer, fname );
					}
					else
						done_count++;

					if ( m_scrape_wheels && ( !my_art.wheel.empty() ) && (!has_artwork( rom, "wheel" )) )
					{
						const char *WHEEL = "wheel/";
						std::string fname = base_path + WHEEL + rom.get_info( FeRomInfo::Romname );
						confirm_directory( base_path, WHEEL );
						q.add_file_task( hostn, base_req + my_art.wheel, fname );
					}
					else
						done_count++;

					if ( m_scrape_marquees && (!my_art.marquee.empty() ) && (!has_artwork( rom, "marquee" )) )
					{
						const char *MARQUEE = "marquee/";
						std::string fname = base_path + MARQUEE + rom.get_info( FeRomInfo::Romname );
						confirm_directory( base_path, MARQUEE );
						q.add_file_task( hostn, base_req + my_art.marquee, fname );
					}
					else
						done_count++;

					if ( m_scrape_snaps && (!my_art.snap.empty() ) && (!has_artwork( rom, "snap" )) )
					{
						const char *SNAP = "snap/";
						std::string fname = base_path + SNAP + rom.get_info( FeRomInfo::Romname );
						confirm_directory( base_path, SNAP );
						q.add_file_task( hostn, base_req + my_art.snap, fname );
					}
					else
						done_count++;

					if ( m_scrape_fanart && !my_art.fanart.empty() )
					{
						const char *FANART = "fanart/";
						std::string fname_base = base_path + FANART + rom.get_info( FeRomInfo::Romname ) + "/";
						confirm_directory( base_path, "" );
						confirm_directory( base_path + FANART, rom.get_info( FeRomInfo::Romname ) );
						bool done_first=false; // we only count the first fanart against our percentage completed...

						for ( std::vector<std::string>::iterator itr = my_art.fanart.begin();
								itr != my_art.fanart.end(); ++itr )
						{
							size_t start_pos = (*itr).find_last_of( "/\\" );
							size_t end_pos = (*itr).find_last_of( '.' );

							if (( start_pos != std::string::npos )
								&& ( !file_exists( fname_base + (*itr).substr( start_pos+1 ) ) ))
							{
								if (( end_pos != std::string::npos ) && ( end_pos > start_pos ))
								{
									q.add_file_task( hostn,
												base_req + (*itr),
												fname_base + (*itr).substr( start_pos+1, end_pos-start_pos-1 ),
												done_first );
									done_first=true;
								}
							}
						}
					}
					else
						done_count++;
				}
				else
					done_count+=NUM_ARTS;
			}

			if ( c.uiupdate )
			{
				int p = c.progress_past + done_count * c.progress_range / ( NUM_ARTS * worklist.size() );
				if ( c.uiupdate( c.uiupdatedata, p ) == false )
					return false;
			}
		}
		else if ( q.output_done() )
		{
			sf::Http::Response::Status status;
			q.do_next_task( status );
		}
		else
			sf::sleep( sf::milliseconds( 10 ) );
	}
#endif
	return true;
}
コード例 #27
0
ファイル: types.c プロジェクト: X4/CPlus
    return True;
  } else {
    return False;
  }
}

instance(Hello, New) = { sizeof(HelloData), Hello_New, Hello_Delete };
instance(Hello, Eq) = { Hello_Eq };

int main(int argc, char** argv) {
 
  Hello = new(Type, "Hello", 2, 
    (var[]){ &HelloNew, &HelloEq }, 
    (const char*[]){ "New", "Eq" } );
  
  printf("%s!\n", as_str(Hello));

  var hello_obj1 = new(Hello, 1);
  var hello_obj2 = new(Hello, 2);

  printf("Equal? %d\n", (int)eq(hello_obj1, hello_obj2) );
  
  delete(hello_obj1);
  delete(hello_obj2);
  
  delete(Hello);
  
  return 0;
}