Пример #1
0
void browse_main()
{
    /*
	    文件浏览器主函数
	*/

    char ncat[64], workdir[64] = "\\\\fls0";    //  当前目录
    f_name *a=get_file_list("\\\\fls0\\*.*");    //  存储文件列表的二维数组
	int pos=0,firstn=0;    //  列表光标位置、列表下移的行数
	unsigned int key;
	char subdir_fn[32];    //  供接收子目录文件名输入的缓冲区
	FONTCHARACTER fname[64];
	int handle = 0;
	
	DefineStatusAreaFlags(3, 0x01 | 0x02 | 0x100, 0, 0);
	
	beg:
	if (a) qsort(a, getn(a), sizeof(char *), cmp);
	
	font16 = open_font("\\\\fls0\\24PX.hzk");
	select_font(font16);
	
	draw_browser(workdir,firstn,pos,a);    //  绘制浏览器界面
	
	close_font(font16);
	
	//  显示当前工作目录于状态栏
	if (strcmp(workdir, "\\\\fls0") == 0)
		DefineStatusMessage("", 0, 0, 0);
	else
	{
		memset(ncat, 0, sizeof(ncat));
		GetDisplayDirName(workdir, ncat);
		DefineStatusMessage(ncat, 0, 0, 0);
	}
	
	while (1)
	{
	    GetKey(&key);
		switch (key)
		{
		    case KEY_CTRL_UP:    //  光标上移
			    if (a)
				{
				    aa(&pos,&firstn,getn(a));
					goto beg;
				}
				break;
				
			case KEY_CTRL_DOWN:    //  光标下移
			    if (a)
				{
				    bb(&pos,&firstn,getn(a));
					goto beg;
				}
				break;
			
			case KEY_CTRL_F6:    //  显示关于信息
			    Disp_About();
				goto beg;
				break;
			
			case KEY_CTRL_F1:    //  打开光标位置的文件
			case KEY_CTRL_EXE:
			    if (a)    //  如果文件列表不为空
			    {
			        if (strchr(a[pos+firstn].name,'['))    //  如果打开的是文件夹
				    {
				        memset(ncat,0,sizeof(ncat));
					    //strcat(ncat,"\\\\fls0\\");
						strcat(ncat, workdir); strcat(ncat, "\\");
				        strcat(ncat, ++a[pos+firstn].name);
					    memset(workdir, 0, sizeof(workdir));
					    strcpy(workdir, ncat);
					    strcat(ncat, "\\*.*");    //  解析出文件夹名称
					    a=get_file_list(ncat);    //  浏览该文件夹
						pos=0; firstn=0;    //  列表初始化
					    goto beg;
				    }
				    else    //  如果打开的是文本文件
				    {	
						memset(ncat,0,sizeof(ncat));
				        strcpy(ncat,workdir);
						strcat(ncat,"\\");
				        strcat(ncat,a[pos+firstn].name);    //  解析出文件名称
						
						iRead_main(ncat);    //  启动阅读器
						goto beg;
				    }
				}
				break;
				
			case KEY_CTRL_F2:	//  根据输入的文件名打开文件
				memset(subdir_fn, 0, sizeof(subdir_fn));
				if (Subdir_Open(subdir_fn))
				{
					memset(ncat, 0, sizeof(ncat));
				    strcpy(ncat, workdir);
					strcat(ncat, "\\");
				    strcat(ncat, subdir_fn);    //  连接上输入的文件名字
					strcat(ncat, ".txt");
						
					char_to_font(ncat, fname);
					handle = Bfile_OpenFile_OS(fname,0);
					if (handle <= 0)    //  如果文件未找到
					{
						Disp_FileNotFound();
						MsgBoxPop();
						goto beg; break;
					}
						
					MsgBoxPop();
					Bfile_CloseFile_OS(handle);
					
					//  重新绘制浏览器界面
					font16 = open_font("\\\\fls0\\24PX.hzk");
					select_font(font16);
	
					draw_browser(workdir, firstn, pos, a);
					close_font(font16);
					
					//  启动阅读器
					iRead_main(ncat);
				}
				
				goto beg; break;
			
			case KEY_CTRL_EXIT:    //  从文件夹返回根目录
			    if (strcmp(workdir,"\\\\fls0")!=0)    //  如果当前在文件夹内
			    {
			        memset(ncat,0,sizeof(ncat));
			        strncpy(ncat,workdir,strlen(workdir)-strlen(strrchr(workdir,'\\')));
				    memset(workdir,0,sizeof(workdir));
				    strcpy(workdir,ncat);
				    strcat(ncat,"\\*.*");    //  解析出上一级目录的名称
			        a=get_file_list(ncat);    //  浏览该文件夹
					pos=0;firstn=0;    //  初始化列表
				    goto beg;
				
				}
				break;
			
		}
	}
}
Пример #2
0
int get_gb_file(char *file_name) {

	struct directory_browser b;
	SDL_Event e;
	int active = 1;
	SDL_Surface *bg = 0;

	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
		return -1;

	if(!(front = SDL_SetVideoMode(640,480,0,0))) 
		return -1;

	stick = SDL_JoystickOpen(0);
	SDL_JoystickEventState(SDL_ENABLE);


	the_font = SDL_InitFont("Resources/arial.mxf");
	SDL_FillRect(front, 0, 0);
	SDL_PrintText(front, the_font, 0,0,SDL_MapRGB(front->format, 255, 0, 0), "Loading...");
	SDL_UpdateRect(front, 0,0,640,480);

	//bg = SDL_LoadBMP("background.bmp");


	fprintf(stderr, "starting to browse\n");
	b.head = ls2link("./",&b.length);
	b.x = 10;
	b.y = 10;
	b.w = 620;
	b.h = 420;
	b.cur_i = 0;
	b.max_col = 10;
    int file_selected = 0;
    int dmg = 0; // DMG mode activated

	while(active == 1) {
        
		char str[255];
		SDL_FillRect(front, 0,0);
		SDL_BlitSurface(bg, 0, front, 0);
		draw_browser(front, &b, the_font);
		sprintf(str, "Index: %d Total: %d", b.cur_i+1, b.length);
		SDL_PrintText(front, the_font, 420,10, SDL_MapRGB(front->format, 255, 255, 255), str);
		if(SDL_PollEvent(&e)) {
            dmg = (e.type == 1);
			switch(e.type) {
				case SDL_QUIT:
					active = 0;
					break;
				case SDL_JOYBUTTONDOWN:
					{
						switch(e.jbutton.button) {
						case 8: // move up
							if(b.cur_i > 0)
								b.cur_i--;
							break;
						case 6:// move down
							if(b.cur_i+1 < b.length)
								b.cur_i++;
							break;
						case 7:// move left if(b.cur_i+1-b.max_col > 0)
								b.cur_i -= b.max_col;
							break;
						case 9://move right
							if(b.cur_i+b.max_col < b.length)
								b.cur_i += b.max_col;
							break;
                        case 10:
                            active = 0;
                            break;
						case 0:
						case 1:
						case 2:
						case 3:
							{
								struct file_node *pnode = skip_nodes(b.head->next, b.cur_i);
								if(pnode != 0 && pnode->is_dir == 1) {
									char buf[1000];
									sprintf(buf,"./%s/", pnode->name);
									struct file_node *new_nodes = ls2link(buf, &b.length);
									free_nodes(b.head);
									b.cur_i = 0;
									b.head = new_nodes;
								}
								else if(pnode != 0 && pnode->is_dir == 0) { // its a file
                                    strncpy(file_name, pnode->name, 0xFF); 
                                    file_selected = 1;
                                    active = 0;
								}
							}

							break;
						}
					}
					break;
			}
		}

		SDL_UpdateRect(front, 0,0,640,480);
	}

	
	free_nodes(b.head);
	SDL_FreeSurface(bg);
	SDL_FreeFont(the_font);
	SDL_FreeSurface(front);
	SDL_JoystickClose(stick);
	SDL_Quit();

	return dmg;
}