Ejemplo n.º 1
0
/****************************************************************************
 * BrowseDevice
 * Displays a list of files on the selected device
 ***************************************************************************/
int BrowseDevice( const std::string &lowestLevel, std::string dir )
{
	memset( browser.dir, 0, sizeof( browser.dir ) );
	memset( rootdir, 0, sizeof( rootdir ) );

	//dir doesnt start with a "/", that is the root directory
	while( dir.size() && dir[ 0 ] == '/' )
		dir.erase( 0, 1 );

	strncpy( browser.dir, dir.c_str(), sizeof( browser.dir ) );
	strncpy( rootdir, lowestLevel.c_str(), sizeof( rootdir ) );

	//make sure rootdir ends with a '/' since this character is used not only for a delimiter, but also the FS root name
	//it just makes things easier
	int len = strlen( rootdir );
	if( rootdir[ len - 1 ] != '/' )
	{
		rootdir[ len ] = '/';
		rootdir[ len + 1 ] = 0;
	}

	//dir doesnt end with a "/"
	len = strlen( browser.dir );
	while( browser.dir[ len - 1 ] == '/' )
	{
		browser.dir[ len - 1 ] = 0;
		len--;
	}

	ParseDirectory(); // Parse root directory
	return browser.numEntries;
}
//--------------------------------------------------------------------------------
bool CFileIndexSubSystem::ParseDirectory(CString sPath, CWriteLock& lock)
	{
	WIN32_FIND_DATA data;

	CFindFileHandle hand = ::FindFirstFile(sPath + "\\*.*", &data);
	if(! hand.IsValid())
		return false;

	CFileIndexDirObject* pDir;
	CFileIndexFileObject* pFile;

	for(;;)
		{
		if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
			if(data.cFileName[0] != '.')
				ParseDirectory(sPath + '\\' + data.cFileName, lock);
			}
		else
			AddFile(sPath, data.cFileName, pDir, pFile, lock);

		if(! ::FindNextFile(hand, &data))
			break;
		}

	return true;
	}
Ejemplo n.º 3
0
/* Main program */
int
main(int argc, char **argv)
{
    XFILE input_file;
    afs_uint32 r;

    parse_options(argc, argv);
    initialize_acfg_error_table();
    initialize_AVds_error_table();
    initialize_rxk_error_table();
    initialize_u_error_table();
    initialize_vl_error_table();
    initialize_vols_error_table();
    initialize_xFil_error_table();
    r = xfopen(&input_file, O_RDONLY, input_path);
    if (r) {
	afs_com_err(argv0, r, "opening %s", input_path);
	exit(2);
    }

    memset(&dp, 0, sizeof(dp));
    dp.cb_error = my_error_cb;
    dp.print_flags = DSPRINT_DIR;
    if (input_file.is_seekable)
	dp.flags |= DSFLAG_SEEK;

    r = ParseDirectory(&input_file, &dp, 0, 1);
    xfclose(&input_file);

    if (verbose && error_count)
	fprintf(stderr, "*** %d errors\n", error_count);
    if (r && !quiet)
	fprintf(stderr, "*** FAILED: %s\n", afs_error_message(r));
    return 0;
}
Ejemplo n.º 4
0
int gxsURL::ParseURL(const gxString &url, gxsURLInfo &u, int strict)
// Extract the specified URL in the following format:
// URL protocol://username:password@hostname:port/path/filename
// Extracts the hostname terminated with `/' or `:'.
// Extracts the port number terminated with `/', or chosen for the protocol.
// The directory name equals everything after the hostname.
// The URL information will be passed back in the "u" variable. 
// Returns false if any errors occur during the parsing
// operation.
{
  u.url = url;

  int rv = ParseProtocol(url, u.proto, u.proto_type);

  if(strict && !rv) return 0;

  gxString clean_url;
  ParseUserName(url, u.user, u.passwd, clean_url);

  if(!ParseHostName(clean_url, u.host)) return 0;

  if(!ParsePortNumber(clean_url, u.port)) GetPortNumber(clean_url, u.port);

  if(u.proto_type == gxs_ftp) ProcessFTPType(clean_url, u.ftp_type);

  ParseDirectory(clean_url, u.path, u.dir, u.file);

  ParseDynamicPage(u);  

  return 1; // No errors reported
}
Ejemplo n.º 5
0
/****************************************************************************
 * BrowserChangeFolder
 *
 * Update current directory and set new entry list if directory has changed
 ***************************************************************************/
int BrowserChangeFolder() {
    if (!UpdateDirName())
        return -1;

    ParseDirectory();

    return browser.numEntries;
}
Ejemplo n.º 6
0
/****************************************************************************
 * ChangeDirectory
 *
 * Update current directory and set new entry list if directory has changed
 ***************************************************************************/
int CustomBrowser::ChangeDirectory()
{
	if(!UpdateDirName())
		return -1;

	ParseDirectory();
	
	return browserList.size();
}
Ejemplo n.º 7
0
// -------------------------------------------------------------
void Actions::Initialize()
{
  //  get the root directory
  std::wstring commandsPath = ::myodd::config::Get( L"paths\\commands", L"" );
  if( myodd::files::ExpandEnvironment(commandsPath, commandsPath) )
  {
    ParseDirectory(commandsPath.c_str(), L"" );
  }
}
hsBool  pfConsoleDirSrc::ParseDirectory(const std::string& path, const std::string& mask /* = "*.*" */)
{
    wchar_t* wPath = hsStringToWString(path.c_str());
    wchar_t* wMask = hsStringToWString(mask.c_str());
    hsBool ret = ParseDirectory(wPath, wMask);
    delete [] wPath;
    delete [] wMask;
    return ret;
}
//--------------------------------------------------------------------------------
bool CFileIndexSubSystem::ParseNewWatchPath(LPCTSTR pPath)
	{
	CWriteLock lock(&m_tree, false);
	if(! lock.Lock(10000))
		return false;

	ParseDirectory(pPath, lock);
	return true;
	}
Ejemplo n.º 10
0
int OpenProfilesFolder()
{
	sprintf(browser.dir, "%s/profiles/", appPath);
	int device = 0;
	FindDevice(browser.dir, &device);
	
	CleanupPath(browser.dir);
	ResetBrowser(); // reset browser

	return ParseDirectory();
}
Ejemplo n.º 11
0
int CustomBrowser::BrowsePath(std::string path)
{
	if(path.empty())
		return -1;
	
	browserRootDir.assign(path);
	browserRootDir.erase(browserRootDir.find_first_of("/")+1);
	
	browserDir.assign(path);
	while(browserDir[browserDir.size()-1] == '/')
		browserDir.erase(browserDir.size()-1, 1);
	browserDir.erase(0, browserDir.find_first_of("/")+1);
	
	return ParseDirectory();
}
Ejemplo n.º 12
0
bool PluginLoader::ParseDirectory(FileSpecifier& dir)
{
  std::vector<dir_entry> de;
  if (!dir.ReadDirectory(de)) {
    return false;
  }

  for (std::vector<dir_entry>::const_iterator it = de.begin(); it != de.end();
       ++it) {
    FileSpecifier file = dir + it->name;
    if (it->name == "Plugin.xml") {
      ParsePlugin(file);
    }
    else if (it->is_directory && it->name[0] != '.') {
      ParseDirectory(file);
    }
#ifdef HAVE_ZZIP
    else if (algo::ends_with(it->name,
                             ".zip") || algo::ends_with(it->name, ".ZIP")) {
      // search it for a Plugin.xml file
      ZZIP_DIR* zzipdir = zzip_dir_open(file.GetPath(), 0);
      if (zzipdir) {
        ZZIP_DIRENT dirent;
        while (zzip_dir_read(zzipdir, &dirent))
        {
          if (algo::ends_with(dirent.d_name, "Plugin.xml")) {
            std::string archive = file.GetPath();
            FileSpecifier file_name =
              FileSpecifier(archive.substr(0,
                                           archive.find_last_of('.'))) +
              dirent.d_name;
            ParsePlugin(file_name);
          }
        }
        zzip_dir_close(zzipdir);
      }
    }
#endif
  }

  return true;
}
Ejemplo n.º 13
0
/****************************************************************************
 * FileSelector
 *
 * Browse directories and select a file from the file listing
 * return ROM size
 *
 ****************************************************************************/ 
