示例#1
0
文件: usrFsLib.c 项目: phoboz/vmx
STATUS ls(
    char *dirname,
    BOOL  doLong
    )
{
    return dirList(stdout, dirname, doLong, FALSE);
}
int main( int, char**) {
    try {
        std::string driverCSVDir = "drivers";
        std::string driverCompressedDir = "drivers_compressed_data";
        
        DirectoryListing dirList( driverCSVDir );
        std::list<std::string> driverDirs = dirList.directoryContent();
        
        ProcessLogger log( driverDirs.size() );
        
        for ( std::list<std::string>::const_iterator iDriverDir = driverDirs.begin();
             iDriverDir != driverDirs.end(); ++iDriverDir ) {
            
            int driverId = 0;
            std::istringstream isId( *iDriverDir );
            isId >> driverId;
            
            DriverTripDataIO dataIO( driverId );
            dataIO.readTripDataFromCSVFiles( driverCSVDir ).writeDataToBinaryFile( driverCompressedDir );
            
            log.taskEnded();
        }
        
    }
    catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
        return -1;
    }
    catch (...) {
        std::cerr << "Unknown error" << std::endl;
        return -1;
    }
    return 0;
}
示例#3
0
bool ServerSocket::RecvData(char *buffer, int size)
{
	int i = recv(mySocket, buffer, size, 0);
	buffer[i] = '\0';

	cout << "<<< " << buffer;

	// Convert to lower-case to compare
	for (int j = 0; j < i; j++)
		buffer[j] = tolower(buffer[j]);

	// Process commands
	if (strncmp(buffer, "list", 4) == 0)
	{
		// Client wants a dir list!
		// We'll just send them the current one
		dirList("./");
	}
	else if (strncmp(buffer, "send", 4) == 0)
	{
		// Client wants a file!
		sendFile(buffer);
	}
	else if (strncmp(buffer, "quit", 4) == 0)
	{
		// Client wants us to go away!
		done = true;
	}
	return true;
}
示例#4
0
int GameList::readGameList()
{
	// Clear list
	fullGameList.clear();
	//! Clear memory of the vector completely
	std::vector<discHeader>().swap(fullGameList);

	int cnt = 0;

	std::string gamePath = CSettings::getValueAsString(CSettings::GamePath);

	DirList dirList(gamePath, 0, DirList::Dirs);
	dirList.SortList();

    for(int i = 0; i < dirList.GetFilecount(); i++)
    {
        const char *filename = dirList.GetFilename(i);
        char id6[7];
        int len = strlen(filename);

        discHeader newHeader;

        if (len <= 8 ||
                ((filename[len - 8] != '[' && filename[len - 6] != '[') || filename[len - 1] != ']'))
        {
            if (GetId6FromMeta((gamePath + "/" + filename + META_PATH).c_str(), id6) == 0)
            {
                newHeader.id = id6;
                newHeader.name = filename;
                newHeader.gamepath = gamePath + "/" + filename;

                fullGameList.push_back(newHeader);
            }
            continue;
        }

        bool id4Title = (filename[len - 8] != '[');

        std::string gamePathName = filename;
        if(id4Title)
        {
            newHeader.id = gamePathName.substr(gamePathName.size() - 5, 4);
            newHeader.name = gamePathName.substr(0, gamePathName.size() - 6);
        }
        else
        {
            newHeader.id = gamePathName.substr(gamePathName.size() - 7, 6);
            newHeader.name = gamePathName.substr(0, gamePathName.size() - 8);
        }
        newHeader.gamepath = gamePath + "/" + filename;

        while(newHeader.name.size() > 0 && newHeader.name[newHeader.name.size()-1] == ' ')
            newHeader.name.resize(newHeader.name.size()-1);

        fullGameList.push_back(newHeader);
    }

	return cnt;
}
示例#5
0
bool LocalRepository::isManaged(const QFileInfo &file) const
{
    QString filename = Utils::cleanPath(file.absoluteFilePath(), false);
    if(filename.startsWith(directory()))
    {
        filename = filename.remove(0, directory().size());
        if(file.isDir())
            return dirList().contains(filename);
        else
            return StatusFileName == filename || fileList().contains(filename);
    }

    return false;
}
示例#6
0
void filestuff::removeDir(QString dirName)
{
    QDir dir(dirName);
    QStringList dirList(dir.entryList(QDir::Files));
    for (int i = 0; i < dirList.count(); i++){
        QString fName(dirName + "/" + dirList[i]);
        QFile::remove(fName);
    }
    dirList.clear();
    dirList = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
    for (int i = 0; i < dirList.count(); i++){
        QString fName(dirName + "/" + dirList[i]);
        removeDir(fName);
    }
    dir.rmdir(dirName);
}
示例#7
0
文件: fs.cpp 项目: zywo/qBittorrent
/**
 * This function will first remove system cache files, e.g. `Thumbs.db`,
 * `.DS_Store`. Then will try to remove the whole tree if the tree consist
 * only of folders
 */
bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
{
    if (path.isEmpty() || !QDir(path).exists())
        return true;

    static const QStringList deleteFilesList = {
        // Windows
        "Thumbs.db",
        "desktop.ini",
        // Linux
        ".directory",
        // Mac OS
        ".DS_Store"
    };

    // travel from the deepest folder and remove anything unwanted on the way out.
    QStringList dirList(path + "/");  // get all sub directories paths
    QDirIterator iter(path, (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories);
    while (iter.hasNext())
        dirList << iter.next() + "/";
    // sort descending by directory depth
    std::sort(dirList.begin(), dirList.end()
              , [](const QString &l, const QString &r) { return l.count("/") > r.count("/"); });

    for (const QString &p : qAsConst(dirList)) {
        // remove unwanted files
        for (const QString &f : deleteFilesList) {
            forceRemove(p + f);
        }

        // remove temp files on linux (file ends with '~'), e.g. `filename~`
        QDir dir(p);
        QStringList tmpFileList = dir.entryList(QDir::Files);
        for (const QString &f : tmpFileList) {
            if (f.endsWith("~"))
                forceRemove(p + f);
        }

        // remove directory if empty
        dir.rmdir(p);
    }

    return QDir(path).exists();
}
 bool copyDirectory(const String& source, const String& dest)
 {
     try
     {
         HashSet<String> dirList(HashSet<String>::newInstance());
         if (!listDirectory(source, true, dirList))
             return false;
         
         createDirectory(dest);
         
         for (HashSet<String>::iterator file = dirList.begin(); file != dirList.end(); ++file)
             copyFile(joinPath(source, *file), joinPath(dest, *file));
     
         return true;
     }
     catch (...)
     {
         return false;
     }
 }
示例#9
0
文件: usrFsLib.c 项目: phoboz/vmx
STATUS llr(
    char *dirname
    )
{
    return dirList(stdout, dirname, TRUE, TRUE);
}
示例#10
0
文件: usrFsLib.c 项目: phoboz/vmx
STATUS lsr(
    char *dirname
    )
{
    return dirList(stdout, dirname, FALSE, TRUE);
}
示例#11
0
文件: usrFsLib.c 项目: phoboz/vmx
STATUS ll(
    char *dirname
    )
{
    return dirList(stdout, dirname, TRUE, FALSE);
}
示例#12
0
文件: usrFsLib.c 项目: phoboz/vmx
STATUS dirList(
    FILE *fp,
    char *dirname,
    BOOL  doLong,
    BOOL  doTree
    )
{
    struct dirent *pDirEnt;
    struct stat    fileStat;
    char           filename[PATH_MAX];
    char           dirName[PATH_MAX];
    DIR           *pDir   = NULL;
    char          *pPat   = NULL;
    STATUS         status = OK;

    if (dirname == NULL)
    {
        strcpy(dirName, ".");
    }
    else
    {
        strcpy(dirName, dirname);
    }

    /* Open directory */
    pDir = opendir(dirName);
    if (pDir == NULL)
    {
        pPat = strrchr(dirName, '/');
        if ((pPat != NULL) && (pPat != dirName) &&
            (nameHasWildcard(pPat) == TRUE))
        {
            *pPat++ = EOS;
            pDir = opendir(dirName);
        }
        else if (nameHasWildcard(dirName) == TRUE)
        {
            pPat = dirName;
            strcpy(dirName, ".");
            pDir = opendir(dirName);
        }
    }

    if (pDir == NULL)
    {
        goto dirListError;
    }

    if (strcmp(dirName, ".") == 0)
    {
        strcpy(dirName, "");
    }
    else if (doLong == TRUE)
    {
        fprintf(fp, "\nListing Directory %s:\n", dirName);
    }

    do
    {
        errnoSet(OK);
        pDirEnt = readdir(pDir);

        if (pDirEnt != NULL)
        {
            if ((pPat != NULL) &&
                (dirListPattern(pPat, pDirEnt->d_name) == FALSE))
            {
                continue;
            }

            if (doLong == TRUE)
            {
                usrPathCat(dirName, pDirEnt->d_name, filename);
                if (stat(filename, &fileStat) != OK)
                {
                    memset(&fileStat, 0, sizeof(struct stat));
                }
            }

            if (dirListEntry(
                    fp,
                    pDirEnt->d_name,
                    &fileStat,
                    dirName,
                    doLong
                    ) == ERROR)
            {
                status = ERROR;
            }
        }
        else
        {
            if (errnoGet() != OK)
            {
                fprintf(
                    stderr,
                    "error reading dir %s, errno: %x\n",
                    dirName,
                    errnoGet()
                    );
                status = ERROR;
            }
        }
    } while (pDirEnt != NULL);

    status |= closedir(pDir);

    if (doTree == TRUE)
    {
        /* Process subdirectories */
        if (dirName[0] == EOS)
        {
            pDir = opendir(".");
        }
        else
        {
            pDir = opendir(dirName);
        }

        if (pDir == NULL)
        {
            goto dirListError;
        }

        do
        {
            errnoSet(OK);

            pDirEnt = readdir(pDir);
            if (pDirEnt != NULL)
            {
                if ((pPat != NULL) &&
                    (dirListPattern(pPat, pDirEnt->d_name) == FALSE))
                {
                    continue;
                }

                usrPathCat(dirName, pDirEnt->d_name, filename);

                if (stat(filename, &fileStat) != OK)
                {
                    memset(&fileStat, 0, sizeof(struct stat));
                }

                /* Ignore dot and dot-dot directories */
                if (S_ISDIR(fileStat.st_mode) &&
                    strcmp(pDirEnt->d_name, ".") &&
                    strcmp(pDirEnt->d_name, ".."))
                {
                    status = dirList(fp, filename, doLong, doTree);
                }
            }
            else
            {
                if (errnoGet() != OK)
                {
                    fprintf(
                        fp,
                        "error reading dir %s, errno: %x\n",
                        dirName,
                        errnoGet()
                        );
                    status = ERROR;
                }
            }
        } while (pDirEnt != NULL);

        /* Close directory */
        status |= closedir(pDir);
    }

    return status;

dirListError:

    fprintf(fp, "Can't open \"%s\".\n", dirName);

    return ERROR;
}
示例#13
0
                        jid = nn.firstChild().toText().data();
                    if (nn.toElement().tagName() == "host")
                        host = nn.firstChild().toText().data();
                    nn = nn.nextSibling();
                }
                createXML(jid, decodePassword(hash, jid), host);
                yyy = yyy.nextSibling();
            }
        }
        node = node.nextSibling();
    }
}


void psi::findConfig() {
    foreach(QString profile, dirList(homeDir() + ".psi/profiles")) {
        QFile file(homeDir() + ".psi/profiles/" + profile + "/config.xml");
        if (file.open(QIODevice::ReadOnly)){
            decoding(file);
            file.close();
        }
        file.setFileName(homeDir() + ".psi/profiles/" + profile + "/accounts.xml");
        if (file.open(QIODevice::ReadOnly))
            decoding(file);
    }
}

psi* psi::instance() {
    if (!instance_)
        instance_ = new psi();
    return instance_;