/**************************************************************************** * MountMC * * Mounts the memory card in the given slot. * Returns the result of the last attempted CARD_Mount command. ***************************************************************************/ static int MountMC(int slot, bool silent) { int ret = -1; int tries = 0; // Initialize Card System SysArea = (u8 *)memalign(32, CARD_WORKAREA); memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("VBA0", "00"); // Mount the card while(tries < 10 && ret != 0) { EXI_ProbeReset(); ret = CARD_Mount (slot, SysArea, NULL); VIDEO_WaitVSync(); tries++; } if(ret != 0 && !silent) { if (slot == CARD_SLOTA) ErrorPrompt("Unable to mount Slot A Memory Card!"); else ErrorPrompt("Unable to mount Slot B Memory Card!"); } return ret; }
/**************************************************************************** * IsValidROM * * Checks if the specified file is a valid ROM * For now we will just check the file extension and file size * If the file is a zip, we will check the file extension / file size of the * first file inside ***************************************************************************/ static bool IsValidROM() { // gdi or mds are small if(browserList[browser.selIndex].length > 1024) { printf("%d\n",browserList[browser.selIndex].length); ErrorPrompt("Invalid file size!"); return false; } if (strlen(browserList[browser.selIndex].filename) > 4) { char * p = strrchr(browserList[browser.selIndex].filename, '.'); if (p != NULL) { char * zippedFilename = NULL; if(p != NULL) { if (stricmp(p, ".gdi") == 0 || stricmp(p, ".mds") == 0) { return true; } } } } ErrorPrompt("Unknown file type!"); return false; }
/**************************************************************************** * Verify Memory Card file against buffer ***************************************************************************/ static int VerifyMCFile (char *buf, int slot, char *filename, int datasize) { card_file CardFile; int CardError; unsigned int blocks; unsigned int SectorSize; int bytesleft = 0; int bytesread = 0; verifybuffer = (u8 *)memalign(32, 262144); memset (verifybuffer, 0, 262144); // Get Sector Size CARD_GetSectorSize (slot, &SectorSize); memset (&CardFile, 0, sizeof (CardFile)); CardError = CARD_Open (slot, filename, &CardFile); if(CardError) { ErrorPrompt("Unable to open file!"); } else { blocks = CardFile.len; if (blocks < SectorSize) blocks = SectorSize; if (blocks % SectorSize) blocks += SectorSize; if (blocks > (unsigned int)datasize) blocks = datasize; bytesleft = blocks; bytesread = 0; while (bytesleft > 0) { CardError = CARD_Read (&CardFile, verifybuffer, SectorSize, bytesread); if (CardError || memcmp (buf + bytesread, verifybuffer, (unsigned int)bytesleft < SectorSize ? bytesleft : SectorSize) ) { bytesread = 0; ErrorPrompt("File integrity could not be verified!"); break; } bytesleft -= SectorSize; bytesread += SectorSize; ShowProgress ("Verifying...", bytesread, blocks); } CARD_Close (&CardFile); CancelAction(); } free(verifybuffer); return bytesread; }
bool DownloadUpdate() { bool result = false; if(updateURL[0] == 0 || appPath[0] == 0 || !ChangeInterface(appPath, NOTSILENT)) { ErrorPrompt("Update failed!"); updateFound = false; // updating is finished (successful or not!) return false; } // stop checking if devices were removed/inserted // since we're saving a file HaltDeviceThread(); int device; FindDevice(appPath, &device); char updateFile[50]; sprintf(updateFile, "%s%s Update.zip", pathPrefix[device], APPNAME); FILE * hfile = fopen (updateFile, "wb"); if (hfile) { if(http_request(updateURL, hfile, NULL, (1024*1024*10), NOTSILENT) > 0) { fclose (hfile); result = unzipArchive(updateFile, (char *)pathPrefix[device]); } else { fclose (hfile); } remove(updateFile); // delete update file } // go back to checking if devices were inserted/removed ResumeDeviceThread(); if(result) InfoPrompt("Update successful!"); else ErrorPrompt("Update failed!"); updateFound = false; // updating is finished (successful or not!) return result; }
/**************************************************************************** * autoLoadMethod() * Auto-determines and sets the load device * Returns device set ****************************************************************************/ int autoLoadMethod() { ShowAction ("Attempting to determine load device..."); int device = DEVICE_AUTO; if(ChangeInterface(DEVICE_SD, SILENT)) device = DEVICE_SD; else if(ChangeInterface(DEVICE_USB, SILENT)) device = DEVICE_USB; else if(ChangeInterface(DEVICE_SD_SLOTA, SILENT)) device = DEVICE_SD_SLOTA; else if(ChangeInterface(DEVICE_SD_SLOTB, SILENT)) device = DEVICE_SD_SLOTB; else if(ChangeInterface(DEVICE_DVD, SILENT)) device = DEVICE_DVD; else if(ChangeInterface(DEVICE_SMB, SILENT)) device = DEVICE_SMB; else ErrorPrompt("Unable to locate a load device!"); if(GCSettings.LoadMethod == DEVICE_AUTO) GCSettings.LoadMethod = device; // save device found for later use CancelAction(); return device; }
/**************************************************************************** * autoSaveMethod() * Auto-determines and sets the save device * Returns device set ****************************************************************************/ int autoSaveMethod(bool silent) { if(!silent) ShowAction ("Attempting to determine save device..."); int device = DEVICE_AUTO; if(ChangeInterface(DEVICE_SD, SILENT)) device = DEVICE_SD; else if(ChangeInterface(DEVICE_USB, SILENT)) device = DEVICE_USB; else if(ChangeInterface(DEVICE_SD_SLOTA, SILENT)) device = DEVICE_SD_SLOTA; else if(ChangeInterface(DEVICE_SD_SLOTB, SILENT)) device = DEVICE_SD_SLOTB; else if(ChangeInterface(DEVICE_SMB, SILENT)) device = DEVICE_SMB; else if(!silent) ErrorPrompt("Unable to locate a save device!"); if(GCSettings.SaveMethod == DEVICE_AUTO) GCSettings.SaveMethod = device; // save device found for later use CancelAction(); return device; }
/**************************************************************************** * UpdateDirName() * Update curent directory name for file browser ***************************************************************************/ int UpdateDirName() { int size=0; char * test; char temp[1024]; int device = 0; if(browser.numEntries == 0) return 1; FindDevice(browser.dir, &device); /* current directory doesn't change */ if (strcmp(browserList[browser.selIndex].filename,".") == 0) { return 0; } /* go up to parent directory */ else if (strcmp(browserList[browser.selIndex].filename,"..") == 0) { // already at the top level if(IsDeviceRoot(browser.dir)) { browser.dir[0] = 0; // remove device - we are going to the device listing screen } else { /* determine last subdirectory namelength */ sprintf(temp,"%s",browser.dir); test = strtok(temp,"/"); while (test != NULL) { size = strlen(test); test = strtok(NULL,"/"); } /* remove last subdirectory name */ size = strlen(browser.dir) - size - 1; browser.dir[size] = 0; } return 1; } /* Open a directory */ else { /* test new directory namelength */ if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN) { /* update current directory name */ sprintf(browser.dir, "%s%s/",browser.dir, browserList[browser.selIndex].filename); return 1; } else { ErrorPrompt("Directory name is too long!"); return -1; } } }
char * GetFirstZipFilename () { char * firstFilename = NULL; char tempbuffer[ZIPCHUNK]; char filepath[1024]; if(!MakeFilePath(filepath, FILE_ROM)) return NULL; // read start of ZIP if(LoadFile (tempbuffer, filepath, ZIPCHUNK, NOTSILENT) < 35) return NULL; tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) int namelength = tempbuffer[26]; // filename length starts 26 bytes in if(namelength < 0 || namelength > 200) // filename is not a reasonable length { ErrorPrompt("Error - Invalid ZIP file!"); return NULL; } firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in firstFilename[namelength] = 0; // truncate at filename length return strdup(firstFilename); }
/**************************************************************************** * LoadSzFile * Loads the selected file # from the specified 7z into rbuffer * Returns file size ***************************************************************************/ size_t LoadSzFile(char * filepath, unsigned char * rbuffer) { size_t size = 0; // stop checking if devices were removed/inserted // since we're loading a file HaltDeviceThread(); // halt parsing HaltParseThread(); file = fopen (filepath, "rb"); if (file > 0) { size = SzExtractFile(browserList[browser.selIndex].filenum, rbuffer); fclose (file); } else { ErrorPrompt("Error opening file!"); } // go back to checking if devices were inserted/removed ResumeDeviceThread(); return size; }
static void DbgToggleUserBreak (unsigned Addr) /* Set a breakpoint */ { register BreakPoint* B = DbgIsBreak (Addr); if (B) { /* We have a breakpoint, remove it */ B->bk_use = BRK_EMPTY; --DbgBreakCount; } else { /* We don't have a breakpoint, set one */ if (DbgBreakCount >= MAX_USERBREAKS) { ErrorPrompt ("Too many breakpoints - press a key"); } else { /* Test if we can set a breakpoint at that address */ if (!DbgIsRAM (Addr)) { BreakInRomError (); } else { /* Set the breakpoint */ B = DbgGetBreakSlot (); B->bk_addr = Addr; B->bk_use = BRK_USER; ++DbgBreakCount; } } } }
bool LoadState (char * filepath, bool silent) { int offset = 0; bool retval = false; int device; if(!FindDevice(filepath, &device)) return 0; AllocSaveBuffer (); offset = LoadFile(filepath, silent); if (offset > 0) { EMUFILE_MEMFILE save(savebuffer, offset); FCEUSS_LoadFP(&save, SSLOADPARAM_NOBACKUP); retval = true; } else { // if we reached here, nothing was done! if(!silent) ErrorPrompt ("State file not found"); } FreeSaveBuffer (); return retval; }
/**************************************************************************** * IsValidROM * * Checks if the specified file is a valid ROM * For now we will just check the file extension and file size * If the file is a zip, we will check the file extension / file size of the * first file inside ***************************************************************************/ static bool IsValidROM() { // file size should be between 96K and 8MB if(browserList[browser.selIndex].length < (1024*96) || browserList[browser.selIndex].length > Memory.MAX_ROM_SIZE) { ErrorPrompt("Invalid file size!"); return false; } if (strlen(browserList[browser.selIndex].filename) > 4) { char * p = strrchr(browserList[browser.selIndex].filename, '.'); if (p != NULL) { char * zippedFilename = NULL; if(stricmp(p, ".zip") == 0 && !inSz) { // we need to check the file extension of the first file in the archive zippedFilename = GetFirstZipFilename (); if(zippedFilename && strlen(zippedFilename) > 4) p = strrchr(zippedFilename, '.'); else p = NULL; } if(p != NULL) { if (stricmp(p, ".smc") == 0 || stricmp(p, ".fig") == 0 || stricmp(p, ".sfc") == 0 || stricmp(p, ".swc") == 0) { if(zippedFilename) free(zippedFilename); return true; } } if(zippedFilename) free(zippedFilename); } } ErrorPrompt("Unknown file type!"); return false; }
static char InputGoto (unsigned* Addr) /* Prompt "Goto" and read an address. Print an error and return 0 on failure. */ { char Ok; Ok = InputHex ("Goto: ", Addr); if (!Ok) { ErrorPrompt ("Invalid input - press a key"); } return Ok; }
/**************************************************************************** * BrowserLoadFile * * Loads the selected ROM ***************************************************************************/ int BrowserLoadFile() { int loaded = 0; int device; if(!FindDevice(browser.dir, &device)) return 0; // check that this is a valid ROM if(!IsValidROM()) goto done; // store the filename (w/o ext) - used for sram/freeze naming StripExt(Memory.ROMFilename, browserList[browser.selIndex].filename); snprintf(GCSettings.LastFileLoaded, MAXPATHLEN, "%s", browserList[browser.selIndex].filename); strncpy(Memory.ROMFilePath, browser.dir, PATH_MAX); SNESROMSize = 0; S9xDeleteCheats(); Memory.LoadROM("ROM"); if (SNESROMSize == 0) { ErrorPrompt("Error loading game!"); } else if(bsxBiosLoadFailed) { ErrorPrompt("BS-X BIOS file not found!"); } else { // load SRAM or snapshot if (GCSettings.AutoLoad == 1) LoadSRAMAuto(SILENT); else if (GCSettings.AutoLoad == 2) LoadSnapshotAuto(SILENT); ResetBrowser(); loaded = 1; } done: CancelAction(); return loaded; }
// No enlargement, just render to the screen void RenderPlain (uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { if (dstPtr == NULL) { ErrorPrompt((char*)"dstPtr is NULL. exiting!"); exit(1); } //memcpy (dstPtr, srcPtr, width*height*srcPitch); return; }
bool AddBrowserEntry() { if(browser.size >= MAX_BROWSER_SIZE) { ErrorPrompt("Out of memory: too many files!"); return false; // out of space } memset(&(browserList[browser.size]), 0, sizeof(BROWSERENTRY)); // clear the new entry browser.size++; return true; }
bool ConnectShare (bool silent) { if(!InitializeNetwork(silent)) return false; if(networkShareInit) return true; int retry = 1; int chkS = (strlen(GCSettings.smbshare) > 0) ? 0:1; int chkI = (strlen(GCSettings.smbip) > 0) ? 0:1; // check that all parameters have been set if(chkS + chkI > 0) { if(!silent) { char msg[50]; char msg2[100]; if(chkS + chkI > 1) // more than one thing is wrong sprintf(msg, "Check settings.xml."); else if(chkS) sprintf(msg, "Share name is blank."); else if(chkI) sprintf(msg, "Share IP is blank."); sprintf(msg2, "Invalid network settings - %s", msg); ErrorPrompt(msg2); } return false; } while(retry) { if(!silent) ShowAction ("Connecting to network share..."); if(smbInit(GCSettings.smbuser, GCSettings.smbpwd, GCSettings.smbshare, GCSettings.smbip)) networkShareInit = true; if(networkShareInit || silent) break; retry = ErrorPromptRetry("Failed to connect to network share."); } if(!silent) CancelAction(); return networkShareInit; }
/**************************************************************************** * ParseMCDirectory * * Parses a list of all files on the specified memory card ***************************************************************************/ int ParseMCDirectory (int slot) { card_dir CardDir; int CardError; int entryNum = 0; // Try to mount the card CardError = MountMC(slot, NOTSILENT); if (CardError == 0) { CardError = CARD_FindFirst (slot, &CardDir, TRUE); while (CardError != CARD_ERROR_NOFILE) { BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (entryNum+1) * sizeof(BROWSERENTRY)); if(!newBrowserList) // failed to allocate required memory { ResetBrowser(); ErrorPrompt("Out of memory: too many files!"); entryNum = -1; break; } else { browserList = newBrowserList; } memset(&(browserList[entryNum]), 0, sizeof(BROWSERENTRY)); // clear the new entry strncpy(browserList[entryNum].filename, (char *)CardDir.filename, MAXJOLIET); StripExt(browserList[entryNum].displayname, browserList[entryNum].filename); // hide file extension browserList[entryNum].length = CardDir.filelen; entryNum++; CardError = CARD_FindNext (&CardDir); } CARD_Unmount(slot); } // Sort the file list qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback); CancelAction(); browser.numEntries = entryNum; return entryNum; }
/**************************************************************************** * BrowserLoadSz * * Opens the selected 7z file, and parses a listing of the files within ***************************************************************************/ int BrowserLoadSz() { memset(szpath, 0, MAXPATHLEN); strncpy(szpath, browser.dir, strlen(browser.dir) - 1); strncpy(szname, strrchr(szpath, '/') + 1, strrchr(szpath, '.') - strrchr(szpath, '/')); *strrchr(szname, '.') = '\0'; int szfiles = SzParse(szpath); if(szfiles) { browser.numEntries = szfiles; inSz = true; } else ErrorPrompt("Error opening archive!"); return szfiles; }
bool DownloadUpdate() { bool result = false; if(strlen(updateURL) > 0) { // stop checking if devices were removed/inserted // since we're saving a file HaltDeviceThread(); FILE * hfile; char updateFile[50]; sprintf(updateFile, "sd:/%s Update.zip", APPNAME); hfile = fopen (updateFile, "wb"); if (hfile > 0) { int retval; retval = http_request(updateURL, hfile, NULL, (1024*1024*5)); fclose (hfile); } bool unzipResult = unzipArchive(updateFile, (char *)"sd:/"); remove(updateFile); // delete update file if(unzipResult) { result = true; InfoPrompt("Update successful!"); } else { result = false; ErrorPrompt("Update failed!"); } updateFound = false; // updating is finished (successful or not!) // go back to checking if devices were inserted/removed ResumeDeviceThread(); } return result; }
/**************************************************************************** * BrowserLoadSz * * Opens the selected 7z file, and parses a listing of the files within ***************************************************************************/ int BrowserLoadSz() { char filepath[MAXPATHLEN]; memset(filepath, 0, MAXPATHLEN); // we'll store the 7z filepath for extraction later if(!MakeFilePath(szpath, FILE_ROM)) return 0; int szfiles = SzParse(szpath); if(szfiles) { browser.numEntries = szfiles; inSz = true; } else ErrorPrompt("Error opening archive!"); return szfiles; }
void InitializeNetwork(bool silent) { // stop if we're already initialized, or if auto-init has failed before // in which case, manual initialization is required if(networkInit || !autoNetworkInit) return; if(!silent) ShowAction ("Initializing network..."); while(inNetworkInit) // a network init is already in progress! usleep(50); if(networkInit) // check again if the network was inited return; inNetworkInit = true; char ip[16]; s32 initResult = if_config(ip, NULL, NULL, true); if(initResult == 0) { networkInit = true; } else { // do not automatically attempt a reconnection autoNetworkInit = false; if(!silent) { char msg[150]; sprintf(msg, "Unable to initialize network (Error #: %i)", initResult); ErrorPrompt(msg); } } if(!silent) CancelAction(); inNetworkInit = false; }
/**************************************************************************** * BrowserLoadFile * * Loads the selected ROM ***************************************************************************/ int BrowserLoadFile() { int loaded = 0; int device; if(!FindDevice(browser.dir, &device)) return 0; GetFileSize(browser.selIndex); // check that this is a valid ROM if(!IsValidROM()) goto done; // store the filename (w/o ext) - used for sram/freeze naming StripExt(Memory.ROMFilename, browserList[browser.selIndex].filename); strcpy(loadedFile, browserList[browser.selIndex].filename); SNESROMSize = 0; S9xDeleteCheats(); Memory.LoadROM("ROM"); if (SNESROMSize <= 0) { ErrorPrompt("Error loading game!"); } else { // load SRAM or snapshot if (GCSettings.AutoLoad == 1) LoadSRAMAuto(SILENT); else if (GCSettings.AutoLoad == 2) LoadSnapshotAuto(SILENT); ResetBrowser(); loaded = 1; } done: CancelAction(); return loaded; }
/**************************************************************************** * IsValidROM * * Checks if the specified file is a valid ROM * For now we will just check the file extension and file size * If the file is a zip, we will check the file extension / file size of the * first file inside ***************************************************************************/ static bool IsValidROM() { if (strlen(browserList[browser.selIndex].filename) > 4) { char * p = strrchr(browserList[browser.selIndex].filename, '.'); if (p != NULL) { char * zippedFilename = NULL; if(strcasecmp(p, ".zip") == 0 && !inSz) { // we need to check the file extension of the first file in the archive zippedFilename = GetFirstZipFilename (); if(zippedFilename && strlen(zippedFilename) > 4) p = strrchr(zippedFilename, '.'); else p = NULL; } if(p != NULL) { if (strcasecmp(p, ".smc") == 0 || strcasecmp(p, ".fig") == 0 || strcasecmp(p, ".sfc") == 0 || strcasecmp(p, ".swc") == 0) { if(zippedFilename) free(zippedFilename); return true; } } if(zippedFilename) free(zippedFilename); } } ErrorPrompt("Unknown file type!"); return false; }
/**************************************************************************** * BrowserLoadFile * * Loads the selected ROM ***************************************************************************/ int BrowserLoadFile() { int device; if(!FindDevice(browser.dir, &device)) return 0; // store the filename (w/o ext) - used for sram/freeze naming StripExt(ROMFilename, browserList[browser.selIndex].filename); snprintf(GCSettings.LastFileLoaded, MAXPATHLEN, "%s", browserList[browser.selIndex].filename); loadingFile = true; ROMLoaded = LoadVBAROM(); loadingFile = false; if (!ROMLoaded) { if(inSz) { browser.selIndex = 0; BrowserChangeFolder(); } ErrorPrompt("Error loading game!"); } else { if (GCSettings.AutoLoad == 1) LoadBatteryOrStateAuto(FILE_SRAM, SILENT); else if (GCSettings.AutoLoad == 2) LoadBatteryOrStateAuto(FILE_SNAPSHOT, SILENT); ResetBrowser(); } CancelAction(); return ROMLoaded; }
int genesis_init() { static int bfirstRun = true; if (bfirstRun) { FirstRun(); bfirstRun = false; } /* set default config */ error_init(); set_config_defaults(); /* Load ROM file */ cart.rom = (unsigned char*) malloc(10 * 1024 * 1024); memset(cart.rom, 0, 10 * 1024 * 1024); // //if (!load_rom("uda:/sonic.smd")) { if (!load_rom(romname)) { char buf[1024]; sprintf(buf, "Error loading file `%s'.", romname); ErrorPrompt(buf); free(cart.rom); return 1; } // now running running = 1; // not exit gen_exit = 0; SYSInputReset(); /* load BIOS */ memset(bios_rom, 0, sizeof (bios_rom)); FILE *f = fopen(OS_ROM, "rb"); if (f != NULL) { fread(&bios_rom, 0x800, 1, f); fclose(f); int i; for (i = 0; i < 0x800; i += 2) { uint8 temp = bios_rom[i]; bios_rom[i] = bios_rom[i + 1]; bios_rom[i + 1] = temp; } config.tmss |= 2; } /* initialize Genesis virtual system */ memset(&bitmap, 0, sizeof (t_bitmap)); // bitmap.width = g_pTexture->width; // bitmap.height = g_pTexture->height; // bitmap.pitch = g_pTexture->wpitch; bitmap.width = 1024; bitmap.height = 576; bitmap.pitch = bitmap.width * 4; bitmap.data = screen; bitmap.viewport.changed = 3; //config.overscan = 0; // disabled /* initialize emulation */ printf("audio_init\r\n"); audio_init(SOUND_FREQUENCY, vdp_pal ? 50.0 : 60.0); printf("system_init\r\n"); system_init(); printf("sramname\r\n"); /* load SRAM */ if (gensettings.saves & SAVES_SRAM) { load_sram(sramname); } /* user cfg */ SetGenConfig(); /* reset emulation */ system_reset(); /* run 1 frame */ system_frame(0); if (gensettings.saves & SAVES_STATES) { load_state(statename); } return 0; }
unsigned __stdcall _OpFileMoveThread(void *pVoid) { OPERATIONSTRUCT os = *reinterpret_cast<POPERATIONSTRUCT>(pVoid); OPCALLBACKDATA ocd; TSTRINGLISTIT it = os.Files.begin(); UINT uiCurFile = 1U; bool bAskOverwrite = true; BOOL bCancelOp = FALSE; TSTRING tsTemp; /* * If the destination directory is invalid, * it's probably been moved, or renamed * since its association with the application. * Prompt the user to see if they'd like to * create it, or abort. */ if (FALSE == PathIsDirectory(os.tsDest.c_str())) { INT_PTR iChoice = PrintMsgBox(os.hWnd, _T("extFileCopy") _T(" : Directory not found"), MB_YESNO | MB_ICONWARNING, _T("The destination directory:\n\n") _T("%s\n\nhas either been moved") _T(" or renamed since its association") _T(" with extFileCopy. Would you like") _T(" to create it?"), os.tsDest.c_str()); switch (iChoice) { case IDYES: { /* * Attempt to create the directory. */ if (FALSE == CreateDirectory(os.tsDest.c_str(), NULL)) { /* * We've failed miserably. * Can't copy any files to a non-existant * directory; done. */ PrintMsgBox(os.hWnd, _T("extFileCopy : ERROR"), MB_OK | MB_ICONSTOP, _T("An error occurred while attempting") _T(" to create the directory:\n\n%s.\n\n") _T("The directory will be disassociated with") _T("extFileCopy.\n\n") _T("Win32 error: %d"), os.tsDest.c_str(), GetLastError()); RegUtil_RemAssociatedDirectory(ExtensionFromList(os.Files), os.tsDest); goto mtFinish; } } break; case IDNO: { /* * User doesn't want to bother creating * the directory; We have to remove * the association in the registry. */ PrintMsgBox(os.hWnd, _T("extFileCopy : Removing association"), MB_OK | MB_ICONWARNING, _T("The inaccessible directory:\n\n%s\n\nwill now") _T(" be disassociated with extFileCopy."), os.tsDest.c_str()); RegUtil_RemAssociatedDirectory(ExtensionFromList(os.Files), os.tsDest); goto mtFinish; } break; } } os.pDlg->SetCancelPtr(&bCancelOp); /* * Set up the dialog UI */ if (os.bCopy) { os.pDlg->SetWindowText(_T("Copying ...")); } else { os.pDlg->SetWindowText(_T("Moving ...")); } os.pDlg->SetElapsedTime(0); for(; it != os.Files.end(); it++) { /* * Check if the operation was cancelled * by the user */ os.pMutex->Lock(); if (TRUE == bCancelOp) { os.pMutex->Unlock(); goto mtFinish; } os.pMutex->Unlock(); /* * Update overall progress */ INT64 iOverallPct = ((uiCurFile * 100) / os.Files.size()); sprintf(tsTemp, _T("Overall Progress (file %d of %d) : %I64d%%"), uiCurFile++, os.Files.size(), iOverallPct); os.pDlg->SetOverallProgress(iOverallPct, tsTemp); /* * Update current file name */ TSTRING tsShortFile = GetFileFromPath((*it)); TSTRING tsDisplay = tsShortFile; /* * Truncate file name if necessary */ tsDisplay = FileGetCompactName(tsDisplay, PD_MAXCURFILE); sprintf(tsTemp, _T("Current file '%s' : %I64d%%"), tsDisplay.c_str(), 0LL); os.pDlg->SetCurrentProgress(0, tsTemp); /* * Reset transfer rate */ os.pDlg->SetTransferRate(_T("Transfer Rate: calculating...")); /* * If the resulting destination path is > MAX_PATH, * we've got to skip this file and tell the user. */ TSTRING tsDest = PathConcatFile(os.tsDest, tsShortFile); if (MAX_PATH < tsDest.size()) { PrintMsgBox(os.hWnd, _T("extFileCopy : Can't copy file"), MB_OK | MB_ICONWARNING, _T("The following destination path:\n\n") _T("%s\n\nis longer than MAX_PATH characters, and") _T(" cannot be created."), tsDest.c_str()); continue; } /* * Make sure the file doesn't exist; if it does, * we've got to prompt the user to overwrite. */ if (-1 != GetFileAttributes(tsDest.c_str())) { /* * Yeah, the file exists. */ if (bAskOverwrite) { OverwriteDlg dlg((*it), tsDest, 1 < os.Files.size()); if (!dlg.DoModal(static_cast<HINSTANCE>(g_hModule), MAKEINTRESOURCE(IDD_OVERWRITE), os.pDlg->m_hWnd)) { MessageBox(os.pDlg->m_hWnd, _T("A fatal internal error has occurred. Cannot continue.\n"), _T("extFileCopy : ERROR"), MB_OK | MB_ICONSTOP); os.pDlg->CleanUp(); _endthreadex(1); } /* * Find out what the user chose */ switch (dlg.Result()) { case YES: /* * Ok to overwrite, but don't touch * bAskOverwrite. */ break; case YESTOALL: /* * Ok to overwrite ALL files. */ bAskOverwrite = false; break; case NO: /* * Don't overwrite this file; * instead skip to the next. */ continue; break; case CANCEL: /* * Forget it. We're outta here. */ os.pMutex->Lock(); bCancelOp = TRUE; os.pMutex->Unlock(); goto mtFinish; break; } } } /* * File doesn't exist, or we don't * really care. Continue normally */ TSTRING tsCurFile = FileGetCompactName(tsShortFile.c_str(), PD_MAXCURFILE); ocd.pbCancel = &bCancelOp; ocd.dwStartTime = (2 == uiCurFile) ? GetTickCount() : ocd.dwStartTime; ocd.dwLastTime = (2 == uiCurFile) ? ocd.dwStartTime : ocd.dwLastTime; ocd.dwLastRate = GetTickCount(); ocd.iLastPct = 0LL; ocd.iThroughput = 0LL; ocd.pDlg = os.pDlg; ocd.pMutex = os.pMutex; ocd.szCurFile = tsCurFile.c_str(); if (os.bCopy) { /* * This is a copy operation */ if (0 == CopyFileEx((*it).c_str(), tsDest.c_str(), _Callback, &ocd, &bCancelOp, 0UL)) { /* * The copy operation has failed! * Let's tell the user, and then * if there's more than one file * being copied, ask the user if * they'd like to continue with * the next file. (If the error * didn't result from user abortion) */ if (ERROR_REQUEST_ABORTED != GetLastError()) { INT_PTR iUser = ErrorPrompt(os.pDlg->m_hWnd, (*it), tsDest, (1 < os.Files.size()) ? true : false, os.bCopy); if (1 < os.Files.size()) { if (IDYES == iUser) { /* * User wishes to try the next file. */ continue; } else if (IDNO == iUser) { break; } } else { continue; } } } } else { /* * This is a move operation */ if (0 == MoveFileWithProgress((*it).c_str(), tsDest.c_str(), _Callback, &ocd, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) { /* * The move operation has failed! * Let's tell the user, and then * if there's more than one file * being copied, ask the user if * they'd like to continue with * the next file. (If the error * didn't result from user abortion) */ if (ERROR_REQUEST_ABORTED != GetLastError()) { INT_PTR iUser = ErrorPrompt(os.pDlg->m_hWnd, (*it), tsDest, (1 < os.Files.size()) ? true : false, os.bCopy); if (1 < os.Files.size()) { if (IDYES == iUser) { /* * User wishes to try the next file. */ continue; } else if (IDNO == iUser) { break; } } else { continue; } } } } } mtFinish: os.pDlg->CleanUp(); _endthreadex(0U); return 0U; }
int SzParse(char * filepath) { if(!filepath) return 0; int device; if(!FindDevice(browser.dir, &device) || !GetFileSize(browser.selIndex)) return 0; int nbfiles = 0; // save the length/offset of this file unsigned int filelen = browserList[browser.selIndex].length; // setup archive stream SzArchiveStream.offset = 0; SzArchiveStream.len = filelen; SzArchiveStream.pos = 0; // open file file = fopen (filepath, "rb"); if(!file) return 0; // set szMethod to current chosen load device szMethod = device; // set handler functions for reading data from SD/USB/SMB/DVD SzArchiveStream.InStream.Read = SzFileReadImp; SzArchiveStream.InStream.Seek = SzFileSeekImp; // set default 7Zip SDK handlers for allocation and freeing memory SzAllocImp.Alloc = SzAlloc; SzAllocImp.Free = SzFree; SzAllocTempImp.Alloc = SzAllocTemp; SzAllocTempImp.Free = SzFreeTemp; // prepare CRC and 7Zip database structures InitCrcTable(); SzArDbExInit(&SzDb); // open the archive SzRes = SzArchiveOpen(&SzArchiveStream.InStream, &SzDb, &SzAllocImp, &SzAllocTempImp); if (SzRes != SZ_OK) { SzDisplayError(SzRes); // free memory used by the 7z SDK SzClose(); } else // archive opened successfully { if(SzDb.Database.NumFiles > 0) { // Parses the 7z into a full file listing HaltParseThread(); // halt parsing ResetBrowser(); // reset browser // add '..' folder in case the user wants exit the 7z AddBrowserEntry(); sprintf(browserList[0].displayname, "Up One Level"); browserList[0].isdir = 1; browserList[0].length = filelen; browserList[0].icon = ICON_FOLDER; // get contents and parse them into file list structure unsigned int SzI, SzJ; SzJ = 1; for (SzI = 0; SzI < SzDb.Database.NumFiles; SzI++) { SzF = SzDb.Database.Files + SzI; // skip directories if (SzF->IsDirectory) continue; if(!AddBrowserEntry()) { ResetBrowser(); ErrorPrompt("Out of memory: too many files!"); SzClose(); SzJ = 0; break; } // parse information about this file to the file list structure snprintf(browserList[SzJ].filename, MAXJOLIET, "%s", SzF->Name); StripExt(browserList[SzJ].displayname, browserList[SzJ].filename); browserList[SzJ].length = SzF->Size; // filesize browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags) browserList[SzJ].filenum = SzI; // the extraction function identifies the file with this number SzJ++; } nbfiles = SzJ; } else { SzClose(); } } CancelAction(); // close file fclose(file); return nbfiles; }
// display an error message static void SzDisplayError(SZ_RESULT res) { char msg[1024]; sprintf(msg, "7z decompression failed: %s", szerrormsg[(res - 1)]); ErrorPrompt(msg); }
bool MakeFilePath(char filepath[], int type, char * filename, int filenum) { char file[512]; char folder[1024]; char ext[4]; char temppath[MAXPATHLEN]; if(type == FILE_ROM) { // Check path length if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } else { sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename); } } else { if(GCSettings.SaveMethod == DEVICE_AUTO) GCSettings.SaveMethod = autoSaveMethod(SILENT); if(GCSettings.SaveMethod == DEVICE_AUTO) return false; switch(type) { case FILE_SRAM: case FILE_SNAPSHOT: sprintf(folder, GCSettings.SaveFolder); if(type == FILE_SRAM) sprintf(ext, "srm"); else sprintf(ext, "frz"); if(filenum >= -1) { if(filenum == -1) sprintf(file, "%s.%s", filename, ext); else if(filenum == 0) if (GCSettings.AppendAuto <= 0) sprintf(file, "%s.%s", filename, ext); else sprintf(file, "%s Auto.%s", filename, ext); else sprintf(file, "%s %i.%s", filename, filenum, ext); } else { sprintf(file, "%s", filename); } break; case FILE_CHEAT: sprintf(folder, GCSettings.CheatFolder); sprintf(file, "%s.cht", Memory.ROMFilename); break; } sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file); } CleanupPath(temppath); // cleanup path snprintf(filepath, MAXPATHLEN, "%s", temppath); return true; }