Ejemplo n.º 1
0
void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions, const oschar_t* rootpath)
{
	u32 siblingoffset = 0;
	oschar_t* currentpath = NULL;
	romfs_fileentry* entry = &ctx->fileentry;


	if (!romfs_fileblock_readentry(ctx, fileoffset, entry))
		return;


//	fprintf(stdout, "%08X %08X %016llX %016llX %08X ", 
//		getle32(entry->parentdiroffset), getle32(entry->siblingoffset), ctx->datablockoffset+getle64(entry->dataoffset),
//			getle64(entry->datasize), getle32(entry->unknown));
//	fwprintf(stdout, L"%ls\n", entry->name);

	if (rootpath && os_strlen(rootpath))
	{
		currentpath = os_AppendUTF16StrToPath(rootpath, (const utf16char_t*)entry->name);
		if (currentpath)
		{
			fputs("Saving ", stdout);
			os_fputs(currentpath, stdout);
			fputs("...\n", stdout);
			romfs_extract_datafile(ctx, getle64(entry->dataoffset), getle64(entry->datasize), currentpath);
		}
		else
		{
			fputs("Error creating file in root ", stderr);
			os_fputs(rootpath, stderr);
			fputs("\n", stderr);
			return;
		}
	}
	else
	{
		currentpath = os_CopyConvertUTF16Str((const utf16char_t*)entry->name);
		if (settings_get_list_romfs_files(ctx->usersettings))
		{
			u32 i;

			for(i=0; i<depth; i++)
				printf(" ");
			os_fputs(currentpath, stdout);
			fputs("\n", stdout);
		}
		free(currentpath);
		currentpath = NULL;
	}

	siblingoffset = getle32(entry->siblingoffset);

	if (siblingoffset != (~0))
		romfs_visit_file(ctx, siblingoffset, depth, actions, rootpath);

	free(currentpath);
}
Ejemplo n.º 2
0
void HTMLOutput( void )
{
#define HTMLREADBUFSIZE 512
	static char buf[HTMLREADBUFSIZE];
	FILE *tpl;
	char *buftemp;
	char *bufptr;
	htmlfunc* htmlfuncptr;

	tpl = os_fopen( html_template, "rt" );
	if( !tpl ) {
		nlog( LOG_WARNING, "Failed to open StatServ HTML template %s.", html_template );
		irc_chanalert( statbot, "Failed to open StatServ HTML template %s.", html_template );
		return;
	}
	opf = os_fopen( StatServ.htmlpath, "wt" );
	if( !opf ) {
		nlog( LOG_WARNING, "Failed to open HTML output file %s. Check file permissions.", StatServ.htmlpath );
		irc_chanalert( statbot, "Failed to open HTML output file %s. Check file permissions.", StatServ.htmlpath );
		return;
	}
	while( os_fgets( buf, HTMLREADBUFSIZE, tpl ) != NULL )
	{
		bufptr = buf;
		htmlfuncptr = htmlfuncs;
		while( htmlfuncptr->directive != NULL )
		{
			buftemp = strstr( bufptr, htmlfuncptr->directive );
			if( buftemp ) {
				os_fwrite( bufptr, ( int )buftemp -( int )bufptr, 1, opf );
				htmlfuncptr->handler();
				bufptr = buftemp + strlen( htmlfuncptr->directive );
			}		
			htmlfuncptr++;
		}
		os_fputs( bufptr, opf );
	}
	os_fclose( tpl );
	os_fclose( opf );
    /* update the umode so others can read it and owner can overwrite it */
    os_chmod( StatServ.htmlpath, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
}
Ejemplo n.º 3
0
void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions, const oschar_t* rootpath)
{
	u32 siblingoffset;
	u32 childoffset;
	u32 fileoffset;
	oschar_t* currentpath;
	romfs_direntry* entry = &ctx->direntry;


	if (!romfs_dirblock_readentry(ctx, diroffset, entry))
		return;


//	fprintf(stdout, "%08X %08X %08X %08X %08X ", 
//			getle32(entry->parentoffset), getle32(entry->siblingoffset), getle32(entry->childoffset), 
//			getle32(entry->fileoffset), getle32(entry->weirdoffset));
//	fwprintf(stdout, L"%ls\n", entry->name);


	if (rootpath && os_strlen(rootpath))
	{
		if (utf16_strlen((const utf16char_t*)entry->name) > 0)
			currentpath = os_AppendUTF16StrToPath(rootpath, (const utf16char_t*)entry->name);
		else // root dir, use the provided extract path instead of the empty root name.
			currentpath = os_CopyStr(rootpath);

		if (currentpath)
		{
			os_makedir(currentpath);
		}
		else
		{
			fputs("Error creating directory in root ", stderr);
			os_fputs(rootpath, stderr);
			fputs("\n", stderr);
			return;
		}
	}
	else
	{
		currentpath = os_CopyConvertUTF16Str((const utf16char_t*)entry->name);
		if (settings_get_list_romfs_files(ctx->usersettings))
		{
			u32 i;

			for(i=0; i<depth; i++)
				printf(" ");
			os_fputs(currentpath, stdout);
			fputs("\n", stdout);
		}
		free(currentpath);
		currentpath = NULL;
	}
	

	siblingoffset = getle32(entry->siblingoffset);
	childoffset = getle32(entry->childoffset);
	fileoffset = getle32(entry->fileoffset);

	if (fileoffset != (~0))
		romfs_visit_file(ctx, fileoffset, depth+1, actions, currentpath);

	if (childoffset != (~0))
		romfs_visit_dir(ctx, childoffset, depth+1, actions, currentpath);

	if (siblingoffset != (~0))
		romfs_visit_dir(ctx, siblingoffset, depth, actions, rootpath);

	free(currentpath);
}
Ejemplo n.º 4
0
static void html_version( void )
{
	os_fputs( me.version, opf );
}