/* * FileNameFinder.cpp * * Created on: Mar 20, 2016 * Author: Hovanes Egiyan */ #include "boost/program_options.hpp" #include "FileNameFinder.hh" using namespace std; namespace po = boost::program_options; FileNameFinder::FileNameFinder( int* ac, char* av[] ) : fnfDirName(""), fnfFileName( "" ) { po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") ("input-file", po::value< string>(), "input file") ("input-directory", po::value< string>(), "input file directory") ; po::positional_options_description p; p.add("input-file", -1); po::variables_map vm; po::store(po::command_line_parser(*ac, av). options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("input-file")) { cout << "Input file is: " << vm["input-file"].as< string >() << "\n"; fnfFileName = vm["input-file"].as< string >(); } if( vm.count("input-directory") ) { cout << "Input file directory is: " << vm["input-directory"].as< string >() << "\n"; fnfDirName = vm["input-directory"].as< string >(); } parseFullFileName( fnfDirName, fnfFileName ); return; } FileNameFinder::~FileNameFinder() { return; } string FileNameFinder::getFileNameFromGUI( TGWindow* window ) { TGFileInfo* scanFileInfo = new TGFileInfo(); const char *fileTypes[] = {"MDA scan files", "*.mda", 0, 0}; scanFileInfo->fFileTypes = fileTypes; char* dirString = new char[1024]; strcpy( dirString, this->getDirName().c_str() ); scanFileInfo->fIniDir = dirString; new TGFileDialog( gClient->GetRoot(), window, kFDOpen, scanFileInfo ); if( scanFileInfo->fFilename == 0 ) { this->setFileName( "" ); return ""; } cout << "Selected directory " << scanFileInfo->fIniDir << " and fileName " << scanFileInfo->fFilename << endl; parseFullFileName( string( scanFileInfo->fIniDir ), string( scanFileInfo->fFilename ) ); delete scanFileInfo; cout << "Deleted fileInfo" << endl; return getFullFileName(); } void FileNameFinder::parseFullFileName( const string& dName, const string& fName ) { string fileName = fName; // string dirName = string( dName + string("/") ); string dirName = dName; if( fName.find("/") != string::npos ) { size_t lastSlashPos = fName.find_last_of("/"); fileName = fName.substr( lastSlashPos, fName.size() - lastSlashPos ); // dirName = fName.substr( 0, lastSlashPos + 1 ); dirName = fName.substr( 0, lastSlashPos ); } if( fName == "" && dName == "" ) { dirName = "."; } cout << "FullFileName is " << fName << " file name is " << fileName << " dir name is " << dirName << endl; this->setFileName( fileName ); this->setDirName( dirName ); return ; }