std::string MapFile::GetFileName() { std::string sFilePath(filePath); auto lastBackslashPos = sFilePath.find_last_of('\\'); if ( lastBackslashPos != std::string::npos && lastBackslashPos+1 < sFilePath.size() ) return std::string(sFilePath.substr(lastBackslashPos+1, sFilePath.size() - lastBackslashPos+1)); else return std::string(""); }
// ------------------------------------------------------------------------- void ScriptEngine::evaluateFile( QString sScriptFile ) { // Extract the arguments from the script call. QString sFilePath(CommonDefinitions::sScriptDir.c_str()); QFile file(sFilePath + "/" + sScriptFile); if (!file.open(QIODevice::ReadOnly)) { cerr << "Error: Could not open " << qPrintable(sScriptFile) << " for reading!" << endl; } QTextStream ts(&file); QString sContents = ts.readAll(); file.close(); evaluateString( sContents ); }
CString ExecuteUpload (CSocket &theSocket, const CString &sCmd) { char *pPos = sCmd.GetParsePointer() + STR_UPLOAD_PREFIX.GetLength(); // Get the filePath if (*pPos == '\"') pPos++; char *pStart = pPos; while (*pPos != ' ' && *pPos != '\"' && *pPos != '\0') pPos++; CString sFilePath(pStart, pPos - pStart); if (*pPos != '\0') pPos++; if (*pPos == '\"') pPos++; // Skip whitespace while (*pPos == ' ') pPos++; // Get the filespec pStart = pPos; while (*pPos != '\0') pPos++; CString sFilespec(pStart, pPos - pStart); // Load the file return UploadFile(theSocket, CMD_UPLOAD, sFilePath, sFilespec); }
void CRemoteFileDialog::UpdateFileResults() { m_aFiles.RemoveAll(); if (m_sFilenames.IsEmpty()) { return; } // we just parse m_sFilenames CString sFileNames(m_sFilenames); BOOL bMustExist = FileMustExist(); // for downloads int nStartQuote = sFileNames.Find(_T('\"')); if (nStartQuote == -1) { // single file sFileNames.TrimLeft(); sFileNames.TrimRight(); int nFindMatch = FindMatch(sFileNames); if (!bMustExist || nFindMatch != -1) { CString sFilePath(sFileNames); if (!m_bRoot) { sFilePath.Format(_T("%s/%s"), m_sCurFolder, sFileNames); } m_aFiles.Add(FILERESULT(sFilePath, GetItemSize(nFindMatch))); } } else // look for pairs of quotes { while (nStartQuote != -1) { int nEndQuote = sFileNames.Find('\"', nStartQuote + 1); if (nEndQuote != -1) { CString sFileName = sFileNames.Mid(nStartQuote + 1, nEndQuote - 1 - nStartQuote); sFileName.TrimLeft(); sFileName.TrimRight(); int nFindMatch = FindMatch(sFileName); if (!bMustExist || nFindMatch != -1) { CString sFilePath(sFileName); if (!m_bRoot) { sFilePath.Format(_T("%s/%s"), m_sCurFolder, sFileName); } m_aFiles.Add(FILERESULT(sFilePath, GetItemSize(nFindMatch))); } // next pair nStartQuote = sFileNames.Find(_T('\"'), nEndQuote + 1); } else { nStartQuote = -1; // we're done } } } }
void CRemoteFileDialog::OnItemchangedFilelist(NMHDR* /*pNMHDR*/, LRESULT* pResult) { *pResult = 0; if (m_bFilling) { return; } // rebuild results at the same time int nSelCount = m_lcFiles.GetSelectedCount(); if (nSelCount == 1) { int nSel = GetFirstSelectedItem(); if (GetItemType(nSel) == RFDT_FILE || FolderSelect()) { // save result CString sFileName = m_lcFiles.GetItemText(nSel, 0); CString sFilePath(sFileName); if (!m_bRoot) { sFilePath.Format(_T("%s/%s"), m_sCurFolder, sFileName); } m_aFiles.RemoveAll(); m_aFiles.Add(FILERESULT(sFilePath, GetItemSize(nSel))); // update current filename m_sFilenames = sFileName; } } else if (nSelCount > 1) { m_sFilenames.Empty(); POSITION pos = m_lcFiles.GetFirstSelectedItemPosition(); while (pos) { int nItem = m_lcFiles.GetNextSelectedItem(pos); if (nItem != -1 && GetItemType(nItem) == RFDT_FILE) { // save result CString sFileName = m_lcFiles.GetItemText(nItem, 0); CString sFilePath(sFileName); if (!m_bRoot) { sFilePath.Format(_T("%s/%s"), m_sCurFolder, sFileName); } m_aFiles.Add(FILERESULT(sFilePath, GetItemSize(nItem))); // update current filename CString sItem; sItem.Format(_T("\"%s\" "), sFileName); m_sFilenames += sItem; } } } UpdateData(FALSE); UpdateOKButton(FALSE); }
HANDLE WINAPI EXP_NAME(OpenPlugin)(int openFrom, INT_PTR item) { PCTSTR filePath; auto_ptr<wchar_t> cmdLine; auto_ptr<PluginPanelItem> panelItem; switch(openFrom) { case OPEN_COMMANDLINE: { if(!item) return INVALID_HANDLE_VALUE; #ifdef FAR3 cmdLine.reset(_wcsdup(((OpenCommandLineInfo*)item)->CommandLine)); filePath = cmdLine.get(); #else filePath = (PCTSTR)item; #endif if(!filePath || !*filePath) return INVALID_HANDLE_VALUE; if(*filePath == '\"') { PTSTR p1 = const_cast<PTSTR>(filePath) + _tcslen(filePath) - 1; if(*p1 == '\"') *p1 = 0; memmove(const_cast<PTSTR>(filePath), filePath + 1, (p1 - filePath + 1) * sizeof(TCHAR)); } } break; case OPEN_PLUGINSMENU: { //assert(item->) filePath = JsonPlugin::ClipboardName; /*panelItem.reset(GetCurrentItem()); panelItem->FileName; if(!filePath || !*filePath) return INVALID_HANDLE_VALUE;*/ } break; #ifdef FAR3 case OPEN_SHORTCUT: if(!item) return INVALID_HANDLE_VALUE; filePath = ((OpenShortcutInfo*)item)->HostFile; break; #endif default: return INVALID_HANDLE_VALUE; } //SaveScreen ss; //PCTSTR Items[]={_T(""),GetMsg(MLoading)}; //Message(0,NULL,Items,_countof(Items),0); // These command lines are possible: // file.json // c:\dir\file.json //??? http://site.com/url tstring sFilePath( #ifdef FAR3 openFrom == OPEN_SHORTCUT ? ((OpenShortcutInfo*)item)->HostFile : #endif filePath); tstring sSubDir; if(openFrom == OPEN_COMMANDLINE) { tstring sCommandLine(filePath); size_t colon = sCommandLine.find(':'); if(colon != tstring::npos) { tstring s1 = sCommandLine.substr(0, colon); if(GetFileAttributes(s1.c_str()) != 0xffffffff) { // file before 1st colon exists, get the rest sFilePath = s1; sSubDir = sCommandLine.substr(colon+1); } else { colon = sCommandLine.find(':', colon+1); sFilePath = sCommandLine.substr(0, colon); if(colon != tstring::npos) // second colon exists, get the rest sSubDir = sCommandLine.substr(colon+1); } } TCHAR absPath[MAX_PATH]; #ifdef UNICODE if(!wcschr(sFilePath.c_str(), ':')) // if rel path, convert it { StartupInfo.FSF->ConvertPath(CPM_FULL, sFilePath.c_str(), absPath, _countof(absPath)); #else if(GetFileAttributes(sFilePath.c_str()) != 0xffffffff) { // if local file exists, use its abs path _tfullpath(absPath, sFilePath.c_str(), _countof(absPath)); #endif sFilePath = absPath; } } JsonPlugin* plugin; try { plugin = new JsonPlugin(sFilePath.c_str()); } catch(WinExcept ex) { WinError(ex); return INVALID_HANDLE_VALUE; } if(plugin->HasParseError()) { auto error = plugin->GetParseError(); auto eroffs = plugin->GetErrorOffset(); delete plugin; tstring err(GetMsg(error + MParseErrorNone - kParseErrorNone)); err += '\n'; LPCTSTR err2 = GetMsg(MParseOffset); vector<TCHAR> err3(_tcslen(err2) + 20); _sntprintf(&err3[0], err3.size()-1, err2, eroffs); err3[err3.size()-1] = 0; err += &err3[0]; WinError(err.c_str()); return INVALID_HANDLE_VALUE; } if(!sSubDir.empty()) try { plugin->SetDirectory(sSubDir.c_str(),0); } catch(...) {} return plugin; } #ifdef FAR3 HANDLE WINAPI AnalyseW(const AnalyseInfo *info) { HANDLE h = OpenFilePluginW(info->FileName, (BYTE*)info->Buffer, (int)info->BufferSize, (int)info->OpMode); return h == INVALID_HANDLE_VALUE ? NULL : h; }
int main( int argc, char* argv[] ) { if ( argc != 6 ) { Mojo::Core::Printf( "Usage: DiceScoreCalculator.exe ground_truth_directory segmentation_directory width height num_images\n\nPress any key to exit." ); getchar(); return -1; } try { boost::filesystem::path gtDir( boost::filesystem::complete( argv[ 1 ] ) ); boost::filesystem::path sDir ( boost::filesystem::complete( argv[ 2 ] ) ); int width = boost::lexical_cast< int >( argv[ 3 ] ); int height = boost::lexical_cast< int >( argv[ 4 ] ); int numImages = boost::lexical_cast< int >( argv[ 5 ] ); RELEASE_ASSERT( boost::filesystem::exists( gtDir) ); RELEASE_ASSERT( boost::filesystem::is_directory( gtDir ) ); RELEASE_ASSERT( boost::filesystem::exists( sDir) ); RELEASE_ASSERT( boost::filesystem::is_directory( sDir ) ); RELEASE_ASSERT( width > 0 ); RELEASE_ASSERT( height > 0 ); RELEASE_ASSERT( numImages > 0 ); boost::filesystem::directory_iterator gtFile; boost::filesystem::directory_iterator sFile; gtFile = boost::filesystem::directory_iterator( gtDir ); sFile = boost::filesystem::directory_iterator( sDir ); int FP = 0; int TP = 0; int FN = 0; int TN = 0; for (; gtFile != boost::filesystem::directory_iterator(); ) { boost::filesystem::path gtFilePath( gtFile->path() ); boost::filesystem::path sFilePath( sFile->path() ); if ( boost::filesystem::is_regular_file( gtFilePath ) && boost::filesystem::is_regular_file( sFilePath ) ) { cv::Mat gtImage = cv::imread( gtFilePath.native_file_string() ); cv::Mat sImage = cv::imread( sFilePath.native_file_string() ); std::vector<cv::Mat> gtImageChannels; std::vector<cv::Mat> sImageChannels; cv::split( gtImage, gtImageChannels ); cv::split( sImage, sImageChannels ); cv::Mat gtImageR = gtImageChannels[2]; cv::Mat gtImageG = gtImageChannels[1]; cv::Mat gtImageB = gtImageChannels[0]; cv::Mat sImageR = sImageChannels[0]; for( int y = 0; y < height; y++ ) { for( int x = 0; x < width; x++ ) { if ( ( gtImageR.at< unsigned char >( y, x ) > 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == POSITIVE ( sImageR.at < unsigned char >( y, x ) >= 1 ) ) // SOURCE == POSITIVE { TP++; } else if ( ( gtImageR.at< unsigned char >( y, x ) > 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == POSITIVE ( sImageR.at < unsigned char >( y, x ) < 1 ) ) // SOURCE == NEGATIVE { FN++; } else if ( ( gtImageR.at< unsigned char >( y, x ) == 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == NEGATIVE ( sImageR.at < unsigned char >( y, x ) >= 1 ) ) // SOURCE == POSITIVE { FP++; } else if ( ( gtImageR.at< unsigned char >( y, x ) == 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == NEGATIVE ( sImageR.at < unsigned char >( y, x ) < 1 ) ) // SOURCE == NEGATIVE { TN++; } else { int gtr = gtImageR.at< unsigned char >( y, x ); int gtg = gtImageB.at< unsigned char >( y, x ); int gtb = gtImageG.at< unsigned char >( y, x ); int sr = gtImageR.at< unsigned char >( y, x ); Mojo::Core::Printf( "gtr ", gtr, ", gtg ", gtg, ", gtb ", gtb, ", sr ", sr ); RELEASE_ASSERT( 0 ); } } } } ++gtFile; ++sFile; } RELEASE_ASSERT( TP + FP + TN + FN == width * height * numImages ); Mojo::Core::Printf( "TP: ", TP ); Mojo::Core::Printf( "FP: ", FP ); Mojo::Core::Printf( "TN: ", TN ); Mojo::Core::Printf( "FN: ", FN ); } catch( std::exception e ) { Mojo::Core::Printf( "Exception: ", e.what() ); return -1; } return 0; }