Exemple #1
0
/**
 * @param selidx filelist中的文件位置
 * @param where 文件位置类型
 *
 */
static int cache_add_by_selidx(dword selidx, int where)
{
	t_fs_filetype type;
	cache_image_t img;
	const char *archname;
	const char *filename;
	dword filesize;

	archname = config.shortpath;

	if (where == scene_in_dir) {
		filename = filelist[selidx].shortname->ptr;
	} else {
		filename = filelist[selidx].compname->ptr;
	}

	filesize = filelist[selidx].data3;

	type = fs_file_get_type(filename);

	if (!fs_is_image(type)) {
		return -1;
	}

	if (cache_get(archname, filename) != NULL) {
		dbg_printf(d, "SERVER: %s: Image %s duplicate load, FIXME", __func__,
				   filename);

		return -1;
	}

	cache_lock();

	memset(&img, 0, sizeof(img));
	img.archname = archname;
	img.filename = filename;
	img.where = where;
	img.status = CACHE_INIT;
	img.selidx = selidx;
	img.filesize = filesize;

	if (ccacher.caches_size < ccacher.caches_cap) {
		ccacher.caches[ccacher.caches_size] = img;
		ccacher.caches_size++;
		cacher_cleared = false;
	} else {
		dbg_printf(d, "SERVER: cannot add cache any more: size %u cap %u",
				   ccacher.caches_size, ccacher.caches_cap);
		cache_unlock();

		return -1;
	}
	cache_unlock();

	return 0;
}
Exemple #2
0
static int chmEnum(struct chmFile *h, struct chmUnitInfo *ui, void *context)
{
	t_win_menuitem item;
	t_fs_filetype ft;
	char fname[PATH_MAX] = "";
	char t[20];

	int size = strlen(ui->path);

	if (size == 0 || ui->path[size - 1] == '/')
		return CHM_ENUMERATOR_CONTINUE;

	ft = fs_file_get_type(ui->path);

	if (ft == fs_filetype_chm || ft == fs_filetype_zip || ft == fs_filetype_rar || ft == fs_filetype_umd || ft == fs_filetype_pdb)
		return CHM_ENUMERATOR_CONTINUE;

	win_menuitem_new(&item);
	buffer_copy_string(item.compname, ui->path);
	SPRINTF_S(t, "%u", (unsigned int) ui->length);
	buffer_copy_string(item.shortname, t);
	if (ui->path[0] == '/') {
		strncpy_s(fname, NELEMS(fname), ui->path + 1, 256);
	} else {
		strncpy_s(fname, NELEMS(fname), ui->path, 256);
	}

	charsets_utf8_conv((unsigned char *) fname, sizeof(fname), (unsigned char *) fname, sizeof(fname));

	item.data = (void *) ft;
	filename_to_itemname(&item, fname);
	item.selected = false;
	item.icolor = ((p_fs_chm_enum) context)->icolor;
	item.selicolor = ((p_fs_chm_enum) context)->selicolor;
	item.selrcolor = ((p_fs_chm_enum) context)->selrcolor;
	item.selbcolor = ((p_fs_chm_enum) context)->selbcolor;
	item.data3 = ui->length;
	win_menu_add(g_menu, &item);

	return CHM_ENUMERATOR_CONTINUE;
}
Exemple #3
0
int start_cache_next_image(void)
{
	cache_image_t *p = NULL;
	cache_image_t tmp;
	t_fs_filetype ft;
	dword free_memory;
	int fid;

	if (avoid_times && curr_times++ < avoid_times) {
//      dbg_printf(d, "%s: curr_times %d avoid time %d", __func__, curr_times, avoid_times);
		return -1;
	}

	free_memory = get_free_mem();

	if (config.scale >= 100) {
		if (free_memory < 8 * 1024 * 1024) {
			return -1;
		}
	} else if (free_memory < 1024 * 1024) {
		return -1;
	}

	cache_lock();

	for (p = ccacher.caches; p != ccacher.caches + ccacher.caches_size; ++p) {
		if (p->status == CACHE_INIT || p->status == CACHE_FAILED) {
			break;
		}
	}

	// if we ecounter FAILED cache, abort the caching, because user will quit when the image shows up
	if (p == ccacher.caches + ccacher.caches_size || p->status == CACHE_FAILED) {
		cache_unlock();
		return 0;
	}

	copy_cache_image(&tmp, p);
	cache_unlock();
	ft = fs_file_get_type(tmp.filename);
	fid = freq_enter_hotzone();

	if (tmp.where == scene_in_dir) {
		char fullpath[PATH_MAX];

		STRCPY_S(fullpath, tmp.archname);
		STRCAT_S(fullpath, tmp.filename);
		tmp.result =
			image_open_archive(fullpath, tmp.archname, ft, &tmp.width,
							   &tmp.height, &tmp.data, &tmp.bgc, tmp.where,
							   &tmp.exif_array);
	} else {
		tmp.result =
			image_open_archive(tmp.filename, tmp.archname, ft, &tmp.width,
							   &tmp.height, &tmp.data, &tmp.bgc, tmp.where,
							   &tmp.exif_array);
	}

	if (tmp.result == 0 && tmp.data != NULL && config.imgbrightness != 100) {
		pixel *t = tmp.data;
		short b = 100 - config.imgbrightness;
		dword i;

		for (i = 0; i < tmp.height * tmp.width; i++) {
			*t = disp_grayscale(*t, 0, 0, 0, b);
			t++;
		}
	}

	freq_leave(fid);

	cache_lock();

	for (p = ccacher.caches; p != ccacher.caches + ccacher.caches_size; ++p) {
		if (p->status == CACHE_INIT || p->status == CACHE_FAILED) {
			break;
		}
	}

	// recheck the first unloaded (and not failed) image, for we haven't locked cache for a while
	if (p == ccacher.caches + ccacher.caches_size || p->status == CACHE_FAILED) {
		free_cache_image(&tmp);
		cache_unlock();
		return 0;
	}

	if (tmp.result == 0) {
		dword memory_used;

		memory_used = tmp.width * tmp.height * sizeof(pixel);

//      dbg_printf(d, "SERVER: Image %u finished loading", (unsigned)tmp.selidx);
//      dbg_printf(d, "%s: Memory usage %uKB", __func__, (unsigned) ccacher.memory_usage / 1024);
		ccacher.memory_usage += memory_used;
		cacher_cleared = false;
		tmp.status = CACHE_OK;
		copy_cache_image(p, &tmp);
		tmp.data = NULL;
		tmp.exif_array = NULL;
		free_cache_image(&tmp);
		curr_times = avoid_times = 0;
	} else if ((tmp.result == 4 || tmp.result == 5)
			   || (tmp.where == scene_in_rar && tmp.result == 6)) {
		// out of memory
		// if unrar throwed a bad_cast exception when run out of memory, result can be 6 also.

		// is memory completely out of memory?
		if (ccacher.memory_usage == 0) {
//          dbg_printf(d, "SERVER: Image %u finished failed(%u), giving up", (unsigned)tmp.selidx, tmp.result);
			tmp.status = CACHE_FAILED;
			copy_cache_image(p, &tmp);
			p->data = NULL;
			p->exif_array = NULL;
		} else {
			// retry later
//          dbg_printf(d, "SERVER: Image %u finished failed(%u), retring", (unsigned)tmp.selidx, tmp.result);
//          dbg_printf(d, "%s: Memory usage %uKB", __func__, (unsigned) ccacher.memory_usage / 1024);
			if (avoid_times) {
				avoid_times *= 2;
			} else {
				avoid_times = 1;
			}

			avoid_times = min(avoid_times, 32767);
			curr_times = 0;
		}

		free_cache_image(&tmp);
	} else {
//      dbg_printf(d, "SERVER: Image %u finished failed(%u)", (unsigned)tmp.selidx, tmp.result);
		tmp.status = CACHE_FAILED;
		copy_cache_image(p, &tmp);
		p->data = NULL;
		p->exif_array = NULL;
		free_cache_image(&tmp);
	}

	cache_unlock();

	return 0;
}
Exemple #4
0
extern u32 fs_rar_to_menu(const char *rarfile, u32 icolor, u32 selicolor, u32 selrcolor, u32 selbcolor)
{
	int fid;
	struct RAROpenArchiveData arcdata;
	struct RARHeaderDataEx header;
	int ret;
	HANDLE hrar;
	t_fs_filetype ft;
	t_win_menuitem item;

	if (menu_renew(&g_menu) == NULL) {
		return 0;
	}

	fid = freq_enter_hotzone();

	arcdata.ArcName = (char *) rarfile;
	arcdata.OpenMode = RAR_OM_LIST;
	arcdata.CmtBuf = NULL;
	arcdata.CmtBufSize = 0;

	hrar = RAROpenArchive(&arcdata);

	if (hrar == 0) {
		freq_leave(fid);
		return 0;
	}

	add_parent_to_menu(g_menu, icolor, selicolor, selrcolor, selbcolor);

	do {
		char t[20];

		if ((ret = RARReadHeaderEx(hrar, &header)) != 0) {
			if (ret != ERAR_UNKNOWN)
				break;
			RARCloseArchive(hrar);
			if ((hrar = reopen_rar_with_passwords(&arcdata)) == 0)
				break;
			if (RARReadHeaderEx(hrar, &header) != 0)
				break;
		}
		if (header.UnpSize == 0)
			continue;

		ft = fs_file_get_type(header.FileName);

		if (ft == fs_filetype_chm || ft == fs_filetype_zip || ft == fs_filetype_rar)
			continue;

		win_menuitem_new(&item);
		item.data = (void *) ft;

		if (header.Flags & 0x200) {
			char str[1024];
			const u8 *uni;

			memset(str, 0, 1024);
			uni = (u8 *) header.FileNameW;
			charsets_utf32_conv(uni, sizeof(header.FileNameW), (u8 *) str, sizeof(str));
			buffer_copy_string_len(item.compname, header.FileName, 256);
			filename_to_itemname(&item, str);
		} else {
			buffer_copy_string_len(item.compname, header.FileName, 256);
			filename_to_itemname(&item, header.FileName);
		}

		SPRINTF_S(t, "%u", (unsigned int) header.UnpSize);
		buffer_copy_string(item.shortname, t);
		item.selected = false;
		item.icolor = icolor;
		item.selicolor = selicolor;
		item.selrcolor = selrcolor;
		item.selbcolor = selbcolor;
		item.data3 = header.UnpSize;
		win_menu_add(g_menu, &item);
	} while (RARProcessFile(hrar, RAR_SKIP, NULL, NULL) == 0);

	RARCloseArchive(hrar);
	freq_leave(fid);

	return g_menu->size;
}
Exemple #5
0
extern u32 fs_zip_to_menu(const char *zipfile, u32 icolor, u32 selicolor, u32 selrcolor, u32 selbcolor)
{
	int fid;
	unzFile unzf;
	t_win_menuitem item;

	if (menu_renew(&g_menu) == NULL) {
		return 0;
	}

	fid = freq_enter_hotzone();
	unzf = unzOpen(zipfile);

	if (unzf == NULL) {
		freq_leave(fid);
		return 0;
	}

	add_parent_to_menu(g_menu, icolor, selicolor, selrcolor, selbcolor);

	if (unzGoToFirstFile(unzf) != UNZ_OK) {
		unzClose(unzf);
		freq_leave(fid);

		return g_menu->size;
	}

	do {
		char fname[PATH_MAX];
		unz_file_info file_info;
		t_fs_filetype ft;
		char t[20];

		if (unzGetCurrentFileInfo(unzf, &file_info, fname, PATH_MAX, NULL, 0, NULL, 0) != UNZ_OK)
			break;

		if (file_info.uncompressed_size == 0)
			continue;

		ft = fs_file_get_type(fname);

		if (ft == fs_filetype_chm || ft == fs_filetype_zip || ft == fs_filetype_rar)
			continue;

		win_menuitem_new(&item);

		item.data = (void *) ft;
		buffer_copy_string(item.compname, fname);

		SPRINTF_S(t, "%u", (unsigned int) file_info.uncompressed_size);
		buffer_copy_string(item.shortname, t);
		filename_to_itemname(&item, fname);
		item.selected = false;
		item.icolor = icolor;
		item.selicolor = selicolor;
		item.selrcolor = selrcolor;
		item.selbcolor = selbcolor;
		item.data3 = file_info.uncompressed_size;
		win_menu_add(g_menu, &item);
	} while (unzGoToNextFile(unzf) == UNZ_OK);

	unzClose(unzf);
	freq_leave(fid);

	return g_menu->size;
}
Exemple #6
0
// New style fat system custom reading
extern u32 fs_dir_to_menu(const char *dir, char *sdir, u32 icolor, u32 selicolor, u32 selrcolor, u32 selbcolor, bool showhidden, bool showunknown)
{
	int fid;
	p_fat_info info;
	u32 count;
	u32 i;
	t_win_menuitem item;

	if (menu_renew(&g_menu) == NULL) {
		return 0;
	}

	fid = freq_enter_hotzone();
	count = fat_readdir(dir, sdir, &info);

	if (count == INVALID) {
		freq_leave(fid);
		return 0;
	}

	add_parent_to_menu(g_menu, icolor, selicolor, selrcolor, selbcolor);

	for (i = 0; i < count; i++) {
		win_menuitem_new(&item);

		if (!showhidden && (info[i].attr & FAT_FILEATTR_HIDDEN) > 0) {
			win_menuitem_free(&item);
			continue;
		}

		if (info[i].attr & FAT_FILEATTR_DIRECTORY) {
			item.data = (void *) fs_filetype_dir;
			buffer_copy_string(item.shortname, info[i].filename);
			buffer_copy_string(item.compname, info[i].longname);
			item.name[0] = '<';
			if ((item.width = strlen(info[i].longname) + 2) > MAX_ITEM_NAME_LEN) {
				strncpy_s(&item.name[1], NELEMS(item.name) - 1, info[i].longname, MAX_ITEM_NAME_LEN - 5);
				item.name[MAX_ITEM_NAME_LEN - 4] = item.name[MAX_ITEM_NAME_LEN - 3] = item.name[MAX_ITEM_NAME_LEN - 2] = '.';
				item.name[MAX_ITEM_NAME_LEN - 1] = '>';
				item.name[MAX_ITEM_NAME_LEN] = 0;
				item.width = MAX_ITEM_NAME_LEN;
			} else {
				strncpy_s(&item.name[1], NELEMS(item.name) - 1, info[i].longname, MAX_ITEM_NAME_LEN);
				item.name[item.width - 1] = '>';
				item.name[item.width] = 0;
			}
		} else {
			t_fs_filetype ft;

			if (info[i].filesize == 0) {
				win_menuitem_free(&item);
				continue;
			}

			ft = fs_file_get_type(info[i].longname);

			if (!showunknown && ft == fs_filetype_unknown) {
				win_menuitem_free(&item);
				continue;
			}

			item.data = (void *) ft;
			buffer_copy_string(item.shortname, info[i].filename);
			buffer_copy_string(item.compname, info[i].longname);
			filename_to_itemname(&item, info[i].longname);
		}
		item.icolor = icolor;
		item.selicolor = selicolor;
		item.selrcolor = selrcolor;
		item.selbcolor = selbcolor;
		item.selected = false;
		item.data2[0] = info[i].cdate;
		item.data2[1] = info[i].ctime;
		item.data2[2] = info[i].mdate;
		item.data2[3] = info[i].mtime;
		item.data3 = info[i].filesize;
		win_menu_add(g_menu, &item);
	}

	free(info);
	freq_leave(fid);

	return g_menu->size;
}
Exemple #7
0
extern u32 fs_flashdir_to_menu(const char *dir, const char *sdir, u32 icolor, u32 selicolor, u32 selrcolor, u32 selbcolor)
{
	int fid;
	SceIoDirent info;
	int fd;
	t_win_menuitem item;

	if (menu_renew(&g_menu) == NULL) {
		return 0;
	}

	fid = freq_enter_hotzone();
	strcpy_s((char *) sdir, 256, dir);
	fd = sceIoDopen(dir);

	if (fd < 0) {
		freq_leave(fid);
		return 0;
	}

	add_parent_to_menu(g_menu, icolor, selicolor, selrcolor, selbcolor);

	memset(&info, 0, sizeof(SceIoDirent));

	while (sceIoDread(fd, &info) > 0) {
		win_menuitem_new(&item);

		if ((info.d_stat.st_mode & FIO_S_IFMT) == FIO_S_IFDIR) {
			if (info.d_name[0] == '.' && info.d_name[1] == 0) {
				win_menuitem_free(&item);
				continue;
			}

			if (strcmp(info.d_name, "..") == 0) {
				win_menuitem_free(&item);
				continue;
			}

			item.data = (void *) fs_filetype_dir;
			buffer_copy_string(item.compname, info.d_name);
			item.name[0] = '<';

			if ((item.width = strlen(info.d_name) + 2) > MAX_ITEM_NAME_LEN) {
				mbcsncpy_s((unsigned char *) &item.name[1], MAX_ITEM_NAME_LEN - 4, (const unsigned char *) info.d_name, -1);
				STRCAT_S(item.name, "...>");
				item.width = MAX_ITEM_NAME_LEN;
			} else {
				mbcsncpy_s((unsigned char *) &item.name[1], MAX_ITEM_NAME_LEN - 1, (const unsigned char *) info.d_name, -1);
				STRCAT_S(item.name, ">");
			}
		} else {
			t_fs_filetype ft = fs_file_get_type(info.d_name);

			item.data = (void *) ft;
			buffer_copy_string(item.compname, info.d_name);
			buffer_copy_string(item.shortname, info.d_name);
			filename_to_itemname(&item, info.d_name);
		}

		item.icolor = icolor;
		item.selicolor = selicolor;
		item.selrcolor = selrcolor;
		item.selbcolor = selbcolor;
		item.selected = false;
		item.data2[0] = ((info.d_stat.st_ctime.year - 1980) << 9) + (info.d_stat.st_ctime.month << 5) + info.d_stat.st_ctime.day;
		item.data2[1] = (info.d_stat.st_ctime.hour << 11) + (info.d_stat.st_ctime.minute << 5) + info.d_stat.st_ctime.second / 2;
		item.data2[2] = ((info.d_stat.st_mtime.year - 1980) << 9) + (info.d_stat.st_mtime.month << 5) + info.d_stat.st_mtime.day;
		item.data2[3] = (info.d_stat.st_mtime.hour << 11) + (info.d_stat.st_mtime.minute << 5) + info.d_stat.st_mtime.second / 2;
		item.data3 = info.d_stat.st_size;

		win_menu_add(g_menu, &item);
	}

	sceIoDclose(fd);
	freq_leave(fid);

	return g_menu->size;
}