int FileSelector(int type)
{
  short p;
  int i;
  int old = -1;
  char fname[MAXPATHLEN];
  FILE *snap;
  gui_menu *m = &menu_selector;

  int offset_ = -1;
  int selection_ = -1;
  int maxfiles_ = -1;

#ifdef HW_RVL
  int x,y;
  gui_butn *button;
#endif

  /* Background overlay */
  if (config.bg_overlay)
  {
    bg_filesel[1].state |= IMAGE_VISIBLE;
  }
  else
  {
    bg_filesel[1].state &= ~IMAGE_VISIBLE;
  }

  /* Hide all cartridge labels */
  for (i=0; i<FILETYPE_MAX; i++)
  {
    bg_filesel[9+i].data = NULL;
    bg_filesel[9+i].state  &= ~IMAGE_VISIBLE;
  }

  /* System ROM selection */
  if (type >= FILETYPE_MAX)
  {
    /* Save current ROM browser */
    offset_ = offset;
    maxfiles_ = maxfiles;
    selection_ = selection;

    /* Initialize ROM browser */
    maxfiles = ParseDirectory();
    selection = offset = 0;
    while (selection < maxfiles)
    {
      if (strstr(config.sys_rom[type-FILETYPE_MAX], filelist[selection].filename))
      {
        offset = selection;
        while ((offset > (maxfiles - 10)) && (offset > 0))
        {
          offset--;
        }
        break;
      }
      selection++;
    }

    /* By default, select first file in directory if ROM is not found */
    if (selection >= maxfiles)
    {
      selection = 0;
    }

    /* Set menu title and cartridge label type */
    switch (type - FILETYPE_MAX)
    {
      case 0:
      {
        strcpy(m->title,"Sega CD (USA) BIOS Selection");
        type = FILETYPE_MD;
        break;
      }

      case 1:
      {
        strcpy(m->title,"Mega CD (PAL) BIOS Selection");
        type = FILETYPE_MD;
        break;
      }

      case 2:
      {
        strcpy(m->title,"Mega CD (JAP) BIOS Selection");
        type = FILETYPE_MD;
        break;
      }

      case 3:
      {
        strcpy(m->title,"Mega Drive/Genesis BootROM Selection");
        type = FILETYPE_MD;
        break;
      }

      case 4:
      {
        strcpy(m->title,"Master System (USA) BootROM Selection");
        type = FILETYPE_MS;
        break;
      }

      case 5:
      {
        strcpy(m->title,"Master System (PAL) BootROM Selection");
        type = FILETYPE_MS;
        break;
      }

      case 6:
      {
        strcpy(m->title,"Master System (JAP) BootROM Selection");
        type = FILETYPE_MS;
        break;
      }

      case 7:
      {
        strcpy(m->title,"Game Gear BootROM Selection");
        type = FILETYPE_GG;
        break;
      }

      case 8:
      {
        strcpy(m->title,"Game Genie ROM Selection");
        type = FILETYPE_MD;
        break;
      }

      case 9:
      {
        strcpy(m->title,"Action Replay (Pro) ROM Selection");
        type = FILETYPE_MD;
        break;
      }

      case 10:
      {
        strcpy(m->title,"Sonic & Knuckles ROM Selection");
        type = FILETYPE_MD;
        break;
      }

      case 11:
      {
        strcpy(m->title,"Sonic 2 & Knuckles ROM Selection");
        type = FILETYPE_MD;
        break;
      }
    }
  }
  else
  {
    /* reset menu title */
    strcpy(m->title, "Game Selection");
  }

  /* Set default helper for Back button */
  strcpy(m->helpers[0]->comment, "Exit");

  /* Check if we are not browsing recent file list */
  if (type >= 0)
  {
    /* Select cartridge type */
    bg_filesel[9 + type].data = Cart_png[type];
    bg_filesel[9 + type].state |= IMAGE_VISIBLE;

    /* Get current directory */
    char *dir = GetCurrentDirectory();

    /* Get current directory name length */
    int size = strlen(dir);

    /* Check if we are not in Root directory */
    if (size > 1)
    {
      if (dir[size - 2] != ':')
      {
        /* Update helper for Back button */
        strcpy(m->helpers[0]->comment, "Previous Directory");
      }
    }

    /* Initialize directory icon */
    dir_icon.texture = gxTextureOpenPNG(Browser_dir_png,0);
    dir_icon.w = dir_icon.texture->width;
    dir_icon.h = dir_icon.texture->height;
    dir_icon.x = 26;
    dir_icon.y = (26 - dir_icon.h)/2;
  }

  /* Initialize selection bar */
  bar_over.texture = gxTextureOpenPNG(Overlay_bar_png,0);
  bar_over.w = bar_over.texture->width;
  bar_over.h = bar_over.texture->height;
  bar_over.x = 16;
  bar_over.y = (26 - bar_over.h)/2;

  /* Initialize Menu */
  GUI_InitMenu(m);
  string_offset = 0;

  while (1)
  {
    /* ROM file snapshot/database */
    if (old != selection)
    {
      /* close any screenshot texture first */
      gxTextureClose(&bg_filesel[8].texture);
      bg_filesel[8].state &= ~IMAGE_VISIBLE;

      old = selection;
      string_offset = 0;

      if (!filelist[selection].flags)
      {
        /* recent game list -> variable game types */
        if (type < 0)
        {
          /* check if game type has changed */
          type = history.entries[selection].filetype;
          if (!(bg_filesel[9 + type].state & IMAGE_VISIBLE))
          {
            /* hide all cartridge labels */
            for (i=0; i<FILETYPE_MAX; i++)
            {
              gxTextureClose(&bg_filesel[9 + i].texture);
              bg_filesel[9 + i].state &= ~IMAGE_VISIBLE;
            }

            /* open cartridge label texture */
            bg_filesel[9 + type].texture = gxTextureOpenPNG(Cart_png[type],0);

            /* show selected cartridge label */
            bg_filesel[9 + type].state |= IMAGE_VISIBLE;
          }

          /* default screenshot file path */
          sprintf(fname,"%s/snaps/%s/%s", DEFAULT_PATH, Cart_dir[type], filelist[selection].filename);

          /* restore recent type flag */
          type = -1;
        }
        else
        {
          /*  default screenshot file path */
          sprintf(fname,"%s/snaps/%s/%s", DEFAULT_PATH, Cart_dir[type], filelist[selection].filename);
        }

        /* remove original file extension */
        i = strlen(fname) - 1;
        while ((i > 0) && (fname[i] != '.')) i--;
        if (i > 0) fname[i] = 0;

        /* add PNG file extension */
        strcat(fname, ".png");

        /* try to load screenshot file */
        snap = fopen(fname, "rb");
        if (snap)
        {
          bg_filesel[8].texture = gxTextureOpenPNG(0,snap);
          if (bg_filesel[8].texture)
          {
            bg_filesel[8].state |= IMAGE_VISIBLE;
          }
          fclose(snap);
        }
      }
    }

    /* update Action button helper */
    if (m->selected != -1)
    {
      /* out of focus */
      strcpy(action_select.comment,"");
    }
    else if (filelist[selection].flags)
    {
      /* this is a directory */
      strcpy(action_select.comment,"Open Directory");
    }
    else
    {
      /* this is a ROM file */
      if (offset_ != -1)
      {
        /* System ROM browser */
        strcpy(action_select.comment,"Select File");
      }
      else
      {
        /* Normal ROM browser */
        strcpy(action_select.comment,"Load File");
      }
    }
 
    /* Draw menu*/
    GUI_DrawMenu(m);

#ifdef HW_RVL
    if (Shutdown)
    {
      gxTextureClose(&bar_over.texture);
      gxTextureClose(&dir_icon.texture);
      gxTextureClose(&w_pointer);
      GUI_DeleteMenu(m);
      GUI_FadeOut();
      shutdown();
      SYS_ResetSystem(SYS_POWEROFF, 0, 0);
    }
    else if (m_input.ir.valid)
    {
      /* get cursor position */
      x = m_input.ir.x;
      y = m_input.ir.y;

      /* draw wiimote pointer */
      gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255);

      /* ensure we are in the selectable area */
      if ((x < 380) && (y >= 108) && (y <= 368))
      {
        /* find selected item */
        selection = (y - 108) / 26;
        if (selection > 9) selection = 9;
        selection += offset;
        if (selection >= maxfiles) selection = old;

        /* reset selection */
        m->selected = -1;
      }
      else
      {
        /* disable selection */
        m->selected = m->max_buttons + 2;

        /* find selected button */
        for (i=0; i<2; i++)
        {
          button = m->arrows[i];
          if (button)
          {
            if (button->state & BUTTON_VISIBLE)
            {
              if ((x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
              {
                m->selected = m->max_buttons + i;
                break;
              }
            }
          }
        }
      }
    }
    else
    {
      /* reset selection */
      m->selected = -1;
    }
#endif

    /* copy EFB to XFB */
    gxSetScreen();

    p = m_input.keys;

    /* highlight next item */
    if (p & PAD_BUTTON_DOWN)
    {
      selection++;
      if (selection >= maxfiles)
        selection = offset = 0;
      else if (selection >= (offset + 10))
        offset++;
    }

    /* highlight previous item */
    else if (p & PAD_BUTTON_UP)
    {
      selection--;
      if (selection < 0)
      {
        selection = maxfiles - 1;
        offset = maxfiles - 10;
        if (offset < 0) offset = 0;
      }
      else if (selection < offset)
        offset --;
    }

    /* go back one page */
    else if (p & (PAD_TRIGGER_L | PAD_BUTTON_LEFT)) 
    {
      if (maxfiles >= 10)
      {
        selection -= 10;
        if (selection < 0)
        {
          /* first page */
          selection = offset = 0;
        }
        else if (selection < offset)
        {
          /* previous page */
          offset -= 10;
          if (offset < 0) offset = 0;
        }
      }
    }

    /* go forward one page */
    else if (p & (PAD_TRIGGER_R | PAD_BUTTON_RIGHT))
    {
      if (maxfiles >= 10)
      {
        selection += 10;
        if (selection > maxfiles - 1)
        {
          /* last page */
          selection = maxfiles - 1;
          offset = maxfiles - 10;
        }
        else if (selection >= (offset + 10))
        {
          /* next page */
          offset += 10;
          if (offset > (maxfiles - 10)) offset = maxfiles - 10;
        }
      }
    }

    /* quit */
    else if (p & PAD_TRIGGER_Z)
    {
      /* System ROM selection */
      if (offset_ != -1)
      {
        /* restore current ROM browser */
        offset = offset_;
        maxfiles = maxfiles_;
        selection = selection_;
      }

      gxTextureClose(&bar_over.texture);
      gxTextureClose(&dir_icon.texture);
      GUI_DeleteMenu(m);
      return -1;
    }

    /* previous directory */
    else if (p & PAD_BUTTON_B)
    {
      string_offset = 0;

      /* recent ROM list */
      if (type < 0)
      {
        /* exit */
        gxTextureClose(&bar_over.texture);
        gxTextureClose(&dir_icon.texture);
        GUI_DeleteMenu(m);
        return -1;
      }

      /* update browser directory (and get current folder)*/
      if (UpdateDirectory(1, prev_folder))
      {
        /* get directory entries */
        maxfiles = ParseDirectory();

        /* Get current directory */
        char *dir = GetCurrentDirectory();

        /* current directory name length */
        int size = strlen(dir);

        /* Adjust helper for back button */
        if ((size > 1) && (dir[size - 2] != ':'))
        {
          /* Back button goes up one directory */
          strcpy(m->helpers[0]->comment, "Previous Directory");
        }
        else
        {
          /* Back button exits from root directory */
          strcpy(m->helpers[0]->comment, "Exit");
        }

        /* clear selection by default */
        selection = offset = 0;
        old = -1;

        /* select previous directory */
        for (i=0; i<maxfiles; i++)
        {
          if ((filelist[i].flags) && !strcmp(prev_folder,filelist[i].filename))
          {
            selection = i;
            while (i  >= (offset + 10))
            {
              offset += 10;
              if (offset > (maxfiles - 10)) offset = maxfiles - 10;
            }
            break;
          }
        }
      }
      else
      {
        /* System ROM selection */
        if (offset_ != -1)
        {
          /* restore current ROM browser */
          offset = offset_;
          maxfiles = maxfiles_;
          selection = selection_;
        }

        /* Exit */
        gxTextureClose(&bar_over.texture);
        gxTextureClose(&dir_icon.texture);
        GUI_DeleteMenu(m);
        return -1;
      }
    }

    /* open selected file or directory */
    else if (p & PAD_BUTTON_A)
    {
      string_offset = 0;

      /* ensure we are in focus area */
      if (m->selected < m->max_buttons)
      {
        if (filelist[selection].flags)
        {
          /* get new directory */
          UpdateDirectory(0, filelist[selection].filename);

          /* get directory entries */
          maxfiles = ParseDirectory();

          /* clear selection by default */
          selection = offset = 0;
          old = -1;
        }
        else
        {
          int ret;

          /* System ROM selection */
          if (offset_ != -1)
          {
            /* return ROM file index */
            ret = selection;

            /* restore current ROM browser */
            offset = offset_;
            maxfiles = maxfiles_;
            selection = selection_;
          }
          else
          {
            /* load ROM file from device then return ROM size (zero if an error occured) */
            ret = LoadFile(selection);
          }

          /* exit menu */
          gxTextureClose(&bar_over.texture);
          gxTextureClose(&dir_icon.texture);
          GUI_DeleteMenu(m);
          return ret;
        }
      }

#ifdef HW_RVL
      /* arrow buttons selected */
      else if (m->selected == m->max_buttons)
      {
        /* up arrow */
        selection--;
        if (selection < 0)
        {
          selection = maxfiles - 1;
          offset = selection - 10 + 1;
        }
        if (selection < offset) offset -= 10;
        if (offset < 0) offset = 0;
      }
      else if (m->selected == (m->max_buttons+1))
      {
        /* down arrow */
        selection++;
        if (selection == maxfiles)
          selection = offset = 0;
        if ((selection - offset) >= 10)
          offset += 10;
      }
#endif
    }
  }
}
Ejemplo n.º 14
0
/****************************************************************************
 * BrowseDevice
 * Displays a list of files on the selected device
 ***************************************************************************/
int BrowseDevice(const char * dir, const char * root) {
    sprintf(browser.dir, dir);
    sprintf(rootdir, root);
    ParseDirectory(); // Parse root directory
    return browser.numEntries;
}
Ejemplo n.º 15
0
/****************************************************************************
 * BrowseDevice
 * Displays a list of files on the selected device
 ***************************************************************************/
int BrowseDevice() {
    sprintf(browser.dir, "/");
    sprintf(rootdir, "uda:/");
    ParseDirectory(); // Parse root directory
    return browser.numEntries;
}
Ejemplo n.º 16
0
/****************************************************************************
 * BrowserChangeFolder
 *
 * Update current directory and set new entry list if directory has changed
 ***************************************************************************/
int BrowserChangeFolder()
{
	int device = 0;
	FindDevice(browser.dir, &device);
	
	if(!UpdateDirName()){
		return -1;
	}

	HaltParseThread(); // halt parsing
	CleanupPath(browser.dir);
	ResetBrowser(); // reset browser

	if(browser.dir[0] != 0){
		ParseDirectory();
	}

	if(browser.numEntries == 0)
	{
		browser.dir[0] = 0;
		int i=0;
		
#if 0
		AddBrowserEntry();
		sprintf(browserList[i].filename, "uda:/");
		sprintf(browserList[i].displayname, "USB Mass Storage");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_USB;
		i++;
		
		AddBrowserEntry();
		sprintf(browserList[i].filename, "sda0:/");
		sprintf(browserList[i].displayname, "Hard Drive");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_SD;
		i++;
                
		AddBrowserEntry();
		sprintf(browserList[i].filename, "smb:/");
		sprintf(browserList[i].displayname, "Network Share");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_SMB;
		i++;
		
		AddBrowserEntry();
		sprintf(browserList[i].filename, "dvd:/");
		sprintf(browserList[i].displayname, "Data DVD");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_DVD;
		i++;
#else
	// dynamic use
		int iusb = 0;
		int ihdd = 0;
		int imisc = 0;
				
		for (int id = 3; id < STD_MAX; id++) {
			if (devoptab_list[id]->structSize) {
				AddBrowserEntry();
				sprintf(browserList[i].filename, "%s:/", devoptab_list[id]->name);				
				browserList[i].length = 0;
				browserList[i].isdir = 1;
				
				switch(browserList[i].filename[0]) {
					case 'u':
					{
						browserList[i].icon = ICON_USB;
						sprintf(browserList[i].displayname, "USB Mass Storage %d", iusb++);
						break;
					}
					case 's':
					{
						browserList[i].icon = ICON_SD;
						sprintf(browserList[i].displayname, "Hard Drive %d", ihdd++);
						break;
					}
					default:
					{
						browserList[i].icon = ICON_DVD;
						sprintf(browserList[i].displayname, "DVD %d", imisc++);
						break;
					}					
				}				
				printf("findDevices : %s\r\n", browserList[i].filename);
				i++;
			}
		}
#endif
		browser.numEntries += i;
	}
	
	if(browser.dir[0] == 0)
	{
		GCSettings.LoadFolder[0] = 0;
		GCSettings.LoadMethod = 0;
	}
	else
	{
		char * path = StripDevice(browser.dir);
		if(path != NULL)
			strcpy(GCSettings.LoadFolder, path);
		FindDevice(browser.dir, &GCSettings.LoadMethod);
	}

	return browser.numEntries;
}
Ejemplo n.º 17
0
/****************************************************************************
 * BrowserChangeFolder
 *
 * Update current directory and set new entry list if directory has changed
 ***************************************************************************/
int BrowserChangeFolder()
{
	int device = 0;
	FindDevice(browser.dir, &device);
	
	if(inSz && browser.selIndex == 0) // inside a 7z, requesting to leave
	{
		inSz = false;
		SzClose();
	}

	if(!UpdateDirName()) 
		return -1;

	HaltParseThread();
	CleanupPath(browser.dir);
	ResetBrowser();

	if(browser.dir[0] != 0)
	{
		if(strstr(browser.dir, ".7z"))
		{
			BrowserLoadSz();
		}
		else 
		{
			ParseDirectory(true, true);
		}
		FindAndSelectLastLoadedFile();
	}

	if(browser.numEntries == 0)
	{
		browser.dir[0] = 0;
		int i=0;
		
#ifdef HW_RVL
		AddBrowserEntry();
		sprintf(browserList[i].filename, "sd:/");
		sprintf(browserList[i].displayname, "SD Card");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_SD;
		i++;

		AddBrowserEntry();
		sprintf(browserList[i].filename, "usb:/");
		sprintf(browserList[i].displayname, "USB Mass Storage");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_USB;
		i++;
#else
		AddBrowserEntry();
		sprintf(browserList[i].filename, "carda:/");
		sprintf(browserList[i].displayname, "SD Gecko Slot A");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_SD;
		i++;
		
		AddBrowserEntry();
		sprintf(browserList[i].filename, "cardb:/");
		sprintf(browserList[i].displayname, "SD Gecko Slot B");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_SD;
		i++;
#endif
		AddBrowserEntry();
		sprintf(browserList[i].filename, "smb:/");
		sprintf(browserList[i].displayname, "Network Share");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_SMB;
		i++;
		
		AddBrowserEntry();
		sprintf(browserList[i].filename, "dvd:/");
		sprintf(browserList[i].displayname, "Data DVD");
		browserList[i].length = 0;
		browserList[i].isdir = 1;
		browserList[i].icon = ICON_DVD;
		i++;
		
		browser.numEntries += i;
	}
	
	if(browser.dir[0] == 0)
	{
		GCSettings.LoadFolder[0] = 0;
		GCSettings.LoadMethod = 0;
	}
	else
	{
		char * path = StripDevice(browser.dir);
		if(path != NULL)
			strcpy(GCSettings.LoadFolder, path);
		FindDevice(browser.dir, &GCSettings.LoadMethod);
	}

	return browser.numEntries;
}
Ejemplo n.º 18
0
// -------------------------------------------------------------
void Actions::ParseDirectory( LPCTSTR rootPath, LPCTSTR extentionPath  )
{
  // make sure that we do not have too many actions
  // this is a sign that something is broken
  // or that we are reading the root directory
  {
    myodd::threads::Lock guard(_mutexActions);
    if (_actions.size() > static_cast<size_t>(::myodd::config::Get(L"paths\\maxcommand", 2048)))
    {
      ASSERT(0); // you have reached the limit!
                   // it is pointless to try and add more command.
      return;
    }
  }

  // make sure that the path that we have is valid.
  ASSERT( _tcslen( rootPath ) > 0 );
  if( _tcslen( rootPath ) == 0 )
  {
    return;
  }

  //  the end path
  std::wstring directory = rootPath;  

  // make sure it has a trailing back slash.
  myodd::files::AddTrailingBackSlash( directory );

  // add the extension
  directory += extentionPath;

  //  add a trailing back slash
  myodd::files::AddTrailingBackSlash( directory );

  //
  //  we could refine the search to
  //  *.bat, *.exe, *.pl
  //  but I am not sure we really need to restrict anything
  // it is up to the user to ensure that they have 
  auto sPath = directory + L"*.*";

  LPTSTR fullPath = NULL;
  if( !myodd::files::ExpandEnvironment( sPath.c_str(), fullPath ) )
  {
    return;
  }
  
  _tfinddata_t fdata;
  const auto ffhandle = _tfindfirst( fullPath, &fdata );
  if( ffhandle != -1 )
  {
    do
    {
      if( _tcscmp(fdata.name, L"." ) == 0 || _tcscmp(fdata.name, L"..") == 0)
      {
        continue;
      }

      //  .svn directories are hidden so we might as well ignore all hidden file.
      if( (fdata.attrib & _A_HIDDEN) == _A_HIDDEN )
      {
        continue;
      }

      if( (fdata.attrib & _A_SUBDIR) == _A_SUBDIR )
      {
        if( IsReservedDir( fdata.name ) )
        {
          continue;
        }
        
        std::wstring subPath( extentionPath );
        subPath += fdata.name;
        myodd::files::AddTrailingBackSlash( subPath );

        ParseDirectory( rootPath, subPath.c_str() );
        continue;
      }

      //  ok add this command
      auto szFullPath( directory);
      szFullPath += fdata.name;

      std::wstring szName( fdata.name);
      szName = myodd::strings::lower(szName );
      
      //  if we don't want to show the extension then strip it.
      if( ::myodd::config::Get( L"commands\\show.extentions", 0 ) == false )
      {
        myodd::files::StripExtension( szName );
      }        

      Add( new Action( _application ,szName, szFullPath));
    }while( _tfindnext( ffhandle, &fdata ) == 0 );

    _findclose( ffhandle );
  }

  delete [] fullPath;
}
Ejemplo n.º 19
0
/***************************************************************************
 * Browse subdirectories
 **************************************************************************/
void CustomBrowser::Refresh()
{
	ParseDirectory();
}
Ejemplo n.º 20
0
Archivo: http.c Proyecto: cobr123/qtVlc
/*****************************************************************************
 * Activate: initialize and create stuff
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t*)p_this;
    intf_sys_t    *p_sys;
    char          *psz_address;
    char          *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
                  *psz_crl = NULL;
    int           i_port       = 0;
    char          *psz_src = NULL;

    psz_address = var_CreateGetNonEmptyString( p_intf, "http-host" );
    if( psz_address != NULL )
    {
        char *psz_parser = strrchr( psz_address, ':' );
        if( psz_parser )
        {
            *psz_parser++ = '\0';
            i_port = atoi( psz_parser );
        }
    }
    else
        psz_address = strdup("");

    p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
    if( !p_intf->p_sys )
    {
        free( psz_address );
        return( VLC_ENOMEM );
    }

    p_sys->p_playlist = pl_Get( p_this );
    p_sys->p_input    = NULL;
    p_sys->p_vlm      = NULL;
    p_sys->psz_address = psz_address;
    p_sys->i_port     = i_port;
    p_sys->p_art_handler = NULL;

    /* determine file handler associations */
    p_sys->i_handlers = 0;
    p_sys->pp_handlers = NULL;
#if defined( HAVE_FORK ) || defined( WIN32 )
    psz_src = var_InheritString( p_intf, "http-handlers" );
    if( psz_src != NULL )
    {
        char *p = psz_src;
        while( p != NULL )
        {
            http_association_t *p_handler;
            char *psz_ext = p;
            char *psz_program, *psz_options;
            p = strchr( p, '=' );
            if( p == NULL ) break;
            *p++ = '\0';
            psz_program = p;
            p = strchr( p, ',' );
            if( p != NULL )
                *p++ = '\0';

            p_handler = malloc( sizeof( http_association_t ) );
            p_handler->psz_ext = strdup( psz_ext );
            psz_options = FirstWord( psz_program, psz_program );
            p_handler->i_argc = 0;
            p_handler->ppsz_argv = NULL;
            TAB_APPEND( p_handler->i_argc, p_handler->ppsz_argv,
                        strdup( psz_program ) );
            while( psz_options != NULL && *psz_options )
            {
                char *psz_next = FirstWord( psz_options, psz_options );
                TAB_APPEND( p_handler->i_argc, p_handler->ppsz_argv,
                            strdup( psz_options ) );
                psz_options = psz_next;
            }
            /* NULL will be appended later on */

            TAB_APPEND( p_sys->i_handlers, p_sys->pp_handlers, p_handler );
        }
        free( psz_src );
    }
#endif

    /* determine SSL configuration */
    psz_cert = var_InheritString( p_intf, "http-intf-cert" );
    if ( psz_cert != NULL )
    {
        msg_Dbg( p_intf, "enabling TLS for HTTP interface (cert file: %s)",
                 psz_cert );
        psz_key = var_InheritString( p_intf, "http-intf-key" );
        psz_ca = var_InheritString( p_intf, "http-intf-ca" );
        psz_crl = var_InheritString( p_intf, "http-intf-crl" );

        if( i_port <= 0 )
            i_port = 8443;
    }
    else
    {
        if( i_port <= 0 )
            i_port= 8080;
    }

    msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );

    p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
                                            i_port, psz_cert, psz_key, psz_ca,
                                            psz_crl );
    free( psz_cert );
    free( psz_key );
    free( psz_ca );
    free( psz_crl );

    if( p_sys->p_httpd_host == NULL )
    {
        msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
        free( p_sys->psz_address );
        free( p_sys );
        return VLC_EGENERIC;
    }
    else
    {
        char psz_tmp[NI_MAXHOST + 6];

        /* Ugly hack to run several HTTP servers on different ports */
        snprintf( psz_tmp, sizeof (psz_tmp), "%s:%d", psz_address, i_port + 1 );
        var_Create(p_intf->p_libvlc, "http-host", VLC_VAR_STRING );
        var_SetString( p_intf->p_libvlc, "http-host", psz_tmp );
    }

    p_sys->i_files  = 0;
    p_sys->pp_files = NULL;

    psz_src = var_InheritString( p_intf, "http-src" );
    if( psz_src == NULL )
    {
        char *data_path = config_GetDataDir( p_intf );
        if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 )
            psz_src = NULL;
        free( data_path );
    }

    if( psz_src == NULL )
    {
        msg_Err( p_intf, "invalid web interface source directory" );
        goto failed;
    }

    /* remove trainling \ or / */
    if( psz_src[strlen( psz_src ) - 1] == '\\' ||
        psz_src[strlen( psz_src ) - 1] == '/' )
    {
        psz_src[strlen( psz_src ) - 1] = '\0';
    }

    ParseDirectory( p_intf, psz_src, psz_src );
    if( p_sys->i_files <= 0 )
    {
        msg_Err( p_intf, "cannot find any file in directory %s", psz_src );
        goto failed;
    }

    if( var_InheritBool( p_intf, "http-album-art" ) )
    {
        /* FIXME: we're leaking h */
        httpd_handler_sys_t *h = malloc( sizeof( httpd_handler_sys_t ) );
        if( !h )
            goto failed;
        h->file.p_intf = p_intf;
        h->file.file = NULL;
        h->file.name = NULL;
        /* TODO: use ACL and login/password stuff here too */
        h->p_handler = httpd_HandlerNew( p_sys->p_httpd_host,
                                         "/art", NULL, NULL, NULL,
                                         ArtCallback, h );
        p_sys->p_art_handler = h->p_handler;
    }

    free( psz_src );
    return VLC_SUCCESS;

