コード例 #1
1
ファイル: analyzer.c プロジェクト: 4396/apkanalyzer
int enum_files(const char* dir, analyzer_callback* cb, void* userp)
{
	HANDLE h;
	WIN32_FIND_DATAA fd; 
	char find[MAX_PATH]; 
	int n = 1;

	strcpy(find, dir); 
	strcat(find, "\\*.*");
	h = FindFirstFileA(find, &fd); 
	if (h == INVALID_HANDLE_VALUE)
	{
		return -1;
	}

	while (1) 
	{ 
		if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
		{ 
			if (fd.cFileName[0] != '.') 
			{ 
				strcpy(find, dir); 
				strcat(find, "\\"); 
				strcat(find, fd.cFileName); 
				if (!enum_files(find, cb, userp))
				{
					n = 0;
					break;
				}
			}
		} 
		else 
		{ 
			FILE* fp;
			char path[MAX_PATH];
			snprintf(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
			fp = fopen(path, "rb");
			if (fp)
			{
				int size;
				void* data = NULL;

				fseek(fp, 0, SEEK_END);
				size = ftell(fp);
				fseek(fp, 0, SEEK_SET);
				if (size)
				{
					data = malloc(size);
					fread(data, 1, size, fp);
				}
				n = (*cb)(path, data, size, userp);
				if (data)
				{
					free(data);
				}
				fclose(fp);
				if (!n)
				{
					break;
				}
			}
		} 

		if (!FindNextFileA(h, &fd))
		{
			break;
		}
	}
	FindClose(h);

	return n;
}
コード例 #2
0
ファイル: libttwatch.cpp プロジェクト: ahoogesteger/ttwatch
//------------------------------------------------------------------------------
int ttwatch_clear_data(TTWATCH *watch)
{
    if (!watch)
        return TTWATCH_InvalidParameter;
    if (watch->current_file)
        return TTWATCH_FileOpen;

    FileList files;
    enum_files(watch, 0, files);

    foreach (it, files)
    {
        uint32_t length;
        TTWATCH_HISTORY_FILE *history;

        switch (it->first & TTWATCH_FILE_TYPE_MASK)
        {
        case TTWATCH_FILE_TTBIN_DATA:
        case TTWATCH_FILE_RACE_HISTORY_DATA:
        case TTWATCH_FILE_HISTORY_DATA:
            RETURN_ERROR(ttwatch_delete_file(watch, it->first));
            break;

        case TTWATCH_FILE_HISTORY_SUMMARY:
            RETURN_ERROR(ttwatch_read_whole_file(watch, it->first, (void**)&history, &length));
            {
                history->entry_count = 0;
                length = sizeof(TTWATCH_HISTORY_FILE) - 1;
                int res = ttwatch_write_verify_whole_file(watch, it->first, history, length);
                free(history);
                RETURN_ERROR(res);
            }
            break;
        }
    }
コード例 #3
0
ファイル: libttwatch.cpp プロジェクト: ahoogesteger/ttwatch
//------------------------------------------------------------------------------
int ttwatch_enumerate_files(TTWATCH *watch, uint32_t type, TTWATCH_FILE_ENUMERATOR enumerator, void *data)
{
    FileList files;
    RETURN_ERROR(enum_files(watch, type, files));

    foreach (it, files)
        enumerator(it->first, it->second, data);
    return TTWATCH_NoError;
}
コード例 #4
0
static bool update_files_to_local(void *param, obs_data_t *local_file)
{
	struct update_info *info = param;
	struct file_update_data data = {
		.name = obs_data_get_string(local_file, "name"),
		.version = (int)obs_data_get_int(local_file, "version")
	};

	enum_files(info->cache_package, newer_than_cache, &data);
	if (data.newer || !data.found)
		copy_local_to_cache(info, data.name);

	return true;
}

static int update_local_version(struct update_info *info)
{
	int local_version;
	int cache_version = 0;

	local_version = (int)obs_data_get_int(info->local_package, "version");
	cache_version = (int)obs_data_get_int(info->cache_package, "version");

	/* if local cached version is out of date, copy new version */
	if (cache_version < local_version) {
		enum_files(info->local_package, update_files_to_local, info);
		copy_local_to_cache(info, "package.json");

		obs_data_release(info->cache_package);
		obs_data_addref(info->local_package);
		info->cache_package = info->local_package;

		return local_version;
	}

	return cache_version;
}
コード例 #5
0
ファイル: analyzer.c プロジェクト: 4396/apkanalyzer
int analyzer_execute(struct analyzer* analyzer, const char* path, 
					 analyzer_callback* cb, void* userp)
{
	int len;
	char buffer[256];
	snprintf(buffer, sizeof(buffer), "d %s", path);
	if (execute_apktool(analyzer->apktool, buffer))
	{
		return 1;
	}

	len = strlen(path);
	while (len && path[len] != '.')
	{
		len--;
	}
	memcpy(buffer, path, len);
	buffer[len] = '\0';
	snprintf(buffer, sizeof(buffer), "%s%csmali", buffer, PATH_SEPARATOR);

	return enum_files(buffer, cb, userp);
}
コード例 #6
0
static bool update_remote_files(void *param, obs_data_t *remote_file)
{
	struct update_info *info = param;

	struct file_update_data data = {
		.name = obs_data_get_string(remote_file, "name"),
		.version = (int)obs_data_get_int(remote_file, "version")
	};

	enum_files(info->cache_package, newer_than_cache, &data);
	if (!data.newer && data.found)
		return true;

	if (!do_relative_http_request(info, info->remote_url, data.name))
		return true;

	if (info->callback) {
		struct file_download_data download_data;
		bool confirm;

		download_data.name = data.name;
		download_data.version = data.version;
		download_data.buffer.da = info->file_data.da;

		confirm = info->callback(info->param, &download_data);

		info->file_data.da = download_data.buffer.da;

		if (!confirm) {
			info("Update file '%s' (version %d) rejected",
					data.name, data.version);
			return true;
		}
	}

	write_file_data(info, info->temp, data.name);
	replace_file(info->temp, info->cache, data.name);

	info("Successfully updated file '%s' (version %d)",
			data.name, data.version);
	return true;
}

static void update_save_metadata(struct update_info *info)
{
	struct dstr path = { 0 };

	if (!info->etag_remote)
		return;

	dstr_copy(&path, info->cache);
	dstr_cat(&path, "meta.json");

	obs_data_t *data;
	data = obs_data_create();
	obs_data_set_string(data, "etag", info->etag_remote);
	obs_data_save_json(data, path.array);
	obs_data_release(data);
}

static void update_remote_version(struct update_info *info, int cur_version)
{
	int remote_version;
	long response_code;

	if (!do_http_request(info, info->url, &response_code))
		return;

	if (response_code == 304)
		return;

	if (!info->file_data.array || info->file_data.array[0] != '{') {
		warn("Remote package does not exist or is not valid json");
		return;
	}

	update_save_metadata(info);

	info->remote_package = obs_data_create_from_json(
			(char*)info->file_data.array);
	if (!info->remote_package) {
		warn("Failed to initialize remote package json");
		return;
	}

	remote_version = (int)obs_data_get_int(info->remote_package, "version");
	if (remote_version <= cur_version)
		return;

	write_file_data(info, info->temp, "package.json");

	info->remote_url = obs_data_get_string(info->remote_package, "url");
	if (!info->remote_url) {
		warn("No remote url in package file");
		return;
	}

	/* download new files */
	enum_files(info->remote_package, update_remote_files, info);

	replace_file(info->temp, info->cache, "package.json");

	info("Successfully updated package (version %d)", remote_version);
	return;
}
コード例 #7
0
ファイル: DirImage.cpp プロジェクト: madrat-/flviewer
size_t DirImage::page() const
{
	if (files_.empty())
		enum_files();
	return page_;
}
コード例 #8
0
ファイル: DirImage.cpp プロジェクト: madrat-/flviewer
size_t DirImage::num_pages() const
{
	if (files_.empty())
		enum_files();
	return files_.size();
}