string CElement::getPath() const
{
    // Take out root element from the path
    if (_pParent && _pParent->_pParent) {

        return _pParent->getPath() + "/" + getPathName();
    }
    return "/" + getPathName();
}
 bool Directory::cp(File* obje)
 {    
     v.push_back(obje);
     obje->setPathName(getPathName()+ obje->getPathName()); 
     Directory* d = dynamic_cast<Directory*>(obje);
     if(d != NULL){            
         for(int i=0; i < d->v.size(); ++i){
             d->v[i]->setPathName(getPathName()+ d->v[i]->getPathName());
         }
     }
     return true;
 }
示例#3
0
void mv(char *pathSource, char *destinyPath)
{
	char *copyName =  (char*)mallocFS(mystrlen(getData(pathSource)));
	copyName = getData(getPathName(getData(pathSource), 2));
	cpy(pathSource, destinyPath, copyName);
	rm(pathSource);
}
示例#4
0
void DirectoryIterator::next() {
  if (!m_dir.same(false)) {
    m_dirEntry = f_readdir(m_dir);
    m_index++;
    m_fileName = getPathName();
  }
}
示例#5
0
bool CExtUpdate::applySettings(std::string & filename, int mode)
{
	if(!FileHelpers)
		FileHelpers = new CFileHelpers();

	if (mode == MODE_EXPERT)
		imgFilename = (std::string)g_settings.update_dir + "/" + FILESYSTEM_ENCODING_TO_UTF8_STRING(filename);
	else
		imgFilename = FILESYSTEM_ENCODING_TO_UTF8_STRING(filename);

	DBG_TIMER_START()

	std::string oldFilename = imgFilename;
	std::string hostName    = netGetHostname();
	std::string orgPath     = getPathName(imgFilename);
	std::string orgName     = getBaseName(imgFilename);
	orgName                 = getFileName(orgName);
	std::string orgExt      = "." + getFileExt(imgFilename);
	std::string timeStr     = getNowTimeStr("_%Y%m%d_%H%M");
	std::string settingsStr = "+settings";

	if (orgPath != "/tmp") {
		if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_HOSTNAME_TIME)
			imgFilename = orgPath + "/" + hostName + timeStr + settingsStr + orgExt;
		else if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_ORGNAME_TIME)
			imgFilename = orgPath + "/" + orgName + timeStr  + settingsStr + orgExt;
		else
			imgFilename = orgPath + "/" + orgName  + settingsStr + orgExt;
		FileHelpers->copyFile(oldFilename.c_str(), imgFilename.c_str(), 0644);
	}
	else
		imgFilename = oldFilename;
	filename = imgFilename;

	bool ret = applySettings();
	DBG_TIMER_STOP("Image editing")
	if (!ret) {
		if ((mtdRamError != "") && (!flashErrorFlag))
			DisplayErrorMessage(mtdRamError.c_str());

		// error, delete image file
		unlink(imgFilename.c_str());
	}
	else {
		if (mode == MODE_EXPERT) {
			if ((mtdNumber < 3) || (mtdNumber > 4)) {
				const char *err = "invalid mtdNumber\n";
				printf(err);
				DisplayErrorMessage(err);
				WRITE_UPDATE_LOG("ERROR: %s", err);
				return false;
			}
		}
		WRITE_UPDATE_LOG("\n");
		WRITE_UPDATE_LOG("##### Settings taken. #####\n");
		if (mode == MODE_EXPERT)
			CFlashExpert::getInstance()->writemtd(filename, mtdNumber);
	}
	return ret;
}
示例#6
0
文件: file.cpp 项目: panone/litewiz
bool File::operator==
(
    File const & file
)
    const
{
    return getPathName() == file.getPathName();
}
示例#7
0
void DirectoryIterator::rewind() {
  if (!m_dir.same(false)) {
    f_rewinddir(m_dir);
    m_dirEntry = f_readdir(m_dir);
    m_index = 0;
    m_fileName = getPathName();
  }
}
示例#8
0
DirectoryIterator::DirectoryIterator(CStrRef path) :
  m_path(path), m_index(0) {
  Variant dir = f_opendir(m_path);
  if (!dir.same(false)) {
    m_dir = dir;
    m_dirEntry = f_readdir(m_dir);
    m_fileName = getPathName();
  }
}
示例#9
0
 bool File::remove()
 {
   CharString longpath = "\\\\?\\" + getPathName();
   
   if (isDirectory())
     return (RemoveDirectory( longpath.buffer() ) == TRUE);
   else
     return (DeleteFile( longpath.buffer() ) == TRUE);
 }
