static void scene_imgkey_predraw(p_win_menuitem item, dword index, dword topindex, dword max_height) { char keyname[256]; int left, right, upper, bottom, lines = 0; dword i; default_predraw(&g_predraw, _("按键设置 △ 删除"), max_height, &left, &right, &upper, &bottom, 8 * DISP_FONTSIZE + 4); for (i = topindex; i < topindex + max_height; i++) { conf_get_keyname(config.imgkey[i], keyname); if (config.imgkey2[i] != 0) { char keyname2[256]; conf_get_keyname(config.imgkey2[i], keyname2); STRCAT_S(keyname, " | "); STRCAT_S(keyname, keyname2); } disp_putstring(left + (right - left) / 2, upper + 2 + (lines + 1 + g_predraw.linespace) * (1 + DISP_FONTSIZE), COLOR_WHITE, (const byte *) keyname); lines++; } }
void filename_to_itemname(p_win_menuitem item, const char *filename) { if ((item->width = strlen(filename)) > MAX_ITEM_NAME_LEN) { mbcsncpy_s(((unsigned char *) item->name), MAX_ITEM_NAME_LEN - 2, ((const unsigned char *) filename), -1); if (strlen(item->name) < MAX_ITEM_NAME_LEN - 3) { mbcsncpy_s(((unsigned char *) item->name), MAX_ITEM_NAME_LEN, ((const unsigned char *) filename), -1); STRCAT_S(item->name, ".."); } else STRCAT_S(item->name, "..."); item->width = MAX_ITEM_NAME_LEN; } else { STRCPY_S(item->name, filename); } }
bool save_passwords(void) { password *pwd; SceUID fd; char path[PATH_MAX]; u32 magic; STRCPY_S(path, scene_appdir()); STRCAT_S(path, "password.lst"); rc4_prepare_key((u8 *) CRYPT_KEY, sizeof(CRYPT_KEY) - 1, &g_key); fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { return false; } magic = CRYPT_MAGIC; sceIoWrite(fd, &magic, sizeof(magic)); for (pwd = g_pwd_head.next; pwd != NULL; pwd = pwd->next) { write_chars(fd, pwd->b->ptr, strlen(pwd->b->ptr)); write_chars(fd, "\r\n", sizeof("\r\n") - 1); } sceIoClose(fd); return true; }
static int dump_freq(void) { char t[128] = { 0 }; int i; sprintf(t, "[ "); for (i = 0; i < freqs_cnt; ++i) { sprintf(t + strlen(t), "%d/%d ", freqs[i].cpu, freqs[i].bus); } STRCAT_S(t, "]"); dbg_printf(d, "%s: Dump freqs table: %s", __func__, t); return 0; }
static int scene_reloadimage(dword selidx) { int result; reset_image_ptr(); if (where == scene_in_zip || where == scene_in_chm || where == scene_in_rar) STRCPY_S(filename, filelist[selidx].compname->ptr); else { STRCPY_S(filename, config.shortpath); STRCAT_S(filename, filelist[selidx].shortname->ptr); } if (config.use_image_queue) { result = cache_get_image(selidx); } else { result = open_image(selidx); } if (result != 0) { report_image_error(result); return -1; } // already calc brightness in cacher if (!config.use_image_queue && config.imgbrightness != 100) { recalc_brightness(); } STRCPY_S(config.lastfile, filelist[selidx].compname->ptr); STRCPY_S(prev_path, config.path); STRCPY_S(prev_shortpath, config.shortpath); STRCPY_S(prev_lastfile, filelist[selidx].compname->ptr); prev_where = where; oldangle = 0; return 0; }
bool load_passwords(void) { SceUID fd; char linebuf[LINEBUF], path[PATH_MAX]; rc4_key *pkey; STRCPY_S(path, scene_appdir()); STRCAT_S(path, "password.lst"); if (is_encrypted(path)) { rc4_prepare_key((u8 *) CRYPT_KEY, sizeof(CRYPT_KEY) - 1, &g_key); pkey = &g_key; } else { pkey = NULL; } fd = sceIoOpen(path, PSP_O_RDONLY, 0); if (fd < 0) { return false; } if (pkey != NULL) { sceIoLseek(fd, 4, PSP_SEEK_SET); } linebuf[sizeof(linebuf) - 1] = '\0'; while (read_lines(fd, linebuf, sizeof(linebuf) - 1, pkey) >= 0) { add_password(linebuf); } sceIoClose(fd); return true; }
int vpbp_dread(SceUID fd, SceIoDirent * dir) { int result, cur_idx, ret; struct IoDirentEntry *entry; lock(); entry = dirent_search(fd); if(entry == NULL) { result = -44; goto exit; } result = sceIoDread(entry->iso_dfd, dir); if(sceKernelFindModuleByName("Game_Categories_Light") == NULL) { while(result > 0 && !is_iso(dir)) { result = sceIoDread(entry->iso_dfd, dir); } } if (result > 0 && is_iso(dir)) { VirtualPBP *vpbp; vpbp = vpbp_realloc(g_vpbps, g_vpbps_cnt+1); if(vpbp == NULL) { result = -42; goto exit; } g_vpbps = vpbp; g_vpbps_cnt++; cur_idx = g_vpbps_cnt-1; vpbp = &g_vpbps[cur_idx]; STRCPY_S(vpbp->name, entry->path); vpbp->name[4] = '\0'; STRCAT_S(vpbp->name, "/ISO"); STRCAT_S(vpbp->name, entry->path + sizeof("xxx:/PSP/GAME") - 1); STRCAT_S(vpbp->name, "/"); STRCAT_S(vpbp->name, dir->d_name); memcpy(&vpbp->ctime, &dir->d_stat.st_ctime, sizeof(vpbp->ctime)); memcpy(&vpbp->mtime, &dir->d_stat.st_mtime, sizeof(vpbp->mtime)); ret = get_cache(vpbp->name, &vpbp->mtime, vpbp); if (ret < 0) { ret = build_vpbp(vpbp); if (ret < 0) { result = -43; goto exit; } } result = add_fake_dirent(dir, cur_idx); } exit: unlock(); return result; }
static void conf_default(p_conf conf) { memset(conf, 0, sizeof(t_conf)); STRCPY_S(conf->path, "ms0:/"); STRCPY_S(conf->shortpath, "ms0:/"); STRCPY_S(conf->lastfile, ""); STRCPY_S(conf->bgarch, ""); STRCPY_S(conf->bgfile, scene_appdir()); STRCAT_S(conf->bgfile, "bg.png"); conf->bgwhere = scene_in_zip; conf->confver = XREADER_VERSION_NUM; conf->forecolor = 0xFFFFFFFF; conf->giftranscolor = 0xFFFFFFFF; conf->bgcolor = 0; conf->have_bg = true; conf->rowspace = 2; conf->wordspace = 0; conf->borderspace = 0; conf->vertread = 0; conf->infobar = conf_infobar_info; conf->infobar_style = 0; conf->rlastrow = false; conf->autobm = true; conf->encode = conf_encode_gbk; conf->fit = conf_fit_none; conf->imginfobar = false; conf->scrollbar = false; conf->scale = 0; conf->rotate = conf_rotate_0; conf->enable_analog = true; conf->img_enable_analog = true; conf->txtkey[0] = PSP_CTRL_SQUARE; conf->txtkey[1] = PSP_CTRL_LTRIGGER; conf->txtkey[2] = PSP_CTRL_RTRIGGER; conf->txtkey[3] = PSP_CTRL_UP | PSP_CTRL_CIRCLE; conf->txtkey[4] = PSP_CTRL_DOWN | PSP_CTRL_CIRCLE; conf->txtkey[5] = PSP_CTRL_LEFT | PSP_CTRL_CIRCLE; conf->txtkey[6] = PSP_CTRL_RIGHT | PSP_CTRL_CIRCLE; conf->txtkey[7] = PSP_CTRL_LTRIGGER | PSP_CTRL_CIRCLE; conf->txtkey[8] = PSP_CTRL_RTRIGGER | PSP_CTRL_CIRCLE; conf->txtkey[9] = 0; conf->txtkey[10] = 0; conf->txtkey[11] = PSP_CTRL_CROSS; conf->txtkey[12] = PSP_CTRL_TRIANGLE; conf->imgkey[0] = PSP_CTRL_LTRIGGER; conf->imgkey[1] = PSP_CTRL_RTRIGGER; conf->imgkey[2] = PSP_CTRL_TRIANGLE; conf->imgkey[3] = PSP_CTRL_UP | PSP_CTRL_CIRCLE; conf->imgkey[4] = PSP_CTRL_DOWN | PSP_CTRL_CIRCLE; conf->imgkey[5] = PSP_CTRL_LEFT | PSP_CTRL_CIRCLE; conf->imgkey[6] = PSP_CTRL_RIGHT | PSP_CTRL_CIRCLE; conf->imgkey[7] = PSP_CTRL_SQUARE; conf->imgkey[8] = PSP_CTRL_CIRCLE; conf->imgkey[9] = PSP_CTRL_CROSS; conf->imgkey[10] = PSP_CTRL_LTRIGGER | PSP_CTRL_CIRCLE; conf->imgkey[11] = 0; conf->imgkey[12] = PSP_CTRL_UP; conf->imgkey[13] = PSP_CTRL_DOWN; conf->imgkey[14] = PSP_CTRL_LEFT; conf->imgkey[15] = PSP_CTRL_RIGHT; conf->flkey[0] = PSP_CTRL_CIRCLE; conf->flkey[1] = PSP_CTRL_LTRIGGER; conf->flkey[2] = PSP_CTRL_RTRIGGER; conf->flkey[3] = PSP_CTRL_CROSS; conf->flkey[4] = 0; conf->flkey[5] = PSP_CTRL_TRIANGLE; conf->flkey[6] = PSP_CTRL_SQUARE; conf->flkey[7] = PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER; conf->bicubic = false; conf->mp3encode = conf_encode_gbk; conf->lyricencode = conf_encode_gbk; conf->mp3cycle = conf_cycle_repeat; conf->isreading = false; conf->slideinterval = 5; conf->hprmctrl = false; conf->grayscale = 30; conf->showhidden = true; conf->showunknown = true; conf->showfinfo = true; conf->allowdelete = true; conf->arrange = conf_arrange_name; conf->enableusb = false; conf->viewpos = conf_viewpos_leftup; conf->imgmvspd = 8; conf->imgpaging = conf_imgpaging_direct; conf->imgpaging_spd = 8; conf->imgpaging_interval = 10; conf->imgpaging_duration = 10; conf->fontsize = 12; conf->bookfontsize = 12; conf->reordertxt = false; conf->pagetonext = false; conf->autopage = 0; conf->autopagetype = 2; conf->autolinedelay = 0; conf->thumb = conf_thumb_scroll; conf->imgpagereserve = 0; #if defined(ENABLE_MUSIC) && defined(ENABLE_LYRIC) conf->lyricex = 1; #else conf->lyricex = 0; #endif conf->autoplay = false; conf->usettf = 0; conf->freqs[0] = 1; conf->freqs[1] = 5; conf->freqs[2] = 8; conf->imgbrightness = 100; conf->dis_scrsave = false; conf->autosleep = 0; conf->load_exif = true; conf->prev_autopage = 2; conf->launchtype = 2; /* conf->titlecolor = RGB(0x80, 0x10, 0x10); conf->menutextcolor = RGB(0xDF, 0xDF, 0xDF); conf->menubcolor = RGB(0x40, 0x10, 0x10); conf->selicolor = RGB(0xFF, 0xFF, 0x40); conf->selbcolor = RGB(0x20, 0x20, 0xDF); conf->msgbcolor = RGB(0x18, 0x28, 0x50); */ conf->titlecolor = RGB(0x30, 0x60, 0x30); conf->menutextcolor = RGB(0xDF, 0xDF, 0xDF); conf->menubcolor = RGB(0x10, 0x30, 0x20); conf->selicolor = RGB(0xFF, 0xFF, 0x40); conf->selbcolor = RGB(0x20, 0x20, 0xDF); conf->msgbcolor = RGB(0x18, 0x28, 0x50); conf->usedyncolor = false; STRCPY_S(conf->cttfpath, scene_appdir()); STRCAT_S(conf->cttfpath, "fonts/gbk.ttf"); STRCPY_S(conf->ettfpath, scene_appdir()); STRCAT_S(conf->ettfpath, "fonts/asc.ttf"); conf->infobar_use_ttf_mode = true; conf->img_no_repeat = false; conf->hide_flash = true; conf->tabstop = 4; conf->apetagorder = true; STRCPY_S(conf->language, "zh_CN"); conf->filelistwidth = 160; if (kuKernelGetModel() == PSP_MODEL_STANDARD) { conf->ttf_load_to_memory = false; } else { conf->ttf_load_to_memory = true; } conf->save_password = true; conf->scrollbar_width = 5; conf->hide_last_row = false; conf->infobar_show_timer = true; conf->infobar_fontsize = 12; conf->englishtruncate = true; conf->image_scroll_chgn_speed = true; conf->ttf_haste_up = true; conf->linenum_style = false; conf->infobar_align = conf_align_left; conf->show_encoder_msg = false; SPRINTF_S(conf->musicdrv_opts, "mp3_brute_mode=off mp3_use_me=on mp3_check_crc=off mp3_buffer_size=%d " "wma_buffer_size=%d aac_buffer_size=%d wav_buffer_size=%d wv_buffer_size=%d " "aa3_buffer_size=%d at3_buffer_size=%d m4a_buffer_size=%d " "flac_buffer_size=%d", BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE, WVPACK_BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE, BUFFERED_READER_BUFFER_SIZE); conf->magnetic_scrolling = true; conf->use_image_queue = true; conf->max_cache_img = 10; }
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; }
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; }