Ejemplo n.º 1
0
//-------------------------------------------------------------------
int gui_read_init(const char* file) {
    static struct STD_stat   st;
    read_file = safe_open(file, O_RDONLY, 0777);
    if (strcmp(file, conf.reader_file)!=0) {
        conf.reader_pos = 0;
        strcpy(conf.reader_file, file);
    }
    read_on_screen = 0;
    read_file_size = (read_file>=0 && safe_stat((char*)file, &st)==0)?st.st_size:0;
    if (read_file_size<=conf.reader_pos) {
        conf.reader_pos = 0;
    }
    pause = 0;
    read_to_draw = 1;
    x=camera_screen.ts_button_border+6;
    y=FONT_HEIGHT;
    w=camera_screen.width-camera_screen.ts_button_border*2-6-6-8;
    h=camera_screen.height-y;
    last_time = get_tick_count();

    reader_is_active=1;
    old_mode = gui_set_mode(&GUI_MODE_READ);

    draw_filled_rect(0, 0, camera_screen.width-1, y-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK));
    draw_filled_rect(0, y, camera_screen.width-1, camera_screen.height-1, MAKE_COLOR(BG_COLOR(conf.reader_color), BG_COLOR(conf.reader_color)));

    gui_read_draw_scroll_indicator();
    gui_read_draw_batt();

    return (read_file >= 0);
}
Ejemplo n.º 2
0
// No need to import such simple
long mkdir_if_not_exist(const char *dirname) 
{
    // Check if directory exists and create it if it does not.
    struct STD_stat st;
    if (safe_stat(dirname,&st) != 0) return mkdir(dirname);
    return 0;   // Success
}
Ejemplo n.º 3
0
static void
safe_lsdir(int round) {
    DIR *dirp = opendir(".");
    assert(dirp != NULL);
    struct dirent *direntp;
    while ((direntp = readdir(dirp)) != NULL) {
        printf("%d: ", round);
        safe_stat(direntp->name);
        printf("%s\n", direntp->name);
    }
    closedir(dirp);
}
Ejemplo n.º 4
0
//---------------------------------------------------------
CMenu* scan_directory(const char* dir) {

    STD_DIR           *d;
    struct STD_dirent *de;
    static struct STD_stat   st;

	char curdir[100];
	strcpy( curdir, dir);

    int iter, count, len;
	CMenu* mmenu = 0;
	CMenuItem* mitems = 0;
	CMenuItem* curitem;

	// Two iterations:
	//		first for draft count possible elements. then allocate
	//		second exact check and filling each elements
	for ( iter=1; iter<=2; iter++ )
	{
	    d = safe_opendir(curdir);
    	if (!d) return 0;

		count = 0;
	    for( de = safe_readdir(d); de; de = safe_readdir(d) ) {

            if (de->d_name[0] == 0xE5 /* deleted entry */ )
				continue;

            if (de->d_name[0] == '.' && de->d_name[1]==0) 
				continue;

            if (de->d_name[0] == '.' && de->d_name[1]=='.' && de->d_name[2] == 0 )
				continue;

           	sprintf(buf, "%s/%s", curdir, de->d_name);
	        if (safe_stat(buf, &st)!=0) 
				continue;
			
			if ( st.st_attrib != DOS_ATTR_DIRECTORY &&
				 st.st_size <= (sizeof(struct flat_hdr)+sizeof(struct ModuleInfo)) ) 
				continue;

			if ( iter==2 ) {

				curitem=mitems+count;

				if ( st.st_attrib == DOS_ATTR_DIRECTORY ) {
					void* submenu = 0;
					submenu = scan_directory( buf );

					if ( submenu==0 )
						continue;

					curitem->text = (int)malloc( strlen(de->d_name)+1 );
					if ( curitem->text==0 ) continue;
					curitem->type = MENUITEM_SUBMENU;
					curitem->value = submenu;
					strcpy( (char*)curitem->text, de->d_name);
				} else {

					char *ext = strchr(de->d_name,'.');
        		    if ( !ext || (ext[1]|0x20)!='f' || (ext[2]|0x20)!='l' || (ext[3]|0x20)!='t' )
						continue;

					if ( !load_module_info(buf) )
						continue;

					if (minfo.flags & MODULEINFO_FLAG_SYSTEM )
						continue;

					len = ( minfo.moduleName < 0 ) ? 0 : strlen(modulename);

					curitem->arg = (int)malloc( len+1 + strlen(buf)-strlen_basepath );
					if ( curitem->arg==0 ) continue;

					curitem->type = MENUITEM_PROC;
					curitem->value = (void*)gui_menu_run_fltmodule;
					strcpy( (void*)curitem->arg, buf+strlen_basepath+1 );

					if ( minfo.moduleName < 0 )
						curitem->text= -minfo.moduleName;
					else {
						curitem->text = curitem->arg + strlen((char*)curitem->arg)+1;
						strcpy( (char*)curitem->text, modulename );
					}
				}

				curitem->symbol=0x5c;
			}

			count++;
		}

		safe_closedir(d);

		// Iteration#1 final: allocate menuitems
		if (iter==1) {

			if ( count==0 )	{ safe_closedir(d); return 0;}

			len = sizeof(CMenu) + sizeof(CMenuItem)*(count+2);
			mmenu=malloc( len );
			if ( mmenu==0 ) return 0;
			mitems = (CMenuItem*) ((char*)mmenu + sizeof(CMenu) );
			memset( mmenu, 0, len );
		}
	}

	// Iteration#2 final

	if ( count == 0 ) {
		free( mmenu );
		return 0;
	}

	// .. fill Cmenu
	mmenu->symbol = 0x29;
	mmenu->on_change = 0;
	mmenu->menu = mitems;
	if ( strlen(curdir)==strlen_basepath )
		strcpy( buf, "Modules");
	else
		sprintf( buf, "Modules %s", curdir+strlen_basepath+1);

	mmenu->title = (int)malloc( strlen(buf)+1 );
	if ( mmenu->title==0 )
	{
		free( mmenu );
		return 0;
	}

	strcpy( (void*)mmenu->title, buf );


	// sort item
    qsort(mitems, count, sizeof(CMenuItem), fselect_sort_nothumb);


	// Add "Back" item
	curitem=mitems+count;
	curitem->text = LANG_MENU_BACK;
	curitem->symbol=0x51;
    curitem->type = MENUITEM_UP;

	return mmenu;
}