示例#10
0
void rm(char * path)
{
	int y, z, dirStart, dirSize,blockEntryToRemove,blockToRemove;
	directoryBlock erasedBlock;
	char *destinyBlock,*dirRm;
	destinyBlock = getPathName(path, 1);
	dirRm  = getPathName(path, 2); 
	blockToRemove = findFileBlockInPath(destinyBlock);
	readsector(blockToRemove, (char*)&erasedBlock);
	blockEntryToRemove = findFileInDirectory(erasedBlock, dirRm);
	if (blockEntryToRemove == -1)
	{
		printstring("Directory does not exist\n");
		return;
	}
	if (erasedBlock.entries[blockEntryToRemove].fileType == IS_FILE)
	{
		dirStart = erasedBlock.entries[blockEntryToRemove].fileBlockStart;
		dirSize = erasedBlock.entries[blockEntryToRemove].fileBlockSize;
		z = dirStart;
		while (z < dirSize)
		{
			setFreeBlock(z);
			z++;
		}
	}
	else if (erasedBlock.entries[blockEntryToRemove].fileType == IS_DIRECTORY)
	{
		rmDir(erasedBlock.entries[blockEntryToRemove].fileBlockStart);
		setFreeBlock(erasedBlock.entries[blockEntryToRemove].fileBlockStart);
	}
	y = 0;
	while (y < sizeof(erasedBlock.entries[blockEntryToRemove].fileName))
	{
		erasedBlock.entries[blockEntryToRemove].fileName[y] = '\0';
	}
	erasedBlock.entries[blockEntryToRemove].fileBlockSize = 0;
	erasedBlock.entries[blockEntryToRemove].fileBlockStart = 0;
	writesector(blockToRemove, (char*)&erasedBlock);
}
示例#11
0
void rn(char *dirPath, char *newDirName)
{
	directoryBlock dir;
	int dirBlockPos,entryNumber, pathLenght,y;
	char *path,*previousDirName,*tempDirName;
	pathLenght = mystrlen(getData(dirPath)); 
	 path= (char*)mallocFS(pathLenght);
	path = getPathName(getData(dirPath), 1);
	previousDirName = getPathName(getData(dirPath), 2);
	dirBlockPos = findFileBlockInPath(path);
	if (dirBlockPos == -1)
	{
		printstring("Directory does not exists");
		return;
	}
	readsector(dirBlockPos, &dir);
	entryNumber = findFileInDirectory(dir, previousDirName);
	if (entryNumber == -1)
	{
		printstring("Directory does not exists");
		return;
	}
	tempDirName = (char*)mallocFS(mystrlen(getData(dirPath)));
	tempDirName = getData(dir.entries[entryNumber].fileName);
	if (strCmp(tempDirName, previousDirName) == 1)
	{
		y = 0;
		while( y < mystrlen(dir.entries[entryNumber].fileName))
		{
			dir.entries[entryNumber].fileName[y] = ' ';
			y++;
		}
		strcpy(dir.entries[entryNumber].fileName, getData(newDirName));
		dir.entries[entryNumber].fileType = IS_DIRECTORY;
		writesector(dirBlockPos, (char*)&dir);
	}
}
示例#12
0
  bool File::rename (const String &name)
  {
    close();

    File newfile( name );
    CharString oldlongpath = "\\\\?\\" + getPathName();
    CharString newlongpath = "\\\\?\\" + newfile.getPathName();
    if (MoveFile( oldlongpath.buffer(), newlongpath.buffer() ) == TRUE)
    {
      this->path = newfile.path;
      this->name = newfile.name;
      return true;
    }
    else return false;
  }
示例#13
0
        void MapData::load()
        {
            m_Layer.clear();
            auto pMap = m_DBMgr.getMapDatabase().getPrototype(m_MapID);
            if (!pMap)
                return;

            m_Layer.resize(pMap->getSize(), pMap->getLayerCount(MAP::LayerType::LAYER_FOREGROUND), pMap->getLayerCount(MAP::LayerType::LAYER_BACKGROUND));

            try
            {
                INPUT::MapBinaryReader reader;
                reader.readFile(Config::get()->getProjectDirectory() + "/maps/" + pMap->getPathName(), *this);
            }
            catch (const std::ios::failure&) {}
        }
