bool settings_save(Settings *setfile)
{
   char setfilename_tmp[1024];
   RFILE *fp = NULL;

   if (!setfile)
      setfile = &normal_settings;

   retro_create_path_string(setfilename_tmp, sizeof(setfilename_tmp), g_dir, setfilename);

   fp = filestream_open(setfilename_tmp, RETRO_VFS_FILE_ACCESS_WRITE, 
         RETRO_VFS_FILE_ACCESS_HINT_NONE);
   if (!fp)
   {
      NX_ERR("Couldn't open file %s.\n", setfilename_tmp);
      return 1;
   }

   NX_LOG("Writing settings...\n");

   for(int i=0;i<INPUT_COUNT;i++)
      setfile->input_mappings[i] = input_get_mapping(i);

   setfile->version = SETTINGS_VERSION;
   filestream_write(fp, setfile, sizeof(Settings));
   filestream_close(fp);
   return 0;
}
Beispiel #2
0
void playlist_write_file(playlist_t *playlist)
{
   size_t i;
   RFILE *file = NULL;

   if (!playlist || !playlist->modified)
      return;

   file = filestream_open(playlist->conf_path,
         RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (!file)
   {
      RARCH_ERR("Failed to write to playlist file: %s\n", playlist->conf_path);
      return;
   }

   for (i = 0; i < playlist->size; i++)
      filestream_printf(file, "%s\n%s\n%s\n%s\n%s\n%s\n",
            playlist->entries[i].path    ? playlist->entries[i].path    : "",
            playlist->entries[i].label   ? playlist->entries[i].label   : "",
            playlist->entries[i].core_path,
            playlist->entries[i].core_name,
            playlist->entries[i].crc32   ? playlist->entries[i].crc32   : "",
            playlist->entries[i].db_name ? playlist->entries[i].db_name : ""
            );

   playlist->modified = false;

   RARCH_LOG("Written to playlist file: %s\n", playlist->conf_path);

   filestream_close(file);
}
static bool tryload(Settings *setfile)
{
   char setfilename_tmp[1024];
   RFILE *fp = NULL;

   retro_create_path_string(setfilename_tmp, sizeof(setfilename_tmp), g_dir, setfilename);

   fp = filestream_open(setfilename_tmp, RETRO_VFS_FILE_ACCESS_READ, 
         RETRO_VFS_FILE_ACCESS_HINT_NONE);
   if (!fp)
   {
      NX_ERR("Couldn't open file %s.\n", setfilename_tmp);
      return 1;
   }

   NX_LOG("Loading settings...\n");

   setfile->version = 0;
   filestream_read(fp, setfile, sizeof(Settings));

   if (setfile->version != SETTINGS_VERSION)
   {
      NX_ERR("Wrong settings version %04x.\n", setfile->version);
      return 1;
   }

   filestream_close(fp);
   return 0;
}
Beispiel #4
0
bool intfstream_open(intfstream_internal_t *intf, const char *path,
      unsigned mode, unsigned hints)
{
   if (!intf)
      return false;

   switch (intf->type)
   {
      case INTFSTREAM_FILE:
         intf->file.fp = filestream_open(path, mode, hints);
         if (!intf->file.fp)
            return false;
         break;
      case INTFSTREAM_MEMORY:
         intf->memory.fp = memstream_open(intf->memory.writable);
         if (!intf->memory.fp)
            return false;
         break;
      case INTFSTREAM_CHD:
#ifdef HAVE_CHD
         intf->chd.fp = chdstream_open(path, intf->chd.track);
         if (!intf->chd.fp)
            return false;
         break;
#else
         return false;
#endif
   }

   return true;
}
static void gfx_ctx_mali_fbdev_destroy(void *data)
{
   int fb;
   RFILE             *fd = NULL;
   mali_ctx_data_t *mali = (mali_ctx_data_t*)data;

   if (mali)
   {
#ifdef HAVE_EGL
       egl_destroy(&mali->egl);
#endif

       mali->resize       = false;
       free(mali);
   }

   /* Clear framebuffer and set cursor on again */
   fd = filestream_open("/dev/tty", RFILE_MODE_READ_WRITE, -1);
   fb = filestream_get_fd(fd);

   ioctl(fb, VT_ACTIVATE,5);
   ioctl(fb, VT_ACTIVATE,1);
   filestream_close(fd);
   system("setterm -cursor on");
}
Beispiel #6
0
int detect_system(const char *track_path, const char **system_name)
{
   int rv;
   char magic[MAGIC_LEN];
   int i;
   RFILE *fd = filestream_open(track_path, RFILE_MODE_READ, -1);
   
   if (!fd)
   {
      RARCH_LOG("Could not open data track of file '%s': %s\n",
            track_path, strerror(errno));
      rv = -errno;
      goto clean;
   }

   RARCH_LOG("%s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
   for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
   {
      filestream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET);

      if (filestream_read(fd, magic, MAGIC_LEN) < MAGIC_LEN)
      {
         RARCH_LOG("Could not read data from file '%s' at offset %d: %s\n",
               track_path, MAGIC_NUMBERS[i].offset, strerror(errno));
         rv = -errno;
         goto clean;
      }

      if (!string_is_empty(MAGIC_NUMBERS[i].magic) &&
          !string_is_empty(magic) &&
          string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
      {
         *system_name = MAGIC_NUMBERS[i].system_name;
         rv = 0;
         goto clean;
      }
   }

   filestream_seek(fd, 0x8008, SEEK_SET);
   if (filestream_read(fd, magic, 8) > 0)
   {
      magic[8] = '\0';
      if (!string_is_empty(magic) &&
            string_is_equal_fast(magic, "PSP GAME", 8))
      {
         *system_name = "psp\0";
         rv = 0;
         goto clean;
      }
   }

   RARCH_LOG("%s\n", msg_hash_to_str(MSG_COULD_NOT_FIND_COMPATIBLE_SYSTEM));
   rv = -EINVAL;

clean:
   filestream_close(fd);
   return rv;
}
Beispiel #7
0
rxml_document_t *rxml_load_document(const char *path)
{
#ifndef RXML_TEST
   RARCH_WARN("Using RXML as drop in for libxml2. Behavior might be very buggy.\n");
#endif

   char *memory_buffer     = NULL;
   char *new_memory_buffer = NULL;
   const char *mem_ptr     = NULL;
   long len                = 0;
   RFILE *file             = filestream_open(path, RFILE_MODE_READ, -1);
   if (!file)
      return NULL;

   rxml_document_t *doc = (rxml_document_t*)calloc(1, sizeof(*doc));
   if (!doc)
      goto error;

   filestream_seek(file, 0, SEEK_END);
   len = filestream_tell(file);
   filestream_rewind(file);

   memory_buffer = (char*)malloc(len + 1);
   if (!memory_buffer)
      goto error;

   memory_buffer[len] = '\0';
   if (filestream_read(file, memory_buffer, len) != (size_t)len)
      goto error;

   filestream_close(file);
   file = NULL;

   mem_ptr = memory_buffer;

   if (!validate_header(&mem_ptr))
      goto error;

   new_memory_buffer = purge_xml_comments(mem_ptr);
   if (!new_memory_buffer)
      goto error;

   free(memory_buffer);
   mem_ptr = memory_buffer = new_memory_buffer;

   doc->root_node = rxml_parse_node(&mem_ptr);
   if (!doc->root_node)
      goto error;

   free(memory_buffer);
   return doc;

error:
   free(memory_buffer);
   filestream_close(file);
   rxml_free_document(doc);
   return NULL;
}
Beispiel #8
0
/**
 * filestream_read_file:
 * @path             : path to file.
 * @buf              : buffer to allocate and read the contents of the
 *                     file into. Needs to be freed manually.
 *
 * Read the contents of a file into @buf.
 *
 * Returns: number of items read, -1 on error.
 */
int filestream_read_file(const char *path, void **buf, ssize_t *len)
{
   ssize_t ret              = 0;
   ssize_t content_buf_size = 0;
   void *content_buf        = NULL;
   RFILE *file              = filestream_open(path, RFILE_MODE_READ, -1);

   if (!file)
   {
      fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
      goto error;
   }

   if (filestream_seek(file, 0, SEEK_END) != 0)
      goto error;

   content_buf_size = filestream_tell(file);
   if (content_buf_size < 0)
      goto error;

   filestream_rewind(file);

   content_buf = malloc(content_buf_size + 1);

   if (!content_buf)
      goto error;

   ret = filestream_read(file, content_buf, content_buf_size);
   if (ret < 0)
   {
      fprintf(stderr, "Failed to read %s: %s\n", path, strerror(errno));
      goto error;
   }

   filestream_close(file);

   *buf    = content_buf;

   /* Allow for easy reading of strings to be safe.
    * Will only work with sane character formatting (Unix). */
   ((char*)content_buf)[content_buf_size] = '\0';

   if (len)
      *len = ret;

   return 1;

error:
   if (file)
      filestream_close(file);
   if (content_buf)
      free(content_buf);
   if (len)
      *len = -1;
   *buf = NULL;
   return 0;
}
/**
 * filestream_read_file:
 * @path             : path to file.
 * @buf              : buffer to allocate and read the contents of the
 *                     file into. Needs to be freed manually.
 *
 * Read the contents of a file into @buf.
 *
 * Returns: number of items read, -1 on error.
 */
int64_t filestream_read_file(const char *path, void **buf, int64_t *len)
{
   int64_t ret              = 0;
   int64_t content_buf_size = 0;
   void *content_buf        = NULL;
   RFILE *file              = filestream_open(path,
         RETRO_VFS_FILE_ACCESS_READ,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (!file)
   {
      fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
      goto error;
   }

   content_buf_size = filestream_get_size(file);

   if (content_buf_size < 0)
      goto error;

   content_buf      = malloc((size_t)(content_buf_size + 1));

   if (!content_buf)
      goto error;
   if ((int64_t)(uint64_t)(content_buf_size + 1) != (content_buf_size + 1))
      goto error;

   ret = filestream_read(file, content_buf, (int64_t)content_buf_size);
   if (ret < 0)
   {
      fprintf(stderr, "Failed to read %s: %s\n", path, strerror(errno));
      goto error;
   }

   filestream_close(file);

   *buf    = content_buf;

   /* Allow for easy reading of strings to be safe.
    * Will only work with sane character formatting (Unix). */
   ((char*)content_buf)[ret] = '\0';

   if (len)
      *len = ret;

   return 1;

error:
   if (file)
      filestream_close(file);
   if (content_buf)
      free(content_buf);
   if (len)
      *len = -1;
   *buf = NULL;
   return 0;
}
Beispiel #10
0
rxml_document_t *rxml_load_document(const char *path)
{
   rxml_document_t *doc;
   char *memory_buffer     = NULL;
   char *new_memory_buffer = NULL;
   const char *mem_ptr     = NULL;
   long len                = 0;
   RFILE *file             = filestream_open(path,
         RETRO_VFS_FILE_ACCESS_READ,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);
   if (!file)
      return NULL;

   doc = (rxml_document_t*)calloc(1, sizeof(*doc));
   if (!doc)
      goto error;

   len           = filestream_get_size(file);
   memory_buffer = (char*)malloc(len + 1);
   if (!memory_buffer)
      goto error;

   memory_buffer[len] = '\0';
   if (filestream_read(file, memory_buffer, len) != (size_t)len)
      goto error;

   filestream_close(file);
   file = NULL;

   mem_ptr = memory_buffer;

   if (!validate_header(&mem_ptr))
      goto error;

   new_memory_buffer = purge_xml_comments(mem_ptr);
   if (!new_memory_buffer)
      goto error;

   free(memory_buffer);
   mem_ptr = memory_buffer = new_memory_buffer;

   doc->root_node = rxml_parse_node(&mem_ptr);
   if (!doc->root_node)
      goto error;

   free(memory_buffer);
   return doc;

error:
   free(memory_buffer);
   filestream_close(file);
   rxml_free_document(doc);
   return NULL;
}
FileStream::FileStream(const char *path, const int mode)
{
   fp = filestream_open(path, (mode == MODE_WRITE || mode == MODE_WRITE_INPLACE) ? RETRO_VFS_FILE_ACCESS_WRITE : RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (!fp)
   {
      ErrnoHolder ene(errno);

      MDFN_Error(ene.Errno(), "Error opening file:\n%s\n%s", path, ene.StrError());
   }
}
int detect_system(const char *track_path, int32_t offset,
        const char **system_name)
{
   int rv;
   char magic[MAGIC_LEN];
   int i;
   RFILE *fd = filestream_open(track_path, RFILE_MODE_READ, -1);
   
   if (!fd)
   {
      RARCH_LOG("Could not open data track of file '%s': %s\n",
            track_path, strerror(errno));
      rv = -errno;
      goto clean;
   }

   filestream_seek(fd, offset, SEEK_SET);
   if (filestream_read(fd, magic, MAGIC_LEN) < MAGIC_LEN)
   {
      RARCH_LOG("Could not read data from file '%s' at offset %d: %s\n",
            track_path, offset, strerror(errno));
      rv = -errno;
      goto clean;
   }

   RARCH_LOG("Comparing with known magic numbers...\n");
   for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
   {
      if (memcmp(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN) == 0)
      {
         *system_name = MAGIC_NUMBERS[i].system_name;
         rv = 0;
         goto clean;
      }
   }

   filestream_seek(fd, 0x8008, SEEK_SET);
   if (filestream_read(fd, magic, 8) > 0)
   {
      magic[8] = '\0';
      if (string_is_equal(magic, "PSP GAME"))
      {
         *system_name = "psp\0";
         rv = 0;
         goto clean;
      }
   }

   RARCH_LOG("Could not find compatible system\n");
   rv = -EINVAL;
clean:
   filestream_close(fd);
   return rv;
}
Beispiel #13
0
static bool gfx_ctx_mali_fbdev_set_video_mode(void *data,
      video_frame_info_t *video_info,
      unsigned width, unsigned height,
      bool fullscreen)
{
   struct fb_var_screeninfo vinfo;
   static const EGLint attribs[] = {
      EGL_CONTEXT_CLIENT_VERSION, 2, /* Use version 2, even for GLES3. */
      EGL_NONE
   };
   mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
   RFILE *fd             = filestream_open("/dev/fb0", RFILE_MODE_READ_WRITE, -1);
   int fb                = filestream_get_fd(fd);

   if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0)
   {
      RARCH_ERR("Error obtaining framebuffer info.\n");
      goto error;
   }

   filestream_close(fd);
   
   width                      = vinfo.xres;
   height                     = vinfo.yres;

   mali->width                = width;
   mali->height               = height;

   mali->native_window.width  = vinfo.xres;
   mali->native_window.height = vinfo.yres;

#ifdef HAVE_EGL
   if (!egl_create_context(&mali->egl, attribs))
   {
      egl_report_error();
      goto error;
   }
#endif

#ifdef HAVE_EGL
   if (!egl_create_surface(&mali->egl, &mali->native_window))
      goto error;
#endif

   return true;

error:
   if (fd)
      filestream_close(fd);
   RARCH_ERR("[Mali fbdev]: EGL error: %d.\n", eglGetError());
   gfx_ctx_mali_fbdev_destroy(data);
   return false;
}
/**
 * filestream_write_file:
 * @path             : path to file.
 * @data             : contents to write to the file.
 * @size             : size of the contents.
 *
 * Writes data to a file.
 *
 * Returns: true (1) on success, false (0) otherwise.
 */
bool filestream_write_file(const char *path, const void *data, ssize_t size)
{
   ssize_t ret   = 0;
   RFILE *file   = filestream_open(path, RFILE_MODE_WRITE, -1);
   if (!file)
      return false;

   ret = filestream_write(file, data, size);
   filestream_close(file);

   return (ret == size);
}
/* Callback wrappers */
bool filestream_exists(const char *path)
{
   RFILE *dummy              = NULL;

   if (!path || !*path)
      return false;

   dummy = filestream_open(path,
         RETRO_VFS_FILE_ACCESS_READ,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (!dummy)
      return false;

   filestream_close(dummy);
   return true;
}
/**
 * filestream_write_file:
 * @path             : path to file.
 * @data             : contents to write to the file.
 * @size             : size of the contents.
 *
 * Writes data to a file.
 *
 * Returns: true (1) on success, false (0) otherwise.
 */
bool filestream_write_file(const char *path, const void *data, int64_t size)
{
   int64_t ret   = 0;
   RFILE *file   = filestream_open(path,
         RETRO_VFS_FILE_ACCESS_WRITE,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);
   if (!file)
      return false;

   ret = filestream_write(file, data, size);
   filestream_close(file);

   if (ret != size)
      return false;

   return true;
}
Beispiel #17
0
/**
 * libretrodb_cursor_open:
 * @db                  : Handle to database.
 * @cursor              : Handle to database cursor.
 * @q                   : Query to execute.
 *
 * Opens cursor to database based on query @q.
 *
 * Returns: 0 if successful, otherwise negative.
 **/
int libretrodb_cursor_open(libretrodb_t *db, libretrodb_cursor_t *cursor,
      libretrodb_query_t *q)
{
   cursor->fd = filestream_open(db->path, RFILE_MODE_READ | RFILE_HINT_MMAP, -1);

   if (!cursor->fd)
      return -errno;

   cursor->db = db;
   cursor->is_valid = 1;
   libretrodb_cursor_reset(cursor);
   cursor->query = q;

   if (q)
      libretrodb_query_inc_ref(q);

   return 0;
}
Beispiel #18
0
int libretrodb_open(const char *path, libretrodb_t *db)
{
   libretrodb_header_t header;
   libretrodb_metadata_t md;
   int rv;
   RFILE *fd = filestream_open(path, RFILE_MODE_READ, -1);

   if (!fd)
      return -errno;

   strlcpy(db->path, path, sizeof(db->path));
   db->root = filestream_seek(fd, 0, SEEK_CUR);

   if ((rv = filestream_read(fd, &header, sizeof(header))) == -1)
   {
      rv = -errno;
      goto error;
   }

   if (strncmp(header.magic_number, MAGIC_NUMBER, sizeof(MAGIC_NUMBER)) != 0)
   {
      rv = -EINVAL;
      goto error;
   }

   header.metadata_offset = swap_if_little64(header.metadata_offset);
   filestream_seek(fd, (ssize_t)header.metadata_offset, SEEK_SET);

   if (libretrodb_read_metadata(fd, &md) < 0)
   {
      rv = -EINVAL;
      goto error;
   }

   db->count = md.count;
   db->first_index_offset = filestream_seek(fd, 0, SEEK_CUR);
   db->fd = fd;
   return 0;

error:
   if (fd)
      filestream_close(fd);
   return rv;
}
Beispiel #19
0
int sha1_calculate(const char *path, char *result)
{
   SHA1Context sha;
   unsigned char buff[4096];
   int rv    = 1;
   RFILE *fd = filestream_open(path, RFILE_MODE_READ, -1);

   if (!fd)
      goto error;

   buff[0] = '\0';

   SHA1Reset(&sha);

   do
   {
      rv = filestream_read(fd, buff, 4096);
      if (rv < 0)
         goto error;

      SHA1Input(&sha, buff, rv);
   }while(rv);

   if (!SHA1Result(&sha))
      goto error;

   sprintf(result, "%08X%08X%08X%08X%08X",
         sha.Message_Digest[0],
         sha.Message_Digest[1],
         sha.Message_Digest[2],
         sha.Message_Digest[3], sha.Message_Digest[4]);

   filestream_close(fd);
   return 0;

error:
   if (fd)
      filestream_close(fd);
   return -1;
}
RFILE* rfopen(const char *path, const char *mode)
{
   RFILE          *output  = NULL;
   unsigned int retro_mode = RETRO_VFS_FILE_ACCESS_READ;
   bool position_to_end    = false;

   if (strstr(mode, "r"))
   {
      retro_mode = RETRO_VFS_FILE_ACCESS_READ;
      if (strstr(mode, "+"))
      {
         retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE | 
            RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING;
      }
   }
   else if (strstr(mode, "w"))
   {
      retro_mode = RETRO_VFS_FILE_ACCESS_WRITE;
      if (strstr(mode, "+"))
         retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE;
   }
   else if (strstr(mode, "a"))
   {
      retro_mode = RETRO_VFS_FILE_ACCESS_WRITE | 
         RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING;
      position_to_end = true;
      if (strstr(mode, "+"))
      {
         retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE | 
            RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING;
      }
   }

   output = filestream_open(path, retro_mode,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);
   if (output && position_to_end)
      filestream_seek(output, 0, RETRO_VFS_SEEK_POSITION_END);

   return output;
}
bool intfstream_open(intfstream_internal_t *intf, const char *path,
      unsigned mode, ssize_t len)
{
   if (!intf)
      return false;

   switch (intf->type)
   {
      case INTFSTREAM_FILE:
         intf->file.fp = filestream_open(path, mode, len);
         if (!intf->file.fp)
            return false;
         break;
      case INTFSTREAM_MEMORY:
         intf->memory.fp = memstream_open(intf->memory.writable);
         if (!intf->memory.fp)
            return false;
         break;
   }

   return true;
}
int find_first_data_track(const char *cue_path,
      int32_t *offset, char *track_path, size_t max_len)
{
   int rv, m, s, f;
   char tmp_token[MAX_TOKEN_LEN];
   char cue_dir[PATH_MAX_LENGTH];
   RFILE *fd;

   strlcpy(cue_dir, cue_path, sizeof(cue_dir));
   path_basedir(cue_dir);

   fd = filestream_open(cue_path, RFILE_MODE_READ, -1);
   if (!fd)
   {
      RARCH_LOG("Could not open CUE file '%s': %s\n", cue_path,
            strerror(errno));
      return -errno;
   }

   RARCH_LOG("Parsing CUE file '%s'...\n", cue_path);

   while (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
   {
      if (string_is_equal(tmp_token, "FILE"))
      {
         get_token(fd, tmp_token, MAX_TOKEN_LEN);
         fill_pathname_join(track_path, cue_dir, tmp_token, max_len);

      }
      else if (string_is_equal_noncase(tmp_token, "TRACK"))
      {
         get_token(fd, tmp_token, MAX_TOKEN_LEN);
         get_token(fd, tmp_token, MAX_TOKEN_LEN);
         if (string_is_equal_noncase(tmp_token, "AUDIO"))
            continue;

         find_token(fd, "INDEX");
         get_token(fd, tmp_token, MAX_TOKEN_LEN);
         get_token(fd, tmp_token, MAX_TOKEN_LEN);

         if (sscanf(tmp_token, "%02d:%02d:%02d", &m, &s, &f) < 3)
         {
            RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token);
            return -errno;
         }

         *offset = ((m * 60) * (s * 75) * f) * 25;

         RARCH_LOG("Found 1st data track on file '%s+%d'\n",
               track_path, *offset);

         rv = 0;
         goto clean;
      }
   }

   rv = -EINVAL;

clean:
   filestream_close(fd);
   return rv;
}
/** 
 * video_shader_resolve_parameters:
 * @conf              : Preset file to read from.
 * @shader            : Shader passes handle.
 *
 * Resolves all shader parameters belonging to shaders. 
 *
 * Returns: true (1) if successful, otherwise false (0).
 **/
bool video_shader_resolve_parameters(config_file_t *conf,
      struct video_shader *shader)
{
   unsigned i;
   struct video_shader_parameter *param = &shader->parameters[0];

   shader->num_parameters = 0;

   /* Find all parameters in our shaders. */

   for (i = 0; i < shader->passes; i++)
   {
#ifdef HAVE_SLANG
      /* First try to use the more robust slang implementation to support #includes. */
      /* FIXME: The check for slang can be removed if it's sufficiently tested for
       * GLSL/Cg as well, it should be the same implementation. */
      if (string_is_equal(path_get_extension(shader->pass[i].source.path), "slang") &&
            slang_preprocess_parse_parameters(shader->pass[i].source.path, shader))
         continue;
      /* If that doesn't work, fallback to the old path.
       * Ideally, we'd get rid of this path sooner or later. */
#endif

      char line[4096];
      RFILE *file = filestream_open(shader->pass[i].source.path, RFILE_MODE_READ_TEXT, -1);

      if (!file)
         continue;

      line[0] = '\0';

      while (shader->num_parameters < ARRAY_SIZE(shader->parameters)
            && filestream_gets(file, line, sizeof(line)))
      {
         int ret = sscanf(line,
               "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f",
               param->id, param->desc, &param->initial,
               &param->minimum, &param->maximum, &param->step);

         if (ret < 5)
            continue;

         param->id[63]   = '\0';
         param->desc[63] = '\0';

         if (ret == 5)
            param->step = 0.1f * (param->maximum - param->minimum);

         RARCH_LOG("Found #pragma parameter %s (%s) %f %f %f %f\n",
               param->desc, param->id, param->initial,
               param->minimum, param->maximum, param->step);
         param->current = param->initial;

         shader->num_parameters++;
         param++;
      }

      filestream_close(file);
   }

   if (conf && !video_shader_resolve_current_parameters(conf, shader))
      return false;

   return true;
}
int detect_psp_game(const char *track_path, char *game_id)
{
   unsigned pos;
   bool rv   = false;
   RFILE *fd = filestream_open(track_path, RFILE_MODE_READ, -1);

   if (!fd)
   {
      RARCH_LOG("Could not open data track: %s\n", strerror(errno));
      return -errno;
   }

   for (pos = 0; pos < 100000; pos++)
   {
      filestream_seek(fd, pos, SEEK_SET);

      if (filestream_read(fd, game_id, 5) > 0)
      {
         game_id[5] = '\0';
         if (string_is_equal(game_id, "ULES-")
          || string_is_equal(game_id, "ULUS-")
          || string_is_equal(game_id, "ULJS-")

          || string_is_equal(game_id, "ULEM-")
          || string_is_equal(game_id, "ULUM-")
          || string_is_equal(game_id, "ULJM-")

          || string_is_equal(game_id, "UCES-")
          || string_is_equal(game_id, "UCUS-")
          || string_is_equal(game_id, "UCJS-")
          || string_is_equal(game_id, "UCAS-")

          || string_is_equal(game_id, "NPEH-")
          || string_is_equal(game_id, "NPUH-")
          || string_is_equal(game_id, "NPJH-")

          || string_is_equal(game_id, "NPEG-")
          || string_is_equal(game_id, "NPUG-")
          || string_is_equal(game_id, "NPJG-")
          || string_is_equal(game_id, "NPHG-")

          || string_is_equal(game_id, "NPEZ-")
          || string_is_equal(game_id, "NPUZ-")
          || string_is_equal(game_id, "NPJZ-")
         )
         {
            filestream_seek(fd, pos, SEEK_SET);
            if (filestream_read(fd, game_id, 10) > 0)
            {
#if 0
               game_id[4] = '-';
               game_id[8] = game_id[9];
               game_id[9] = game_id[10];
#endif
               game_id[10] = '\0';
               rv = true;
            }
            break;
         }
      }
      else
         break;
   }

   filestream_close(fd);
   return rv;
}
Beispiel #25
0
int find_first_data_track(const char *cue_path,
      int32_t *offset, char *track_path, size_t max_len)
{
   int rv;
   char tmp_token[MAX_TOKEN_LEN];
   RFILE *fd                     = 
      filestream_open(cue_path, RFILE_MODE_READ, -1);

   if (!fd)
   {
      RARCH_LOG("Could not open CUE file '%s': %s\n", cue_path,
            strerror(errno));
      return -errno;
   }

   RARCH_LOG("Parsing CUE file '%s'...\n", cue_path);

   tmp_token[0] = '\0';

   while (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
   {
      if (!string_is_empty(tmp_token))
      {
         if (string_is_equal_fast(tmp_token, "FILE", 4))
         {
            char cue_dir[PATH_MAX_LENGTH];

            cue_dir[0] = '\0';

            fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));

            get_token(fd, tmp_token, MAX_TOKEN_LEN);
            fill_pathname_join(track_path, cue_dir, tmp_token, max_len);

         }
         else if (string_is_equal_fast(tmp_token, "TRACK", 5))
         {
            int m, s, f;
            get_token(fd, tmp_token, MAX_TOKEN_LEN);
            get_token(fd, tmp_token, MAX_TOKEN_LEN);

            if (string_is_equal_fast(tmp_token, "AUDIO", 5))
               continue;

            find_token(fd, "INDEX");
            get_token(fd, tmp_token, MAX_TOKEN_LEN);
            get_token(fd, tmp_token, MAX_TOKEN_LEN);

            if (sscanf(tmp_token, "%02d:%02d:%02d", &m, &s, &f) < 3)
            {
               RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token);
               filestream_close(fd);
               return -errno;
            }

            *offset = ((m * 60) * (s * 75) * f) * 25;

            RARCH_LOG("%s '%s+%d'\n",
                  msg_hash_to_str(MSG_FOUND_FIRST_DATA_TRACK_ON_FILE),
                  track_path, *offset);

            rv = 0;
            goto clean;
         }
      }
   }

   rv = -EINVAL;

clean:
   filestream_close(fd);
   return rv;
}
static int detect_ps1_game_sub(const char *track_path,
      char *game_id, int sub_channel_mixed)
{
   uint8_t* tmp;
   uint8_t buffer[2048 * 2];
   int skip, frame_size, is_mode1, cd_sector;
   RFILE *fp = filestream_open(track_path, RFILE_MODE_READ, -1);
   if (!fp)
      return 0;

   is_mode1 = 0;
   filestream_seek(fp, 0, SEEK_END);

   if (!sub_channel_mixed)
   {
      if (!(filestream_tell(fp) & 0x7FF))
      {
         unsigned int mode_test = 0;

         filestream_seek(fp, 0, SEEK_SET);
         filestream_read(fp, &mode_test, 4);
         if (mode_test != MODETEST_VAL)
            is_mode1 = 1;
      }
   }

   skip       = is_mode1? 0: 24;
   frame_size = sub_channel_mixed? 2448: is_mode1? 2048: 2352;

   filestream_seek(fp, 156 + skip + 16 * frame_size, SEEK_SET);
   filestream_read(fp, buffer, 6);

   cd_sector = buffer[2] | (buffer[3] << 8) | (buffer[4] << 16);
   filestream_seek(fp, skip + cd_sector * frame_size, SEEK_SET);
   filestream_read(fp, buffer, 2048 * 2);

   tmp = buffer;
   while (tmp < (buffer + 2048 * 2))
   {
      if (!*tmp)
         return 0;

      if (!strncasecmp((const char*)(tmp + 33), "SYSTEM.CNF;1", 12))
         break;

      tmp += *tmp;
   }
   if(tmp >= (buffer + 2048 * 2))
      return 0;

   cd_sector = tmp[2] | (tmp[3] << 8) | (tmp[4] << 16);
   filestream_seek(fp, 13 + skip + cd_sector * frame_size, SEEK_SET);
   filestream_read(fp, buffer, 256);

   tmp = (uint8_t*)strrchr((const char*)buffer, '\\');
   if(!tmp)
      tmp = buffer;
   else
      tmp++;

   *game_id++ = toupper(*tmp++);
   *game_id++ = toupper(*tmp++);
   *game_id++ = toupper(*tmp++);
   *game_id++ = toupper(*tmp++);
   *game_id++ = '-';
   tmp++;
   *game_id++ = *tmp++;
   *game_id++ = *tmp++;
   *game_id++ = *tmp++;
   tmp++;
   *game_id++ = *tmp++;
   *game_id++ = *tmp++;
   *game_id = 0;

   filestream_close(fp);
   return 1;
}
Beispiel #27
0
/* Parses log file referenced by runtime_log->path.
 * Does nothing if log file does not exist. */
static void runtime_log_read_file(runtime_log_t *runtime_log)
{
   unsigned runtime_hours = 0;
   unsigned runtime_minutes = 0;
   unsigned runtime_seconds = 0;
   
   unsigned last_played_year = 0;
   unsigned last_played_month = 0;
   unsigned last_played_day = 0;
   unsigned last_played_hour = 0;
   unsigned last_played_minute = 0;
   unsigned last_played_second = 0;
   
   RtlJSONContext context = {0};
   RFILE *file = NULL;
   int ret = 0;
   
   /* Check if log file exists */
   if (!filestream_exists(runtime_log->path))
      return;
   
   /* Attempt to open log file */
   file = filestream_open(runtime_log->path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
   
   if (!file)
   {
      RARCH_ERR("Failed to open runtime log file: %s\n", runtime_log->path);
      return;
   }
   
   /* Initialise JSON parser */
   context.runtime_string = NULL;
   context.last_played_string = NULL;
   context.parser = JSON_Parser_Create(NULL);
   context.file = file;
   
   if (!context.parser)
   {
      RARCH_ERR("Failed to create JSON parser.\n");
      goto end;
   }
   
   /* Configure parser */
   JSON_Parser_SetAllowBOM(context.parser, JSON_True);
   JSON_Parser_SetStringHandler(context.parser, &RtlJSONStringHandler);
   JSON_Parser_SetObjectMemberHandler(context.parser, &RtlJSONObjectMemberHandler);
   JSON_Parser_SetUserData(context.parser, &context);
   
   /* Read file */
   while (!filestream_eof(file))
   {
      /* Runtime log files are tiny - use small chunk size */
      char chunk[128] = {0};
      int64_t length = filestream_read(file, chunk, sizeof(chunk));
      
      /* Error checking... */
      if (!length && !filestream_eof(file))
      {
         RARCH_ERR("Failed to read runtime log file: %s\n", runtime_log->path);
         JSON_Parser_Free(context.parser);
         goto end;
      }
      
      /* Parse chunk */
      if (!JSON_Parser_Parse(context.parser, chunk, length, JSON_False))
      {
         RARCH_ERR("Error parsing chunk of runtime log file: %s\n---snip---\n%s\n---snip---\n", runtime_log->path, chunk);
         RtlJSONLogError(&context);
         JSON_Parser_Free(context.parser);
         goto end;
      }
   }
   
   /* Finalise parsing */
   if (!JSON_Parser_Parse(context.parser, NULL, 0, JSON_True))
   {
      RARCH_WARN("Error parsing runtime log file: %s\n", runtime_log->path);
      RtlJSONLogError(&context);
      JSON_Parser_Free(context.parser);
      goto end;
   }
   
   /* Free parser */
   JSON_Parser_Free(context.parser);
   
   /* Process string values read from JSON file */
   
   /* Runtime */
   ret = 0;
   if (!string_is_empty(context.runtime_string))
      ret = sscanf(context.runtime_string, LOG_FILE_RUNTIME_FORMAT_STR,
                  &runtime_hours, &runtime_minutes, &runtime_seconds);
   
   if (ret != 3)
   {
      RARCH_ERR("Runtime log file - invalid 'runtime' entry detected: %s\n", runtime_log->path);
      goto end;
   }
   
   /* Last played */
   ret = 0;
   if (!string_is_empty(context.last_played_string))
      ret = sscanf(context.last_played_string, LOG_FILE_LAST_PLAYED_FORMAT_STR,
                  &last_played_year, &last_played_month, &last_played_day,
                  &last_played_hour, &last_played_minute, &last_played_second);
   
   if (ret != 6)
   {
      RARCH_ERR("Runtime log file - invalid 'last played' entry detected: %s\n", runtime_log->path);
      goto end;
   }
   
   /* If we reach this point then all is well
    * > Assign values to runtime_log object */
   runtime_log->runtime.hours = runtime_hours;
   runtime_log->runtime.minutes = runtime_minutes;
   runtime_log->runtime.seconds = runtime_seconds;
   
   runtime_log->last_played.year = last_played_year;
   runtime_log->last_played.month = last_played_month;
   runtime_log->last_played.day = last_played_day;
   runtime_log->last_played.hour = last_played_hour;
   runtime_log->last_played.minute = last_played_minute;
   runtime_log->last_played.second = last_played_second;
   
end:
   
   /* Clean up leftover strings */
   if (context.runtime_string)
      free(context.runtime_string);
   if (context.last_played_string)
      free(context.last_played_string);
   
   /* Close log file */
   filestream_close(file);
}
Beispiel #28
0
static config_file_t *config_file_new_internal(
      const char *path, unsigned depth, config_file_cb_t *cb)
{
   RFILE              *file = NULL;
   struct config_file *conf = (struct config_file*)malloc(sizeof(*conf));
   if (!conf)
      return NULL;

   conf->path                     = NULL;
   conf->entries                  = NULL;
   conf->tail                     = NULL;
   conf->last                     = NULL;
   conf->includes                 = NULL;
   conf->include_depth            = 0;
   conf->guaranteed_no_duplicates = false ;

   if (!path || !*path)
      return conf;

   if (path_is_directory(path))
      goto error;

   conf->path          = strdup(path);
   if (!conf->path)
      goto error;

   conf->include_depth = depth;
   file                = filestream_open(path,
         RETRO_VFS_FILE_ACCESS_READ,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (!file)
   {
      free(conf->path);
      goto error;
   }

   while (!filestream_eof(file))
   {
      char *line                     = NULL;
      struct config_entry_list *list = (struct config_entry_list*)malloc(sizeof(*list));

      if (!list)
      {
         config_file_free(conf);
         filestream_close(file);
         return NULL;
      }

      list->readonly  = false;
      list->key       = NULL;
      list->value     = NULL;
      list->next      = NULL;

      line            = filestream_getline(file);

      if (!line)
      {
         free(list);
         continue;
      }

      if (*line && parse_line(conf, list, line, cb))
      {
         if (conf->entries)
            conf->tail->next = list;
         else
            conf->entries = list;

         conf->tail = list;

         if (cb != NULL && list->key != NULL && list->value != NULL)
            cb->config_file_new_entry_cb(list->key, list->value) ;
      }

      free(line);

      if (list != conf->tail)
         free(list);
   }

   filestream_close(file);

   return conf;

error:
   free(conf);

   return NULL;
}
Beispiel #29
0
/* Saves specified runtime log to disk */
void runtime_log_save(runtime_log_t *runtime_log)
{
   RtlJSONContext context = {0};
   RFILE *file = NULL;
   char value_string[64]; /* 64 characters should be enough for a very long runtime... :) */
   int n;
   
   if (!runtime_log)
      return;
   
   RARCH_LOG("Saving runtime log file: %s\n", runtime_log->path);
   
   /* Attempt to open log file */
   file = filestream_open(runtime_log->path, RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);
   
   if (!file)
   {
      RARCH_ERR("Failed to open runtime log file: %s\n", runtime_log->path);
      return;
   }
   
   /* Initialise JSON writer */
   context.writer = JSON_Writer_Create(NULL);
   context.file = file;
   
   if (!context.writer)
   {
      RARCH_ERR("Failed to create JSON writer.\n");
      goto end;
   }
   
   /* Configure JSON writer */
   JSON_Writer_SetOutputEncoding(context.writer, JSON_UTF8);
   JSON_Writer_SetOutputHandler(context.writer, &RtlJSONOutputHandler);
   JSON_Writer_SetUserData(context.writer, &context);
   
   /* Write output file */
   JSON_Writer_WriteStartObject(context.writer);
   JSON_Writer_WriteNewLine(context.writer);
   
   /* > Version entry */
   JSON_Writer_WriteSpace(context.writer, 2);
   JSON_Writer_WriteString(context.writer, "version", strlen("version"), JSON_UTF8);
   JSON_Writer_WriteColon(context.writer);
   JSON_Writer_WriteSpace(context.writer, 1);
   JSON_Writer_WriteString(context.writer, "1.0", strlen("1.0"), JSON_UTF8);
   JSON_Writer_WriteComma(context.writer);
   JSON_Writer_WriteNewLine(context.writer);
   
   /* > Runtime entry */
   value_string[0] = '\0';
   n = snprintf(value_string, sizeof(value_string), LOG_FILE_RUNTIME_FORMAT_STR,
         runtime_log->runtime.hours, runtime_log->runtime.minutes, runtime_log->runtime.seconds);
   if ((n < 0) || (n >= 64))
      n = 0; /* Silence GCC warnings... */
   
   JSON_Writer_WriteSpace(context.writer, 2);
   JSON_Writer_WriteString(context.writer, "runtime", strlen("runtime"), JSON_UTF8);
   JSON_Writer_WriteColon(context.writer);
   JSON_Writer_WriteSpace(context.writer, 1);
   JSON_Writer_WriteString(context.writer, value_string, strlen(value_string), JSON_UTF8);
   JSON_Writer_WriteComma(context.writer);
   JSON_Writer_WriteNewLine(context.writer);
   
   /* > Last played entry */
   value_string[0] = '\0';
   n = snprintf(value_string, sizeof(value_string), LOG_FILE_LAST_PLAYED_FORMAT_STR,
         runtime_log->last_played.year, runtime_log->last_played.month, runtime_log->last_played.day,
         runtime_log->last_played.hour, runtime_log->last_played.minute, runtime_log->last_played.second);
   if ((n < 0) || (n >= 64))
      n = 0; /* Silence GCC warnings... */
   
   JSON_Writer_WriteSpace(context.writer, 2);
   JSON_Writer_WriteString(context.writer, "last_played", strlen("last_played"), JSON_UTF8);
   JSON_Writer_WriteColon(context.writer);
   JSON_Writer_WriteSpace(context.writer, 1);
   JSON_Writer_WriteString(context.writer, value_string, strlen(value_string), JSON_UTF8);
   JSON_Writer_WriteNewLine(context.writer);
   
   /* > Finalise */
   JSON_Writer_WriteEndObject(context.writer);
   JSON_Writer_WriteNewLine(context.writer);
   
   /* Free JSON writer */
   JSON_Writer_Free(context.writer);
   
end:
   
   /* Close log file */
   filestream_close(file);
}
Beispiel #30
0
static void *gfx_ctx_drm_init(void *video_driver)
{
   int fd, i;
   unsigned monitor_index;
   unsigned gpu_index                   = 0;
   const char *gpu                      = NULL;
   struct string_list *gpu_descriptors  = NULL;
   gfx_ctx_drm_data_t *drm          = (gfx_ctx_drm_data_t*)
      calloc(1, sizeof(gfx_ctx_drm_data_t));

   if (!drm)
      return NULL;

   gpu_descriptors = dir_list_new("/dev/dri", NULL, false, true, false, false);

nextgpu:
   free_drm_resources(drm);

   if (!gpu_descriptors || gpu_index == gpu_descriptors->size)
   {
      RARCH_ERR("[KMS]: Couldn't find a suitable DRM device.\n");
      goto error;
   }
   gpu = gpu_descriptors->elems[gpu_index++].data;

   drm->drm    = filestream_open(gpu, RFILE_MODE_READ_WRITE, -1);
   if (!drm->drm)
   {
      RARCH_WARN("[KMS]: Couldn't open DRM device.\n");
      goto nextgpu;
   }

   fd = filestream_get_fd(drm->drm);

   if (!drm_get_resources(fd))
      goto nextgpu;

   if (!drm_get_connector(fd))
      goto nextgpu;

   if (!drm_get_encoder(fd))
      goto nextgpu;

   drm_setup(fd);

   /* First mode is assumed to be the "optimal" 
    * one for get_video_size() purposes. */
   drm->fb_width    = g_drm_connector->modes[0].hdisplay;
   drm->fb_height   = g_drm_connector->modes[0].vdisplay;

   g_gbm_dev        = gbm_create_device(fd);

   if (!g_gbm_dev)
   {
      RARCH_WARN("[KMS]: Couldn't create GBM device.\n");
      goto nextgpu;
   }

   dir_list_free(gpu_descriptors);

   /* Setup the flip handler. */
   g_drm_fds.fd                   = fd;
   g_drm_fds.events               = POLLIN;
   g_drm_evctx.version            = DRM_EVENT_CONTEXT_VERSION;
   g_drm_evctx.page_flip_handler  = drm_flip_handler;

   g_drm_fd                       = fd;

   return drm;

error:
   dir_list_free(gpu_descriptors);

   gfx_ctx_drm_destroy_resources(drm);

   if (drm)
      free(drm);

   return NULL;
}