RString LastDayToLocalizedString(int iLastDayIndex) { RString s = LastDayToString(iLastDayIndex); s.Replace("Day", ""); s.Replace("Ago", " Ago"); return s; }
RString LastWeekToLocalizedString(int iLastWeekIndex) { RString s = LastWeekToString(iLastWeekIndex); s.Replace("Week", ""); s.Replace("Ago", " Ago"); return s; }
RString DoPathReplace(const RString &sPath) { RString TempPath = sPath; #if defined(XBOX) TempPath.Replace( "//", "\\" ); TempPath.Replace( "/", "\\" ); #endif return TempPath; }
void Resume::ReadVlcResumeFile() { Sleep(100); //wait for VLC to write file (TODO: make threaded) //get username TCHAR username[UNLEN + 1]; DWORD username_len = UNLEN + 1; GetUserName(username, &username_len); RString strTemp; RString strVlcFile; //build path to vlc info file RString strFilePath = _T("C:\\Users\\"); strFilePath += username; strFilePath += _T("\\AppData\\Roaming\\vlc\\vlc-qt-interface.ini"); //read VLC resume file into str if (!FileToString(strFilePath, strVlcFile)) return; if (GetFirstMatch(strVlcFile, _T("list=([^$]*?$)"), &strTemp)) { strTemp.Replace(_T(" "), _T("")); RArray<const TCHAR*> moviesTemp = SplitString(strTemp, _T(","), true); size = moviesTemp.GetSize(); if (size > MAX_SIZE) size = MAX_SIZE; for(int i=0; i<size; i++) { //remove % codes and turn + to space RString strTempMovie = URLDecode(moviesTemp[i]); //remove file:/// or file:// if (strTempMovie.Left(8) == _T("file:///")) strTempMovie = strTempMovie.Right(strTempMovie.GetLength() - 8); else strTempMovie = strTempMovie.Right(strTempMovie.GetLength() - 5); strTempMovie.Replace(_T("/"), _T("\\\\")); movies[i] = strTempMovie; } } if (GetFirstMatch(strVlcFile, _T("times=([^$]*?$)"), &strTemp)) { strTemp.Replace(_T(" "), _T("")); RArray<const TCHAR*> strTimes = SplitString(strTemp, _T(","), true); for(int i=0; i<strTimes.GetSize(); i++) times[i] = StringToNumber(strTimes[i])/1000; //milliseconds to seconds } UpdateResumeTimes(); }
RString werr_ssprintf( int err, const char *fmt, ... ) { char buf[1024] = ""; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0, buf, sizeof(buf), NULL); // Why is FormatMessage returning text ending with \r\n? (who? -aj) // Perhaps it's because you're on Windows, where newlines are \r\n. -aj RString text = buf; text.Replace( "\n", "" ); text.Replace( "\r", " " ); // foo\r\nbar -> foo bar TrimRight( text ); // "foo\r\n" -> "foo" va_list va; va_start(va, fmt); RString s = vssprintf( fmt, va ); va_end(va); return s += ssprintf( " (%s)", text.c_str() ); }
void Resume::UpdateResumeTimes() { //foreach entry in the vlc list, //update resume time in database for (int i = 0; i < size; i++) { RString tempMovieStr = movies[i]; tempMovieStr.Replace(_T("\\\\"), _T("\\")); GetDB()->UpdateResumeTime(tempMovieStr, times[i]); } }
void ScreenSelectMaster::Init() { SHOW_ICON.Load( m_sName, "ShowIcon" ); SHOW_SCROLLER.Load( m_sName, "ShowScroller" ); SHOW_CURSOR.Load( m_sName, "ShowCursor" ); SHARED_SELECTION.Load( m_sName, "SharedSelection" ); USE_ICON_METRICS.Load( m_sName, "UseIconMetrics" ); NUM_CHOICES_ON_PAGE_1.Load( m_sName, "NumChoicesOnPage1" ); CURSOR_OFFSET_X_FROM_ICON.Load( m_sName, CURSOR_OFFSET_X_FROM_ICON_NAME, NUM_PLAYERS ); CURSOR_OFFSET_Y_FROM_ICON.Load( m_sName, CURSOR_OFFSET_Y_FROM_ICON_NAME, NUM_PLAYERS ); PER_CHOICE_ICON_ELEMENT.Load( m_sName, "PerChoiceIconElement" ); PRE_SWITCH_PAGE_SECONDS.Load( m_sName, "PreSwitchPageSeconds" ); POST_SWITCH_PAGE_SECONDS.Load( m_sName, "PostSwitchPageSeconds" ); OPTION_ORDER.Load( m_sName, OPTION_ORDER_NAME, NUM_MenuDir ); DO_SWITCH_ANYWAYS.Load( m_sName, "DoSwitchAnyways" ); WRAP_CURSOR.Load( m_sName, "WrapCursor" ); WRAP_SCROLLER.Load( m_sName, "WrapScroller" ); LOOP_SCROLLER.Load( m_sName, "LoopScroller" ); PER_CHOICE_SCROLL_ELEMENT.Load( m_sName, "PerChoiceScrollElement" ); ALLOW_REPEATING_INPUT.Load( m_sName, "AllowRepeatingInput" ); SCROLLER_SECONDS_PER_ITEM.Load( m_sName, "ScrollerSecondsPerItem" ); SCROLLER_NUM_ITEMS_TO_DRAW.Load( m_sName, "ScrollerNumItemsToDraw" ); SCROLLER_TRANSFORM.Load( m_sName, "ScrollerTransform" ); //SCROLLER_TWEEN.Load( m_sName, "ScrollerTween" ); SCROLLER_SUBDIVISIONS.Load( m_sName, "ScrollerSubdivisions" ); DEFAULT_CHOICE.Load( m_sName, "DefaultChoice" ); DOUBLE_PRESS_TO_SELECT.Load(m_sName,"DoublePressToSelect"); ScreenSelect::Init(); m_TrackingRepeatingInput = GameButton_Invalid; vector<PlayerNumber> vpns; GetActiveElementPlayerNumbers( vpns ); #define PLAYER_APPEND_NO_SPACE(p) (SHARED_SELECTION ? RString() : ssprintf("P%d",(p)+1)) this->SubscribeToMessage( SM_MenuTimer ); // init cursor if( SHOW_CURSOR ) { FOREACH( PlayerNumber, vpns, p ) { RString sElement = "Cursor" + PLAYER_APPEND_NO_SPACE(*p); m_sprCursor[*p].Load( THEME->GetPathG(m_sName,sElement) ); sElement.Replace( " ", "" ); m_sprCursor[*p]->SetName( sElement ); this->AddChild( m_sprCursor[*p] ); LOAD_ALL_COMMANDS( m_sprCursor[*p] ); } }
void PercentageDisplay::Refresh() { const int iActualDancePoints = m_pPlayerStageStats->m_iActualDancePoints; const int iCurPossibleDancePoints = m_pPlayerStageStats->m_iCurPossibleDancePoints; if( iActualDancePoints == m_Last && iCurPossibleDancePoints == m_LastMax ) return; m_Last = iActualDancePoints; m_LastMax = iCurPossibleDancePoints; RString sNumToDisplay; if( ShowDancePointsNotPercentage() ) { sNumToDisplay = ssprintf( "%*d", m_iDancePointsDigits, max( 0, iActualDancePoints ) ); } else { float fPercentDancePoints = m_pPlayerStageStats->GetPercentDancePoints(); // clamp percentage - feedback is that negative numbers look weird here. CLAMP( fPercentDancePoints, 0.f, 1.f ); if( m_bUseRemainder ) { int iPercentWhole = int(fPercentDancePoints*100); int iPercentRemainder = int( (fPercentDancePoints*100 - int(fPercentDancePoints*100)) * 10 ); sNumToDisplay = ssprintf( m_sPercentFormat, iPercentWhole ); m_textPercentRemainder.SetText( ssprintf(m_sRemainderFormat, iPercentRemainder) ); } else { if(m_FormatPercentScore.GetLuaType() == LUA_TFUNCTION) { Lua *L = LUA->Get(); m_FormatPercentScore.PushSelf( L ); LuaHelpers::Push( L, fPercentDancePoints ); RString Error= "Error running FormatPercentScore: "; LuaHelpers::RunScriptOnStack(L, Error, 1, 1, true); // 1 arg, 1 result LuaHelpers::Pop( L, sNumToDisplay ); LUA->Release(L); } // HACK: Use the last frame in the numbers texture as '-' sNumToDisplay.Replace('-','x'); } } m_textPercent.SetText( sNumToDisplay ); }
int Resume::GetTime(RString str) { //If movie path str is in the list return its time. //Otherwise return 0 str.Replace(_T("\\"), _T("\\\\")); for(int i=0; i<size; i++) { if (str == movies[i]) return(times[i]); } return 0; }
RString StepsTypeToString( StepsType st ) { RString s = GAMEMAN->GetStepsTypeInfo( st ).szName; // "dance-single" /* foo-bar -> Foo_Bar */ s.Replace('-','_'); bool bCapitalizeNextLetter = true; for( int i=0; i<(int)s.length(); i++ ) { if( bCapitalizeNextLetter ) { s[i] = toupper(s[i]); bCapitalizeNextLetter = false; } if( s[i] == '_' ) bCapitalizeNextLetter = true; } return s; }
void RageDisplay::ProcessStatsOnFlip() { g_iFramesRenderedSinceLastCheck++; g_iFramesRenderedSinceLastReset++; if( g_LastCheckTimer.PeekDeltaTime() >= 1.0f ) // update stats every 1 sec. { float fActualTime = g_LastCheckTimer.GetDeltaTime(); g_iNumChecksSinceLastReset++; g_iFPS = lrintf( g_iFramesRenderedSinceLastCheck / fActualTime ); g_iCFPS = g_iFramesRenderedSinceLastReset / g_iNumChecksSinceLastReset; g_iCFPS = lrintf( g_iCFPS / fActualTime ); g_iVPF = g_iVertsRenderedSinceLastCheck / g_iFramesRenderedSinceLastCheck; g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = 0; if( LOG_FPS ) { RString sStats = GetStats(); sStats.Replace( "\n", ", " ); LOG->Trace( "%s", sStats.c_str() ); } } }
bool Steps::GetNoteDataFromSimfile() { // Replace the line below with the Steps' cache file. RString stepFile = this->GetFilename(); RString extension = GetExtension(stepFile); extension.MakeLower(); // must do this because the code is expecting lowercase if (extension.empty() || extension == "ssc" || extension == "ats") // remember cache files. { SSCLoader loader; if ( ! loader.LoadNoteDataFromSimfile(stepFile, *this) ) { /* HACK: 7/20/12 -- see bugzilla #740 users who edit songs using the ever popular .sm file that remove or tamper with the .ssc file later on complain of blank steps in the editor after reloading. Despite the blank steps being well justified since the cache files contain only the SSC step file, give the user some leeway and search for a .sm replacement */ SMLoader backup_loader; RString transformedStepFile = stepFile; transformedStepFile.Replace(".ssc", ".sm"); return backup_loader.LoadNoteDataFromSimfile(transformedStepFile, *this); } else { return true; } } else if (extension == "sm") { SMLoader loader; return loader.LoadNoteDataFromSimfile(stepFile, *this); } else if (extension == "sma") { SMALoader loader; return loader.LoadNoteDataFromSimfile(stepFile, *this); } else if (extension == "dwi") { return DWILoader::LoadNoteDataFromSimfile(stepFile, *this); } else if (extension == "ksf") { return KSFLoader::LoadNoteDataFromSimfile(stepFile, *this); } else if (extension == "bms" || extension == "bml" || extension == "bme" || extension == "pms") { return BMSLoader::LoadNoteDataFromSimfile(stepFile, *this); } else if (extension == "edit") { // Try SSC, then fallback to SM. SSCLoader ldSSC; if(ldSSC.LoadNoteDataFromSimfile(stepFile, *this) != true) { SMLoader ldSM; return ldSM.LoadNoteDataFromSimfile(stepFile, *this); } else return true; } return false; }
void ParseFileName(RString_ strFileName, RString &strTitle, RString &strYear) { INT_PTR m, n; RString strTemp; strTitle = strFileName; strYear.Empty(); // only keep file name n = strTitle.ReverseFind(_T('\\')); if (n != -1) strTitle = strTitle.Mid(n + 1); //strTitle.MakeLower(); // strip file extension (max 4 chars) n = strTitle.ReverseFind(_T('.')); if (n != -1 && strTitle.GetLength() - n < 6) strTitle = strTitle.Left(n); // replace []{} by () strTitle.Replace(_T('['), _T('(')); strTitle.Replace(_T(']'), _T(')')); strTitle.Replace(_T('{'), _T('(')); strTitle.Replace(_T('}'), _T(')')); /* // replace anything not ,()0-9a-zA-Z by a space for (int i = 0; i < strTitle.GetLength(); i++) if (!(strTitle[i] == _T(',')) && !(strTitle[i] == _T('\'')) && !(strTitle[i] == _T('(')) && !(strTitle[i] == _T(')')) && !(strTitle[i] >= _T('0') && strTitle[i] <= _T('9')) && !(strTitle[i] >= _T('A') && strTitle[i] <= _T('Z')) && !(strTitle[i] >= _T('a') && strTitle[i] <= _T('z'))) *((LPTSTR)(LPCTSTR)strTitle + i) = _T(' '); */ // replace ._ by a space strTitle.Replace(_T('.'), _T(' ')); strTitle.Replace(_T('_'), _T(' ')); // remove redundant space while (strTitle.Replace(_T(" "), _T(" "))); strTitle.Trim(); // find year between (), strip anything following it for (n = 0; (n = strTitle.Find(_T('('), n)) != -1; n++) { if (n+5 < strTitle.GetLength() && strTitle[n+5] == _T(')')) { strTemp = strTitle.Mid(n+1, 4); if (StringToNumber(strTemp) > 1900) { strYear = strTemp; strTitle = strTitle.Left(n); break; } } } // remove anything between () for (m = 0, n = 0; (m = strTitle.Find(_T('('), n)) != -1 && (n = strTitle.Find(_T(')'), m)) != -1; m = 0, n = 0) strTitle = strTitle.Left(m) + strTitle.Mid(n+1); // find year not in (), but not as first word, strip anything following it strTitle.Replace(_T('('), _T(' ')); strTitle.Replace(_T(')'), _T(' ')); while (strTitle.Replace(_T(" "), _T(" "))); strTitle.Trim(); if (strYear.IsEmpty()) { m = 0; while (true) { if (m >= strTitle.GetLength()) break; n = strTitle.Find(_T(' '), m); if (n == -1) n = strTitle.GetLength(); if (m == n) {m = n + 1; continue;} if (n - m == 4) { strTemp = strTitle.Mid(m, n - m); if (StringToNumber(strTemp) > 1900 && m > 0) { strYear = strTemp; strTitle = strTitle.Left(m); break; } } m = n + 1; } } while (strTitle.Replace(_T(" "), _T(" "))); strTitle.Trim(); // place some literals in front if (strTitle.GetLength() > 5 && strTitle.Right(5) == _T(", the")) strTitle = _T("the ") + strTitle.Left(strTitle.GetLength() - 5); if (strTitle.GetLength() > 5 && strTitle.Right(5) == _T(", The")) strTitle = _T("The ") + strTitle.Left(strTitle.GetLength() - 5); if (strTitle.GetLength() > 3 && strTitle.Right(3) == _T(", a")) strTitle = _T("a ") + strTitle.Left(strTitle.GetLength() - 3); if (strTitle.GetLength() > 3 && strTitle.Right(3) == _T(", A")) strTitle = _T("A ") + strTitle.Left(strTitle.GetLength() - 3); strTitle.Replace(_T(','), _T(' ')); while (strTitle.Replace(_T(" "), _T(" "))); strTitle.Trim(); //TRACE0(_T("ParseFileName\n strFileName = ") + strFileName + _T("\n strTitle = ") + // strTitle + _T("\n strYear = ") + strYear + _T("\n")); }
static RString GetDirOfExecutable( RString argv0 ) { // argv[0] can be wrong in most OS's; try to avoid using it. RString sPath; #if defined(WIN32) char szBuf[MAX_PATH]; GetModuleFileName( NULL, szBuf, sizeof(szBuf) ); sPath = szBuf; #else sPath = argv0; #endif sPath.Replace( "\\", "/" ); bool bIsAbsolutePath = false; if( sPath.size() == 0 || sPath[0] == '/' ) bIsAbsolutePath = true; #if defined(WIN32) if( sPath.size() > 2 && sPath[1] == ':' && sPath[2] == '/' ) bIsAbsolutePath = true; #endif // strip off executable name sPath = ExtractDirectory(sPath); if( !bIsAbsolutePath ) { #if defined(UNIX) || defined(MACOSX) if( sPath.empty() ) { // This is in our path so look for it. const char *path = getenv( "PATH" ); if( !path ) path = _PATH_DEFPATH; vector<RString> vPath; split( path, ":", vPath ); FOREACH( RString, vPath, i ) { if( access(*i + "/" + argv0, X_OK|R_OK) ) continue; sPath = ExtractDirectory(ReadlinkRecursive(*i + "/" + argv0)); break; } if( sPath.empty() ) sPath = GetCwd(); // What? else if( sPath[0] != '/' ) // For example, if . is in $PATH. sPath = GetCwd() + "/" + sPath; } else { sPath = ExtractDirectory(ReadlinkRecursive(GetCwd() + "/" + argv0)); } #else sPath = GetCwd() + "/" + sPath; sPath.Replace( "\\", "/" ); #endif }
void CReBar::OnCommand(WORD id, WORD notifyCode, HWND hWndControl) { switch (id) { case ID_TOOLS: { // If the button is clicked again while menu is shown, we shouldn't show it again static bool bIgnoreNext = false; if (hWndControl == (HWND)-1) { bIgnoreNext = true; return; } if (bIgnoreNext) { bIgnoreNext = false; return; } // Install a hook to capture mouse events when the menu is shown HHOOK hHook = SetWindowsHookEx(WH_MOUSE_LL, LLMouseProc, GetModuleHandle(NULL), 0); ASSERT(hHook); LLMouseProc(-1, -1, (LPARAM)hHook); LLMouseProc(-2, -2, (LPARAM)this); // Show menu, make sure commands get sent to the main window RECT rc; GetWindowRect(m_btnTools, &rc); VERIFY(TrackPopupMenu(m_hToolsMenu, TPM_RIGHTALIGN|TPM_TOPALIGN, rc.right, rc.bottom, 0, GetTopLevelParent(m_hWnd), NULL)); UnhookWindowsHookEx(hHook); // Restore button state POINT pt; GetCursorPos(&pt); ScreenToClient(m_btnTools, &pt); PostMessage(m_btnTools, WM_LBUTTONUP, 0, MAKELPARAM(pt.x, pt.y)); } break; case ID_TOOLS_STATUSBAR: CheckMenuItem(m_hToolsMenu, ID_TOOLS_STATUSBAR, (GETPREFBOOL(_T("MainWnd"), _T("ShowStatusBar")) ? MF_CHECKED : MF_UNCHECKED)); break; case ID_TOOLS_LOG: CheckMenuItem(m_hToolsMenu, ID_TOOLS_LOG, (GETPREFBOOL(_T("MainWnd"), _T("ShowLog")) ? MF_CHECKED : MF_UNCHECKED)); break; case ID_SEEN: m_btnSeen.SetCheck(!m_btnSeen.GetCheck()); SETPREFBOOL(_T("ShowSeenMovies"), m_btnSeen.GetCheck()); SendMessage(*GetDB(), WM_PREFCHANGED); GetDB()->Filter(); break; case ID_VIEW: m_btnView.SetCheck(!m_btnView.GetCheck()); SETPREFBOOL(_T("ViewType"), m_btnView.GetCheck()); SendMessage(GetMainWnd(), WM_SWITCHVIEW); break; case ID_TOGGLEVIEWSTATUS: m_btnView.SetCheck(!m_btnView.GetCheck()); break; case ID_SORT: { // If the button is clicked again while menu is shown, we shouldn't show it again static bool bIgnoreNext = false; if (hWndControl == (HWND)-1) { bIgnoreNext = true; return; } if (bIgnoreNext) { bIgnoreNext = false; return; } // Install a hook to capture mouse events when the menu is shown HHOOK hHook = SetWindowsHookEx(WH_MOUSE_LL, LLMouseProc, GetModuleHandle(NULL), 0); ASSERT(hHook); LLMouseProc(-1, -1, (LPARAM)hHook); LLMouseProc(-2, -2, (LPARAM)this); // Show menu, make sure commands get sent to THIS window RECT rc; GetWindowRect(m_btnSort, &rc); VERIFY(TrackPopupMenu(m_hSortMenu, TPM_RIGHTALIGN|TPM_TOPALIGN, rc.right, rc.bottom, 0, m_hWnd, NULL)); UnhookWindowsHookEx(hHook); // Restore button state POINT pt; GetCursorPos(&pt); ScreenToClient(m_btnSort, &pt); PostMessage(m_btnSort, WM_LBUTTONUP, 0, MAKELPARAM(pt.x, pt.y)); } break; case ID_SEARCH: if (notifyCode == EN_RETURN || (m_bInstantSearch && notifyCode == EN_CHANGE)) { RString strText = m_eSearch.GetText(); RObArray<RString> keywords; if (m_bLiteralSearch) { if (!strText.IsEmpty()) keywords.Add(strText); } else { RRegEx re(_T("(?:\"([^\"]+)\")|([^ ]+)")); if (!strText.IsEmpty()) keywords.Add(strText); while (re.Search(strText)) { RString strMatch; for (INT_PTR i = 1; i < re.GetMatchCount() && strMatch.IsEmpty(); ++i) strMatch = re.GetMatch(i); strMatch.Replace(_T("\""), _T("")); keywords.Add(strMatch); strText.Replace(re.GetMatch(0), _T("")); } } GetDB()->FilterByKeywords(keywords); } break; case ID_SORT_TITLEASC: case ID_SORT_TITLEDES: case ID_SORT_YEARASC: case ID_SORT_YEARDES: case ID_SORT_RATINGASC: case ID_SORT_RATINGDES: case ID_SORT_FILETIMEASC: case ID_SORT_FILETIMEDES: SETPREFINT(_T("SortBy"), id - ID_SORT_TITLEASC); CheckMenuRadioItem(m_hSortMenu, ID_SORT_TITLEASC, ID_SORT_FILETIMEDES, id, MF_CHECKED); PostMessage(*GetDB(), WM_PREFCHANGED); PostMessage(m_hWnd, WM_COMMAND, MAKEWPARAM(ID_SEARCH, EN_RETURN), (LPARAM)(HWND)m_eSearch); break; default: ASSERT(false); } }
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" ); }
void ParseFileName(RString_ strFileName, RString &strTitle, RString &strYear, INT_PTR &nSeason, INT_PTR &nEpisode, RString &strAirDate, BYTE &bType) { INT_PTR m, n; RString strTemp, strSeason, strEpisode; RString strYearTmp, strMonthTmp, strDayTmp; strTitle = strFileName; strYear.Empty(); // only keep file name n = strTitle.ReverseFind(_T('\\')); if (n != -1) strTitle = strTitle.Mid(n + 1); //strTitle.MakeLower(); // strip file extension (max 4 chars) n = strTitle.ReverseFind(_T('.')); if (n != -1 && strTitle.GetLength() - n < 6) strTitle = strTitle.Left(n); // replace []{} by () strTitle.Replace(_T('['), _T('(')); strTitle.Replace(_T(']'), _T(')')); strTitle.Replace(_T('{'), _T('(')); strTitle.Replace(_T('}'), _T(')')); /* // replace anything not ,()0-9a-zA-Z by a space for (int i = 0; i < strTitle.GetLength(); i++) if (!(strTitle[i] == _T(',')) && !(strTitle[i] == _T('\'')) && !(strTitle[i] == _T('(')) && !(strTitle[i] == _T(')')) && !(strTitle[i] >= _T('0') && strTitle[i] <= _T('9')) && !(strTitle[i] >= _T('A') && strTitle[i] <= _T('Z')) && !(strTitle[i] >= _T('a') && strTitle[i] <= _T('z'))) *((LPTSTR)(LPCTSTR)strTitle + i) = _T(' '); */ // remove urls RString strUrl; if (GetFirstMatch(strTitle, _T("([wW][wW][wW]\\.[^\\.]*?\\.[cC][oO][mM])"), &strUrl, NULL)) { m = strTitle.Find(strUrl, 0); if (m >= 0) strTitle = strTitle.Left(m) + strTitle.Right(strTitle.GetLength() - (m + strUrl.GetLength())); } // replace ._ -by a space strTitle.Replace(_T('.'), _T(' ')); strTitle.Replace(_T('_'), _T(' ')); strTitle.Replace(_T('-'), _T(' ')); // remove redundant space while (strTitle.Replace(_T(" "), _T(" "))); strTitle.Trim(); // find year between (), strip anything following it for (n = 0; (n = strTitle.Find(_T('('), n)) != -1; n++) { if (n + 5 < strTitle.GetLength() && strTitle[n + 5] == _T(')')) { strTemp = strTitle.Mid(n + 1, 4); if (StringToNumber(strTemp) > 1900) { strYear = strTemp; strTitle = strTitle.Left(n); break; } } } // remove anything between () for (m = 0, n = 0; (m = strTitle.Find(_T('('), n)) != -1 && (n = strTitle.Find(_T(')'), m)) != -1; m = 0, n = 0) strTitle = strTitle.Left(m) + strTitle.Mid(n + 1); // for TV shows. Find the season and episode and remove everything following it if (GetFirstMatch(strTitle, _T("([Ss]\\d?\\d[Ee]\\d?\\d)"), &strTemp, NULL)) { m = strTitle.Find(strTemp, 0); if (GetFirstMatch(strTemp, _T("[Ss](\\d?\\d)[Ee](\\d?\\d)"), &strSeason, &strEpisode, NULL)) { nSeason = StringToNumber(strSeason); nEpisode = StringToNumber(strEpisode); bType = DB_TYPE_TV; } if (m >= 0) strTitle = strTitle.Left(m); } // for TV shows by date and parse date aired if (GetFirstMatch(strTitle, _T("(\\d\\d\\d\\d) (\\d?\\d) (\\d?\\d)"), &strYearTmp, &strMonthTmp, &strDayTmp, NULL)) { const RString Month[12] = { _T("Jan"), _T("Feb"), _T("Mar"), _T("Apr"), _T("May"), _T("Jun"), _T("Jul"), _T("Aug"), _T("Sep"), _T("Oct"), _T("Nov"), _T("Dec") }; strAirDate = strDayTmp + _T(" ") + Month[StringToNumber(strMonthTmp) - 1] + _T(". ") + strYearTmp; bType = DB_TYPE_TV; } // find year not in (), but not as first word, strip anything following it strTitle.Replace(_T('('), _T(' ')); strTitle.Replace(_T(')'), _T(' ')); while (strTitle.Replace(_T(" "), _T(" "))); strTitle.Trim(); if (strYear.IsEmpty()) { m = 0; while (m < strTitle.GetLength()) { n = strTitle.Find(_T(' '), m); if (n == -1) n = strTitle.GetLength(); if (m == n) { m = n + 1; continue; } if (n - m == 4) { strTemp = strTitle.Mid(m, n - m); if (StringToNumber(strTemp) > 1900 && m > 0) { strYear = strTemp; strTitle = strTitle.Left(m); break; } } m = n + 1; } } // strip 'season[s] \\d' and anything following it RString strSeasons; if (GetFirstMatch(strTitle, _T("([Ss]eason[s]? ?\\d?\\d(?: ?- ?\\d?\\d)?)"), &strSeasons, NULL)) { m = strTitle.Find(strSeasons, 0); if (m >= 0) strTitle = strTitle.Left(m); bType = DB_TYPE_TV; } //Remove episode numbers of the form XXofYY - TODO: process to return episode number RString strOf; if (GetFirstMatch(strTitle, _T("(\\d?\\d[oO][fF]\\d?\\d)"), &strOf, NULL)) { m = strTitle.Find(strOf, 0); if (m > 0) strTitle = strTitle.Left(m); bType = DB_TYPE_TV; } // strip common movie descriptors and everything after static const RString strDescriptors[] = { _T("webrip"), _T("dvdrip"), _T("dvdscr"), _T("xvid"), _T("bdrip"), _T("brrip"), _T("hdtv"), _T("pdtv"), _T("box set"), _T("box-set"), _T("x264") }; foreach(strDescriptors, strD) { m = strTitle.FindNoCase(strD, 0); if (m > 0) strTitle = strTitle.Left(m); }
static NoteData ParseNoteData(RString &step1, RString &step2, Steps &out, const RString &path) { g_mapDanceNoteToNoteDataColumn.clear(); switch( out.m_StepsType ) { case StepsType_dance_single: g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_LEFT] = 0; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_DOWN] = 1; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_UP] = 2; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_RIGHT] = 3; break; case StepsType_dance_double: case StepsType_dance_couple: g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_LEFT] = 0; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_DOWN] = 1; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_UP] = 2; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_RIGHT] = 3; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD2_LEFT] = 4; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD2_DOWN] = 5; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD2_UP] = 6; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD2_RIGHT] = 7; break; case StepsType_dance_solo: g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_LEFT] = 0; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_UPLEFT] = 1; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_DOWN] = 2; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_UP] = 3; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_UPRIGHT] = 4; g_mapDanceNoteToNoteDataColumn[DANCE_NOTE_PAD1_RIGHT] = 5; break; DEFAULT_FAIL( out.m_StepsType ); } NoteData newNoteData; newNoteData.SetNumTracks( g_mapDanceNoteToNoteDataColumn.size() ); for( int pad=0; pad<2; pad++ ) // foreach pad { RString sStepData; switch( pad ) { case 0: sStepData = step1; break; case 1: if( step2 == "" ) // no data continue; // skip sStepData = step2; break; DEFAULT_FAIL( pad ); } sStepData.Replace("\n", ""); sStepData.Replace("\r", ""); sStepData.Replace("\t", ""); sStepData.Replace(" ", ""); double fCurrentBeat = 0; double fCurrentIncrementer = 1.0/8 * BEATS_PER_MEASURE; for( size_t i=0; i<sStepData.size(); ) { char c = sStepData[i++]; switch( c ) { // begins a series case '(': fCurrentIncrementer = 1.0/16 * BEATS_PER_MEASURE; break; case '[': fCurrentIncrementer = 1.0/24 * BEATS_PER_MEASURE; break; case '{': fCurrentIncrementer = 1.0/64 * BEATS_PER_MEASURE; break; case '`': fCurrentIncrementer = 1.0/192 * BEATS_PER_MEASURE; break; // ends a series case ')': case ']': case '}': case '\'': case '>': fCurrentIncrementer = 1.0/8 * BEATS_PER_MEASURE; break; default: // this is a note character { if( c == '!' ) { LOG->UserLog( "Song file", path, "has an unexpected character: '!'." ); continue; } bool jump = false; if( c == '<' ) { /* Arr. Is this a jump or a 1/192 marker? */ if( Is192( sStepData, i ) ) { fCurrentIncrementer = 1.0/192 * BEATS_PER_MEASURE; break; } /* It's a jump. * We need to keep reading notes until we hit a >. */ jump = true; i++; } const int iIndex = BeatToNoteRow( (float)fCurrentBeat ); i--; do { c = sStepData[i++]; if( jump && c == '>' ) break; int iCol1, iCol2; DWIcharToNoteCol( c, (GameController)pad, iCol1, iCol2, path ); if( iCol1 != -1 ) newNoteData.SetTapNote(iCol1, iIndex, TAP_ORIGINAL_TAP); if( iCol2 != -1 ) newNoteData.SetTapNote(iCol2, iIndex, TAP_ORIGINAL_TAP); if(i>=sStepData.length()) { break; //we ran out of data //while looking for the ending > mark } if( sStepData[i] == '!' ) { i++; const char holdChar = sStepData[i++]; DWIcharToNoteCol(holdChar, (GameController)pad, iCol1, iCol2, path ); if( iCol1 != -1 ) newNoteData.SetTapNote(iCol1, iIndex, TAP_ORIGINAL_HOLD_HEAD); if( iCol2 != -1 ) newNoteData.SetTapNote(iCol2, iIndex, TAP_ORIGINAL_HOLD_HEAD); } } while( jump ); fCurrentBeat += fCurrentIncrementer; } break; } } } /* Fill in iDuration. */ for( int t=0; t<newNoteData.GetNumTracks(); ++t ) { FOREACH_NONEMPTY_ROW_IN_TRACK( newNoteData, t, iHeadRow ) { TapNote tn = newNoteData.GetTapNote( t, iHeadRow ); if( tn.type != TapNote::hold_head ) continue; int iTailRow = iHeadRow; bool bFound = false; while( !bFound && newNoteData.GetNextTapNoteRowForTrack(t, iTailRow) ) { const TapNote &TailTap = newNoteData.GetTapNote( t, iTailRow ); if( TailTap.type == TapNote::empty ) continue; newNoteData.SetTapNote( t, iTailRow, TAP_EMPTY ); tn.iDuration = iTailRow - iHeadRow; newNoteData.SetTapNote( t, iHeadRow, tn ); bFound = true; } if( !bFound ) { /* The hold was never closed. */ LOG->UserLog("Song file", path, "failed to close a hold note in \"%s\" on track %i", DifficultyToString(out.GetDifficulty()).c_str(), t); newNoteData.SetTapNote( t, iHeadRow, TAP_EMPTY ); } } }