示例#14
0
void cpy(char *pathSource, char *destinyPath, char *copyName)
{
	directoryBlock source, destiny;
	int sourceBlock, destinyBlock, newBlockDir, z;
	char *sourcePathName,*dirName;
	sourceBlock = findFileBlockInPath(getData(pathSource));
	destinyBlock = findFileBlockInPath(getData(destinyPath));
	if (sourceBlock == 0 || destinyBlock == 0)
	{
		return;
	}
	sourcePathName = getPathName(getData(pathSource), 2);
	readsector(sourceBlock, (char *)&source);
	readsector(destinyBlock, (char *)&destiny);
	{
		newBlockDir = mkdir(getData(destinyPath), getData(copyName));
		if (strCmp(getData(getData(destinyPath)), "/") != 1)
		{
			dirName = mistrcat(getData(destinyPath), "/");
			dirName = mistrcat(getData(dirName), getData(copyName));
			dirName = getData(dirName);
		}
		else	
			dirName = getData(getData(destinyPath));
		z = 0;
		while(z < DIRECTORYENTRYCOUNT)
		{
			if (destiny.entries[z].fileBlockStart == 0)
			{
				destiny.entries[z].fileName[0] = '\0';
				strcpy(getData(copyName), destiny.entries[z].fileName);
				destiny.entries[z].fileType = IS_DIRECTORY;
				destiny.entries[z].fileBlockStart = newBlockDir;
				destiny.entries[z].fileBlockSize = 1;
				break;
			}
			z++;
		}
		writesector(destinyBlock, (char *)&destiny);
		cpyDir(sourceBlock, newBlockDir, dirName);
	}
}
示例#15
0
  bool File::open (FileAccess::Enum access, FileCondition::Enum condition)
  {
    DWORD winAccess = 0;
    DWORD winCondition = 0;

    //Setup access permissions
    switch (access) {
    case FileAccess::Read:
      winAccess = GENERIC_READ;
      break;
    case FileAccess::Write:    
      winAccess = GENERIC_WRITE;
      break;
    case FileAccess::ReadWrite:
      winAccess = GENERIC_READ | GENERIC_WRITE;
      break;
    }

    //Setup creation disposition
    if (condition & FileCondition::MustNotExist) {
      winCondition = CREATE_NEW;
    }
    else if (condition & FileCondition::MustExist) {
      if (condition & FileCondition::Truncate)
        winCondition = TRUNCATE_EXISTING;
      else winCondition = OPEN_EXISTING;
    }
    else {
      if (condition & FileCondition::Truncate)
        winCondition = CREATE_ALWAYS;
      else winCondition = OPEN_ALWAYS;
    }

    //Create the file
    CharString longpath = "\\\\?\\" + getPathName();
    handle = CreateFile( longpath.buffer(), winAccess, 0, NULL, winCondition, 0, NULL );
    return (handle != INVALID_HANDLE_VALUE);
  }
示例#16
0
/*
 * Scans the specified directory and its subdirectories to find a
 * zoneinfo file which has the same content as /etc/localtime on Linux
 * or /usr/share/lib/zoneinfo/localtime on Solaris given in 'buf'.
 * If file is symbolic link, then the contents it points to are in buf.
 * Returns a zone ID if found, otherwise, NULL is returned.
 */
