// Screen shot保存 boolean PSPEMU_SaveScreenShot(void) { char szFullPath[MAX_PATH]; uint32 nCount = 0; SceIoStat stat; // 保存するファイル名のパスを作る sceIoMkdir("ms0:/PSP/PHOTO" ,0777); sceIoMkdir("ms0:/PSP/PHOTO/NesterJ" ,0777); do { sprintf(szFullPath, "ms0:/PSP/PHOTO/NesterJ/%s%04d.png", NES_ROM_GetRomName(), nCount); nCount++; } while (sceIoGetstat(szFullPath, &stat) >= 0); // szFullPathに保存する return CreateScreenShotFile(szFullPath); }
void OSystem_PSP2::init() { #if __PSP2_DEBUG__ gDebugLevel = 3; #endif // Initialze File System Factory sceIoMkdir("ux0:data", 0755); sceIoMkdir("ux0:data/scummvm", 0755); sceIoMkdir("ux0:data/scummvm/saves", 0755); _fsFactory = new PSP2FilesystemFactory(); // Invoke parent implementation of this method OSystem_SDL::init(); }
extern u32 copy_dir(const char *src, const char *dest, t_copy_cb cb, t_copy_overwritecb ocb, void *data) { int dl = sceIoDopen(src); u32 result = 0; SceIoDirent sid; if (dl < 0) { if (cb != NULL) cb(src, dest, false, data); return 0; } sceIoMkdir(dest, 0777); memset(&sid, 0, sizeof(SceIoDirent)); while (sceIoDread(dl, &sid)) { char copysrc[260], copydest[260]; if (sid.d_name[0] == '.') continue; SPRINTF_S(copysrc, "%s/%s", src, sid.d_name); SPRINTF_S(copydest, "%s/%s", dest, sid.d_name); if (FIO_S_ISDIR(sid.d_stat.st_mode)) { result += copy_dir(copysrc, copydest, cb, ocb, data); continue; } if (copy_file(copysrc, copydest, cb, ocb, data)) ++result; memset(&sid, 0, sizeof(SceIoDirent)); } sceIoDclose(dl); return result; }
/** * path_mkdir_norecurse: * @dir : directory * * Create directory on filesystem. * * Returns: true (1) if directory could be created, otherwise false (0). **/ bool mkdir_norecurse(const char *dir) { int ret; #if defined(_WIN32) ret = _mkdir(dir); #elif defined(IOS) ret = mkdir(dir, 0755); #elif defined(VITA) || defined(PSP) ret = sceIoMkdir(dir, 0777); #else ret = mkdir(dir, 0750); #endif /* Don't treat this as an error. */ #if defined(VITA) if ((ret == SCE_ERROR_ERRNO_EEXIST) && path_is_directory(dir)) ret = 0; #elif defined(PSP) if ((ret == -1) && path_is_directory(dir)) ret = 0; #else if (ret < 0 && errno == EEXIST && path_is_directory(dir)) ret = 0; #endif if (ret < 0) printf("mkdir(%s) error: %s.\n", dir, strerror(errno)); return ret == 0; }
int hcWriteFile(char* file, void* buffer, int size) { int i; int pathlen = 0; char path[128]; // because I'm so lazy, I need folders created "on the fly" // this does so, create every folder in the path of the // file we are to save. // A little bruty forcy, yah, but it does the job :-D for (i = 1; i < (strlen(file)); i++) { if (strncmp(file + i - 1, "/", 1) == 0) { pathlen = i - 1; strncpy(path, file, pathlen); path[pathlen] = 0; sceIoMkdir(path, 0777); } } // now up to the file write.... SceUID fd = sceIoOpen(file, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { return -1; } int written = sceIoWrite(fd, buffer, size); if (sceIoClose(fd) < 0) return -1; return written; }
static int mkdir_recursive(const char *path) { int exit_status = 1; SceIoStat stat; if (sceIoGetstat(path, &stat) == 0){ /* If not a directory, cannot continue; otherwise success */ exit_status = SCE_S_ISDIR(stat.st_mode); return exit_status; } /* First, try creating its parent directory */ char *slash_pos = strrchr(path, '/'); if (!slash_pos); /* Top level */ else if (slash_pos != path && slash_pos[-1] == ':'); /* Top level */ else { char *parent = strdup(path); parent[slash_pos - path] = '\0'; exit_status = mkdir_recursive(parent); free(parent); } if (exit_status && slash_pos[1] != '\0') { int status = sceIoMkdir(path, 0777); if (status != 0) exit_status = 0; } return exit_status; }
int hook_sceIoMkdir(const char *dir, SceMode mode) { sceKernelCheckCallback(); char tmpPath[MAX_PATH_LENGTH]; char *tmp=TranslateVFS(tmpPath, dir); return sceIoMkdir(tmp, mode); }
int hook_sceIoMkdir(const char *dir, SceMode mode) { state_machine_checkState(); char tmpPath[MAX_PATH_LENGTH]; char *tmp=TranslateVFS(tmpPath, dir); return sceIoMkdir(tmp, mode); }
bool DirectoryCreate(const char *strDirectoryName) { #if defined(_WIN32) return CreateDirectory(strDirectoryName, NULL) != 0; #elif defined(PLATFORM_PSP2) return sceIoMkdir(strDirectoryName, 0777) >= 0; #endif return false; }
void Cross::CreateDir(std::string const& in) { #ifdef WIN32 mkdir(in.c_str()); #elif defined(VITA) sceIoMkdir(in.c_str(), 0700); #else mkdir(in.c_str(),0700); #endif }
static void create_dir(ClientInfo *client, const char *path) { DEBUG("Creating: %s\n", path); if (sceIoMkdir(path, 0777) >= 0) { client_send_ctrl_msg(client, "226 Directory created.\n"); } else { client_send_ctrl_msg(client, "550 Could not create the directory.\n"); } }
void PBPParse::Parse(const char *file){ fid = sceIoOpen(file, PSP_O_RDONLY, 0777); sceIoMkdir("ms0:/TMP", 0777); if (fid >= 0) { if (sceIoRead(fid, &header, sizeof(PBPHeader)) == sizeof(PBPHeader)){ char *temp = (char*)malloc(header.icon0 - header.sfo); sceIoLseek(fid, header.sfo, PSP_SEEK_SET); sceIoRead(fid, temp, header.icon0 - header.sfo); SceUID sfoFile = sceIoOpen("ms0:/TMP/PARAM.SFO", PSP_O_CREAT | PSP_O_WRONLY, 0777); sceIoWrite(sfoFile, temp, header.icon0 - header.sfo); sceIoClose(sfoFile); free(temp); sfo.Parse("ms0:/TMP/PARAM.SFO"); temp = (char*)malloc(header.icon1 - header.icon0); sceIoLseek(fid, header.icon0, PSP_SEEK_SET); sceIoRead(fid, temp, header.icon1 - header.icon0); SceUID icoFile = sceIoOpen("ms0:/TMP/ICON0.PNG", PSP_O_CREAT | PSP_O_WRONLY, 0777); sceIoWrite(icoFile, temp, header.icon1 - header.icon0); sceIoClose(icoFile); if (header.icon1 - header.icon0 > 0){ OSL_IMAGE *ico = oslLoadImageFilePNG("ms0:/TMP/ICON0.PNG", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650); icon = oslScaleImageCreate(ico, OSL_IN_RAM, 64, 64, OSL_PF_5650); oslDeleteImage(ico); oslWriteImageFilePNG(icon, "ms0:/TMP/ICON0.PNG", 0); } else{ icon = oslCreateImageCopy(defaultUNKN, OSL_IN_RAM); } free(temp); temp = (char*)malloc(header.snd - header.pic1); sceIoLseek(fid, header.pic1, PSP_SEEK_SET); sceIoRead(fid, temp, header.snd - header.pic1); SceUID picFile = sceIoOpen("ms0:/TMP/PIC1.PNG", PSP_O_CREAT | PSP_O_WRONLY, 0777); sceIoWrite(picFile, temp, header.snd - header.pic1); sceIoClose(picFile); if (header.snd - header.pic1 > 0){ pic = oslLoadImageFilePNG("ms0:/TMP/PIC1.PNG", OSL_IN_RAM, OSL_PF_8888); OSL_IMAGE *tmpPic = oslScaleImageCreate(pic, OSL_IN_RAM, 128, 128, OSL_PF_8888); oslUnswizzleImage(tmpPic); oslWriteImageFilePNG(tmpPic, "ms0:/TMP/PIC1SC.PNG", 0); oslDeleteImage(tmpPic); oslDeleteImage(pic); //Get rid of the pic file for now, we don't need it } free(temp); sceIoClose(fid); } } }
void GBAConfigDirectory(char* out, size_t outLength) { struct VFile* portable; #ifdef _WIN32 wchar_t wpath[MAX_PATH]; wchar_t wprojectName[MAX_PATH]; MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH); HMODULE hModule = GetModuleHandleW(NULL); GetModuleFileNameW(hModule, wpath, MAX_PATH); PathRemoveFileSpecW(wpath); WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); StringCchCatA(out, outLength, "\\portable.ini"); portable = VFileOpen(out, O_RDONLY); if (portable) { portable->close(portable); } else { wchar_t* home; SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home); StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName); CoTaskMemFree(home); CreateDirectoryW(wpath, NULL); } WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); #elif defined(PSP2) UNUSED(portable); snprintf(out, outLength, "cache0:/%s", projectName); sceIoMkdir(out, 0777); #elif defined(GEKKO) UNUSED(portable); snprintf(out, outLength, "/%s", projectName); mkdir(out, 0777); #elif defined(_3DS) UNUSED(portable); snprintf(out, outLength, "/%s", projectName); FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, out), 0); #else getcwd(out, outLength); strncat(out, PATH_SEP "portable.ini", outLength - strlen(out)); portable = VFileOpen(out, O_RDONLY); if (portable) { getcwd(out, outLength); portable->close(portable); return; } char* home = getenv("HOME"); snprintf(out, outLength, "%s/.config", home); mkdir(out, 0755); snprintf(out, outLength, "%s/.config/%s", home, binaryName); mkdir(out, 0755); #endif }
/* Creation de l'image ppm dans un fichier */ void create_image(uint32_t *picture, int32_t size_x, int32_t size_y, char *filename) { #ifdef PSP2 char buf[255]; sceIoMkdir("pss0:/top/Documents/screens", 0777); sprintf(buf, "pss0:/top/Documents/screens/%s", filename); FILE *file = fopen(buf, "wb"); #else FILE *file = fopen(filename, "wb"); #endif if (file != NULL) { const uint32_t LEN = size_x * size_y; uint32_t pixel; char buffer[3]; fprintf( file, "P6\n" "%d %d\n" "255\n", size_x, size_y ); for (uint32_t i = 0; i < LEN; i++) { pixel = picture[i]; /* Rouge */ buffer[0] = pixel; /* Vert */ buffer[1] = pixel >> 8; /* Bleu */ buffer[2] = pixel >> 16; fwrite(buffer, 3, 1, file); } fclose(file); printf("%s saved", filename); } else {
void PSPSaveFileManager::checkPath(const Common::FSNode &dir) { const char *savePath = dir.getPath().c_str(); clearError(); PowerMan.beginCriticalSection(); //check if the save directory exists SceUID fd = sceIoDopen(savePath); if (fd < 0) { //No? then let's create it. sceIoMkdir(savePath, 0777); } else { //it exists, so close it again. sceIoDclose(fd); } PowerMan.endCriticalSection(); }
int sctrlSESetConfig(TNConfig *config) { int k1 = pspSdkSetK1(0); sceIoMkdir("ms0:/PSP/SYSTEM", 0777); SceUID fd = sceIoOpen("ms0:/PSP/SYSTEM/CONFIG.TN", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if(fd < 0) { pspSdkSetK1(k1); return fd; } memcpy(&conf, config, sizeof(TNConfig)); int written = sceIoWrite(fd, config, sizeof(TNConfig)); sceIoClose(fd); pspSdkSetK1(k1); return written; }
void sceIoMvdir(char *oldPath, char *newPath){ if (Dir_NotExist(newPath)){ sceIoMkdir(newPath, 0777); } char *fullOldPath; char *fullNewPath; SceIoDirent oneDir; int oDir = sceIoDopen(oldPath); if (oDir < 0){ return; } while (1){ memset(&oneDir, 0, sizeof(SceIoDirent)); if (sceIoDread(oDir, &oneDir) <= 0) break; if (!strcmp(oneDir.d_name, ".") || !strcmp(oneDir.d_name, "..")) continue; if (oldPath[strlen(oldPath)-1] != '/'){ fullOldPath = (char *)calloc(strlen(oldPath)+strlen(oneDir.d_name)+2,sizeof(char)); fullNewPath = (char *)calloc(strlen(newPath)+strlen(oneDir.d_name)+2,sizeof(char)); sprintf(fullOldPath,"%s/%s",oldPath,oneDir.d_name); sprintf(fullNewPath,"%s/%s",newPath,oneDir.d_name); } else { fullOldPath = (char *)calloc(strlen(oldPath)+strlen(oneDir.d_name)+1,sizeof(char)); fullNewPath = (char *)calloc(strlen(newPath)+strlen(oneDir.d_name)+1,sizeof(char)); sprintf(fullOldPath,"%s%s",oldPath,oneDir.d_name); sprintf(fullNewPath,"%s%s",newPath,oneDir.d_name); } if (FIO_S_ISDIR(oneDir.d_stat.st_mode)){ sceIoMvdir(fullOldPath,fullNewPath); } else if(FIO_S_ISREG(oneDir.d_stat.st_mode)){ sceIoMove(fullOldPath,fullNewPath); } free(fullOldPath); free(fullNewPath); } sceIoDclose(oDir); sceIoRmdir(oldPath); }
int ZipExtractCurrentFile(Zip *zip, int *nopath, const char *password, const char* path) { //void(overwrite); char filenameinzip[256]; char extract_path[1024]; char* filenameWithoutPath; char *p; void *buffer; unsigned int buffersize = TMPBUF_SIZE; int err = 0; FILE *fout = NULL; zipFileInfo fileInfo; err = ZitCurrentFileInfo(zip, &fileInfo, filenameinzip, sizeof(filenameinzip), NULL, 0, NULL, 0); if(err != 0) { printf("error %d with zipfile in ZitCurrentFileInfo\n", err); return -1; } buffer = (void *)MallocPatch(buffersize); if(!buffer) { printf("Error allocating buffer\n"); return 0; } p = filenameWithoutPath = filenameinzip; while((*p) != '\0') { if(((*p) == '/') || ((*p) == '\\')) filenameWithoutPath = p + 1; p++; } if((*filenameWithoutPath) == '\0') { if((*nopath) == 0) { //printf("Creating directory: %s\n", filenameinzip); sprintf(extract_path,"%s/%s",path, filenameinzip); sceIoMkdir(extract_path, 0777); } } else { const char *writeFilename; if((*nopath) == 0) writeFilename = filenameinzip; else writeFilename = filenameWithoutPath; err = ZipOpenCurrentFile(zip, password); if(err != _ZIP_OK) printf("Error with zipfile in ZipOpenCurrentFile\n"); sprintf(extract_path,"%s/%s",path, writeFilename); fout = fopen(extract_path, "wb"); if((fout == NULL) && ((*nopath) == 0) && (filenameWithoutPath != (char *)filenameinzip)) { char c = *(filenameWithoutPath - 1); *(filenameWithoutPath - 1) = '\0'; sceIoMkdir(writeFilename, 0777); *(filenameWithoutPath - 1) = c; fout = fopen(writeFilename, "wb"); } if(fout == NULL) printf("Error opening file\n"); void* extractBuffer = buffer; unsigned int remainingSize = buffersize; do { err = ZipReadCurrentFile(zip, extractBuffer, remainingSize); if(err < 0) { printf("Error with zipfile in ZipReadCurrentFile\n"); break; } if(err > 0) { remainingSize = remainingSize - err; if (remainingSize == 0){ fwrite(buffer, 1, buffersize, fout); remainingSize = buffersize; extractBuffer = buffer; }else extractBuffer = extractBuffer+err; } } while (err > 0); if (remainingSize != buffersize) fwrite(buffer, 1, buffersize-remainingSize, fout); fclose(fout); err = ZipCloseCurrentFile(zip); if(err != _ZIP_OK) printf("Error with zipfile in ZipCloseCurrentFile\n"); } if(buffer) FreePatch(buffer); return err; }
int split_thread(SceSize args_size, SplitArguments *args) { SceUID thid = -1; // Set progress to 0% sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 0); sceKernelDelayThread(DIALOG_WAIT); // Needed to see the percentage SceUID fd = -1; void *buf = NULL; FileListEntry *file_entry = fileListGetNthEntry(args->file_list, args->index); char path[MAX_PATH_LENGTH]; snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, file_entry->name); // Get file size SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); int res = sceIoGetstat(path, &stat); if (res < 0) { closeWaitDialog(); errorDialog(res); goto EXIT; } // Update thread thid = createStartUpdateThread((uint32_t)stat.st_size); // Make folder char folder[MAX_PATH_LENGTH]; snprintf(folder, MAX_PATH_LENGTH, "%s%s", path, SPLIT_SUFFIX); sceIoMkdir(folder, 0777); // Split process fd = sceIoOpen(path, SCE_O_RDONLY, 0); if (fd < 0) { closeWaitDialog(); errorDialog(fd); goto EXIT; } buf = malloc(SPLIT_PART_SIZE); uint32_t seek = 0; while (seek < (uint32_t)stat.st_size) { int read = sceIoRead(fd, buf, SPLIT_PART_SIZE); if (read < 0) { closeWaitDialog(); errorDialog(read); goto EXIT; } int part_num = seek / SPLIT_PART_SIZE; int folder_num = part_num / SPLIT_MAX_FILES; int file_num = part_num % SPLIT_MAX_FILES; char new_path[MAX_PATH_LENGTH]; snprintf(new_path, MAX_PATH_LENGTH, "%s%s/%04d/%04d", path, SPLIT_SUFFIX, folder_num, file_num); int written = WriteFile(new_path, buf, read); // Failed, maybe folder doesn't exist yet? if (written < 0) { // Make folder char folder[MAX_PATH_LENGTH]; snprintf(folder, MAX_PATH_LENGTH, "%s%s/%04d", path, SPLIT_SUFFIX, folder_num); sceIoMkdir(folder, 0777); // Retry written = WriteFile(new_path, buf, read); } if (written < 0) { closeWaitDialog(); errorDialog(written); goto EXIT; } seek += read; SetProgress(seek, stat.st_size); } // Write size char size_path[MAX_PATH_LENGTH]; snprintf(size_path, MAX_PATH_LENGTH, "%s%s/%s", path, SPLIT_SUFFIX, SPLIT_SIZE_NAME); WriteFile(size_path, &seek, sizeof(uint32_t)); // Set progress to 100% sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 100); sceKernelDelayThread(COUNTUP_WAIT); // Close sceMsgDialogClose(); dialog_step = DIALOG_STEP_SPLITTED; EXIT: if (buf) free(buf); if (fd >= 0) sceIoClose(fd); if (thid >= 0) sceKernelWaitThreadEnd(thid, NULL, NULL); return sceKernelExitDeleteThread(0); }
int main(int argc, char *argv[]) { int i; pspDebugScreenInit(); SceUID mod = pspSdkLoadStartModule ("flash0:/kd/chnnlsv.prx",PSP_MEMORY_PARTITION_KERNEL); if (mod < 0) { printf("Error 0x%08X loading/starting chnnlsv.prx.\n", mod); } mod = pspSdkLoadStartModule ("kernelcall.prx",PSP_MEMORY_PARTITION_KERNEL); if (mod < 0) { printf("Error 0x%08X loading/starting kernelcall.prx.\n", mod); } sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); for(;;) { printf("===================================================================="); printf("PPSSPP Save Tool\n"); printf("====================================================================\n\n\n"); switch(currentMenu) { case 0: { int maxOption = 0; for(i = 0; menuList0[i]; i++) { if(i == selectedOption) printf(" > %s\n",menuList0[i]); else printf(" %s\n",menuList0[i]); maxOption++; } int input = ProcessInput(maxOption, &selectedOption); if(input == 0) { currentMenu = 1; selectedOption = 0; } else if(input == 1) { currentMenu = 4; selectedOption = 0; } else if(input == 2) { sceKernelExitGame(); } } break; case 4: case 1: { int maxOption = 0; printf("PPSSPP Decrypted Save Directory : \n"); for(i = 0; menuList1[i]; i++) { if(i == selectedOption) printf(" > %s\n",menuList1[i]); else printf(" %s\n",menuList1[i]); maxOption++; } int input = ProcessInput(maxOption, &selectedOption); if(input == maxOption-1) { if(currentMenu == 1) selectedOption = 0; else selectedOption = 1; currentMenu = 0; } else if(input >= 0) { basePath = selectedOption; if(currentMenu == 1) { currentMenu = 2; UpdateValidDir(1); } else { currentMenu = 5; UpdateValidDir(0); } selectedOption = 0; } } break; case 5: case 2: { int maxOption = 0; if(currentMenu == 2) printf("Save to encrypt : \n"); else printf("Save to decrypt : \n"); if(numDirList == 0) { printf("No compatible data, see README for help on use\n"); } for(i = 0; i < numDirList; i++) { if(i == selectedOption) printf(" > %s\n",dirList[i].name); else printf(" %s\n",dirList[i].name); maxOption++; } for(i = 0; menuList2[i]; i++) { if((i+numDirList) == selectedOption) printf(" > %s\n",menuList2[i]); else printf(" %s\n",menuList2[i]); maxOption++; } printf("\n Invalid path : \n"); for(i = 0; i < numInvalidDirList && i < (22-numDirList); i++) { switch(invalidDirList[i].errorId) { case 1: printf(" %s : ENCRYPT_INFO.BIN not found\n",invalidDirList[i].name); break; case 2: printf(" %s : ENCRYPT_INFO.BIN read error\n",invalidDirList[i].name); break; case 3: printf(" %s : ENCRYPT_INFO.BIN wrong version\n",invalidDirList[i].name); break; case 4: printf(" %s : PARAM.SFO not found\n",invalidDirList[i].name); break; case 5: printf(" %s : PARAM.SFO read error\n",invalidDirList[i].name); break; case 6: printf(" %s : SAVEDATA_FILE_LIST not found in PARAM.SFO\n",invalidDirList[i].name); break; case 7: printf(" %s : no save name in SAVEDATA_FILE_LIST\n",invalidDirList[i].name); break; case 8: printf(" %s : no save found\n",invalidDirList[i].name); break; default: break; } } int input = ProcessInput(maxOption, &selectedOption); if(input == numDirList) { if(currentMenu == 2) currentMenu = 1; else currentMenu = 4; selectedOption = basePath; } else if(input >= 0) { if(currentMenu == 2) currentMenu = 3; else currentMenu = 6; workDir = input; selectedOption = 0; } } break; case 6: case 3: { EncryptFileInfo encryptInfo; if(FileRead(menuList1[basePath], dirList[workDir].name, "ENCRYPT_INFO.BIN",(u8*)&encryptInfo,sizeof(encryptInfo)) < 0) { printf("Can't read encrypt file\n"); } else { printf("Key : "); for(i = 0; i < 16; i++) printf(" %02x",(u8)encryptInfo.key[i]); printf("\n"); printf("SDK Version : 0x%x\n",encryptInfo.sdkVersion); char srcPath[128]; char dstPath[128]; if(currentMenu == 3) { sprintf(srcPath,"%s%s",menuList1[basePath], dirList[workDir].name); sprintf(dstPath,"ms0:/PSP/SAVEDATA/%s",dirList[workDir].name); sceIoMkdir(dstPath,0777); } else { sprintf(srcPath,"ms0:/PSP/SAVEDATA/%s",dirList[workDir].name); sprintf(dstPath,"%s%s",menuList1[basePath], dirList[workDir].name); } int dfd; dfd = sceIoDopen(srcPath); if(dfd >= 0) { SceIoDirent dirinfo; while(sceIoDread(dfd, &dirinfo) > 0) { if(!(dirinfo.d_stat.st_mode & 0x2000)) // is not a file continue; if(strcmp(dirinfo.d_name,"ENCRYPT_INFO.BIN") == 0) // don't copy encrypt info continue; FileCopy(srcPath, dstPath, dirinfo.d_name); } sceIoDclose(dfd); } if(currentMenu == 3) { char decryptedFile[258], encryptedFile[258], srcSFO[258], dstSFO[258]; sprintf(decryptedFile,"%s/%s",srcPath ,dirList[workDir].saveFile); sprintf(srcSFO,"%s/PARAM.SFO",srcPath); sprintf(encryptedFile,"%s/%s",dstPath ,dirList[workDir].saveFile); sprintf(dstSFO,"%s/PARAM.SFO",dstPath); printf("Encoding %s into %s\n",decryptedFile, encryptedFile); int ret = encrypt_file(decryptedFile, encryptedFile, dirList[workDir].saveFile, srcSFO, dstSFO, encryptInfo.key[0] != 0 ? encryptInfo.key : NULL, GetSDKMainVersion(encryptInfo.sdkVersion) ); if(ret < 0) { printf("Error: encrypt_file() returned %d\n\n", ret); } else { printf("Successfully wrote %d bytes to\n", ret); printf(" %s\n", encryptedFile); printf("and updated hashes in\n"); printf(" %s\n\n", dstSFO); } } else { char decryptedFile[258], encryptedFile[258]; sprintf(encryptedFile,"%s/%s",srcPath ,dirList[workDir].saveFile); sprintf(decryptedFile,"%s/%s",dstPath ,dirList[workDir].saveFile); printf("Decoding %s into %s\n",encryptedFile, decryptedFile); int ret = decrypt_file(decryptedFile, encryptedFile, encryptInfo.key[0] != 0 ? encryptInfo.key : NULL, GetSDKMainVersion(encryptInfo.sdkVersion)); if(ret < 0) { printf("Error: decrypt_file() returned %d\n\n", ret); } else { printf("Successfully wrote %d bytes to\n", ret); printf(" %s\n", decryptedFile); } } printf(" > Back\n"); int input = ProcessInput(1, &selectedOption); if(input >= 0) { if(currentMenu == 3) currentMenu = 2; else currentMenu = 5; selectedOption = 0; } } } break; default: sceKernelExitGame(); break; } pspDebugScreenClear(); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); } return 0; }
int mkdir(const char *path,mode_t mode){ char fullpath[PATH_MAX]; return seterrno(sceIoMkdir(convert_path(fullpath,path),mode)); }
global void ini_file_load(void) { #if 1 /* sceIoMkdir();でパスを作成する場合、最後が '/' だと作成されないので注意。 */ // 要望があったので全力で対応 // sceIoMkdir(const char *aaa_dir, SceMode mode); sceIoMkdir("ms0:/PICTURE", 0777); /* "ms0:/PICTURE"がない場合、 "ms0:/PICTURE/東方模倣風"が作れないので、必ず必要。 ない場合、無視されるのではなくて、最悪「ハングアップしたりする」。 */ // sceIoMkdir("ms0:/PICTURE/東方模倣風/", 0777);/* 出来ない */ sceIoMkdir("ms0:/PICTURE/東方模倣風", 0777);/* 出来る */ #endif // char my_file_common_name[128/*64 50*/]; // strcpy(my_file_common_name, "./" FILE_NAME_SETTING_TXT); strcpy(my_file_common_name, FILE_NAME_SETTING_TXT); int int_result; int_result = 0;/* 異常 */ int ng1; ng1 = 0;/*fopen()成功*/ // // FILE *fp; if (NULL == /* fp =*/ my_file_fopen()) /* 開けなかったとき */ /*my_file_common_name, "r"*/ { /* 読み込み失敗 */ ng1 = 1;/*fopen()失敗*/ goto error00; } /* キーコンフィグ設定の読み込み */ { char key_config_tag[4]; key_config_tag[0] = 'K'; key_config_tag[1] = '0'; // key_config_tag[2] = ('a'+i); key_config_tag[3] = 0; { unsigned int i; for (i=0; i<KINOU_08_WARIATE_MAX; i++) { key_config_tag[2] = ('a'+i); // { int value; value = ini_load_value(key_config_tag, NULL);/*fp,*/ if (0 > value) {goto error00; } else {pad_config[i] = value; } } } } } /* オプション設定の読み込み */ { unsigned int i; for (i=0; i<OPTION_CONFIG_08_MAX; i++) { int value; value = ini_load_value((char *)my_config_title[i], NULL);/*fp,*/ if (0 > value) {goto error00; } else {option_config[i] = value; } } } int_result = 1;/* 正常 */ // error00: /* high_score load */ { int ng2; int tmpscore; ng2 = ng1; tmpscore = 0; char search_str_name32[8];/*(検索する名前)*/ //-----------------01234567 strcpy(search_str_name32, "SCORE00"); search_str_name32[7] = 0;/* 念の為 */ // int j; for (j=0; j<MAX_8_SAVE_PLAYERS; j++) { search_str_name32[5] = '0'+j;/* PLAYER */ unsigned int i; for (i=0; i<MAX_5_RANKING; i++) { search_str_name32[6] = '0'+i;/* score rank number. 順位 */ if (0==ng2) { //#define readed_str_name32 my_file_line_buffer256 char readed_str_name32[64/*50*/]; // if (1 == fscanf(fp, "%23s\n", readed_str_name32 )) // if (0 != my_fgets(/*fp, "%23s\n", readed_str_name32*/ )) int value; value = ini_load_value(search_str_name32, readed_str_name32); if (0 > value) {ng2 = 1;/* エラー */} else { /* 埋め込む */ high_score_table[j][i].final_stage = readed_str_name32[1/*10*/]-('0'); // strncpy(high_score_table[j][i].name, &readed_str_name32[10], 3); high_score_table[j][i].name[0] = readed_str_name32[2];/*10*/ high_score_table[j][i].name[1] = readed_str_name32[3];/*11*/ high_score_table[j][i].name[2] = readed_str_name32[4];/*12*/ high_score_table[j][i].name[3] = readed_str_name32[5];/*13*/ // high_score_table[j][i].name[4] = readed_str_name32[6];/*14*/ high_score_table[j][i].name[5] = readed_str_name32[7];/*15*/ high_score_table[j][i].name[6] = readed_str_name32[8];/*16*/ high_score_table[j][i].name[7] = readed_str_name32[9];/*16*/ { char tmp_str32bytes[32];/*(atoiの場合、バッファ長32[bytes]==最大31文字に統一)*/ strcpy(tmp_str32bytes, &readed_str_name32[10]);/*5 13*/ tmpscore = atoi(tmp_str32bytes); } } } #if (1) /* else // 直前の ini_load_value() でエラーが起きた場合に初期化するので このelse無効。 */ // if (1==ng2) /* pspは0レジスタがあるので0と比較したほうが速い */ if (0!=ng2)/*(エラー発生している場合、強制的にスコアテーブルを初期化する。)*/ { high_score_table[j][i].final_stage = (6-i);/* 到達ステージ */ static const int init_score_tbl[5] = { score(100000000),//score(70000000),//score(50000000), score( 50000000),//score(60000000),//score(4000000), score( 10000000),//score(50000000),//score(300000), score( 5000000),//score(10000000),//score(20000), score( 1000000),//score( 5000000),//score(1000), }; // strcpy(high_score_table[j][i].name, "12345678"); // strcpy(high_score_table[j][i].name, "ZUN "); strcpy(high_score_table[j][i].name, "Nanashi "); tmpscore = init_score_tbl[i]; } #endif high_score_table[j][i].score = tmpscore; } } // top_score = high_score_table[0][0].score; // 常に表示するハイコアの取得=>score.cで利用 } // if (0==ng1) { my_file_fclose();/*fp*/ //fclose(fp); } //return (int_result)/*1*/; if (0==(int_result)) // 20090110 { // chooseModDir(); set_default_key(pad_config, 0/*0==type 01 模倣風 標準*/); set_default_option(option_config);/* OPTION_CONFIG_00_PLAYER から OPTION_CONFIG_03_SOUND まで設定 */ // option_config[OPTION_CONFIG_04_CURRENT_DIFFICULTY] = 0; // option_config[OPTION_CONFIG_05_CURRENT_PLAYER] = 0; // option_config[OPTION_CONFIG_06_ANALOG] = 0; option_config[OPTION_CONFIG_07_OPEN] = 0x0500; } /* 範囲外チェック(範囲外の場合は修正) */ check_limit_value_option(option_config);/* */ /* 読み込んだデーターで初期設定 */ cg.game_difficulty = option_config[OPTION_CONFIG_04_CURRENT_DIFFICULTY]; cg_game_select_player = option_config[OPTION_CONFIG_05_CURRENT_PLAYER]; #if 1/*(範囲外の場合は強制的に修正する。)*/ cg.game_difficulty &= 0x03;/* (easy)0 1 2 3(Lunatic) */ cg_game_select_player &= 0x07; #endif }
int makeCxmbThemeFile( unsigned int cxmb_magic, const char * cxmb_theme_file ) { const char * folders_name[] = { "/data/cert", "/dic", "/font", "/kd", "/kd/resource", "/vsh/etc", "/vsh/module", "/vsh/resource" }; int folders_count = 8; const char * support_exts[] = { ".prx", ".rco", ".bmp", ".pmf", ".res", ".pgf", ".bwfon", ".rsc", ".dat", ".img", ".bin", ".cet", ".dic" }; int exts_count = 13; int dfd, heap_id, fd, i, bytes, file_count = 0; unsigned int ptf_h[5]; char path[128], file[128], preview[64]; u8 * buf; // dectect if theme file in conf exist int ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDONLY, 0644 ); if ( ctf >= 0 ) { log( "theme file exist!\n" ); sceIoClose( ctf ); return 0; } dfd = sceIoDopen( "ms0:/cxmb" ); if ( dfd < 0 ) { log( "no cxmb folder found!\n" ); return 0; } sceIoDclose( dfd ); sprintf( preview, "ms0:/cxmb%s", &cxmb_theme_file[14] ); preview[strlen( preview ) - 3] = 'p'; log( "preview: %s\n", preview ); fd = sceIoOpen( preview, PSP_O_RDONLY, 0644 ); if ( fd < 0 ) { log( "no preview ptf file found!\n" ); return 0; } sceIoLseek( fd, 0x100, PSP_SEEK_SET ); sceIoRead( fd, ptf_h, 20 ); // create CXMB_MKCTF_BUF_SIZE + 32kb heap heap_id = sceKernelCreateHeap( 2, CXMB_MKCTF_BUF_SIZE + 1024 * 32 , 1, "cxmb_tmp_heap"); if ( heap_id < 0 ) { log( "failed in create heap in making cxmb theme file!\n" ); return -1; } CtfHeader * ch = ( CtfHeader * )sceKernelAllocHeapMemory( heap_id, sizeof( CtfHeader ) * 64 ); memset( ch, 0, sizeof( CtfHeader ) * 64 ); SceIoDirent * ent = ( SceIoDirent * )sceKernelAllocHeapMemory( heap_id, sizeof( SceIoDirent ) ); memset( ent, 0, sizeof( SceIoDirent ) ); sceIoMkdir( "ms0:/PSP/THEME", 0777 ); ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC, 0777 ); if ( ctf < 0 ) { log( "failed in opening %s\n", cxmb_theme_file ); sceKernelFreeHeapMemory( heap_id, ent ); sceKernelFreeHeapMemory( heap_id, ch ); sceKernelDeleteHeap( heap_id ); return -1; } else { if ( ptf_h[2] == 0 ) ptf_h[2] = sceIoLseek( fd, 0, PSP_SEEK_END ); log( "ptf sections size %08x\n", ptf_h[2] ); buf = sceKernelAllocHeapMemory( heap_id, ptf_h[2] ); if ( buf ) { sceIoLseek( fd, 0, PSP_SEEK_SET ); sceIoRead( fd, buf, ptf_h[2] ); sceIoWrite( ctf, buf, ptf_h[2] ); sceIoClose( fd ); sceKernelFreeHeapMemory( heap_id, buf ); sceIoLseek( ctf, 0x10, PSP_SEEK_SET ); sceIoWrite( ctf, &cxmb_magic, 4 ); sceIoLseek( ctf, 0x1C, PSP_SEEK_SET ); sceIoWrite( ctf, &ptf_h[2], 4 ); memset( &ptf_h[2], 0, 12 ); sceIoLseek( ctf, 0x100, PSP_SEEK_SET ); sceIoWrite( ctf, ptf_h, 20 ); sceIoLseek( ctf, 0, PSP_SEEK_END ); for ( i = 0; i < folders_count; i ++ ) { sprintf( path, "ms0:/cxmb%s", folders_name[i] ); dfd = sceIoDopen( path ); if ( dfd < 0 ) { log( "folder %s not found!\n", path ); continue; } log( "parsing %s\n", path ); while ( sceIoDread( dfd, ent ) > 0 ) { log( "found %s\n", ent->d_name ); if ( ( ent->d_stat.st_attr & FIO_SO_IFDIR ) || ent->d_name[0] == '.' ) { log( "ignore %s\n", ent->d_name ); continue; } if ( endwithistrs( ent->d_name, support_exts, exts_count ) ) { sprintf( file, "%s/%s", path, ent->d_name ); sprintf( ch[file_count].name, "%s/%s", folders_name[i], ent->d_name ); ch[file_count].start = sceIoLseek( ctf, 0, PSP_SEEK_CUR ); ch[file_count].size = 0; if ( cmpistrs( ent->d_name, diff_files, diff_count ) ) { char ori_file[128]; sprintf( ori_file, "%s/%s", CXMB_SUPPORT_FOLDER, ent->d_name ); ch[file_count].size = makeDiff( file, ori_file, heap_id, ctf ); } else { log( "dealing with %s\n", ent->d_name ); fd = sceIoOpen( file, PSP_O_RDONLY, 0644 ); if ( fd < 0 ) { log( "failed in opening %s\n", file ); continue; } buf = ( u8 * )sceKernelAllocHeapMemory( heap_id, CXMB_MKCTF_BUF_SIZE ); bytes = sceIoRead( fd, buf, CXMB_MKCTF_BUF_SIZE ); while( bytes > 0 ) { ch[file_count].size += sceIoWrite( ctf, buf, bytes ); bytes = sceIoRead( fd, buf, CXMB_MKCTF_BUF_SIZE ); } sceKernelFreeHeapMemory( heap_id, buf ); sceIoClose( fd ); } if ( ch[file_count].size > 0 && ch[file_count].size < CXMB_MAX_FILE_SIZE ) { log( "start: %08x size: %08x\n", ch[file_count].start, ch[file_count].size ); file_count ++; } } else { log( "ignore %s\n", ent->d_name ); } } sceIoDclose( dfd ); } } else { log( "failed in allocating %08x heap\n", ptf_h[2] ); } } log( "file_count: %d\n", file_count ); if ( file_count > 0 ) { u8 sha1[20]; sceKernelUtilsSha1Digest( ( u8 * )ch, sizeof( CtfHeader ) * file_count, sha1 ); sceIoWrite( ctf, ch, sizeof( CtfHeader ) * file_count ); sceIoLseek( ctf, 0x14, PSP_SEEK_SET ); sceIoWrite( ctf, &sha1[0], 4 ); sceIoWrite( ctf, &file_count, 4 ); sceIoClose( ctf ); } else { sceIoClose( ctf ); sceIoRemove( cxmb_theme_file ); } sceKernelFreeHeapMemory( heap_id, ent ); sceKernelFreeHeapMemory( heap_id, ch ); sceKernelDeleteHeap( heap_id ); return 0; }
bool Create( const char * p_path ) { return sceIoMkdir( p_path, 0777 ) == 0; }
int copyPath(char *src_path, char *dst_path, uint32_t *value, uint32_t max, void (* SetProgress)(uint32_t value, uint32_t max)) { // The source and destination paths are identical if (strcmp(src_path, dst_path) == 0) { return -1; } // The destination is a subfolder of the source folder int len = strlen(src_path); if (strncmp(src_path, dst_path, len) == 0 && dst_path[len] == '/') { return -1; } SceUID dfd = sceIoDopen(src_path); if (dfd >= 0) { int ret = sceIoMkdir(dst_path, 0777); if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) { sceIoDclose(dfd); return ret; } if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0) continue; char *new_src_path = malloc(strlen(src_path) + strlen(dir.d_name) + 2); snprintf(new_src_path, MAX_PATH_LENGTH, "%s/%s", src_path, dir.d_name); char *new_dst_path = malloc(strlen(dst_path) + strlen(dir.d_name) + 2); snprintf(new_dst_path, MAX_PATH_LENGTH, "%s/%s", dst_path, dir.d_name); if (SCE_S_ISDIR(dir.d_stat.st_mode)) { copyPath(new_src_path, new_dst_path, value, max, SetProgress); } else { copyFile(new_src_path, new_dst_path, value, max, SetProgress); } free(new_dst_path); free(new_src_path); } } while (res > 0); sceIoDclose(dfd); } else { copyFile(src_path, dst_path, value, max, SetProgress); } return 0; }
int main(void) { int err = 0; scePowerSetClockFrequency(333, 333, 166); pspDebugScreenInit(); printf("#### PSCRYPTER v2.0 by Carlosgs ####\nEncrypt EBOOT.PBP files directly from the PSP\nUses the code made by 'bbtgp' and parts of the PSPSDK\nv2.0 added realocation fixing by JJS\nTHANK YOU!\n\n"); sceIoMkdir("./sign/", 0777); chdir("./sign/"); sceIoRemove("EBOOT_signed.PBP"); sceIoRemove("param.sfo"); sceIoRemove("icon0.png"); sceIoRemove("icon1.pmf"); sceIoRemove("pic0.png"); sceIoRemove("pic1.png"); sceIoRemove("snd0.at3"); sceIoRemove("data.psp"); sceIoRemove("data_unsigned.psp"); sceIoRemove("data.psar"); printf("Unpacking EBOOT file...\n"); err = main_unpack_pbp(); if(err != 0) { printf("Error while unpacking: %d\n",err); myexit(); } printf("\nFixing PRX realocations...\n"); err = main_fix_realocations(); if(err != 0) { printf("Error while fixing realocations: %d\n",err); myexit(); } printf("\nCrypting PRX file...\n"); err = main_crypter(); if(err != 0) { printf("Error while crypting: %d\n",err); myexit(); } printf("\nPacking new EBOOT file...\n"); err = main_pack_pbp(10, filename_list); if(err != 0) { printf("Error while packing: %d\n",err); myexit(); } printf("\n\nFinished! Hope it works!\n"); myexit(); return 0; }
int extractArchivePath(char *src, char *dst, FileProcessParam *param) { if (!uf) return -1; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); if (archiveFileGetstat(src, &stat) < 0) { FileList list; memset(&list, 0, sizeof(FileList)); fileListGetArchiveEntries(&list, src, SORT_NONE); int ret = sceIoMkdir(dst, 0777); if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) { fileListEmpty(&list); return ret; } if (param) { if (param->value) (*param->value) += DIRECTORY_SIZE; if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); if (param->cancelHandler && param->cancelHandler()) { fileListEmpty(&list); return 0; } } FileListEntry *entry = list.head->next; // Ignore .. int i; for (i = 0; i < list.length - 1; i++) { char *src_path = malloc(strlen(src) + strlen(entry->name) + 2); snprintf(src_path, MAX_PATH_LENGTH, "%s%s", src, entry->name); char *dst_path = malloc(strlen(dst) + strlen(entry->name) + 2); snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", dst, entry->name); int ret = extractArchivePath(src_path, dst_path, param); free(dst_path); free(src_path); if (ret <= 0) { fileListEmpty(&list); return ret; } entry = entry->next; } fileListEmpty(&list); } else { SceUID fdsrc = archiveFileOpen(src, SCE_O_RDONLY, 0); if (fdsrc < 0) return fdsrc; SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); if (fddst < 0) { archiveFileClose(fdsrc); return fddst; } void *buf = malloc(TRANSFER_SIZE); uint64_t seek = 0; while (1) { int read = archiveFileRead(fdsrc, buf, TRANSFER_SIZE); if (read < 0) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return read; } if (read == 0) break; int written = sceIoWrite(fddst, buf, read); if (written == SCE_ERROR_ERRNO_ENODEV) { fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT, 0777); if (fddst >= 0) { sceIoLseek(fddst, seek, SCE_SEEK_SET); written = sceIoWrite(fddst, buf, read); } } if (written < 0) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return written; } seek += written; if (param) { if (param->value) (*param->value) += read; if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); if (param->cancelHandler && param->cancelHandler()) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return 0; } } } free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); } return 1; }
/** * path_mkdir: * @dir : directory * * Create directory on filesystem. * * Returns: true (1) if directory could be created, otherwise false (0). **/ bool path_mkdir(const char *dir) { /* Use heap. Real chance of stack overflow if we recurse too hard. */ const char *target = NULL; bool sret = false; bool norecurse = false; char *basedir = NULL; if (dir && *dir) basedir = strdup(dir); if (!basedir) return false; path_parent_dir(basedir); if (!*basedir || !strcmp(basedir, dir)) goto end; if (path_is_directory(basedir)) { target = dir; norecurse = true; } else { target = basedir; sret = path_mkdir(basedir); if (sret) { target = dir; norecurse = true; } } if (norecurse) { #if defined(_WIN32) #ifdef LEGACY_WIN32 int ret = _mkdir(dir); #else wchar_t *dirW = utf8_to_utf16_string_alloc(dir); int ret = -1; if (dirW) { ret = _wmkdir(dirW); free(dirW); } #endif #elif defined(IOS) int ret = mkdir(dir, 0755); #elif defined(VITA) || defined(PSP) int ret = sceIoMkdir(dir, 0777); #elif defined(__QNX__) int ret = mkdir(dir, 0777); #else int ret = mkdir(dir, 0750); #endif /* Don't treat this as an error. */ if (path_mkdir_error(ret) && path_is_directory(dir)) ret = 0; if (ret < 0) printf("mkdir(%s) error: %s.\n", dir, strerror(errno)); sret = (ret == 0); } end: if (target && !sret) printf("Failed to create directory: \"%s\".\n", target); free(basedir); return sret; }