Example #1
0
void OpenFileDialog::on_treeView_activated(const QModelIndex &index)
{
    if (mDirModel->isDir(index))
    {
        auto mSelectedDir = mDirModel->filePath(index);
        if (mSelectedDir.endsWith(".."))
        {
            // remove "/.."
            mSelectedDir = mSelectedDir.left(mSelectedDir.length()-3);
            QFileInfo info = (mSelectedDir);
            // get parent directory
            mSelectedDir = info.path();
        }

        setDirectory(mSelectedDir);
        mDirModel->setRootPath(getDirectory());
        mDirModel->setFilter(QDir::NoDot | QDir::AllEntries);
        ui->treeView->setRootIndex(mDirModel->index(getDirectory()));
    }
    else
    {
        mSelectedFile = mDirModel->filePath(index);
        this->accept();
    }
}
Example #2
0
/** Saves a file to the table item based on the @param fileData: */
QString TableItem::saveFile(QByteArray fileData, QString fileType)
{
    if (getDirectory().isEmpty()) return "";

    /* Create all the folders necessary if they don't exist: */
    QDir dir;
    dir.mkpath(getDirectory());

    /* Get the path name: */
    int extension = getAvailableFileExtension(fileType);
    QString filePath = makeFilepath(getName(), getDirectory(), fileType, extension);

    /* Save the file into the folderpath location: */
    QFile itemFile(filePath);
    if(!itemFile.open(QIODevice::WriteOnly))
        return "";

    /* Write data into the file: */
    itemFile.write(fileData);
    itemFile.flush();
    itemFile.close();

    /* Set a hash for the file to identify it: */
    setFileHash( QCryptographicHash::hash(fileData,QCryptographicHash::Md5) );
    return filePath;
}
    void ContentModule::initializeTextures() const
    {
        
		String resourceGroup = isCommon() ?
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME : getId();

		StringVector texLocations = getTextureLocations();
		for(StringVector::iterator iter = texLocations.begin();
			iter != texLocations.end();
			iter++)
		{
			String location = *iter;
			if (location.find(".zip") != String::npos)
			{
                ResourceGroupManager::getSingleton().addResourceLocation(
                	getDirectory() + "/materials/" + location, "Zip", resourceGroup);
			}
			else
			{
                ResourceGroupManager::getSingleton().addResourceLocation(
                	getDirectory() + "/materials/" + location, "FileSystem", resourceGroup);
			}
		}

		addSearchPath(getDirectory()+"/materials", resourceGroup);
    }