static char *
findZoneinfoFile(char *buf, size_t size, const char *dir)
{
    DIR *dirp = NULL;
    struct stat statbuf;
    struct dirent64 *dp = NULL;
    struct dirent64 *entry = NULL;
    char *pathname = NULL;
    int fd = -1;
    char *dbuf = NULL;
    char *tz = NULL;

    dirp = opendir(dir);
    if (dirp == NULL) {
        return NULL;
    }

    entry = (struct dirent64 *) malloc((size_t) pathconf(dir, _PC_NAME_MAX));
    if (entry == NULL) {
        (void) closedir(dirp);
        return NULL;
    }

    while (readdir64_r(dirp, entry, &dp) == 0 && dp != NULL) {
        /*
         * Skip '.' and '..' (and possibly other .* files)
         */
        if (dp->d_name[0] == '.') {
            continue;
        }

        /*
         * Skip "ROC", "posixrules", and "localtime".
         */
        if ((strcmp(dp->d_name, "ROC") == 0)
            || (strcmp(dp->d_name, "posixrules") == 0)
#if defined(__solaris__)
            /*
             * Skip the "src" and "tab" directories on Solaris.
             */
            || (strcmp(dp->d_name, "src") == 0)
            || (strcmp(dp->d_name, "tab") == 0)
#endif
            || (strcmp(dp->d_name, "localtime") == 0)) {
            continue;
        }

        pathname = getPathName(dir, dp->d_name);
        if (pathname == NULL) {
            break;
        }
        if (stat(pathname, &statbuf) == -1) {
            break;
        }

        if (S_ISDIR(statbuf.st_mode)) {
            tz = findZoneinfoFile(buf, size, pathname);
            if (tz != NULL) {
                break;
            }
        } else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
            dbuf = (char *) malloc(size);
            if (dbuf == NULL) {
                break;
            }
            if ((fd = open(pathname, O_RDONLY)) == -1) {
                break;
            }
            if (read(fd, dbuf, size) != (ssize_t) size) {
                break;
            }
            if (memcmp(buf, dbuf, size) == 0) {
                tz = getZoneName(pathname);
                if (tz != NULL) {
                    tz = strdup(tz);
                }
                break;
            }
            free((void *) dbuf);
            dbuf = NULL;
            (void) close(fd);
            fd = -1;
        }
        free((void *) pathname);
        pathname = NULL;
    }

    if (entry != NULL) {
        free((void *) entry);
    }
    if (dirp != NULL) {
        (void) closedir(dirp);
    }
    if (pathname != NULL) {
        free((void *) pathname);
    }
    if (fd != -1) {
        (void) close(fd);
    }
    if (dbuf != NULL) {
        free((void *) dbuf);
    }
    return tz;
}
示例#17
0
/*
 * Scans the specified directory and its subdirectories to find a
 * zoneinfo file which has the same content as /etc/localtime on Linux
 * or /usr/share/lib/zoneinfo/localtime on Solaris given in 'buf'.
 * If file is symbolic link, then the contents it points to are in buf.
 * Returns a zone ID if found, otherwise, NULL is returned.
 */
static char *
findZoneinfoFile(char *buf, size_t size, const char *dir)
{
    DIR *dirp = NULL;
    struct stat statbuf;
    struct dirent *dp = NULL;
    struct dirent *entry = NULL;
    char *pathname = NULL;
    int fd = -1;
    char *dbuf = NULL;
    char *tz = NULL;

    dirp = opendir(dir);
    if (dirp == NULL) {
        return NULL;
    }

    entry = (struct dirent *) malloc((size_t) pathconf(dir, _PC_NAME_MAX));
    if (entry == NULL) {
        (void) closedir(dirp);
        return NULL;
    }

#if defined(__linux__) || defined(MACOSX) || (defined(__solaris__) \
    && (defined(_POSIX_PTHREAD_SEMANTICS) || defined(_LP64)))
    while (readdir_r(dirp, entry, &dp) == 0 && dp != NULL) {
#else
    while ((dp = readdir_r(dirp, entry)) != NULL) {
#endif

        /*
         * Skip '.' and '..' (and possibly other .* files)
         */
        if (dp->d_name[0] == '.') {
            continue;
        }

        /*
         * Skip "ROC", "posixrules", and "localtime".
         */
        if ((strcmp(dp->d_name, "ROC") == 0)
            || (strcmp(dp->d_name, "posixrules") == 0)
#ifdef __solaris__
            /*
             * Skip the "src" and "tab" directories on Solaris.
             */
            || (strcmp(dp->d_name, "src") == 0)
            || (strcmp(dp->d_name, "tab") == 0)
#endif
            || (strcmp(dp->d_name, "localtime") == 0)) {
            continue;
        }

        pathname = getPathName(dir, dp->d_name);
        if (pathname == NULL) {
            break;
        }
        if (stat(pathname, &statbuf) == -1) {
            break;
        }

        if (S_ISDIR(statbuf.st_mode)) {
            tz = findZoneinfoFile(buf, size, pathname);
            if (tz != NULL) {
                break;
            }
        } else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
            dbuf = (char *) malloc(size);
            if (dbuf == NULL) {
                break;
            }
            if ((fd = open(pathname, O_RDONLY)) == -1) {
                fd = 0;
                break;
            }
            if (read(fd, dbuf, size) != (ssize_t) size) {
                break;
            }
            if (memcmp(buf, dbuf, size) == 0) {
                tz = getZoneName(pathname);
                if (tz != NULL) {
                    tz = strdup(tz);
                }
                break;
            }
            free((void *) dbuf);
            dbuf = NULL;
            (void) close(fd);
            fd = 0;
        }
        free((void *) pathname);
        pathname = NULL;
    }

    if (entry != NULL) {
        free((void *) entry);
    }
    if (dirp != NULL) {
        (void) closedir(dirp);
    }
    if (pathname != NULL) {
        free((void *) pathname);
    }
    if (fd != 0) {
        (void) close(fd);
    }
    if (dbuf != NULL) {
        free((void *) dbuf);
    }
    return tz;
}

