Example #1
0
//-------------------------------------------------
//  load a game name and offset into an
//  indexed array
//-------------------------------------------------
int datfile_manager::index_datafile(fileptr &&fp, dataindex &index, int &swcount, std::string &rev, std::string const &tag, char sep)
{
	std::string readbuf;
	auto const tag_size = tag.size();
	auto const t_info = TAG_INFO.size();
	auto const t_bio = TAG_BIO.size();
	char rbuf[64 * 1024];
	while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);

		if (!tag.empty())
		{
			if (rev.empty() && readbuf.compare(0, tag_size, tag) == 0)
			{
				if (sep != 's')
					rev = readbuf.substr(tag_size + 1, readbuf.find(sep, tag_size + 1) - tag_size);
				else
					rev = readbuf.substr(tag_size + 1);
			}
		}

		if (readbuf.compare(0, t_info, TAG_INFO) == 0)
		{
			// search for game info
			auto rd = readbuf.substr(t_info + 1);
			std::vector<std::string> gamelist = tokenize(rd, ',');
			for (auto & e : gamelist)
			{
				auto game_index = driver_list::find(e.c_str());
				if (game_index != -1)
					index.emplace(&driver_list::driver(game_index), std::ftell(fp.get()));
			}
		}
		else if (!readbuf.empty() && readbuf[0] == DATAFILE_TAG[0])
		{
			// search for software info
			std::fgets(rbuf, 64 * 1024, fp.get());
			std::string readbuf_2(chartrimcarriage(rbuf));
			if (readbuf_2.compare(0, t_bio, TAG_BIO) == 0)
			{
				auto eq_sign = readbuf.find('=');
				std::string s_list(readbuf.substr(1, eq_sign - 1));
				std::string s_roms(readbuf.substr(eq_sign + 1));
				std::vector<std::string> token_list = tokenize(s_list, ',');
				std::vector<std::string> token_roms = tokenize(s_roms, ',');
				for (auto & li : token_list)
					for (auto & ro : token_roms)
						m_swindex[li].emplace(ro, std::ftell(fp.get()));
				swcount++;
			}
		}
	}
	return index.size();
}
Example #2
0
//-------------------------------------------------
//  load a game name and offset into an
//  indexed array (mameinfo)
//-------------------------------------------------
int datfile_manager::index_mame_mess_info(fileptr &&fp, dataindex &index, drvindex &index_drv, int &drvcount)
{
	size_t foundtag;
	auto t_mame = TAG_MAMEINFO_R.size();
	auto t_mess = TAG_MESSINFO_R.size();
	auto t_ginit = TAG_GAMEINIT_R.size();
	auto t_info = TAG_INFO.size();

	char rbuf[64 * 1024];
	std::string readbuf, xid, name;
	while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);
		if (m_mame_rev.empty() && readbuf.compare(0, t_mame, TAG_MAMEINFO_R) == 0)
		{
			auto found = readbuf.find(" ", t_mame + 1);
			m_mame_rev = readbuf.substr(t_mame + 1, found - t_mame);
		}
		else if (m_mess_rev.empty() && (foundtag = readbuf.find(TAG_MESSINFO_R)) != std::string::npos)
		{
			auto found = readbuf.find(" ", foundtag + t_mess + 1);
			m_mess_rev = readbuf.substr(foundtag + t_mess + 1, found - t_mess - foundtag);
		}
		else if (m_ginit_rev.empty() && readbuf.compare(0, t_ginit, TAG_GAMEINIT_R) == 0)
		{
			auto found = readbuf.find(" ", t_ginit + 1);
			m_ginit_rev = readbuf.substr(t_ginit + 1, found - t_ginit);
		}
		else if (readbuf.compare(0, t_info, TAG_INFO) == 0)
		{
			// TAG_INFO
			std::fgets(rbuf, 64 * 1024, fp.get());
			xid = chartrimcarriage(rbuf);
			name = readbuf.substr(t_info + 1);
			if (xid == TAG_MAME)
			{
				// validate driver
				auto game_index = driver_list::find(name.c_str());
				if (game_index != -1)
					index.emplace(&driver_list::driver(game_index), std::ftell(fp.get()));
			}
			else if (xid == TAG_DRIVER)
			{
				index_drv.emplace(name, std::ftell(fp.get()));
				drvcount++;
			}
		}
	}
	return index.size();
}
Example #3
0
//-------------------------------------------------
//  load command text into the buffer
//-------------------------------------------------
void datfile_manager::load_command_info(std::string &buffer, std::string const &sel)
{
	fileptr const datfile = parseopen("command.dat");
	if (datfile)
	{
		// open and seek to correct point in datafile
		auto const offset = m_menuidx.at(sel);
		std::fseek(datfile.get(), offset, SEEK_SET);
		char rbuf[64 * 1024];
		std::string readbuf;
		while (std::fgets(rbuf, 64 * 1024, datfile.get()) != nullptr)
		{
			readbuf = chartrimcarriage(rbuf);

			// skip separator lines
			if (readbuf == TAG_COMMAND_SEPARATOR)
				continue;

			// end entry when a tag is encountered
			if (readbuf == TAG_END)
				break;

			// add this string to the buffer
			buffer.append(readbuf).append("\n");;
		}
	}
}
Example #4
0
//-------------------------------------------------
//  load software info
//-------------------------------------------------
void datfile_manager::load_software_info(std::string const &softlist, std::string &buffer, std::string const &softname, std::string const &parentname)
{
	if (m_swindex.empty())
		return;

	// Load history text
	fileptr const datfile = parseopen("history.dat");
	if (datfile)
	{
		// Find software in software list index
		long const *const s_offset = find_software(softlist, softname, parentname);
		if (!s_offset)
			return;

		char rbuf[64 * 1024];
		std::fseek(datfile.get(), *s_offset, SEEK_SET);
		std::string readbuf;
		while (std::fgets(rbuf, 64 * 1024, datfile.get()) != nullptr)
		{
			readbuf = chartrimcarriage(rbuf);

			// end entry when a end tag is encountered
			if (readbuf == TAG_END)
				break;

			// add this string to the buffer
			buffer.append(readbuf).append("\n");
		}
	}
}
Example #5
0
//-------------------------------------------------
//  load a driver name and offset into an
//  indexed array
//-------------------------------------------------
void datfile_manager::load_driver_text(FILE *fp, game_driver const *drv, std::string &buffer, drvindex const &idx, std::string const &tag)
{
	std::string s(core_filename_extract_base(drv->source_file));
	auto index = idx.find(s);

	// if driver not found, return
	if (index == idx.end())
		return;

	buffer.append("\n--- DRIVER INFO ---\n").append("Driver: ").append(s).append("\n\n");
	auto s_offset = index->second;
	std::fseek(fp, s_offset, SEEK_SET);
	char rbuf[64 * 1024];
	std::string readbuf;
	while (std::fgets(rbuf, 64 * 1024, fp) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);

		// end entry when a end tag is encountered
		if (readbuf == TAG_END)
			break;

		// continue if a specific tag is encountered
		if (readbuf == tag)
			continue;

		// add this string to the buffer
		buffer.append(readbuf).append("\n");
	}
}
Example #6
0
//-------------------------------------------------
//  load software info
//-------------------------------------------------
void datfile_manager::load_software_info(std::string &softlist, std::string &buffer, std::string &softname, std::string &parentname)
{
	// Load history text
	if (!m_swindex.empty() && parseopen("history.dat"))
	{
		// Find software in software list index
		if (m_swindex.find(softlist) == m_swindex.end())
			return;

		drvindex::iterator itemsiter;
		itemsiter = m_swindex[softlist].find(softname);
		if (itemsiter == m_swindex[softlist].end() && !parentname.empty())
			itemsiter = m_swindex[softlist].find(parentname);

		if (itemsiter == m_swindex[softlist].end())
			return;

		long s_offset = (*itemsiter).second;
		char rbuf[64 * 1024];
		fseek(fp, s_offset, SEEK_SET);
		std::string readbuf;
		while (fgets(rbuf, 64 * 1024, fp) != nullptr)
		{
			readbuf = chartrimcarriage(rbuf);

			// end entry when a end tag is encountered
			if (readbuf == TAG_END)
				break;

			// add this string to the buffer
			buffer.append(readbuf).append("\n");
		}
		parseclose();
	}
}
Example #7
0
//-------------------------------------------------
//  create the menu index
//-------------------------------------------------
void datfile_manager::index_menuidx(const game_driver *drv, dataindex &idx, drvindex &index)
{
	dataindex::iterator itemsiter = idx.find(drv);
	if (itemsiter == idx.end())
	{
		int cloneof = driver_list::non_bios_clone(*drv);
		if (cloneof == -1)
			return;
		else
		{
			const game_driver *c_drv = &driver_list::driver(cloneof);
			itemsiter = idx.find(c_drv);
			if (itemsiter == idx.end())
				return;
		}
	}

	// seek to correct point in datafile
	long s_offset = (*itemsiter).second;
	fseek(fp, s_offset, SEEK_SET);
	size_t tinfo = TAG_INFO.size();
	char rbuf[64 * 1024];
	std::string readbuf;
	while (fgets(rbuf, 64 * 1024, fp) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);

		if (!core_strnicmp(TAG_INFO.c_str(), readbuf.c_str(), tinfo))
			break;

		// TAG_COMMAND identifies the driver
		if (readbuf == TAG_COMMAND)
		{
			fgets(rbuf, 64 * 1024, fp);
			chartrimcarriage(rbuf);
			index.emplace(rbuf, ftell(fp));
		}
	}
}
Example #8
0
//-------------------------------------------------
//  create the menu index
//-------------------------------------------------
void datfile_manager::index_menuidx(fileptr &&fp, const game_driver *drv, dataindex const &idx, drvindex &index)
{
	auto itemsiter = idx.find(drv);
	if (itemsiter == idx.end())
	{
		auto const cloneof = driver_list::non_bios_clone(*drv);
		if (cloneof == -1)
			return;

		auto const c_drv = &driver_list::driver(cloneof);
		if ((itemsiter = idx.find(c_drv)) == idx.end())
			return;
	}

	// seek to correct point in datafile
	auto const s_offset = itemsiter->second;
	std::fseek(fp.get(), s_offset, SEEK_SET);
	auto const tinfo = TAG_INFO.size();
	char rbuf[64 * 1024];
	std::string readbuf;
	while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);

		if (!core_strnicmp(TAG_INFO.c_str(), readbuf.c_str(), tinfo))
			break;

		// TAG_COMMAND identifies the driver
		if (readbuf == TAG_COMMAND)
		{
			std::fgets(rbuf, 64 * 1024, fp.get());
			chartrimcarriage(rbuf);
			index.emplace(rbuf, std::ftell(fp.get()));
		}
	}
}
Example #9
0
void inifile_manager::load_ini_category(std::vector<int> &temp_filter)
{
	if (ini_index.empty())
		return;

	bool search_clones = false;
	std::string filename(ini_index[c_file].first);
	long offset = ini_index[c_file].second[c_cat].second;

	if (!core_stricmp(filename.c_str(), "category.ini") || !core_stricmp(filename.c_str(), "alltime.ini"))
		search_clones = true;

	if (parseopen(filename.c_str()))
	{
		fseek(fp, offset, SEEK_SET);
		int num_game = driver_list::total();
		char rbuf[MAX_CHAR_INFO];
		std::string readbuf;
		while (fgets(rbuf, MAX_CHAR_INFO, fp) != nullptr)
		{
			readbuf = chartrimcarriage(rbuf);

			if (readbuf.empty() || readbuf[0] == '[')
				break;

			int dfind = driver_list::find(readbuf.c_str());
			if (dfind != -1 && search_clones)
			{
				temp_filter.push_back(dfind);
				int clone_of = driver_list::non_bios_clone(dfind);
				if (clone_of == -1)
				{
					for (int x = 0; x < num_game; x++)
						if (readbuf == driver_list::driver(x).parent && readbuf != driver_list::driver(x).name)
							temp_filter.push_back(x);
				}
			}
			else if (dfind != -1)
				temp_filter.push_back(dfind);
		}
		parseclose();
	}
}
Example #10
0
//-------------------------------------------------
//  load a game text into the buffer
//-------------------------------------------------
void datfile_manager::load_data_text(FILE *fp, game_driver const *drv, std::string &buffer, dataindex const &idx, std::string const &tag)
{
	auto itemsiter = idx.find(drv);
	if (itemsiter == idx.end())
	{
		auto cloneof = driver_list::non_bios_clone(*drv);
		if (cloneof == -1)
			return;
		else
		{
			auto c_drv = &driver_list::driver(cloneof);
			itemsiter = idx.find(c_drv);
			if (itemsiter == idx.end())
				return;
		}
	}

	auto s_offset = itemsiter->second;
	std::fseek(fp, s_offset, SEEK_SET);
	char rbuf[64 * 1024];
	std::string readbuf;
	while (std::fgets(rbuf, 64 * 1024, fp) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);

		// end entry when a end tag is encountered
		if (readbuf == TAG_END)
			break;

		// continue if a specific tag is encountered
		if (readbuf == tag)
			continue;

		// add this string to the buffer
		buffer.append(readbuf).append("\n");
	}
}
Example #11
0
void favorite_manager::parse_favorite()
{
	emu_file file(mame_machine_manager::instance()->ui().options().ui_path(), OPEN_FLAG_READ);
	if (file.open(favorite_filename) == osd_file::error::NONE)
	{
		char readbuf[1024];
		file.gets(readbuf, 1024);

		while (readbuf[0] == '[')
			file.gets(readbuf, 1024);

		while (file.gets(readbuf, 1024))
		{
			ui_software_info tmpmatches;
			tmpmatches.shortname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.longname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.parentname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.year = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.publisher = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.supported = atoi(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.part = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			chartrimcarriage(readbuf);
			int dx = driver_list::find(readbuf);
			if (dx == -1) continue;
			tmpmatches.driver = &driver_list::driver(dx);
			file.gets(readbuf, 1024);
			tmpmatches.listname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.interface = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.instance = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.startempty = atoi(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.parentlongname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.usage = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.devicetype = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.available = atoi(readbuf);
			m_list.push_back(tmpmatches);
		}
		file.close();
	}
}
Example #12
0
//-------------------------------------------------
//  load a game name and offset into an
//  indexed array
//-------------------------------------------------
int datfile_manager::index_datafile(dataindex &index, int &swcount)
{
	std::string  readbuf, name;
	size_t t_hist = TAG_HISTORY_R.size();
	size_t t_story = TAG_STORY_R.size();
	size_t t_sysinfo = TAG_SYSINFO_R.size();
	size_t t_info = TAG_INFO.size();
	size_t t_bio = TAG_BIO.size();
	char rbuf[64 * 1024];
	while (fgets(rbuf, 64 * 1024, fp) != nullptr)
	{
		readbuf = chartrimcarriage(rbuf);

		if (m_history_rev.empty() && readbuf.compare(0, t_hist, TAG_HISTORY_R) == 0)
		{
			size_t found = readbuf.find(" ", t_hist + 1);
			m_history_rev = readbuf.substr(t_hist + 1, found - t_hist);
		}
		else if (m_sysinfo_rev.empty() && readbuf.compare(0, t_sysinfo, TAG_SYSINFO_R) == 0)
		{
			size_t found = readbuf.find(".", t_sysinfo + 1);
			m_sysinfo_rev = readbuf.substr(t_sysinfo + 1, found - t_sysinfo);
		}
		else if (m_story_rev.empty() && readbuf.compare(0, t_story, TAG_STORY_R) == 0)
			m_story_rev = readbuf.substr(t_story + 1);

		// TAG_INFO identifies the driver
		else if (readbuf.compare(0, t_info, TAG_INFO) == 0)
		{
			int curpoint = t_info + 1;
			int ends = readbuf.size();
			while (curpoint < ends)
			{
				// search for comma
				size_t found = readbuf.find(",", curpoint);

				// found it
				if (found != std::string::npos)
				{
					// copy data and validate driver
					name = readbuf.substr(curpoint, found - curpoint);

					// validate driver
					int game_index = driver_list::find(name.c_str());
					if (game_index != -1)
						index.emplace(&driver_list::driver(game_index), ftell(fp));

					// update current point
					curpoint = ++found;
				}
				// if comma not found, copy data while until reach the end of string
				else if (curpoint < ends)
				{
					name = readbuf.substr(curpoint);
					int game_index = driver_list::find(name.c_str());
					if (game_index != -1)
						index.emplace(&driver_list::driver(game_index), ftell(fp));

					// update current point
					curpoint = ends;
				}
			}
		}
		// search for software info
		else if (!readbuf.empty() && readbuf[0] == DATAFILE_TAG[0])
		{
			fgets(rbuf, 64 * 1024, fp);
			std::string readbuf_2(chartrimcarriage(rbuf));

			// TAG_BIO identifies software list
			if (readbuf_2.compare(0, t_bio, TAG_BIO) == 0)
			{
				size_t eq_sign = readbuf.find("=");
				std::string s_list(readbuf.substr(1, eq_sign - 1));
				std::string s_roms(readbuf.substr(eq_sign + 1));
				int ends = s_list.size();
				int curpoint = 0;

				while (curpoint < ends)
				{
					size_t found = s_list.find(",", curpoint);

					// found it
					if (found != std::string::npos)
					{
						name = s_list.substr(curpoint, found - curpoint);
						curpoint = ++found;
					}
					else
					{
						name = s_list;
						curpoint = ends;
					}

					// search for a software list in the index, if not found then allocates
					std::string lname(name);
					int cpoint = 0;
					int cends = s_roms.size();

					while (cpoint < cends)
					{
						// search for comma
						size_t found = s_roms.find(",", cpoint);

						// found it
						if (found != std::string::npos)
						{
							// copy data
							name = s_roms.substr(cpoint, found - cpoint);

							// add a SoftwareItem
							m_swindex[lname].emplace(name, ftell(fp));

							// update current point
							cpoint = ++found;
							swcount++;
						}
						else
						{
							// if reach the end, bail out
							if (s_roms[cpoint] == '\r' || s_roms[cpoint] == '\n')
								break;

							// copy data
							name = s_roms.substr(cpoint);

							// add a SoftwareItem
							m_swindex[lname].emplace(name, ftell(fp));

							// update current point
							cpoint = cends;
							swcount++;
						}
					}
				}
			}
		}
	}
	return index.size();
}
Example #13
0
favorite_manager::favorite_manager(ui_options &options)
	: m_options(options)
	, m_favorites()
	, m_sorted()
	, m_need_sort(true)
{
	emu_file file(m_options.ui_path(), OPEN_FLAG_READ);
	if (file.open(FAVORITE_FILENAME) == osd_file::error::NONE)
	{
		char readbuf[1024];
		file.gets(readbuf, 1024);

		while (readbuf[0] == '[')
			file.gets(readbuf, 1024);

		while (file.gets(readbuf, 1024))
		{
			ui_software_info tmpmatches;
			tmpmatches.shortname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.longname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.parentname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.year = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.publisher = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.supported = atoi(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.part = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			chartrimcarriage(readbuf);
			auto dx = driver_list::find(readbuf);
			if (0 > dx)
				continue;
			tmpmatches.driver = &driver_list::driver(dx);
			file.gets(readbuf, 1024);
			tmpmatches.listname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.interface = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.instance = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.startempty = atoi(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.parentlongname = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.usage = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.devicetype = chartrimcarriage(readbuf);
			file.gets(readbuf, 1024);
			tmpmatches.available = atoi(readbuf);
			m_favorites.emplace(std::move(tmpmatches));
		}
		file.close();
	}
}