Example #4
0
void makeDirectory(const std::string& path)
{
    if(path.empty())
    {
        return;
    }

    if(isDirectory(path))
    {
        return;
    }

    if(!isDirectory(getDirectory(path)))
    {
        makeDirectory(getDirectory(path));
    }

    #ifndef _WIN32
    int status = mkdir(path.c_str(), 0755);

    if(status != 0)
    {
        throw std::runtime_error("Failed to make directory '" + path + "'.");
    }
    #else
    assertM(false, "Not implemented for this platform.");
    #endif
}
Example #5
0
int LocalPackage::fill_filelist(PACKAGE *package, bool)
{
	if (!package) package=&data;
	//mDebug("fill_filelist start");
	// Retrieving regular files
	// For setup mode, we can try to enable cached filelists
	vector<string> file_names;
	string fname;
	bool fname_temp = false;
	if (setupMode && FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist")) {
		fname = getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist";
	}
	else {
		fname = get_tmp_file();
		fname_temp = true;
		system("tar tf "+filename+" --exclude install " +" > "+fname + " 2>/dev/null");
	}
	// Parsing file list
	file_names=ReadFileStrings(fname);
	if (fname_temp) unlink(fname.c_str());
	if (file_names.size()>2) file_names.erase(file_names.begin(), file_names.begin()+2);
	else {
		mWarning("Empty file list in package " + package->get_name());
		file_names.clear();
	}
	package->set_files(file_names);
	// Retrieving symlinks (from doinst.sh).
	string dt;
	bool dt_temp=false;
	// Extracting file to the temp dir
	if (setupMode && FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/doinst.sh")) {
		dt = getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/doinst.sh";
	}
	else if (!setupMode || !FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist")) { // Assuming that doinst.sh isn't present if flist is cached
		dt = get_tmp_file();
		extractFromTgz(filename, "install/doinst.sh", dt);
		dt_temp = true;
	}

	
	if (!dt.empty() && FileExists(dt)) {
		string lnfname=get_tmp_file();
		string sed_cmd = "sed -n 's,^( *cd \\([^ ;][^ ;]*\\) *; *rm -rf \\([^ )][^ )]*\\) *) *$,\\1/\\2,p' < ";
		sed_cmd += dt + " > " + lnfname;
		system(sed_cmd);
		vector<string>link_names=ReadFileStrings(lnfname);
		for (size_t i=0; i<link_names.size(); ++i) {
			if (!link_names[i].empty()) package->get_files_ptr()->push_back(link_names[i]);
		}
		if (dt_temp) unlink(dt.c_str());
		unlink(lnfname.c_str());
	}

	delete_tmp_files();
	return 0;
}
Example #6
0
void respond(int pSocket, string version, string path, string reqPath) {
	struct stat filestat;
	if(stat(path, filestat) == ERROR) {
		writeLine(pSocket, version + " 404 NOT FOUND");
		writeLine(pSocket, "Content-Type: text/html");
		string body = get404();
		string contentLength = to_string(body.length());
		writeLine(pSocket, "Content-Length: " + contentLength);
		writeLine(pSocket);
		write(pSocket, body);
	} else if(S_ISREG(filestat.st_mode)) {
		writeLine(pSocket, version + " 200 OK");
		writeLine(pSocket, "Content-Type: " + getContentType(path));
		string contentLength = to_string(filestat.st_size);
		writeLine(pSocket, "Content-Length: " + contentLength);
		writeLine(pSocket);
		writeFile(pSocket, path);
	} else if(S_ISDIR(filestat.st_mode)) {
		writeLine(pSocket, version + " 200 OK");
		writeLine(pSocket, "Content-Type: text/html");
		struct stat indexStat;
		string indexPath = joinPath(path, "index.html");
		if(stat(indexPath, indexStat) == ERROR) {
			string body = getDirectory(path, reqPath);
			writeLine(pSocket, "Content-Length: " + to_string(body.length()));
			writeLine(pSocket);
			write(pSocket, body);
		} else {
			writeLine(pSocket, "Content-Length: " + to_string(indexStat.st_size));
			writeLine(pSocket);
			writeFile(pSocket, indexPath);
		}
	}
}
Example #7
0
CIndex::CIndex(CDirectory* pDirectory,ACCESS_MODE am)
    :m_pReader(NULL)
    ,m_pWriter(NULL)
    ,m_accessMode(am)
    ,m_pFactoryFinder(NULL)
    ,m_pDocSchema(new CDocumentSchema())
    ,m_bDirty(false)
{
    m_pBarrelsInfo = new CBarrelsInfo();

    m_pBarrelsInfo->read(pDirectory);//¶ÁÈ¡BarrelsInfo
    if((am & ACCESS_CREATE) == ACCESS_CREATE)
    {
        m_pBarrelsInfo->remove(getDirectory());
    }
    else
    {
        if(_tcsicmp(m_pBarrelsInfo->getVersion(),FIRTEX_VERSION))
        {
            delete m_pBarrelsInfo;
            m_pBarrelsInfo = NULL;
            FIRTEX_THROW2(VERSION_ERROR,_T("incompatible version."));
        }
    }
}
Example #8
0
void Sound_initTracks(void) {
  const char *music_path;
  nebu_List *soundList;
  nebu_List *p;
  int i;

  music_path = getDirectory( PATH_MUSIC );
	soundList = readDirectoryContents(music_path, NULL);
  if(soundList->next == NULL) {
    fprintf(stderr, "[sound] no music files found...exiting\n");
    nebu_assert(0); exit(1); // TODO: handle missing songs somewhere else
  }
    
  i = 1;
  for(p = soundList; p->next != NULL; p = p->next) {
    
    // bugfix: filter track list to readable files (and without directories)
    char *path = getPossiblePath( PATH_MUSIC, (char*)p->data );
  	if( path != NULL && nebu_FS_Test( path ) ) {
    	scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data);
        i++;
    	free( path );
		
    }
	free(p->data);
  }
  nebu_List_Free(soundList);
  scripting_Run("setupSoundTrack()");
}
Example #9
0
bool VNoteFile::renameAttachment(const QString &p_oldName, const QString &p_newName)
{
    int idx = findAttachment(p_oldName);
    if (idx == -1) {
        return false;
    }

    QDir dir(fetchAttachmentFolderPath());
    if (!dir.rename(p_oldName, p_newName)) {
        qWarning() << "fail to rename attachment file" << p_oldName << p_newName;
        return false;
    }

    m_attachments[idx].m_name = p_newName;

    if (!getDirectory()->updateFileConfig(this)) {
        qWarning() << "fail to rename attachment in config" << p_oldName << p_newName;

        m_attachments[idx].m_name = p_oldName;
        dir.rename(p_newName, p_oldName);

        return false;
    }

    return true;
}
Example #10
0
bool VNoteFile::addAttachment(const QString &p_file)
{
    if (p_file.isEmpty() || !QFileInfo::exists(p_file)) {
        return false;
    }

    QString folderPath = fetchAttachmentFolderPath();
    QString name = VUtils::fileNameFromPath(p_file);
    Q_ASSERT(!name.isEmpty());
    // For attachments, we do not use complete base name.
    // abc.tar.gz should be abc_001.tar.gz instead of abc.tar_001.gz.
    name = VUtils::getFileNameWithSequence(folderPath, name, false);
    QString destPath = QDir(folderPath).filePath(name);
    if (!VUtils::copyFile(p_file, destPath, false)) {
        return false;
    }

    m_attachments.push_back(VAttachment(name));

    if (!getDirectory()->updateFileConfig(this)) {
        qWarning() << "fail to update config of file" << m_name
                   << "in directory" << fetchBasePath();
        return false;
    }

    return true;
}
int c_loadDirectory(lua_State *L) {
	int dir;
	const char *dirPath;
	nebu_List *files, *p;
	int nFiles = 0;

	// load directory enum from stack
	int top = lua_gettop(L); // number of arguments
	if(top != 1) {
		// wrong number of arguments
		// lua_error(L, "wrong number of arguments for function "
		//	"c_loadDirectory: should be 1\n");
	}
	if(!lua_isnumber(L, -1)) {
		// lua_error(L, "number  expected for arg1 to function "
		//	"c_loadDirecotry");
	}
	dir = (int) lua_tonumber(L, -1);

	dirPath = getDirectory(dir); // PATH_ART or PATH_LEVEL or PATH_MUSIC
	files = readDirectoryContents(dirPath, NULL);

	lua_newtable(L);
	for(p = files; p->next; p = p->next) {
		lua_pushstring(L, p->data);
		lua_rawseti(L, -2, nFiles + 1);
		nFiles++;
	}
	/* FIXME: when does the list get freed */
	return 1;
}
Example #12
0
void CIndex::open(const tchar* path,ACCESS_MODE am)
{
    close();

    if ((m_accessMode & ACCESS_APPEND) == ACCESS_APPEND )
    {
        tstring strBarrel = path;
        strBarrel += PATH_DELIMITERA;
        strBarrel += BARRELS_INFONAME;
        if(!firtex::utility::CMisc::dirExists(path) || !firtex::utility::CMisc::dirExists(strBarrel.c_str()))
        {
            m_accessMode = m_accessMode & (~ACCESS_APPEND);
            m_accessMode = m_accessMode|ACCESS_CREATE;
        }
    }

    m_pDirectory = CFSDirectory::getDirectory(path,((m_accessMode & ACCESS_CREATE) == ACCESS_CREATE));

    m_pBarrelsInfo = new CBarrelsInfo();

    m_pBarrelsInfo->read(m_pDirectory);//¶ÁÈ¡BarrelsInfo
    if((am & ACCESS_CREATE) == ACCESS_CREATE)
    {
        m_pBarrelsInfo->remove(getDirectory());
    }
    else
    {
        if(_tcsicmp(m_pBarrelsInfo->getVersion(),FIRTEX_VERSION))
        {
            delete m_pBarrelsInfo;
            m_pBarrelsInfo = NULL;
            FIRTEX_THROW2(VERSION_ERROR,"incompatible version.");
        }
    }
}
Example #13
0
void Sound_initTracks(void) {
  const char *music_path;
  List *soundList;
  List *p;
  int i;

  music_path = getDirectory( PATH_MUSIC );
	soundList = readDirectoryContents(music_path, NULL);
  if(soundList->next == NULL) {
    fprintf(stderr, "[sound] no music files found...exiting\n");
    exit(1); // FIXME: handle missing songs somewhere else
  }
  
  //soundList->data="revenge_of_cats.it";
  
  i = 1;
  for(p = soundList; p->next != NULL; p = p->next) {
    
    // bugfix: filter track list to readable files (and without directories)
    char *path = getPossiblePath( PATH_MUSIC, (char*)p->data );
  	if( path != NULL && fileExists( path ) ) {
    	scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data);
        i++;
    	free( path );
    }
  }
  scripting_Run("setupSoundTrack()");
}
Example #14
0
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: attachSexyAPI(); break;
        case 1: { QStringList _r = exec((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< QStringList*>(_a[0]) = _r; }  break;
        case 2: { QStringList _r = exec((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< QStringList*>(_a[0]) = _r; }  break;
        case 3: alert((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 4: quit(); break;
        case 5: windowMinimize(); break;
        case 6: windowMaximize(); break;
        case 7: windowResize((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 8: { int _r = windowWidth();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        case 9: { int _r = windowHeight();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        case 10: { QStringList _r = getOpenFileName((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< QStringList*>(_a[0]) = _r; }  break;
        case 11: { QStringList _r = getOpenFileName((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< QStringList*>(_a[0]) = _r; }  break;
        case 12: { QStringList _r = getOpenFileName();
            if (_a[0]) *reinterpret_cast< QStringList*>(_a[0]) = _r; }  break;
        case 13: { QString _r = getSaveFileName((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 14: { QString _r = getSaveFileName((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 15: { QString _r = getSaveFileName();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 16: { QString _r = getDirectory((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 17: { QString _r = getDirectory();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 18: { QStringList _r = getArgs();
            if (_a[0]) *reinterpret_cast< QStringList*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 19;
    }
    return _id;
}
Example #15
0
void
SFMLLoader::addSprite(string const &path, Resources *resources, string const &name) {
  if (doc == NULL) {
    cerr << "Resource file not loaded: " << resourceFile << endl;
    assert(!(doc == NULL));
  }
  // Load and parse
  loadSpriteFromXML(getDirectory(doc->Value()), doc, path, resources, name);
}
std::string urdf_traverser::helpers::getDirectoryName(const std::string& path)
{
    std::string dir = getDirectory(path);
    // dir will now be a directory (enforced to end with / by getDirectory()).
    // So parent_path will return path to the parent directory where it looks
    // like it was a file.
    boost::filesystem::path ret(dir);
    return ret.parent_path().filename().string();
}
Example #17
0
MachOFile::MachOFile(const std::string& filename,const MachOFile* parent,  bool reversedByteOrder) :
    file(InternalFile::create(filename)), position(0), reversedByteOrder(reversedByteOrder), parent(parent)
{
    if (parent) {
        executablePath = parent->executablePath;
    } else {
        executablePath = getDirectory();
    }
}
Example #18
0
int TableItem::getAvailableFileExtension(QString fileExt)
{
    QString path;
    int repetitions = 0;
    do {
        repetitions++;
        path = makeFilepath(name, getDirectory(), fileExt, repetitions);
    }
    while (QFile(path).exists());
    return repetitions;
}
Example #19
0
bool GetPbkg::processEvent(cafe::Event& event)
{
    cafe::Collection<TMBJet> GoodJets = event.getCollection<TMBJet>(jbranch.c_str());
    cafe::Collection<TMBEMCluster> GoodElectrons = event.getCollection<TMBEMCluster>(ebranch.c_str());
    cafe::Collection<TMBMuon> GoodMuons = event.getCollection<TMBMuon>(mbranch.c_str());
    cafe::Collection<TMBTrack> GoodTracks = event.getCollection<TMBTrack>(trbranch.c_str());

    if( GoodJets.size() < min_jets || GoodJets.size() > max_jets
        || ( _channel == "ee" && GoodElectrons.size() < 2 )
        || ( _channel == "emu" && ( GoodElectrons.size() < 1 || GoodMuons.size() < 1 ) )
        || ( _channel == "mumu" && GoodMuons.size() < 2 )
        || ( _channel == "etrk" && ( GoodElectrons.size() < 1 || GoodTracks.size() < 1 ) )
        || ( _channel == "mutrk" && ( GoodMuons.size() < 1 || GoodTracks.size() < 1 ) )
        || GoodJets[0].Pt() < _lead_jet_pt )
        return false;

    if( ( _channel == "ee" && ( GoodElectrons[0].Pt() < _lead_lepton_pt || GoodElectrons[0].Pt() > 300. ) )
          || ( _channel == "emu" && ( TMath::Max( GoodElectrons[0].Pt() , GoodMuons[0].Pt() ) < _lead_lepton_pt || TMath::Max( GoodElectrons[0].Pt() , GoodMuons[0].Pt() ) > 300. ) )
          || ( _channel == "mumu" && ( GoodMuons[0].Pt() < _lead_lepton_pt || GoodMuons[0].Pt() > 300. ) ) 
          || ( _channel == "etrk" && ( TMath::Max( GoodElectrons[0].Pt() , GoodTracks[0].Pt() ) < _lead_lepton_pt || TMath::Max( GoodElectrons[0].Pt() , GoodTracks[0].Pt() ) > 300. ) )
          || ( _channel == "mutrk" && ( TMath::Max( GoodMuons[0].Pt() , GoodTracks[0].Pt() ) < _lead_lepton_pt || TMath::Max( GoodMuons[0].Pt() , GoodTracks[0].Pt() ) > 300. ) ) )
        return false;

    d_event->Clear();
    std::string _track_for_met_branch = "";
    if( d_event->read_event( event , ebranch , mbranch , trbranch , _track_for_met_branch , jbranch , metbranch , bad_jbranch ) )
    {
        bool is_good = false;
//         if( d_output_filename != "" )
//             is_good = d_event->write_event( d_outputfile );
        getDirectory()->cd();

        double res=0 , err=0;
        if( d_me_sample->get_bkg_prob( *d_event , d_title ,  res , err , _ps_type , _fs_type , iterations ) )
        {
            if( d_event->met.Mod() < _min_met ) return false;
            if( d_output_filename != "" )
            {
//                 d_event->write_event( d_output_filename );
                d_outputfile << d_event->run << " " << d_event->event << " " << d_event->mcweight << " " << res << " " << err << endl;
//                 d_outputfile << endl;
            }
            if( res > 1e-50 )
            {
                res = TMath::Log10(res);
            }
            else
                res = -50;
            pbkg_plot->Fill( res , d_event->mcweight );
            return true;
        }
    }
    return true;
};
Example #20
0
/*
 *	serviceSighupRequest()
 *
 */
static void serviceSighupRequest(void *pParam)
{
	struct ioc_log_server	*pserver = (struct ioc_log_server *)pParam;
	char			buff[256];
	int			status;

	/*
	 * Read and discard message from pipe.
	 */
	(void) read(sighupPipe[0], buff, sizeof buff);

	/*
	 * Determine new log file name.
	 */
	status = getDirectory();
	if (status<0){
		fprintf(stderr, "iocLogServer: failed to determine new log "
			"file name\n");
		return;
	}

	/*
	 * Try (re)opening the file.
	 */
	status = openLogFile(pserver);
	if(status<0){
		fprintf(stderr,
			"File access problems to `%s' because `%s'\n", 
			ioc_log_file_name,
			strerror(errno));
		/* Revert to old filename */
		strcpy(ioc_log_file_name, pserver->outfile);
		status = openLogFile(pserver);
		if(status<0){
			fprintf(stderr,
				"File access problems to `%s' because `%s'\n",
				ioc_log_file_name,
				strerror(errno));
			return;
		}
		else {
			fprintf(stderr,
				"iocLogServer: re-opened old log file %s\n",
				ioc_log_file_name);
		}
	}
	else {
		fprintf(stderr,
			"iocLogServer: opened new log file %s\n",
			ioc_log_file_name);
	}
}
bool urdf_traverser::helpers::getRelativeDirectory(const std::string& path, const std::string& relTo, std::string& result)
{
    // ROS_INFO_STREAM("Get relative dir of "<<path<<" to "<<relTo);

    boost::filesystem::path _path(boost::filesystem::absolute(path));
    boost::filesystem::path _relTo(boost::filesystem::absolute(relTo));

    std::string commonParent;
    if (!getCommonParentPath(path, relTo, commonParent))
    {
        ROS_ERROR_STREAM("Directories " << path << " and " << relTo << " have no common parent directory.");
        return false;
    }
    // ROS_INFO_STREAM("Common parent: "<<commonParent);

    // get both directories relative to the common parent directory:

    std::string relPath;
    if (!urdf_traverser::helpers::getSubdirPath(commonParent, path, relPath))
    {
        ROS_ERROR_STREAM("The file " << path << " is not in a subdirectory of " << commonParent);
        return false;
    }
    // ROS_INFO_STREAM("Path relative to common: "<<relPath);

    std::string relToTarget;
    if (!urdf_traverser::helpers::getSubdirPath(commonParent, relTo, relToTarget))
    {
        ROS_ERROR_STREAM("Relative path " << relTo << " is not a subdirectory of " << commonParent);
        return false;
    }
    // ROS_INFO_STREAM("relTo relative to common: "<<relToTarget);

    // make sure this is a directory, not a file (remove filename if that's the case)
    std::string relToDir = getDirectory(relToTarget);
    // ROS_INFO_STREAM("relTo relative to common: "<<relToDir);

    // Go up in the hierarchie the number of directories in \e relTo which it takes
    // to get to the common parent directory
    int relToLen = numDirectories(relToDir);
    // ROS_INFO_STREAM("Num dirs in "<<relToTarget<<"("<<relToDir<<"):"<<relToLen);
    std::stringstream upDirs;
    for (int i = 0; i < relToLen; ++i)
        upDirs << ".." << boost::filesystem::path::preferred_separator;

    // append the relative path from common parent dir to \e path
    upDirs << relPath;

    result = upDirs.str();

    return true;
}
void CGameLauncher::setupDosExecDialog()
{
    const std::string dataDir = getDirectory( m_chosenGame );

    // TODO: fetch the List of available patch files
    // Get the list of ".pat" files
    DosExecListFiller dosExecList;
    FindFiles(dosExecList, dataDir, false, FM_REG);

    if( dosExecList.list.empty() )
    {
        mExecFilename = "";
        mDoneExecSelection=true;
        return;
    }

    // If the there are not at least 2 mods to select, do not create the patch selection dialog
    if( dosExecList.list.size() == 1 )
    {
        mExecFilename = *(dosExecList.list.begin());
        mDoneExecSelection=true;
        return;
    }

    mpDosExecDialog.reset(new CGUIDialog(GsRect<float>(0.1f, 0.1f, 0.8f, 0.85f), CGUIDialog::EXPAND)),
    mpDosExecDialog->initEmptyBackground();


    if(!mDosExecStrVec.empty())
        mDosExecStrVec.clear();

    mpDosExecSelList = new CGUITextSelectionList();


    for( auto &elem : dosExecList.list )
    {
        const std::string dirname = GetDirName(elem);
        std::string name = elem.substr(dirname.size()+1);
        mDosExecStrVec.push_back(elem);
        mpDosExecSelList->addText(name);
    }

    mpDosExecSelList->setConfirmButtonEvent(new GMDosExecSelected());
    mpDosExecSelList->setBackButtonEvent(new GMQuit());

    mpDosExecDialog->addControl(new CGUIText("Choose your executable:"), GsRect<float>(0.0f, 0.0f, 1.0f, 0.05f));
    mpDosExecDialog->addControl(mpDosExecSelList, GsRect<float>(0.01f, 0.07f, 0.49f, 0.87f));


    mpDosExecDialog->addControl(new GsButton( "Start >", new GMDosExecSelected() ), GsRect<float>(0.65f, 0.865f, 0.3f, 0.07f) );
}
Example #23
0
void OpenFileDialog::listFiles()
{
    mDirModel->setRootPath(QDir::currentPath());
    mDirModel->setFilter(QDir::NoDot | QDir::AllEntries);
    ui->treeView->setModel(mDirModel);
    ui->treeView->setRootIndex(mDirModel->index(getDirectory()));

//    ui->treeView->setSortingEnabled(true);
//    mProxyModel->setSourceModel(mDirModel);
//    ui->treeView->setModel(mProxyModel);
//    ui->treeView->setRootIndex(mProxyModel->mapFromSource(mDirModel->index(getDirectory())));

//    mProxyModel->sort(0, Qt::AscendingOrder);
}
Example #24
0
bool VNoteFile::deleteAttachments(const QVector<QString> &p_names,
                                  bool p_omitMissing)
{
    if (p_names.isEmpty()) {
        return true;
    }

    QDir dir(fetchAttachmentFolderPath());
    bool ret = true;
    for (int i = 0; i < p_names.size(); ++i) {
        int idx = findAttachment(p_names[i]);
        if (idx == -1) {
            ret = false;
            continue;
        }

        m_attachments.remove(idx);

        QString filePath = dir.filePath(p_names[i]);
        if (p_omitMissing
            && !QFileInfo::exists(filePath)) {
            // The attachment file does not exist. We skip it to avoid error.
            continue;
        }

        if (!VUtils::deleteFile(getNotebook(), filePath, false)) {
            ret = false;
            qWarning() << "fail to delete attachment" << p_names[i]
                       << "for note" << m_name;
        }
    }

    // Delete the attachment folder if m_attachments is empty now.
    if (m_attachments.isEmpty()) {
        dir.cdUp();
        if (!dir.rmdir(m_attachmentFolder)) {
            ret = false;
            qWarning() << "fail to delete attachment folder" << m_attachmentFolder
                       << "for note" << m_name;
        }
    }

    if (!getDirectory()->updateFileConfig(this)) {
        ret = false;
        qWarning() << "fail to update config of file" << m_name
                   << "in directory" << fetchBasePath();
    }

    return ret;
}
Example #25
0
const wxString mmex::getPathUser(EUserFile f)
{
    static const wxString files[USER_FILES_MAX] = {
      getSettingsFileName(),
      getDirectory()
    };

    wxASSERT(f >= 0 && f < USER_FILES_MAX);

    wxFileName fname = GetUserDir(true);
    fname.SetFullName(files[f]);

    return fname.GetFullPath();
}
Example #26
0
string
joinPaths(string const &path, string const &file) {
  string tmppath(path);
  if ((tmppath.length() > 0) && (tmppath[tmppath.length() - 1] == '/')) {
    tmppath = tmppath.substr(0, tmppath.length() - 1);
  }
  string tmpfile(file);
  while ((tmpfile.length() >= 3) && (tmpfile.substr(0, 3) == "../")) {
    tmppath = getDirectory(tmppath);
    tmpfile = tmpfile.substr(3);
  }
  
  return tmppath + "/" + tmpfile;
}
Example #27
0
/*!
 * Show a dialog for the user to select the directory into which the
 * data files will be saved.
 * \return whether the user selected a valid directory.
 */
bool SimpleRawDataSink::getCaptureInfo()
{
    QString dir = getDirectory();
    if (dir.isEmpty())
        return false;

    dataDir.setPath(dir);
    dataDir.makeAbsolute();
    if (dataDir.exists()) {
        QSettings().setValue(dataDirKey, dataDir.absolutePath());
        return true;
    }

    return false;
}
Example #28
0
const ShareManager::Directory::File* ShareManager::getFile(const string& realPath, Directory::Ptr d) noexcept {
	if(!d) {
		d = getDirectory(realPath);
		if(!d) {
			return nullptr;
		}
	}

	auto i = d->findFile(Util::getFileName(realPath));
	if(i == d->files.end()) {
		/* should never happen, but let's fail gracefully (maybe a synchro issue with a dir being
		removed during hashing...)... */
		dcdebug("ShareManager::getFile: the file <%s> could not be found, strange!\n", realPath.c_str());
		return nullptr;
	}

	if( (!i->realPath.empty()) && (i->realPath == realPath)) {
		/* lucky! the base file already had a real path set (should never happen - it's only for
		dupes). */
		dcdebug("ShareManager::getFile: wtf, a non-renamed file has realPath set: <%s>\n", realPath.c_str());
		return &(*i);
	}

	/* see if the files sorted right before this one have a real path we are looking for. this is
	the most common case for dupes: "x (1).ext" is sorted before "x.ext". */
	auto real = i;
	--real;
	while((real != d->files.end()) && (!real->realPath.empty())) {
		if(real->realPath == realPath) {
			return &(*real);
		}
		--real;
	}

	/* couldn't find it before the base file? maybe it's sorted after; could happen with files with
	no ext: "x (1)" is sorted after "x". */
	real = i;
	++real;
	while((real != d->files.end()) && (!real->realPath.empty())) {
		if(real->realPath == realPath) {
			return &(*real);
		}
		++real;
	}

	/* most common case: no duplicate; just return the base file. */
	return &(*i);
}
CSafeStream::CSafeStream(LPCTSTR lpszPath, bool bMakeBackup)
:	m_sPath(lpszPath),
	m_bNeedToClose(FALSE),
	m_bMakeBackup(bMakeBackup),
	m_pOut(NULL)
{
	//m_sTempPath.Format("%s-tmp.%s",getFileName(lpszPath), getFileExt(lpszPath));

	UINT iUniqueNum = GetTempFileName(
		getDirectory(m_sPath), 	// directory name for temporary file  ("." = use current dir)
		getFileName(m_sPath).Left(3), // address of filename prefix
		NULL , // make up a number
		m_sTempPath.GetBuffer(MAX_PATH+1)
		);
	m_sTempPath.ReleaseBuffer();
}
Example #30
0
bool IHttpDirectory::process(shared_ptr<HttpSession> session, const HttpPath &path)
{
	if(isActive() == false)
		return false;

	if(isAccessible(session) == false)
		return false;

	if(handle(session, path))
		return true;

	shared_ptr<IHttpDirectory> directory = getDirectory(path.getDirectory());
	if(directory != nullptr && directory->process(session, path.getTarget()))
		return true;

	return false;
}