#if defined(__linux__) || defined(MACOSX)

/*
 * Performs Linux specific mapping and returns a zone ID
 * if found. Otherwise, NULL is returned.
 */
static char *
getPlatformTimeZoneID()
{
    struct stat statbuf;
    char *tz = NULL;
    FILE *fp;
    int fd;
    char *buf;
    size_t size;

#ifdef __linux__
    /*
     * Try reading the /etc/timezone file for Debian distros. There's
     * no spec of the file format available. This parsing assumes that
     * there's one line of an Olson tzid followed by a '\n', no
     * leading or trailing spaces, no comments.
     */
    if ((fp = fopen(ETC_TIMEZONE_FILE, "r")) != NULL) {
        char line[256];

        if (fgets(line, sizeof(line), fp) != NULL) {
            char *p = strchr(line, '\n');
            if (p != NULL) {
                *p = '\0';
            }
            if (strlen(line) > 0) {
                tz = strdup(line);
            }
        }
        (void) fclose(fp);
        if (tz != NULL) {
            return tz;
        }
    }
#endif /* __linux__ */

    /*
     * Next, try /etc/localtime to find the zone ID.
     */
    if (lstat(DEFAULT_ZONEINFO_FILE, &statbuf) == -1) {
        return NULL;
    }

    /*
     * If it's a symlink, get the link name and its zone ID part. (The
     * older versions of timeconfig created a symlink as described in
     * the Red Hat man page. It was changed in 1999 to create a copy
     * of a zoneinfo file. It's no longer possible to get the zone ID
     * from /etc/localtime.)
     */
    if (S_ISLNK(statbuf.st_mode)) {
        char linkbuf[PATH_MAX+1];
        int len;

        if ((len = readlink(DEFAULT_ZONEINFO_FILE, linkbuf, sizeof(linkbuf)-1)) == -1) {
            jio_fprintf(stderr, (const char *) "can't get a symlink of %s\n",
                        DEFAULT_ZONEINFO_FILE);
            return NULL;
        }
        linkbuf[len] = '\0';
        tz = getZoneName(linkbuf);
        if (tz != NULL) {
            tz = strdup(tz);
            return tz;
        }
    }

    /*
     * If it's a regular file, we need to find out the same zoneinfo file
     * that has been copied as /etc/localtime.
     * If initial symbolic link resolution failed, we should treat target
     * file as a regular file.
     */
    if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
        return NULL;
    }
    if (fstat(fd, &statbuf) == -1) {
        (void) close(fd);
        return NULL;
    }
    size = (size_t) statbuf.st_size;
    buf = (char *) malloc(size);
    if (buf == NULL) {
        (void) close(fd);
        return NULL;
    }

    if (read(fd, buf, size) != (ssize_t) size) {
        (void) close(fd);
        free((void *) buf);
        return NULL;
    }
    (void) close(fd);

    tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
    free((void *) buf);
    return tz;
}
#else
#ifdef __solaris__
#if !defined(__sparcv9) && !defined(amd64)

/*
 * Those file* functions mimic the UNIX stream io functions. This is
 * because of the limitation of the number of open files on Solaris
 * (32-bit mode only) due to the System V ABI.
 */

#define BUFFER_SIZE     4096

static struct iobuffer {
    int     magic;      /* -1 to distinguish from the real FILE */
    int     fd;         /* file descriptor */
    char    *buffer;    /* pointer to buffer */
    char    *ptr;       /* current read pointer */
    char    *endptr;    /* end pointer */
};

