コード例 #1
0
ファイル: lzo_main.cpp プロジェクト: ratalaika/edge2d
void decompress( const char *archive_name, const char *out_dir )
{
	char path[MAX_PATH];
	char file[MAX_PATH];
	construct_file_name( path, out_dir, "", true );

	/// create the base directory recusely
	create_directory( "./", path );

	/// load the lzo archive
	lzo_archive *archive = lzo_load_archive( archive_name );

	/// get the file count in the archive
	unsigned long count = lzo_get_file_count( archive );
	
	/// decompress all files in the archive
	for( unsigned long i = 0; i < count; ++ i )
	{
		lzo_file_info *info = lzo_get_file_info_byid( archive, i );
		create_directory( path, info->name );
			
		unsigned char *buf = (unsigned char*) malloc( info->decom_size );
		lzo_read_file( archive, info, buf );

		construct_file_name( file, path, info->name, true );
		FILE *fp = fopen( file, "wb" );
		if( fp == 0 )
		{
			printf( "open file %s to write failed\n", file );
		}
		fwrite( buf, info->decom_size, 1, fp );
		fclose( fp );

		free( buf );
	}

	/// free resources
	lzo_free_archive( archive );
}
コード例 #2
0
ファイル: config_rw.c プロジェクト: alip2890/Rippix
void
read_config (void)
{
  FILE *file;
  char buf[MAX_CONFIG_LINE_LENGTH + 1];
  int i, offset;
  int flag;
  GtkWidget *main_window = main_window_handler(MW_REQUEST_MW, NULL, NULL);

  memset (&config, 0, sizeof (_config));

  file = fopen (construct_file_name (getenv ("HOME"), ".ripperXrc"), "r");

  if (file == NULL)
    {
      config_to_default (-1);
      if (errno != ENOENT)
	{
	  err_handler (GTK_WINDOW(main_window), CONFIG_OPEN_ERR, NULL);
	  return;
	}
      write_config ();
      return;
    }

  while (fgets (buf, sizeof (buf), file) != NULL)
    {
      /* Comments */
      if (strncasecmp ("//", buf, 2) == 0)
	continue;
      for (i = 0, offset = 0; i < num_entry && offset == 0; i++)
	{
	  /* Find the match */
	  if (strncasecmp (config_rw_data[i].f_id, buf,
			   strlen (config_rw_data[i].f_id)) == 0)
	    {
	      /* General::WavRatio = asdf... */
	      offset += strlen (config_rw_data[i].f_id);
	      while (buf[offset++] != '=');
	    }
	}
      i--;

      /* Mark that this field has been read */
      config_rw_data[i].flag = TRUE;

      /* Skip blank lines */
      if (is_str_blank (buf + offset))
	continue;

      /* Skip spaces */
      while (isspace (buf[offset++]));
      offset--;

      read_an_item (i, buf + offset);
    }

  for (i = 0, flag = FALSE; i < num_entry; i++)
    {
      if (config_rw_data[i].flag == FALSE)
	{
	  flag = TRUE;
	  config_to_default (i);
	}
    }

  if (flag)
    err_handler (GTK_WINDOW(main_window), CONFIG_EMPTY_ITEM_ERR, "");

  return;
}
コード例 #3
0
ファイル: config_rw.c プロジェクト: alip2890/Rippix
void
write_config (void)
{
  FILE *file;
  int fd;
  int i;
  char *str;
  char t_char;
  float t_float;
  int t_int;
  GtkWidget *main_window = main_window_handler(MW_REQUEST_MW, NULL, NULL);

  fd = open (construct_file_name (getenv ("HOME"), ".ripperXrc"),
	     O_WRONLY | O_TRUNC);

  if (fd < 0)
    {
      if (errno == ENOENT)
	{
	  if (dialog_handler (WIDGET_CREATE, FALSE, DL_CREATE_CONFIG_CONFIRM,
			      FALSE, NULL, NULL, 0) == FALSE)
	    return;
	  fd = open (construct_file_name (getenv ("HOME"), ".ripperXrc"),
		     O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
	  if (fd < 0)
	    {
	      err_handler (GTK_WINDOW(main_window), CONFIG_CREATION_ERR, "");
	      return;
	    }
	}
      else
	err_handler (GTK_WINDOW(main_window), CONFIG_OPEN_ERR, "");
    }

  if ((file = fdopen (fd, "w")) == NULL)
    {
      err_handler (GTK_WINDOW(main_window), FDOPEN_ERR, "Cannot re-open config file as a stream");
      close (fd);
      return;
    }

  fputs ("//\n", file);
  fputs ("// ~/.ripperXrc\n", file);
  fputs ("// This is the resource file for ripperX.\n", file);
  fputs ("// If you edit this file with an editor, you must leave all\n",
	 file);
  fputs ("// parameters in the order in which they appear.  Also note\n",
	 file);
  fputs ("// that this file is overwritten each time ripperX is run.\n",
	 file);
  fputs
    ("//\n// You can configure everything in the config menu within ripperX.\n",
     file);
  fputs ("//\n\n", file);

  fprintf (file, "//-V %s\n\n", VERSION);

  for (i = 0; i < num_entry; i++)
    {
      switch (config_rw_data[i].type)
	{
	case STRING:
	  str = (char *) config_rw_data[i].m_id;

	  fprintf (file, "%s = %s\n", config_rw_data[i].f_id, str);
	  break;

	case CHAR:
	  t_char = *(char *) config_rw_data[i].m_id;

	  fprintf (file, "%s = %c\n", config_rw_data[i].f_id, t_char);
	  break;

	case FLOAT:
	  t_float = *(float *) config_rw_data[i].m_id;

	  fprintf (file, "%s = %f\n", config_rw_data[i].f_id, t_float);
	  break;

	case INT:
	  t_int = *(int *) config_rw_data[i].m_id;

	  fprintf (file, "%s = %d\n", config_rw_data[i].f_id, t_int);
	  break;
	}
    }
  fclose (file);
  return;
}
コード例 #4
0
ファイル: lzo_main.cpp プロジェクト: ratalaika/edge2d
file_name *get_file_name_list( const char *path, const char *_file, bool recurse, bool bpath )
{
	const char *file = "*.*";
	char full_path[MAX_PATH];
	file_name *header = 0;

	/// it works on Windows
	WIN32_FIND_DATA file_data;
	HANDLE file_handle;

	construct_file_name( full_path, path, file, true );

	file_handle = FindFirstFile( full_path, &file_data );
	if( file_handle == INVALID_HANDLE_VALUE )
	{
		return 0;
	}

	/// igone '.' and '..' files
	while( strcmp( file_data.cFileName, "." ) == 0 || strcmp( file_data.cFileName, ".." ) == 0 )
	{
		if( !FindNextFile( file_handle, &file_data ) )
		{
			return 0;
		}
	}

	/// deal with sub directory
	if( recurse && file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
	{
		char subpath[MAX_PATH];
		construct_file_name( subpath, path, file_data.cFileName, true );
		header = get_file_name_list( subpath, _file, true, bpath );
	}
	else if( !( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
		compare_postfix( file_data.cFileName, _file ) )
	{
		file_name *filename = (file_name*) malloc( sizeof( file_name ) );
		construct_file_name( filename->name, path, file_data.cFileName, bpath );
		construct_file_name( filename->file, path, file_data.cFileName, true );

		if( strcmp( get_self_name(), filename->file ) != 0 &&
			strcmp( get_self_log_name(), filename->file ) != 0 )
		{
			filename->next = header;
			header = filename;
		}
		else
		{
			free( filename );
		}
	}

	/// deal with others
	while( FindNextFile( file_handle, &file_data ) )
	{
		if( recurse && file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
		{
			char subpath[MAX_PATH];
			construct_file_name( subpath, path, file_data.cFileName, true );
			file_name *sub_list = get_file_name_list( subpath, _file, true, bpath );
			if( sub_list != 0 )
			{
				file_name *tail = get_tail( sub_list );
				tail->next = header;
				header = sub_list;
			}
		}
		else if( !( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
			compare_postfix( file_data.cFileName, _file ) )
		{
			file_name *new_file = (file_name*) malloc( sizeof( file_name ) );
			construct_file_name( new_file->name, path, file_data.cFileName, bpath );
			construct_file_name( new_file->file, path, file_data.cFileName, true );

			if( strcmp( get_self_name(), new_file->file ) != 0 &&
				strcmp( get_self_log_name(), new_file->file ) != 0 )
			{
				new_file->next = header;
				header = new_file;
			}
			else
			{
				free( new_file );
			}
		}
	}

	return header;
}