コード例 #1
0
//! Changes the current Working Directory to the given string.
bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
{
	bool success=false;

	if (FileSystemType != FILESYSTEM_NATIVE)
	{
		WorkingDirectory[FILESYSTEM_VIRTUAL].append(newDirectory);
		flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], "");
		success = 1;
	}
	else
	{
		WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;

#if defined(_IRR_WINDOWS_CE_PLATFORM_)
		success = true;
#elif defined(_MSC_VER)
	#if defined(_IRR_WCHAR_FILESYSTEM)
		success=(_wchdir(newDirectory.c_str()) == 0);
	#else
		success=(_chdir(newDirectory.c_str()) == 0);
	#endif
#else
		success=(chdir(newDirectory.c_str()) == 0);
#endif
	}

	return success;
}
コード例 #2
0
ファイル: oc3_filepath.cpp プロジェクト: nickers/opencaesar3
FilePath FilePath::getAbsolutePath() const
{
#if defined(_WIN32)
  char *p=0;
  char fpath[_MAX_PATH];

  p = _fullpath(fpath, _d->path.c_str(), _MAX_PATH);
  std::string tmp(p);
  StringHelper::replace( tmp, "\\", "/");
  return tmp;
#else
  char* p=0;
  char fpath[4096];
  fpath[0]=0;
  p = realpath( _d->path.c_str(), fpath);
  if (!p)
  {
    // content in fpath is unclear at this point
    if (!fpath[0]) // seems like fpath wasn't altered, use our best guess
    {
      FilePath tmp(_d->path);
      return flattenFilename(tmp);
    }
    else
      return FilePath(fpath);
  }

  if( *(_d->path.rbegin())=='/')
    return FilePath( std::string(p) + "/" );
  else
    return FilePath( std::string(p) );
#endif
}
コード例 #3
0
//! Creates a list of files and directories in the current working directory
IFileList* CFileSystem::createFileList()
{
	FileEntry e2;
	FileEntry e3;

	if ( FileSystemType == FILESYSTEM_NATIVE )
		return new CFileList();

	CFileList* r = new CFileList( "virtual" );
	r->Path = WorkingDirectory [ FILESYSTEM_VIRTUAL ];

	for ( u32 i = 0; i != FileArchives.size(); ++i)
	{
		CFileList* flist[2] = { 0, 0 };

		//! merge relative folder file archives
		if ( FileArchives[i]->getArchiveType() == "mount" )
		{
			EFileSystemType currentType = setFileListSystem ( FILESYSTEM_NATIVE );

			core::string<c16> save ( getWorkingDirectory () );
			core::string<c16> current;

			current = FileArchives[i]->getArchiveName() + WorkingDirectory [ FILESYSTEM_VIRTUAL ];
			flattenFilename ( current );

			if ( changeWorkingDirectoryTo ( current ) )
			{
				flist[0] = new CFileList( "mountpoint" );
				flist[0]->constructNative ();
				changeWorkingDirectoryTo ( save );
			}

			setFileListSystem ( currentType );
		}
		else
		if ( FileArchives[i]->getArchiveType() == "zip" )
		{
			flist[0] = new CFileList( "zip" );
			flist[1] = new CFileList( "zip directory" );

			// add relative navigation
			e2.isDirectory = 1;
			e2.Name = ".";
			e2.FullName = r->Path + e2.Name;
			e2.Size = 0;
			flist[1]->Files.push_back ( e2 );

			e2.Name = "..";
			e2.FullName = r->Path + e2.Name;
			flist[1]->Files.push_back ( e2 );

			for ( u32 g = 0; g < FileArchives[i]->getFileCount(); ++g)
			{
				const SZipFileEntry *e = (SZipFileEntry*) FileArchives[i]->getFileInfo(g);
				s32 test = isInSameDirectory ( r->Path, e->zipFileName );
				if ( test < 0 || test > 1 )
					continue;

				e2.Size = e->header.DataDescriptor.UncompressedSize;
				e2.isDirectory = e2.Size == 0;

				// check missing directories
				if ( !e2.isDirectory && test == 1 )
				{
					e3.Size = 0;
					e3.isDirectory = 1;
					e3.FullName = e->path;
					e3.Name = e->path.subString ( r->Path.size(), e->path.size() - r->Path.size() - 1 );

					if ( flist[1]->Files.binary_search ( e3 ) < 0 )
						flist[1]->Files.push_back ( e3 );
				}
				else
				{
					e2.FullName = e->zipFileName;
					e2.Name = e->simpleFileName;

					if ( !e2.isDirectory )
						core::deletePathFromFilename ( e2.Name );
					flist[0]->Files.push_back ( e2 );
				}
			}
		}

		// add file to virtual directory
		for ( u32 g = 0; g < 2; ++g )
		{
			if ( !flist[g] )
				continue;
			for ( u32 j = 0; j != flist[g]->Files.size(); ++j )
				r->Files.push_back ( flist[g]->Files[j] );

			flist[g]->drop();
		}
	}

	r->Files.sort();
	return r;
}