static int
fileclose(FILE *stream)
{
    struct iobuffer *iop = (struct iobuffer *) stream;

    if (iop->magic != -1) {
        return fclose(stream);
    }

    if (iop == NULL) {
        return 0;
    }
    close(iop->fd);
    free((void *)iop->buffer);
    free((void *)iop);
    return 0;
}

static FILE *
fileopen(const char *fname, const char *fmode)
{
    FILE *fp;
    int fd;
    struct iobuffer *iop;

    if ((fp = fopen(fname, fmode)) != NULL) {
        return fp;
    }

    /*
     * It assumes read open.
     */
    if ((fd = open(fname, O_RDONLY)) == -1) {
        return NULL;
    }

    /*
     * Allocate struct iobuffer and its buffer
     */
    iop = malloc(sizeof(struct iobuffer));
    if (iop == NULL) {
        (void) close(fd);
        errno = ENOMEM;
        return NULL;
    }
    iop->magic = -1;
    iop->fd = fd;
    iop->buffer = malloc(BUFFER_SIZE);
    if (iop->buffer == NULL) {
        (void) close(fd);
        free((void *) iop);
        errno = ENOMEM;
        return NULL;
    }
    iop->ptr = iop->buffer;
    iop->endptr = iop->buffer;
    return (FILE *)iop;
}
/*
 * Scans the specified directory and its subdirectories to find a
 * zoneinfo file which has the same content as /etc/localtime given in
 * 'buf'. Returns a zone ID if found, otherwise, NULL is returned.
 */
static char *
findZoneinfoFile(char *buf, size_t size, const char *dir)
{
    DIR *dirp = NULL;
    struct stat statbuf;
    struct dirent *dp;
    char *pathname = NULL;
    int fd = -1;
    char *dbuf = NULL;
    char *tz = NULL;

    dirp = opendir(dir);
    if (dirp == NULL) {
	return NULL;
    }

    while ((dp = readdir(dirp)) != NULL) {
	/*
	 * Skip '.' and '..' (and possibly other .* files)
	 */
	if (dp->d_name[0] == '.') {
	    continue;
	}

	pathname = getPathName(dir, dp->d_name); 
	if (pathname == NULL) {
	    break;
	}
	if (stat(pathname, &statbuf) == -1) {
	    break;
	}

	if (S_ISDIR(statbuf.st_mode)) {
	    tz = findZoneinfoFile(buf, size, pathname);
	    if (tz != NULL) {
		break;
	    }
	} else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
	    dbuf = (char *) malloc(size);
	    if (dbuf == NULL) {
		break;
	    }
	    if ((fd = open(pathname, O_RDONLY)) == -1) {
		fd = 0;
		break;
	    }
	    if (read(fd, dbuf, size) != (ssize_t) size) {
		break;
	    }
	    if (memcmp(buf, dbuf, size) == 0) {
		tz = getZoneName(pathname);
		if (tz != NULL) {
		    tz = strdup(tz);
		}
		break;
	    }
	    free((void *) dbuf);
	    dbuf = NULL;
	    (void) close(fd);
	    fd = 0;
	}
	free((void *) pathname);
	pathname = NULL;
    }

    if (dirp != NULL) {
	(void) closedir(dirp);
    }
    if (pathname != NULL) {
	free((void *) pathname);
    }
    if (fd != 0) {
	(void) close(fd);
    }
    if (dbuf != NULL) {
	free((void *) dbuf);
    }
    return tz;
}
示例#19
0
 bool File::exists() const
 {
   CharString longpath = "\\\\?\\" + getPathName();
   DWORD atts = GetFileAttributes( longpath.buffer() );
   return atts != INVALID_FILE_ATTRIBUTES;
 }
示例#20
0
 bool File::isDirectory() const
 {
   CharString longpath = "\\\\?\\" + getPathName();
   DWORD atts = GetFileAttributes( longpath.buffer() );
   return (atts & FILE_ATTRIBUTE_DIRECTORY) != 0;
 }
