コード例 #1
0
ファイル: FileListView.cpp プロジェクト: huairen/JArchive
//--------------------------------------------------------------------------------
void CFileListView::RefreshFileList()
{
	archive_file *pFile;

	strcpy_s(m_FileList.szName, 64, "root");
	m_FileList.nFileSize = 0;
	m_FileList.nCompSize = 0;
	m_FileList.FileTime = 0;
	m_FileList.Chlids.clear();

	m_FileStack.clear();
	m_FileStack.push_back(&m_FileList);

	if(m_pArchive == NULL)
		return;

	char szFilename[MAX_PATH];

	pFile = archive_find_first(m_pArchive);
	while(pFile != NULL)
	{
		memset(szFilename, 0, MAX_PATH);
		archive_file_property(pFile, JARCHIVE_FILE_NAME, szFilename, MAX_PATH);
		FileInfo& item = PushToFileList(m_FileList, szFilename);

		archive_file_property(pFile, JARCHIVE_FILE_SIZE, &(item.nFileSize), 4);
		archive_file_property(pFile, JARCHIVE_FILE_COMPRESS_SIZE, &(item.nCompSize), 4);
		archive_file_property(pFile, JARCHIVE_FILE_IS_COMPLETE, &(item.bDataComplete), 1);
		archive_file_property(pFile, JARCHIVE_FILE_TIME, &(item.FileTime), 8);

		if( !archive_find_next(pFile) )
			break;
	}
	archive_file_close(pFile);
}
コード例 #2
0
/**
 * Updates the file listing from an archive file.
 *
 * @param parent the parent directory the archive file resides in
 * @param name the UTF-8 encoded base name of the archive file
 * @param st stat() information on the archive file
 * @param plugin the archive plugin which fits this archive type
 */
static void
update_archive_file(struct directory *parent, const char *name,
		    const struct stat *st,
		    const struct archive_plugin *plugin)
{
	GError *error = NULL;
	char *path_fs;
	struct archive_file *file;
	struct directory *directory;
	char *filepath;

	directory = dirvec_find(&parent->children, name);
	if (directory != NULL && directory->mtime == st->st_mtime &&
	    !walk_discard)
		/* MPD has already scanned the archive, and it hasn't
		   changed since - don't consider updating it */
		return;

	path_fs = map_directory_child_fs(parent, name);

	/* open archive */
	file = archive_file_open(plugin, path_fs, &error);
	if (file == NULL) {
		g_free(path_fs);
		g_warning("%s", error->message);
		g_error_free(error);
		return;
	}

	g_debug("archive %s opened", path_fs);
	g_free(path_fs);

	if (directory == NULL) {
		g_debug("creating archive directory: %s", name);
		directory = make_subdir(parent, name);
		/* mark this directory as archive (we use device for
		   this) */
		directory->device = DEVICE_INARCHIVE;
	}

	directory->mtime = st->st_mtime;

	archive_file_scan_reset(file);

	while ((filepath = archive_file_scan_next(file)) != NULL) {
		/* split name into directory and file */
		g_debug("adding archive file: %s", filepath);
		update_archive_tree(directory, filepath);
	}

	archive_file_close(file);
}
コード例 #3
0
/**
 * select correct archive plugin to handle the input stream
 * may allow stacking of archive plugins. for example for handling
 * tar.gz a gzip handler opens file (through inputfile stream)
 * then it opens a tar handler and sets gzip inputstream as
 * parent_stream so tar plugin fetches file data from gzip
 * plugin and gzip fetches file from disk
 */
static struct input_stream *
input_archive_open(const char *pathname, GError **error_r)
{
	const struct archive_plugin *arplug;
	struct archive_file *file;
	char *archive, *filename, *suffix, *pname;
	struct input_stream *is;

	if (!g_path_is_absolute(pathname))
		return NULL;

	pname = g_strdup(pathname);
	// archive_lookup will modify pname when true is returned
	if (!archive_lookup(pname, &archive, &filename, &suffix)) {
		g_debug("not an archive, lookup %s failed\n", pname);
		g_free(pname);
		return NULL;
	}

	//check which archive plugin to use (by ext)
	arplug = archive_plugin_from_suffix(suffix);
	if (!arplug) {
		g_warning("can't handle archive %s\n",archive);
		g_free(pname);
		return NULL;
	}

	file = archive_file_open(arplug, archive, error_r);
	if (file == NULL)
		return NULL;

	//setup fileops
	is = archive_file_open_stream(file, filename, error_r);
	archive_file_close(file);
	g_free(pname);

	return is;
}