failed:
    free( psz_src );
    free( p_sys->pp_files );
    httpd_HostDelete( p_sys->p_httpd_host );
    free( p_sys->psz_address );
    free( p_sys );
    return VLC_EGENERIC;
}
Ejemplo n.º 21
0
/****************************************************************************
 * OpenDir
 *
 * Function to open a directory and load ROM file list.
 ****************************************************************************/ 
int OpenDirectory(int device, int type)
{
  int max = 0;

  if (device == TYPE_RECENT)
  {
    /* fetch history list */
    int i;
    for(i=0; i < NUM_HISTORY_ENTRIES; i++)
    {
      if(history.entries[i].filepath[0] > 0)
      {
        filelist[i].flags = 0;
        strncpy(filelist[i].filename,history.entries[i].filename, MAXJOLIET-1);
        filelist[i].filename[MAXJOLIET-1] = '\0';
        max++;
      }
      else
      {
        /* Found the end of the list. */
        break;
      }
    }
  }
  else
  {
    /* only DVD hot swap is supported */
    if (device == TYPE_DVD)
    {
      /* try to access root directory */
      DIR *dir = opendir(rootdir[TYPE_DVD]);
      if (dir == NULL)
      {
        /* mount DVD */
        if (!MountDVD()) return 0;
        deviceType = -1;
      }
      else
      {
        closedir(dir);
      }
    }

    /* parse last directory */
    fileDir = config.lastdir[type][device];
    max = ParseDirectory();
    if (max <= 0)
    {
      /* parse root directory */
      strcpy(fileDir, rootdir[device]);
      max = ParseDirectory();
      if (max < 0)
      {
        GUI_WaitPrompt("Error","Unable to open directory !");
        return 0;
      }
      deviceType = -1;
    }
  }

  if (max == 0)
  {
    GUI_WaitPrompt("Error","No files found !");
    return 0;
  }

  /* check if device or file type has changed */
  if ((device != deviceType) || (type != fileType))
  {
    /* reset current types */
    deviceType = device;
    fileType = type;

    /* reset File selector */
    ClearSelector(max);
  }

  return 1;
}
Ejemplo n.º 22
0
/* Parse a directory and recursively add files */
int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
                        char *psz_dir )
{
    intf_sys_t     *p_sys = p_intf->p_sys;
    char           dir[MAX_DIR_SIZE];
    DIR           *p_dir;
    vlc_acl_t     *p_acl;
    FILE          *file;

    char          *user = NULL;
    char          *password = NULL;

    int           i_dirlen;

    if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL )
    {
        if( errno != ENOENT && errno != ENOTDIR )
            msg_Err( p_intf, "cannot open directory (%s)", psz_dir );
        return VLC_EGENERIC;
    }

    i_dirlen = strlen( psz_dir );
    if( i_dirlen + 10 > MAX_DIR_SIZE )
    {
        msg_Warn( p_intf, "skipping too deep directory (%s)", psz_dir );
        closedir( p_dir );
        return 0;
    }

    msg_Dbg( p_intf, "dir=%s", psz_dir );

    snprintf( dir, sizeof( dir ), "%s"DIR_SEP".access", psz_dir );
    if( ( file = utf8_fopen( dir, "r" ) ) != NULL )
    {
        char line[1024];
        int  i_size;

        msg_Dbg( p_intf, "find .access in dir=%s", psz_dir );

        i_size = fread( line, 1, 1023, file );
        if( i_size > 0 )
        {
            char *p;
            while( i_size > 0 && ( line[i_size-1] == '\n' ||
                   line[i_size-1] == '\r' ) )
            {
                i_size--;
            }

            line[i_size] = '\0';

            p = strchr( line, ':' );
            if( p )
            {
                *p++ = '\0';
                user = strdup( line );
                password = strdup( p );
            }
        }
        msg_Dbg( p_intf, "using user=%s (read=%d)", user, i_size );

        fclose( file );
    }

    snprintf( dir, sizeof( dir ), "%s"DIR_SEP".hosts", psz_dir );
    p_acl = ACL_Create( p_intf, false );
    if( ACL_LoadFile( p_acl, dir ) )
    {
        ACL_Destroy( p_acl );

        struct stat st;
        if( utf8_stat( dir, &st ) == 0 )
        {
            free( user );
            free( password );
            closedir( p_dir );
            return VLC_EGENERIC;
        }
        p_acl = NULL;
    }

    for( ;; )
    {
        char *psz_filename;
        /* parse psz_src dir */
        if( ( psz_filename = utf8_readdir( p_dir ) ) == NULL )
        {
            break;
        }

        if( ( psz_filename[0] == '.' )
         || ( i_dirlen + strlen( psz_filename ) > MAX_DIR_SIZE ) )
        {
            free( psz_filename );
            continue;
        }

        snprintf( dir, sizeof( dir ), "%s"DIR_SEP"%s", psz_dir, psz_filename );
        free( psz_filename );

        if( ParseDirectory( p_intf, psz_root, dir ) )
        {
            httpd_file_sys_t *f = NULL;
            httpd_handler_sys_t *h = NULL;
            bool b_index;
            char *psz_name, *psz_ext;

            psz_name = FileToUrl( &dir[strlen( psz_root )], &b_index );
            psz_ext = strrchr( dir, '.' );
            if( psz_ext != NULL )
            {
                int i;
                psz_ext++;
                for( i = 0; i < p_sys->i_handlers; i++ )
                    if( !strcmp( p_sys->pp_handlers[i]->psz_ext, psz_ext ) )
                        break;
                if( i < p_sys->i_handlers )
                {
                    f = malloc( sizeof( httpd_handler_sys_t ) );
                    h = (httpd_handler_sys_t *)f;
                    f->b_handler = true;
                    h->p_association = p_sys->pp_handlers[i];
                }
            }
            if( f == NULL )
            {
                f = malloc( sizeof( httpd_file_sys_t ) );
                f->b_handler = false;
            }

            f->p_intf  = p_intf;
            f->p_file = NULL;
            f->p_redir = NULL;
            f->p_redir2 = NULL;
            f->file = strdup (dir);
            f->name = psz_name;
            f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) || strstr( &dir[strlen( psz_root )], ".xml" ) ? true : false;

            if( !f->name )
            {
                msg_Err( p_intf , "unable to parse directory" );
                closedir( p_dir );
                free( f );
                return( VLC_ENOMEM );
            }
            msg_Dbg( p_intf, "file=%s (url=%s)",
                     f->file, f->name );

            if( !f->b_handler )
            {
                char *psz_type = strdup( "text/html; charset=UTF-8" );
                if( strstr( &dir[strlen( psz_root )], ".xml" ) )
                {
                    char *psz = strstr( psz_type, "html;" );
                    if( psz )
                    {
                        psz[0] = 'x';
                        psz[1] = 'm';
                        psz[2] = 'l';
                        psz[3] = ';';
                        psz[4] = ' ';
                    }
                }
                f->p_file = httpd_FileNew( p_sys->p_httpd_host,
                                           f->name,
                                           f->b_html ? psz_type : NULL,
                                           user, password, p_acl,
                                           HttpCallback, f );
                free( psz_type );
                if( f->p_file != NULL )
                {
                    TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
                }
            }
            else
            {
                h->p_handler = httpd_HandlerNew( p_sys->p_httpd_host,
                                                 f->name,
                                                 user, password, p_acl,
                                                 HandlerCallback, h );
                if( h->p_handler != NULL )
                {
                    TAB_APPEND( p_sys->i_files, p_sys->pp_files,
                                (httpd_file_sys_t *)h );
                }
            }

            /* for url that ends by / add
             *  - a redirect from rep to rep/
             *  - in case of index.* rep/index.html to rep/ */
            if( f && f->name[strlen(f->name) - 1] == '/' )
            {
                char *psz_redir = strdup( f->name );
                char *p;
                psz_redir[strlen( psz_redir ) - 1] = '\0';

                msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
                f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
                free( psz_redir );

                if( b_index && ( p = strstr( f->file, "index." ) ) )
                {
                    if( asprintf( &psz_redir, "%s%s", f->name, p ) != -1 )
                    {
                        msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
                        f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
                                                         f->name, psz_redir );

                        free( psz_redir );
                    }
                }
            }
        }
    }

    free( user );
    free( password );

    ACL_Destroy( p_acl );
    closedir( p_dir );

    return VLC_SUCCESS;
}
Ejemplo n.º 23
0
/****************************************************************************
 * FileSelector
 *
 * Browse directories and select a file from the file listing
 * return ROM size
 *
 ****************************************************************************/