示例#21
0
/// Generic object access, given a path from the current context
///
/// Note that the template wrapper method should generally be used to have the correct return type,
void* GNode::getObject(const sofa::core::objectmodel::ClassInfo& class_info, const std::string& path) const
{
    if (path.empty())
    {
        return Node::getObject(class_info, Local);
    }
    else if (path[0] == '/')
    {
        if (parent()) return parent()->getObject(class_info, path);
        else return getObject(class_info,std::string(path,1));
    }
    else if (std::string(path,0,2)==std::string("./"))
    {
        std::string newpath = std::string(path, 2);
        while (!newpath.empty() && path[0] == '/')
            newpath.erase(0);
        return getObject(class_info,newpath);
    }
    else if (std::string(path,0,3)==std::string("../"))
    {
        std::string newpath = std::string(path, 3);
        while (!newpath.empty() && path[0] == '/')
            newpath.erase(0);
        if (parent()) return parent()->getObject(class_info,newpath);
        else return getObject(class_info,newpath);
    }
    else
    {
        std::string::size_type pend = path.find('/');
        if (pend == std::string::npos) pend = path.length();
        std::string name ( path, 0, pend );
        Node* child = getChild(name);
        if (child)
        {
            while (pend < path.length() && path[pend] == '/')
                ++pend;
            return child->getObject(class_info, std::string(path, pend));
        }
        else if (pend < path.length())
        {
            //std::cerr << "ERROR: child node "<<name<<" not found in "<<getPathName()<<std::endl;
            return NULL;
        }
        else
        {
            core::objectmodel::BaseObject* obj = simulation::Node::getObject(name);
            if (obj == NULL)
            {
                //std::cerr << "ERROR: object "<<name<<" not found in "<<getPathName()<<std::endl;
                return NULL;
            }
            else
            {
                void* result = class_info.dynamicCast(obj);
                if (result == NULL)
                {
                    std::cerr << "ERROR: object "<<name<<" in "<<getPathName()<<" does not implement class "<<class_info.name()<<std::endl;
                    return NULL;
                }
                else
                {
                    return result;
                }
            }
        }
    }
}
示例#22
0
/// Generic object access, given a path from the current context
///
/// Note that the template wrapper method should generally be used to have the correct return type,
void* DAGNode::getObject(const sofa::core::objectmodel::ClassInfo& class_info, const std::string& path) const
{
    if (path.empty())
    {
        // local object
        return Node::getObject(class_info, Local);
    }
    else if (path[0] == '/')
    {
        // absolute path; let's start from root
        Parents parents = getParents();
        if (parents.empty()) return getObject(class_info,std::string(path,1));
        else return getRootContext()->getObject(class_info,path);
    }
    else if (std::string(path,0,2)==std::string("./"))
    {
        std::string newpath = std::string(path, 2);
        while (!newpath.empty() && path[0] == '/')
            newpath.erase(0);
        return getObject(class_info,newpath);
    }
    else if (std::string(path,0,3)==std::string("../"))
    {
        // tricky case:
        // let's test EACH parent and return the first object found (if any)
        std::string newpath = std::string(path, 3);
        while (!newpath.empty() && path[0] == '/')
            newpath.erase(0);
        Parents parents = getParents();
        if (!parents.empty())
        {
            for (Parents::iterator it = parents.begin(); it!=parents.end(); it++)
            {
                void* obj = dynamic_cast<Node*>(*it)->getObject(class_info,newpath);
                if (obj) return obj;
            }
            return 0;   // not found in any parent node at all
        }
        else return getObject(class_info,newpath);
    }
    else
    {
        std::string::size_type pend = path.find('/');
        if (pend == std::string::npos) pend = path.length();
        std::string name ( path, 0, pend );
        Node* child = getChild(name);
        if (child)
        {
            while (pend < path.length() && path[pend] == '/')
                ++pend;
            return child->getObject(class_info, std::string(path, pend));
        }
        else if (pend < path.length())
        {
            //std::cerr << "ERROR: child node "<<name<<" not found in "<<getPathName()<<std::endl;
            return NULL;
        }
        else
        {
            core::objectmodel::BaseObject* obj = simulation::Node::getObject(name);
            if (obj == NULL)
            {
                //std::cerr << "ERROR: object "<<name<<" not found in "<<getPathName()<<std::endl;
                return NULL;
            }
            else
            {
                void* result = class_info.dynamicCast(obj);
                if (result == NULL)
                {
                    std::cerr << "ERROR: object "<<name<<" in "<<getPathName()<<" does not implement class "<<class_info.name()<<std::endl;
                    return NULL;
                }
                else
                {
                    return result;
                }
            }
        }
    }
}
 string Directory::path()
 {
     return getPathName();
 }