示例#1
0
文件: smsid.cpp 项目: mnstrmnch/meka
int main(int argc, char* argv[])
{
	const char* filename = NULL;
	const char* opt_meka_nam = "meka.nam";
	bool opt_copy_to_clipboard = false;

	for (int n = 1; n < argc; n++)
	{
		const char* arg = argv[n];
		if (arg[0] == '-' || arg[0] == '/')
		{
			if (strcmp(arg+1, "c") == 0)
			{
				opt_copy_to_clipboard = true;
			}
			else if (strcmp(arg+1, "db") == 0)
			{
				n++;
				if (n >= argc)
				{
					printf("Error: missing filename as argument to option '%s'\n", arg);
					return 1;
				}
				opt_meka_nam = argv[n];
			}
			else
			{
				printf("Error: unknown argument '%s'\n", arg);
				return 1;
			}
		}
		else
		{
			filename = arg;
		}
	}

	if (filename == NULL)
	{
		printf("smsid 1.0\n");
		printf("Syntax: smsid [/db <file>] [/c] <rom>\n");
		printf(" /db    path to meka.nam [meka.nam]\n");
		printf(" /c     copy text to OS clipboard [false]\n");
		return 0;
	}

	FILE* f = fopen(filename, "rb");
	if (!f)
	{
		printf("Error: unable to input file '%s', aborting.\n", filename);
		return 1;
	}

	fseek(f, 0, SEEK_END);
	const int rom_size = ftell(f);
	fseek(f, 0, SEEK_SET);

	unsigned char* rom_data = new unsigned char[rom_size];
	if (fread(rom_data, 1, rom_size, f) != rom_size)
	{
		printf("Error: unable to read file data, aborting.\n");
		return 1;
	}

	const u32 crc = crc32(0, rom_data, rom_size);
	//const u32 crc = 0xe5ff50d8;
	//const u32 crc = 0xaed9aac4;
	fclose(f);
	delete[] rom_data;

	if (!DB_Init(opt_meka_nam, false))
	{
		printf("Error: failed to open DB file '%s'\n", opt_meka_nam);
		return 1;
	}

	if (opt_copy_to_clipboard)
		printf("(copying following output to OS clipboard)\n");

	std::string s;

	t_db_entry* entry = DB_Entry_Find(crc, NULL);
	if (entry)
	{
		char buf[256];
		sprintf(buf, "%s %08x %08X%08X   %s", 
			DB_FindDriverNameById(entry->system),
			entry->crc_crc32, 
			entry->crc_mekacrc.v[0], entry->crc_mekacrc.v[1],
			entry->names[0]);
		s += buf;

		int countries = 0;
		for (int i = 0; i != DB_COUNTRY_COUNT_; i++)
		{
			if (entry->country & (1 << i))
			{
				if (countries == 0)
					s += " (";
				else
					s += ",";
				s += DB_FindCountryNameByFlag(1 << i);
				countries++;
			}
		}
		if (countries > 0)
			s += ")";
		s += "\n";
	}
	else
	{
		s = "Unknown.\n";
	}
	printf("%s", s.c_str());

	if (opt_copy_to_clipboard)
	{
		System_SetClipboardText(s.c_str());
	}

	return 0;
}
示例#2
0
文件: vlfn.c 项目: dafyddcrosby/meka
//-----------------------------------------------------------------------------
// VLFN_DataBase_Load (void)
// Load VLFN database from MEKA.FDB file.
//-----------------------------------------------------------------------------
void            VLFN_DataBase_Load (void)
{
    t_tfile *   tf;
    t_list *    lines;
    char *      line;
    int         line_cnt;

    ConsolePrint (Msg_Get (MSG_FDB_Loading));

    // Open and read file
    tf = tfile_read (VLFN_DataBase.filename);
    if (tf == NULL)
    {
        ConsolePrintf ("%s\n", meka_strerror());
        return;
    }

    // Ok
    ConsolePrint ("\n");

    // Parse each line
    line_cnt = 0;
    for (lines = tf->data_lines; lines; lines = lines->next)
    {
        char *  w;

        line_cnt += 1;
        line = lines->elem;

        w = parse_getword(NULL, 0, &line, "/", ';', 0);
        if (w == NULL)
            continue;
        else
        {
            char            buf[1024];
            char *          file_name;
            u32             crc_crc32;
            t_meka_crc      crc_mekacrc;

            // Save allocated filename
            file_name = w;

            // Get CRCs
            crc_crc32 = 0;
            crc_mekacrc.v[0] = crc_mekacrc.v[1] = 0;
            while ((w = parse_getword(buf, 1024, &line, "/", ';', 0)) != NULL)
            {
                if (!strncmp(w, "MEKACRC:", 8))
                {
                    if (sscanf(w + 8, "%08X%08X", &crc_mekacrc.v[0], &crc_mekacrc.v[1]) != 2)
                        continue; // Syntax error
                }
                else if (!strncmp(w, "CRC32:", 6))
                {
                    if (sscanf(w + 6, "%08x", &crc_crc32) != 1)
                        continue; // Syntax error
                }
            }

            // Requires at least MekaCRC
            // (to be changed by CRC32 when MekaCRC is dropped)
            if (crc_mekacrc.v[0] == 0 && crc_mekacrc.v[1] == 0)
                continue;

            {
                // Find DB entry
                t_db_entry *db_entry = DB_Entry_Find (crc_crc32, &crc_mekacrc);
                if (db_entry)
                {
                    // Create VLFN entry
                    t_vlfn_entry *  entry;
                    entry = VLFN_Entry_New (file_name, db_entry);
                    list_add (&VLFN_DataBase.entries, entry);
                }
            }
        }
    }

    // Free file data
    tfile_free (tf);
}