int FileSelector(int type)
{
    short p;
    int i;
    int old = -1;
    char fname[MAXPATHLEN];
    FILE *snap;
    gui_menu *m = &menu_selector;

#ifdef HW_RVL
    int x,y;
    gui_butn *button;
#endif

    /* Background overlay */
    if (config.bg_overlay)
    {
        bg_filesel[1].state |= IMAGE_VISIBLE;
    }
    else
    {
        bg_filesel[1].state &= ~IMAGE_VISIBLE;
    }

    /* Hide all cartridge labels */
    for (i=0; i<FILETYPE_MAX; i++)
    {
        bg_filesel[9+i].state  &= ~IMAGE_VISIBLE;
    }

    /* Cartridge type */
    if (type < 0)
    {
        /* Recent game list -> select all cartridge type */
        for (i=0; i<FILETYPE_MAX; i++)
        {
            bg_filesel[9+i].data = Cart_png[i];
        }
    }
    else
    {
        /* Clear all cartridges type */
        for (i=0; i<FILETYPE_MAX; i++)
        {
            bg_filesel[9+i].data = NULL;
        }

        /* Select cartridge type */
        bg_filesel[9 + type].data = Cart_png[type];
        bg_filesel[9 + type].state |= IMAGE_VISIBLE;
    }

    /* Initialize Menu */
    GUI_InitMenu(m);
    string_offset = 0;

    while (1)
    {
        /* ROM file snapshot/database */
        if (old != selection)
        {
            /* close any existing texture first */
            gxTextureClose(&bg_filesel[8].texture);
            bg_filesel[8].state &= ~IMAGE_VISIBLE;

            old = selection;
            string_offset = 0;

            if (!filelist[selection].flags)
            {
                /* recent game list -> variable game types */
                if (type < 0)
                {
                    /* hide all cartridge labels */
                    for (i=0; i<FILETYPE_MAX; i++)
                    {
                        bg_filesel[9+i].state  &= ~IMAGE_VISIBLE;
                    }

                    /* detect cartridge type */
                    type = history.entries[selection].filetype;

                    /* show selected cartridge label */
                    bg_filesel[9 + type].state |= IMAGE_VISIBLE;

                    /*  default screenshot file path */
                    sprintf(fname,"%s/snaps/%s/%s", DEFAULT_PATH, Cart_dir[type], filelist[selection].filename);

                    /* restore recent type flag */
                    type = -1;
                }
                else
                {
                    /*  default screenshot file path */
                    sprintf(fname,"%s/snaps/%s/%s", DEFAULT_PATH, Cart_dir[type], filelist[selection].filename);
                }

                /* remove original file extension */
                i = strlen(fname) - 1;
                while ((i > 0) && (fname[i] != '.')) i--;
                if (i > 0) fname[i] = 0;

                /* add PNG file extension */
                strcat(fname, ".png");

                /* try to load screenshot file */
                snap = fopen(fname, "rb");
                if (snap)
                {
                    bg_filesel[8].texture = gxTextureOpenPNG(0,snap);
                    if (bg_filesel[8].texture)
                    {
                        bg_filesel[8].state |= IMAGE_VISIBLE;
                    }
                    fclose(snap);
                }
            }
        }

        /* update helper */
        if (m->selected != -1)
        {
            /* out of focus */
            strcpy(action_select.comment,"");
        }
        else if (filelist[selection].flags)
        {
            /* this is a directory */
            strcpy(action_select.comment,"Open Directory");
        }
        else
        {
            /* this is a ROM file */
            strcpy(action_select.comment,"Load File");
        }

        /* Draw menu*/
        GUI_DrawMenu(m);

#ifdef HW_RVL
        if (Shutdown)
        {
            gxTextureClose(&w_pointer);
            GUI_DeleteMenu(m);
            GUI_FadeOut();
            shutdown();
            SYS_ResetSystem(SYS_POWEROFF, 0, 0);
        }
        else if (m_input.ir.valid)
        {
            /* get cursor position */
            x = m_input.ir.x;
            y = m_input.ir.y;

            /* draw wiimote pointer */
            gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255);

            /* ensure we are in the selectable area */
            if ((x < 380) && (y >= 108) && (y <= 368))
            {
                /* find selected item */
                selection = (y - 108) / 26;
                if (selection > 9) selection = 9;
                selection += offset;
                if (selection >= maxfiles) selection = old;

                /* reset selection */
                m->selected = -1;
            }
            else
            {
                /* disable selection */
                m->selected = m->max_buttons + 2;

                /* find selected button */
                for (i=0; i<2; i++)
                {
                    button = m->arrows[i];
                    if (button)
                    {
                        if (button->state & BUTTON_VISIBLE)
                        {
                            if ((x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
                            {
                                m->selected = m->max_buttons + i;
                                break;
                            }
                        }
                    }
                }
            }
        }
        else
        {
            /* reset selection */
            m->selected = -1;
        }
#endif

        /* copy EFB to XFB */
        gxSetScreen();

        p = m_input.keys;

        /* highlight next item */
        if (p & PAD_BUTTON_DOWN)
        {
            selection++;
            if (selection == maxfiles)
                selection = offset = 0;
            if ((selection - offset) >= 10)
                offset += 10;
        }

        /* highlight previous item */
        else if (p & PAD_BUTTON_UP)
        {
            selection--;
            if (selection < 0)
            {
                selection = maxfiles - 1;
                offset = maxfiles - 10;
            }
            if (selection < offset)
                offset -= 10;
            if (offset < 0)
                offset = 0;
        }

        /* go back one page */
        else if (p & (PAD_TRIGGER_L | PAD_BUTTON_LEFT))
        {
            if (maxfiles >= 10)
            {
                selection -= 10;
                if (selection < 0)
                {
                    selection = offset = 0;
                }
                else if (selection < offset)
                {
                    offset -= 10;
                    if (offset < 0) offset = 0;
                }
            }
        }

        /* go forward one page */
        else if (p & (PAD_TRIGGER_R | PAD_BUTTON_RIGHT))
        {
            if (maxfiles >= 10)
            {
                selection += 10;
                if (selection > maxfiles - 1)
                {
                    /* last page */
                    selection = maxfiles - 1;
                    offset = maxfiles - 10;
                }
                else if (selection  >= (offset + 10))
                {
                    /* next page */
                    offset += 10;
                    if (offset > (maxfiles - 10)) offset = maxfiles - 10;
                }
            }
        }

        /* quit */
        else if (p & PAD_TRIGGER_Z)
        {
            GUI_DeleteMenu(m);
            return 0;
        }

        /* previous directory */
        else if (p & PAD_BUTTON_B)
        {
            string_offset = 0;

            /* update browser directory (and get current folder)*/
            if (UpdateDirectory(1, prev_folder))
            {
                /* get directory entries */
                maxfiles = ParseDirectory();

                /* clear selection by default */
                selection = offset = 0;
                old = -1;

                /* select previous directory */
                for (i=0; i<maxfiles; i++)
                {
                    if ((filelist[i].flags) && !strcmp(prev_folder,filelist[i].filename))
                    {
                        selection = i;
                        while (i  >= (offset + 10))
                        {
                            offset += 10;
                            if (offset > (maxfiles - 10)) offset = maxfiles - 10;
                        }
                        break;
                    }
                }
            }
            else
            {
                /* exit */
                GUI_DeleteMenu(m);
                return 0;
            }
        }

        /* open selected file or directory */
        else if (p & PAD_BUTTON_A)
        {
            string_offset = 0;

            /* ensure we are in focus area */
            if (m->selected < m->max_buttons)
            {
                if (filelist[selection].flags)
                {
                    /* get new directory */
                    UpdateDirectory(0, filelist[selection].filename);

                    /* get directory entries */
                    maxfiles = ParseDirectory();

                    /* clear selection by default */
                    selection = offset = 0;
                    old = -1;
                }
                else
                {
                    /* load ROM file from device */
                    int ret = LoadFile(selection);

                    /* exit menu */
                    GUI_DeleteMenu(m);

                    /* return ROM size (or zero if an error occured) */
                    return ret;
                }
            }

#ifdef HW_RVL
            /* arrow buttons selected */
            else if (m->selected == m->max_buttons)
            {
                /* up arrow */
                selection--;
                if (selection < 0)
                {
                    selection = maxfiles - 1;
                    offset = selection - 10 + 1;
                }
                if (selection < offset) offset -= 10;
                if (offset < 0) offset = 0;
            }
            else if (m->selected == (m->max_buttons+1))
            {
                /* down arrow */
                selection++;
                if (selection == maxfiles)
                    selection = offset = 0;
                if ((selection - offset) >= 10)
                    offset += 10;
            }
#endif
        }
    }
}
Ejemplo n.º 24
0
int gxsURL::ParseDynamicPage(const gxString &url, 
			     const gxString &my_dynamic_file_types,
			     const gxString &my_dynamic_dir_types,
			     int &is_dynamic,
			     gxString &query_string,
			     gxString &file_extension,
			     gxString &bin_dir,
			     gxString &local_query_file)
{
  is_dynamic = 0;
  query_string.Clear();
  file_extension.Clear();
  bin_dir.Clear();
  local_query_file.Clear();
  char words[MAXWORDS][MAXWORDLENGTH];
  int num_words, i;

  gxString url_buf = url;

  // Set the default host name ID and protocol string
  // if not already set by the caller.
  SetDefaultProto(url_buf);

  // Check for query sep character first converting
  // any hex codes in the URL to ASCII. Some
  // Web sites use hex code in place of the query 
  // string characters.
  url_buf.ConvertEscapeSeq('%', 2);
  if(url_buf.Find("?") != -1) {
    is_dynamic = 1;
    query_string = url_buf;
    query_string.DeleteBefore("?");
  }

  // Check for known dyanmic dot extenstions and bin directories
  gxString path, dir, file;
  ParseDirectory(url_buf, path, dir, file);

  if(file == "?") { // Assume this is a file 
    file = path;
    file.DeleteBeforeLastIncluding("/");
    file.FilterString("/");
    dir.FilterString(file);
  }

  if(!file.is_null()) { // Record the file's dot extension
    if(file.Find(".") != -1) {
      file_extension = file;
      // 09/10/2006: Must account for dynamic pages and targets
      file_extension.DeleteAfterIncluding("?");
      file_extension.DeleteAfterIncluding("#");

      // 03/30/2009: Account for JS session IDs
      // Example: /switchsite.ds;jsessionid=54D3A5C9DC8A767DF64B3A377FB3EA8B
      file_extension.DeleteAfterIncluding(";");

      file_extension.DeleteBeforeLast(".");
    }
    else {
      file_extension.Clear(); // This file has no extention
    }
  }

  if(!is_dynamic) {
    if(!file_extension.is_null()) {
      if(parse(my_dynamic_file_types.c_str(), words, &num_words, ' ') == 0) {
	for(i = 0; i < num_words; i++) {
	  if(*words[i] == 0) break;
	  if(file_extension.IFind(words[i]) != -1) {
	    is_dynamic = 1;
	    break;
	  }	
	}
      }
      else {
	if(my_dynamic_file_types.IFind(file_extension, 
				       file_extension.length(), 0) != -1) {
	  is_dynamic = 1;
	}
      }
    }
  }

  if(!is_dynamic) { // Check for known binary dirs used on the Web
    if(!dir.is_null()) {
      bin_dir = dir;
      if(bin_dir[bin_dir.length()-1] == '/') {
	bin_dir.DeleteAfterLastIncluding("/");
      }
      bin_dir.DeleteBeforeLastIncluding("/");
      if(bin_dir[0] != '/') {
	bin_dir.InsertAt(0, "/", 1);
      }
      bin_dir << "/";
      if(my_dynamic_dir_types.IFind(bin_dir) != -1) {
	is_dynamic = 1;
      }
      bin_dir.FilterString("/");
    }
  }

  if(is_dynamic) { 
    if(!file.is_null()) {
      // Clean the local file name so that is can be stored
      // to disk with a unique name for each dynamic page.
      if(!file_extension.is_null()) {
	int file_is_dynamic_page = 0;

	if(parse(my_dynamic_file_types.c_str(), words, &num_words, ' ') == 0) {
	  for(i = 0; i < num_words; i++) {
	    if(*words[i] == 0) break;
	    if(file_extension.IFind(words[i]) != -1) {
	      file_is_dynamic_page = 1;
	      break;
	    }	
	  }
	}
	else {
	  if(my_dynamic_file_types.IFind(file_extension, file_extension.length(), 0) != -1) {
	    file_is_dynamic_page = 1;	 
	  }
	}

	if(file_is_dynamic_page) {
	  // We know this a dyanmic Web page so make the local copy a static HTML page.
	  local_query_file << clear << file << ".html";
	}
	else {
	  // If this is a Web object we must keep the 
	  // orginal file extension.
	  gxString ext_buf = file.Right(file_extension.length());
	  if(ext_buf != file_extension) {
	    local_query_file << clear << file << file_extension;
	  }
	  else { // Prevent double file extensions
	    local_query_file << clear << file;
	  }
	}
      }
      else {
	local_query_file << clear << file << ".html";
      }
    }
    else {
      // No file was contained in the URL so the we a 
      // performing a query on the default index page in 
      // this directory.
      if(query_string.is_null()) {
	local_query_file = "index.html"; 
      }
      else {
	local_query_file << clear << "index.html" << query_string << ".html"; 
      }
    }
  }
  
  if(is_dynamic) { 
    if(!local_query_file.is_null()) {
      // Clean the local file name so that is can be stored
      // to disk with a unique name for each dynamic page.
      FilterQueryCharacters(local_query_file);

      // 11/15/2006: Remove any path characters from the file name
      local_query_file.ReplaceString("/", "_");

      // 12/05/2007: Ensure that the local file has a dot extension 
      gxString static_ext = local_query_file.Right(5);
      static_ext.ToLower();
      if(static_ext != ".html") local_query_file << ".html";

    }
    else {
      local_query_file = "index.html"; 
    }
  }

  // Return true if this is a dynamic Web page
  return is_dynamic == 1;
}