Пример #1
0
int
utils_find_file_path( const char *filename, char *ret_path,
		      utils_aux_type type )
{
  path_context ctx;
  struct stat stat_info;

  /* If given an absolute path, just look there */
  if( compat_is_absolute_path( filename ) ) {
    strncpy( ret_path, filename, PATH_MAX );
    return 0;
  }

  /* Otherwise look in some likely locations */
  init_path_context( &ctx, type );

  while( compat_get_next_path( &ctx ) ) {

#ifdef AMIGA
    snprintf( ret_path, PATH_MAX, "%s%s", ctx.path, filename );
#else
    snprintf( ret_path, PATH_MAX, "%s" FUSE_DIR_SEP_STR "%s", ctx.path,
              filename );
#endif
    if( !stat( ret_path, &stat_info ) ) return 0;

  }

  return 1;
}
Пример #2
0
int
compat_get_next_path( path_context *ctx )
{
  char buffer[ PATH_MAX ];
  const char *path_segment, *path2;

  switch( (ctx->state)++ ) {

    /* First look relative to the current directory */
  case 0:
    strncpy( ctx->path, ".", PATH_MAX );
    return 1;

    /* Then relative to the Fuse executable */
  case 1:

    switch( ctx->type ) {
    case UTILS_AUXILIARY_LIB: path_segment = "lib"; break;
    case UTILS_AUXILIARY_ROM: path_segment = "roms"; break;
    case UTILS_AUXILIARY_WIDGET: path_segment = "ui/widget"; break;
    case UTILS_AUXILIARY_GTK: path_segment = "ui/gtk"; break;
    default:
      ui_error( UI_ERROR_ERROR, "unknown auxiliary file type %d", ctx->type );
      return 0;
    }

    if( compat_is_absolute_path( fuse_progname ) ) {
      strncpy( buffer, fuse_progname, PATH_MAX );
      buffer[ PATH_MAX - 1 ] = '\0';
    } else {
      size_t len;
      len = PATH_MAX - strlen( fuse_progname ) - strlen( FUSE_DIR_SEP_STR );
      if( !getcwd( buffer, len ) ) {
        ui_error( UI_ERROR_ERROR, "error getting current working directory: %s",
	          strerror( errno ) );
        return 0;
      }
      strcat( buffer, FUSE_DIR_SEP_STR );
      strcat( buffer, fuse_progname );
    }

    path2 = dirname( buffer );
    snprintf( ctx->path, PATH_MAX, "%s" FUSE_DIR_SEP_STR "%s", path2,
              path_segment );
    return 1;

    /* Then where we may have installed the data files */
  case 2:

    path2 = "sd:/apps/fuse";
    strncpy( ctx->path, path2, PATH_MAX ); buffer[ PATH_MAX - 1 ] = '\0';
    return 1;

  case 3: return 0;
  }
  ui_error( UI_ERROR_ERROR, "unknown path_context state %d", ctx->state );
  fuse_abort();
}
Пример #3
0
int
compat_get_next_path( path_context *ctx )
{
  char buffer[ PATH_MAX ];
  const char *path_segment, *path2;

  switch( ctx->type ) {
  case UTILS_AUXILIARY_LIB: path_segment = "lib"; break;
  case UTILS_AUXILIARY_ROM: path_segment = "roms"; break;
  case UTILS_AUXILIARY_WIDGET: path_segment = "ui/widget"; break;
  case UTILS_AUXILIARY_GTK: path_segment = "ui/gtk"; break;
  default:
    ui_error( UI_ERROR_ERROR, "unknown auxiliary file type %d", ctx->type );
    return 0;
  }

  switch( (ctx->state)++ ) {

    /* First look relative to the Fuse executable */
  case 0:
    if( compat_is_absolute_path( fuse_progname ) ) {
      strncpy( buffer, fuse_progname, PATH_MAX );
      buffer[ PATH_MAX - 1 ] = '\0';
    } else {
      DWORD retval; 
      retval = GetModuleFileName( NULL, buffer, PATH_MAX );
      if( !retval ) return 0;
    }

    path2 = dirname( buffer );
    snprintf( ctx->path, PATH_MAX, "%s" FUSE_DIR_SEP_STR "%s", path2,
              path_segment );
    return 1;

    /* Then relative to %APPDATA%/Fuse directory */
  case 1:
    path2 = getenv( "APPDATA" );
    if( !path2 ) return 0;
    snprintf( ctx->path, PATH_MAX, "%s" FUSE_DIR_SEP_STR "Fuse" 
              FUSE_DIR_SEP_STR "%s", path2, path_segment );

    return 1;

    /* Then relative to the current directory */
  case 2:
    snprintf( ctx->path, PATH_MAX, "." FUSE_DIR_SEP_STR "%s",
              path_segment );
    return 1;

  case 3: return 0;
  }

  ui_error( UI_ERROR_ERROR, "unknown path_context state %d", ctx->state );
  fuse_abort();
}
Пример #4
0
/* Find the auxiliary file called `filename'; returns a fd for the
   file on success, -1 if it couldn't find the file */
static compat_fd
utils_find_auxiliary_file( const char *filename, utils_aux_type type )
{
  compat_fd fd;

  char path[ PATH_MAX ];

  /* If given an absolute path, just look there */
  if( compat_is_absolute_path( filename ) )
    return compat_file_open( filename, 0 );

  /* Otherwise look in some likely locations */
  if( utils_find_file_path( filename, path, type ) ) {
    return COMPAT_FILE_OPEN_FAILED;
  }

  fd = compat_file_open( path, 0 );

  if( fd != COMPAT_FILE_OPEN_FAILED ) return fd;

  /* Give up. Couldn't find this file */
  return COMPAT_FILE_OPEN_FAILED;
}