bool UpdateXferProgress( uint64_t iBytesCurrent, uint64_t iBytesTotal ) { bool bInterrupt = false; FOREACH_EnabledPlayer(pn) { bInterrupt |= INPUTMAPPER->IsButtonDown( MenuInput(pn, MENU_BUTTON_SELECT) ); bInterrupt |= INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_LEFT)) && INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_RIGHT)); } if ( bInterrupt ) { InputEventArray throwaway; INPUTFILTER->GetInputEvents( throwaway ); return false; } // Draw() is very expensive: only do it on occasion. if( DrawTimer.Ago() < DRAW_UPDATE_TIME ) return true; /* this truncates to int, but that's okay for our purposes */ float iTransferRate = iBytesCurrent / g_UpdateDuration.Ago(); float fPercent = iBytesCurrent / (iBytesTotal/100); const CString sRate = FormatByteValue( iTransferRate ) + "/sec"; CString sMessage = ssprintf( "\n\n%s\n%.2f%% %s\n\n%s", USER_PACK_WAIT_TEXT.GetValue().c_str(), fPercent, sRate.c_str(), USER_PACK_CANCEL_TEXT.GetValue().c_str() ); SCREENMAN->OverlayMessage( sMessage ); SCREENMAN->Draw(); DrawTimer.Touch(); return true; }
void ScreenUserPacks::HandleScreenMessage( const ScreenMessage SM ) { #if 0 /* Not compatible with FileCopy callback system; was this ever used? -- vyhd */ if ( SM == SM_CancelTransfer ) { Dialog::OK("SM_CancelTransfer"); InterruptCopy(); InputEventArray throwaway; INPUTFILTER->GetInputEvents( throwaway ); LOG->Warn("Cancelled Transfer of user pack."); } #endif if ( SM == SM_LinkedMenuChange ) { m_pCurLOM = m_pCurLOM->SwitchToNextMenu(); return; } if ( SM == SM_ConfirmDeleteZip ) { SCREENMAN->Prompt( SM_AnswerConfirmDeleteZip, "Proceed to delete pack from machine?", PROMPT_YES_NO, ANSWER_NO ); } if ( SM == SM_AnswerConfirmDeleteZip ) { if (ScreenPrompt::s_LastAnswer == ANSWER_NO) return; CString sSelection = m_AddedZips.GetCurrentSelection(); g_CurSelection = sSelection; bool bSuccess = UPACKMAN->Remove( USER_PACK_SAVE_PATH + sSelection ); if (bSuccess) { m_SoundDelete.Play(); ReloadZips(); m_bRestart = true; } else { SCREENMAN->SystemMessage( "Failed to delete zip file from machine. Check your file permissions." ); } } if ( SM == SM_ConfirmAddZip ) { SCREENMAN->Prompt( SM_AnswerConfirmAddZip, "Proceed to add pack to machine?", PROMPT_YES_NO, ANSWER_NO ); } if ( SM == SM_AnswerConfirmAddZip ) { CString sError; m_bPrompt = false; if (ScreenPrompt::s_LastAnswer == ANSWER_NO) return; m_bStopThread = true; m_PlayerSongLoadThread.Wait(); MountMutex.Lock(); #if defined(LINUX) && defined(ITG_ARCADE) system( "mount -o remount,rw /itgdata" ); #endif MEMCARDMAN->LockCards(); MEMCARDMAN->MountCard(m_CurPlayer, 99999); CString sSelection = m_USBZips.GetCurrentSelection(); { //////////////////////// #define XFER_CLEANUP MEMCARDMAN->UnmountCard(m_CurPlayer); \ MEMCARDMAN->UnlockCards(); \ MountMutex.Unlock(); \ m_bStopThread = false; \ m_PlayerSongLoadThread.Create( InitSASSongThread, this ) //////////////////////// g_CurXferFile = MEM_CARD_MOUNT_POINT[m_CurPlayer] + "/" + USER_PACK_TRANSFER_PATH + sSelection; if ( !UPACKMAN->IsPackTransferable( sSelection, g_CurXferFile, sError ) || !UPACKMAN->IsPackMountable( g_CurXferFile, sError ) ) { SCREENMAN->SystemMessage( "Could not add pack to machine:\n" + sError ); XFER_CLEANUP; return; } sError = ""; // ?? RageTimer start; DrawTimer.Touch(); g_iLastCurrentBytes = 0; g_UpdateDuration.Touch(); if (!UPACKMAN->TransferPack( g_CurXferFile, sSelection, UpdateXferProgress, sError ) ) { SCREENMAN->SystemMessage( "Transfer error:\n" + sError ); XFER_CLEANUP; SCREENMAN->HideOverlayMessage(); SCREENMAN->ZeroNextUpdate(); return; } LOG->Debug( "Transferred %s in %f seconds.", g_CurXferFile.c_str(), start.Ago() ); } #if defined(LINUX) && defined(ITG_ARCADE) sync(); system( "mount -o remount,ro /itgdata" ); #endif SCREENMAN->HideOverlayMessage(); SCREENMAN->ZeroNextUpdate(); FILEMAN->FlushDirCache(USER_PACK_SAVE_PATH); m_bRestart = true; m_SoundTransferDone.Play(); ReloadZips(); XFER_CLEANUP; #undef XFER_CLEANUP } switch( SM ) { case SM_GoToNextScreen: case SM_GoToPrevScreen: SCREENMAN->SetNewScreen( PREV_SCREEN ); break; } }
void MemoryCardDriverThreaded_Linux::GetUSBStorageDevices( vector<UsbStorageDevice>& vDevicesOut ) { LOG->Trace( "GetUSBStorageDevices" ); vDevicesOut.clear(); { vector<RString> asDevices; RString sBlockDevicePath = "/sys/block/"; GetFileList( sBlockDevicePath, asDevices ); for( unsigned i = 0; i < asDevices.size(); ++i ) { const RString &sDevice = asDevices[i]; if( sDevice == "." || sDevice == ".." ) continue; UsbStorageDevice usbd; RString sPath = sBlockDevicePath + sDevice + "/"; usbd.sSysPath = sPath; /* Ignore non-removable devices. */ RString sBuf; if( !ReadFile( sPath + "removable", sBuf ) ) continue; // already warned if( atoi(sBuf) != 1 ) continue; /* * The kernel isn't exposing all of /sys atomically, so we end up missing * the partition due to it not being shown yet. It won't show up until the * kernel has scanned the partition table, which can take a variable amount * of time, sometimes over a second. Watch for the "queue" sysfs directory, * which is created after this, to tell when partition directories are created. */ RageTimer WaitUntil; WaitUntil += 5; RString sQueueFilePath = usbd.sSysPath + "queue"; while(1) { if( WaitUntil.Ago() >= 0 ) { LOG->Warn( "Timed out waiting for %s", sQueueFilePath.c_str() ); break; } if( access(usbd.sSysPath, F_OK) == -1 ) { LOG->Warn( "Block directory %s went away while we were waiting for %s", usbd.sSysPath.c_str(), sQueueFilePath.c_str() ); break; } if( access(sQueueFilePath, F_OK) != -1 ) break; usleep(10000); } /* Wait for udev to finish handling device node creation */ ExecuteCommand( "udevadm settle" ); /* If the first partition device exists, eg. /sys/block/uba/uba1, use it. */ if( access(usbd.sSysPath + sDevice + "1", F_OK) != -1 ) { LOG->Trace("OK"); usbd.sDevice = "/dev/" + sDevice + "1"; } else { LOG->Trace("error %s", strerror(errno)); usbd.sDevice = "/dev/" + sDevice; } /* * sPath/device should be a symlink to the actual device. For USB * devices, it looks like this: * * device -> ../../devices/pci0000:00/0000:00:02.1/usb2/2-1/2-1:1.0 * * "2-1" is "bus-port". */ char szLink[256]; int iRet = readlink( sPath + "device", szLink, sizeof(szLink) ); if( iRet == -1 ) { LOG->Warn( "readlink(\"%s\"): %s", (sPath + "device").c_str(), strerror(errno) ); } else { /* * The full path looks like * * ../../devices/pci0000:00/0000:00:02.1/usb2/2-2/2-2.1/2-2.1:1.0 * * In newer kernels, it looks like: * * ../../../3-2.1:1.0 * * Each path element refers to a new hop in the chain. * "usb2" = second USB host * 2- second USB host, * -2 port 1 on the host, * .1 port 1 on an attached hub * .2 ... port 2 on the next hub ... * * We want the bus number and the port of the last hop. The level is * the number of hops. */ szLink[iRet] = 0; vector<RString> asBits; split( szLink, "/", asBits ); RString sHostPort = asBits[asBits.size()-1]; if( !sHostPort.empty() ) { /* Strip off the endpoint information after the colon. */ size_t pos = sHostPort.find(':'); if( pos != string::npos ) sHostPort.erase( pos ); /* sHostPort is eg. 2-2.1. */ sHostPort.Replace( "-", "." ); asBits.clear(); split( sHostPort, ".", asBits ); if( asBits.size() > 1 ) { usbd.iBus = atoi( asBits[0] ); usbd.iPort = atoi( asBits[asBits.size()-1] ); usbd.iLevel = asBits.size() - 1; } } } if( ReadFile( sPath + "device/../idVendor", sBuf ) ) sscanf( sBuf, "%x", &usbd.idVendor ); if( ReadFile( sPath + "device/../idProduct", sBuf ) ) sscanf( sBuf, "%x", &usbd.idProduct ); if( ReadFile( sPath + "device/../serial", sBuf ) ) { usbd.sSerial = sBuf; TrimRight( usbd.sSerial ); } if( ReadFile( sPath + "device/../product", sBuf ) ) { usbd.sProduct = sBuf; TrimRight( usbd.sProduct ); } if( ReadFile( sPath + "device/../manufacturer", sBuf ) ) { usbd.sVendor = sBuf; TrimRight( usbd.sVendor ); } vDevicesOut.push_back( usbd ); } } { // Find where each device is mounted. Output looks like: // /dev/sda1 /mnt/flash1 auto noauto,owner 0 0 // /dev/sdb1 /mnt/flash2 auto noauto,owner 0 0 // /dev/sdc1 /mnt/flash3 auto noauto,owner 0 0 RString fn = "/rootfs/etc/fstab"; RageFile f; if( !f.Open(fn) ) { LOG->Warn( "can't open '%s': %s", fn.c_str(), f.GetError().c_str() ); return; } RString sLine; while( !f.AtEOF() ) { switch( f.GetLine(sLine) ) { case 0: continue; /* eof */ case -1: LOG->Warn( "error reading '%s': %s", fn.c_str(), f.GetError().c_str() ); return; } char szScsiDevice[1024]; char szMountPoint[1024]; int iRet = sscanf( sLine, "%s %s", szScsiDevice, szMountPoint ); if( iRet != 2 || szScsiDevice[0] == '#') continue; // don't process this line /* Get the real kernel device name, which should match * the name from /sys/block, by following symlinks in * /dev. This allows us to specify persistent names in * /etc/fstab using things like /dev/device/by-path. */ char szUnderlyingDevice[PATH_MAX]; if( realpath(szScsiDevice, szUnderlyingDevice) == NULL ) { // "No such file or directory" is understandable if (errno != ENOENT) LOG->Warn( "realpath(\"%s\"): %s", szScsiDevice, strerror(errno) ); continue; } RString sMountPoint = szMountPoint; TrimLeft( sMountPoint ); TrimRight( sMountPoint ); // search for the mountpoint corresponding to the device for( unsigned i=0; i<vDevicesOut.size(); i++ ) { UsbStorageDevice& usbd = vDevicesOut[i]; if( usbd.sDevice == szUnderlyingDevice ) // found our match { // Use the device entry from fstab so the mount command works usbd.sDevice = szScsiDevice; usbd.sOsMountDir = sMountPoint; break; // stop looking for a match } } } } for( unsigned i=0; i<vDevicesOut.size(); i++ ) { UsbStorageDevice& usbd = vDevicesOut[i]; LOG->Trace( " sDevice: %s, iBus: %d, iLevel: %d, iPort: %d, id: %04X:%04X, Vendor: '%s', Product: '%s', sSerial: \"%s\", sOsMountDir: %s", usbd.sDevice.c_str(), usbd.iBus, usbd.iLevel, usbd.iPort, usbd.idVendor, usbd.idProduct, usbd.sVendor.c_str(), usbd.sProduct.c_str(), usbd.sSerial.c_str(), usbd.sOsMountDir.c_str() ); } /* Remove any devices that we couldn't find a mountpoint for. */ for( unsigned i=0; i<vDevicesOut.size(); i++ ) { UsbStorageDevice& usbd = vDevicesOut[i]; if( usbd.sOsMountDir.empty() ) { LOG->Trace( "Ignoring %s (couldn't find in /etc/fstab)", usbd.sDevice.c_str() ); vDevicesOut.erase( vDevicesOut.begin()+i ); --i; } } LOG->Trace( "Done with GetUSBStorageDevices" ); }