예제 #1
0
int CFileZillaApi::Rename(CString oldName, CString newName, const CServerPath &path /*=CServerPath()*/, const CServerPath &newPath /*=CServerPath()*/)
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (IsConnected()==FZ_REPLY_NOTCONNECTED)
		return FZ_REPLY_NOTCONNECTED;
	if (IsBusy()==FZ_REPLY_BUSY)
		return FZ_REPLY_BUSY;
	if (oldName==_MPT("") || newName==_MPT(""))
		return FZ_REPLY_INVALIDPARAM;

	CServerPath path2 = path;
	if (path2.IsEmpty())
	{
		m_pMainThread->GetCurrentPath(path2);
		if (path2.IsEmpty())
			return FZ_REPLY_INVALIDPARAM;
	}

	t_command command;
	command.id = FZ_COMMAND_RENAME;
	command.param1 = oldName;
	command.param2 = newName;
	command.path = path2;
	command.newPath = newPath;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
	
	return FZ_REPLY_ERROR;
}
예제 #2
0
BOOL CServerPath::AddSubdir(CString subdir)
{
	subdir.TrimLeft( _T(" ") );
	subdir.TrimRight( _T(" ") );
	if (subdir == _MPT(""))
		return FALSE;

	if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && m_Prefix != _T("."))
		return FALSE;

	m_Segments.push_back(subdir);

	if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && !m_Segments.empty())
	{
		if (m_Segments.back().Right(1) == _T("."))
		{
			m_Segments.back().TrimRight(_MPT('.'));
			m_Prefix = _T(".");
		}
		else
			m_Prefix = _T("");
	}

	m_bEmpty = FALSE;
	
	return TRUE;
}
예제 #3
0
CServerPath::CServerPath(CString path)
{
	m_nServerType = FZ_SERVERTYPE_FTP;
	path.TrimLeft( _T(" ") );
	path.TrimRight( _T(" ") );
	if (path == _MPT(""))
	{
		m_bEmpty = TRUE;
		return;
	}
	else
		m_bEmpty = FALSE;

	int pos1 = path.Find( _T(":[") );
	if (pos1 != -1 && path.Right(1) == _MPT("]") && pos1 != (path.GetLength()-1))
		m_nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
	else if (path.GetLength() >= 3 && _istalpha(path[0]) && path[1] == _MPT(':') && (path[2] == _MPT('\\') || path[2] == _MPT('/')))
		m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
	else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
		m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
	else if (path.GetLength() > 2 && path[0] == _MPT('\'') && path.Right(1) == _T("'") && path.Find(_MPT('/')) == -1 && path.Find(_MPT('\\')) == -1)
		m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
	else if (path.GetLength() >= 2 && path[0] != _MPT('/') && path.Right(1) == _T("."))
		m_nServerType |= FZ_SERVERTYPE_SUB_FTP_UNKNOWN;

	*this = CServerPath(path, m_nServerType);
}
예제 #4
0
int CFileZillaApi::Connect(const t_server &server)
{
	//Check parameters
	if (server.host==_MPT("") || server.port<1 || server.port>65535)
		return FZ_REPLY_INVALIDPARAM;

#ifndef MPEXT_NO_GSS
	BOOL bUseGSS = FALSE;
	if (COptions::GetOptionVal(OPTION_USEGSS))
	{
		USES_CONVERSION;

		CString GssServers = COptions::GetOption(OPTION_GSSSERVERS);
		hostent *fullname = gethostbyname(T2CA(server.host));
		CString host;
		if (fullname)
			host = fullname->h_name;
		else
			host = server.host;
		host.MakeLower();
		int i;
		while ((i=GssServers.Find( _T(";") ))!=-1)
		{
			if ((_MPT(".")+GssServers.Left(i))==host.Right(GssServers.Left(i).GetLength()+1) || GssServers.Left(i)==host)
			{
				bUseGSS = TRUE;
				break;
			}
			GssServers = GssServers.Mid(i+1);
		}
	}
	if (!bUseGSS && server.user == _MPT(""))
		return FZ_REPLY_INVALIDPARAM;
#endif

	if (!(server.nServerType&FZ_SERVERTYPE_HIGHMASK))
		return FZ_REPLY_INVALIDPARAM;

	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (m_pMainThread->IsBusy())
		return FZ_REPLY_BUSY;

	t_command command;
	command.id=FZ_COMMAND_CONNECT;
	command.server=server;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
}
예제 #5
0
void CApiLog::LogMessage(CString SourceFile, int nSourceLine, void *pInstance, int nMessageType, LPCTSTR pMsgFormat, ...) const
{
	ASSERT(nMessageType>=4 && nMessageType<=8);
	ASSERT(m_hTargetWnd || m_pApiLogParent);
	ASSERT(nSourceLine>0);


	int pos=SourceFile.ReverseFind(_MPT('\\'));
	if (pos!=-1)
		SourceFile=SourceFile.Mid(pos+1);

	va_list ap;
    
	va_start(ap, pMsgFormat);
	CString text;
	text.FormatV(pMsgFormat, ap);
	va_end(ap);

#ifdef MPEXT
	if (nMessageType>=FZ_LOG_DEBUG)
		return;
#endif

	CString msg;
	msg.Format(_T("%s(%d): %s   caller=0x%08x"), (LPCTSTR)SourceFile, nSourceLine, (LPCTSTR)text, (int)this);
	
	SendLogMessage(nMessageType, msg);
}
예제 #6
0
int CFileZillaApi::CustomCommand(CString CustomCommand)
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (IsConnected()==FZ_REPLY_NOTCONNECTED)
		return FZ_REPLY_NOTCONNECTED;
	if (IsBusy()==FZ_REPLY_BUSY)
		return FZ_REPLY_BUSY;
	t_server server;
	int res=GetCurrentServer(server);
	if (res!=FZ_REPLY_OK)
		return res;
#ifndef MPEXT_NO_SFTP
	if (server.nServerType&FZ_SERVERTYPE_SUB_FTP_SFTP)
		return FZ_REPLY_NOTSUPPORTED;
#endif
	if (CustomCommand==_MPT(""))
		return FZ_REPLY_INVALIDPARAM;

	t_command command;
	command.id=FZ_COMMAND_CUSTOMCOMMAND;
	command.param1=CustomCommand;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
}
예제 #7
0
const bool operator == (const t_server &a,const t_server &b)
{
	if (a.host!=b.host)
		return false;
	if (a.port!=b.port)
		return false;
	if (a.user!=b.user)
		return false;
	if (a.account != b.account)
		return false;
	if (a.pass!=b.pass && a.user!=_MPT("anonymous"))
		return false;
	if (a.nServerType!=b.nServerType)
		return false;
	if (a.nPasv != b.nPasv)
		return false;
	if (a.nTimeZoneOffset != b.nTimeZoneOffset)
		return false;
	if (a.nUTF8 != b.nUTF8)
		return false;
#ifdef MPEXT
	if (a.iForcePasvIp != b.iForcePasvIp)
		return false;
	if (a.iUseMlsd != b.iUseMlsd)
		return false;
#endif
	return true;
}
예제 #8
0
void CControlSocket::ShowStatus(CString status, int type) const
{
	if ( status.Left(5)==_T("PASS ") )
	{
		int len=status.GetLength()-5;
		status=_T("PASS ");
		for (int i=0;i<len;i++)
			status+=_MPT("*");
	}
	else if ( status.Left(5)==_T("ACCT ") )
	{
		int len=status.GetLength()-5;
		status=_T("ACCT ");
		for (int i=0;i<len;i++)
			status+=_MPT("*");
	}
	LogMessageRaw(type, (LPCTSTR)status);
}
예제 #9
0
int CFileZillaApi::FileTransfer(const t_transferfile &TransferFile)
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (IsConnected()==FZ_REPLY_NOTCONNECTED)
		return FZ_REPLY_NOTCONNECTED;
	if (TransferFile.remotefile==_MPT("") || TransferFile.localfile==_MPT("") || TransferFile.remotepath.IsEmpty())
		return FZ_REPLY_INVALIDPARAM;
	if (IsBusy()==FZ_REPLY_BUSY)
		return FZ_REPLY_BUSY;
	t_command command;
	command.id=FZ_COMMAND_FILETRANSFER;
	command.transferfile=TransferFile;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
}
예제 #10
0
void CControlSocket::ShowStatus(CString status, int type) const
{
	if (!COptions::GetOptionVal(OPTION_MPEXT_LOG_SENSITIVE))
	{
		if ( status.Left(5)==_T("PASS ") )
		{
			int len=status.GetLength()-5;
			status=_T("PASS ");
			for (int i=0;i<len;i++)
				status+=_MPT("*");
		}
		else if ( status.Left(5)==_T("ACCT ") )
		{
			int len=status.GetLength()-5;
			status=_T("ACCT ");
			for (int i=0;i<len;i++)
				status+=_MPT("*");
		}
	}
	LogMessageRaw(type, (LPCTSTR)status);
}
예제 #11
0
CString CServerPath::GetSafePath() const
{
	if (m_bEmpty)
		return _T("");

	CString safepath;
	safepath.Format(_T("%d %d "), m_nServerType, m_Prefix.GetLength());
	if (m_Prefix!=_MPT(""))
		safepath+=m_Prefix+_MPT(" ");
	tConstIter iter = m_Segments.begin();
	while(iter!=m_Segments.end())
	{
		CString len;
		len.Format(_T("%d "), iter->GetLength());
		safepath+=len;
		safepath+=*iter;
		++iter;
		if (iter!=m_Segments.end())
			safepath+=_MPT(" ");
	}
	return safepath;
}
예제 #12
0
const CString CServerPath::GetPath() const
{
	if (m_bEmpty)
		return _MPT("");
	CString path;
	tConstIter iter;
	switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
	{
	case FZ_SERVERTYPE_FTP:
		switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
		{
		case FZ_SERVERTYPE_SUB_FTP_MVS:
		case FZ_SERVERTYPE_SUB_FTP_BS2000:
			path = _MPT("'");
			for (iter = m_Segments.begin(); iter != m_Segments.end(); ++iter)
			{
				if (iter != m_Segments.begin())
					path += _T(".");
				path += *iter;
			}
			path += m_Prefix + _MPT("'");
			break;
		case FZ_SERVERTYPE_SUB_FTP_VMS:
			path = m_Prefix + _MPT("[");
			for (iter = m_Segments.begin(); iter != m_Segments.end(); ++iter)
				path += *iter + _T(".");
			path.TrimRight( _T(".") );
			path += _MPT("]");
			break;
		case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
			for (iter=m_Segments.begin(); iter!=m_Segments.end(); ++iter)
				path+=*iter + _T(".");
			break;
		default:
			if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
				path=_MPT("/");
			for (iter=m_Segments.begin(); iter!=m_Segments.end(); ++iter)
				path+=*iter + _T("/");
			break;
		}
		break;
	case FZ_SERVERTYPE_LOCAL:
		path=m_Prefix;
		if (!m_Segments.empty())
			path+=_MPT("\\");
		for (iter=m_Segments.begin(); iter!=m_Segments.end(); ++iter)
			path+=*iter + _T("\\");

		break;
	default:
		ASSERT(FALSE);
	}
	return path;
}
예제 #13
0
int CFileZillaApi::Command(t_command *pCommand)
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;

	//Dispatch command to command specific functions
	switch(pCommand->id)
	{
	case FZ_COMMAND_LIST:
		if (pCommand->param1!=_MPT(""))
			return List(pCommand->path,pCommand->param1,pCommand->param4);
		else if (!pCommand->path.IsEmpty())
			return List(pCommand->path,pCommand->param4);
		else
			return List(pCommand->param4);
		break;
	case FZ_COMMAND_CONNECT:
		return Connect(pCommand->server);
		break;
	case FZ_COMMAND_DISCONNECT:
		return Disconnect();
		break;
	case FZ_COMMAND_FILETRANSFER:
		return FileTransfer(pCommand->transferfile);
		break;
	case FZ_COMMAND_DELETE:
		return Delete(pCommand->param1, pCommand->path);
		break;
	case FZ_COMMAND_REMOVEDIR:
		return RemoveDir(pCommand->param1, pCommand->path);
		break;
	case FZ_COMMAND_MAKEDIR:
		return MakeDir(pCommand->path);
		break;
	case FZ_COMMAND_RENAME:
		return Rename(pCommand->param1, pCommand->param2, pCommand->path, pCommand->newPath);
		break;
	case FZ_COMMAND_CUSTOMCOMMAND:
		return CustomCommand(pCommand->param1);
		break;
	case FZ_COMMAND_CHMOD:
		return Chmod(pCommand->param4, pCommand->param1, pCommand->path);
		break;
	}
	return FZ_REPLY_INVALIDPARAM;
}
예제 #14
0
파일: ApiLog.cpp 프로젝트: elazzi/winscp
void CApiLog::LogMessageRaw(CString SourceFile, int nSourceLine, void *pInstance, int nMessageType, LPCTSTR pMsg) const
{
	ASSERT(nMessageType>=FZ_LOG_LIST && FZ_LOG_DEBUG<=FZ_LOG_DEBUG);
	ASSERT(m_hTargetWnd || m_pApiLogParent);
	ASSERT(nSourceLine>0);

	int pos=SourceFile.ReverseFind(_MPT('\\'));
	if (pos!=-1)
		SourceFile=SourceFile.Mid(pos+1);
	
#ifdef MPEXT
	if (nMessageType>=FZ_LOG_DEBUG)
		return;
#endif

	CString msg;
	msg.Format(_T("%s(%d): %s   caller=0x%08x"), SourceFile, nSourceLine, pMsg, (int)this);
	
	SendLogMessage(nMessageType, msg);
}
예제 #15
0
BOOL CServerPath::SetSafePath(CString path)
{
	m_bEmpty = TRUE;
	m_Prefix = _MPT("");
	m_Segments.clear();

	int pos1 = path.Find( _T(" ") );
	int pos2 = 0;
	if (pos1 <= pos2)
		return FALSE;
	m_nServerType = _ttoi(path.Mid(pos2,pos1));
	pos2 = pos1 + 1;

	pos1=path.Find(_T(" "), pos2);
	if (pos1<=pos2)
		return FALSE;
	int len = _ttoi(path.Mid(pos2,pos1));
	pos2=pos1+1;

	if (len)
	{
		m_Prefix=path.Mid(pos2,len);
		pos2+=len+1;
	}
	
	while (pos2<path.GetLength())
	{
		pos1=path.Find(_T(" "), pos2);
		if (pos1<=pos2)
			return FALSE;
		int len=_ttoi(path.Mid(pos2,pos1));
			pos2=pos1+1;
		if (len)
		{
			m_Segments.push_back(path.Mid(pos2,len));
			pos2+=len+1;
		}
	}
	m_bEmpty=FALSE;
	return TRUE;
}
예제 #16
0
int CFileZillaApi::Chmod(int nValue, CString FileName, const CServerPath &path /*=CServerPath()*/ )
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (IsConnected()==FZ_REPLY_NOTCONNECTED)
		return FZ_REPLY_NOTCONNECTED;
	if (IsBusy()==FZ_REPLY_BUSY)
		return FZ_REPLY_BUSY;
	if (FileName==_MPT(""))
		return FZ_REPLY_INVALIDPARAM;

	t_command command;
	command.id=FZ_COMMAND_CHMOD;
	command.param1=FileName;
	command.param4=nValue;
	command.path=path;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
}
예제 #17
0
BOOL CServerPath::AddSubdirs(CString subdirs)
{
	// Do nothing if subdirs is empty
	if (subdirs == _T(""))
		return TRUE;

	int pos1;
	int pos2 = 0;
	if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && m_Prefix != _T("."))
		return FALSE;
	
	while (pos2 < subdirs.GetLength())
	{
		pos1 = subdirs.Find(_T(" "), pos2);
		if (pos1 <= pos2)
			return FALSE;
		int len = _ttoi(subdirs.Mid(pos2, pos1));
			pos2 = pos1 + 1;
		if (len)
		{
			m_Segments.push_back(subdirs.Mid(pos2, len));
			pos2 += len + 1;
		}
	}
	if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && !m_Segments.empty())
	{
		if (m_Segments.back().Right(1) == _T("."))
		{
			m_Segments.back().TrimRight(_MPT('.'));
			m_Prefix = _T(".");
		}
		else
			m_Prefix = _T("");
	}
	
	return TRUE;
}
예제 #18
0
CServerPath::CServerPath(CString subdir, const CServerPath &parent)
{
	*this=parent;
	subdir.TrimLeft( _T(" ") );
	subdir.TrimRight( _T(" ") );

	if ( subdir==_T("") )
	{
		if (IsEmpty())
			ASSERT(FALSE);
		else
			return;
	}

	if (!(m_nServerType&FZ_SERVERTYPE_HIGHMASK))
		m_nServerType=FZ_SERVERTYPE_FTP;
	
	m_bEmpty = FALSE;

	switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
	{
	case FZ_SERVERTYPE_FTP:
		switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
		{
		case FZ_SERVERTYPE_SUB_FTP_MVS:
		case FZ_SERVERTYPE_SUB_FTP_BS2000:
			{
				subdir.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
				subdir.TrimRight(FTP_MVS_DOUBLE_QUOTA);

				if (subdir.Left(1) == _MPT("'"))
				{
					if (subdir.Right(1) == _MPT("'"))
					{
					   	if (!SetPath(subdir))
							m_bEmpty = true;
					}
					else
						m_bEmpty = true;
				}
				else if (subdir.Right(1) == _MPT("'"))
					m_bEmpty = true;
				else if (!m_bEmpty)
				{
					if (m_Prefix != _T("."))
						m_bEmpty  = true;
					else
					{
						subdir.TrimLeft(_MPT('.'));
						while (subdir.Replace(_T(".."), _T(".")));

						int pos = subdir.Find(_MPT('.'));
						while (pos != -1)
						{
							m_Segments.push_back(subdir.Left(pos));
							subdir = subdir.Mid(pos + 1);
						}
						if (subdir != _T(""))
						{
							m_Prefix = _T("");
							m_Segments.push_back(subdir);
						}
					}
				}
				else if (!SetPath(subdir))
					m_bEmpty = true;
			}
			break;
		case FZ_SERVERTYPE_SUB_FTP_VMS:
			{
				int pos1=subdir.Find( _T("[") );
				if (pos1==-1)
				{
					ASSERT( subdir.Right(1)!=_T("]") );
					while ( subdir.Replace( _T(".."), _T(".") ) );
				}
				else
				{
					if (subdir.Right(1)!=_MPT("]"))
						ASSERT(FALSE);
					subdir=subdir.Left(subdir.GetLength()-1);
					if (pos1)
						m_Prefix=subdir.Left(pos1);
					else
						m_Prefix=_MPT("");
					m_Segments.clear();
					subdir=subdir.Mid(pos1+1);

					pos1=subdir.Find( _T("[") );
					int pos2=subdir.Find( _T("]") );
					if (pos1!=-1 || pos2!=-1)
						ASSERT(FALSE);
				}
				int pos=subdir.Find( _T(".") );
				while(pos!=-1)
				{
					m_Segments.push_back(subdir.Left(pos));
					subdir=subdir.Mid(pos+1);
					pos=subdir.Find( _T(".") );
				}
				if (subdir!=_MPT(""))
					m_Segments.push_back(subdir);
			}
			break;
		case FZ_SERVERTYPE_SUB_FTP_WINDOWS:
			{
				subdir.Replace( _T("\\"), _T("/") );
				while(subdir.Replace( _T("//"), _T("/") ));
				if (subdir.GetLength() >= 2 && subdir[1] == _MPT(':'))
					m_Segments.clear();
				else if (subdir[0]==_MPT('/'))
				{
					CString firstSegment;
					if (m_Segments.empty())
						firstSegment = _MPT("C:");
					else
						firstSegment = m_Segments.front();
					m_Segments.clear();
					m_Segments.push_back(firstSegment);
					subdir.TrimLeft( _T("/") );
				}
				subdir.TrimRight( _T("/") );
				int pos = subdir.Find( _T("/") );
				while(pos!=-1)
				{
					m_Segments.push_back(subdir.Left(pos));
					subdir=subdir.Mid(pos+1);
					pos=subdir.Find( _T("/") );
				}
				if (subdir!=_MPT(""))
					m_Segments.push_back(subdir);
				break;
			}
		case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
			subdir.Replace(_MPT('.'), _MPT('/'));
		default:
			subdir.Replace( _T("\\"), _T("/") );
			while(subdir.Replace( _T("//"), _T("/") ));
			if (subdir[0]==_MPT('/'))
			{
				m_Segments.clear();
				subdir.TrimLeft( _T("/") );
			}
			subdir.TrimRight( _T("/") );
			int pos=subdir.Find( _T("/") );
			while(pos!=-1)
			{
				m_Segments.push_back(subdir.Left(pos));
				subdir=subdir.Mid(pos+1);
				pos=subdir.Find( _T("/") );
			}
			if (subdir!=_MPT(""))
				m_Segments.push_back(subdir);
			break;
		}
		break;
	case FZ_SERVERTYPE_LOCAL:
		{
			subdir.TrimRight( _T("\\") );
			while (subdir.Replace( _T("\\\\"), _T("\\") ));
			subdir.TrimLeft( _T("\\") );
			int pos=subdir.Find( _T(":") );

			if (pos==1) //subdir is absolute path
			{
				m_Segments.clear();
				m_Prefix=subdir.Left(pos+1);
				subdir=subdir.Mid(pos+1);
				subdir.TrimLeft( _T("\\") );
				if (subdir.Find( _T(":") )!=-1)
					ASSERT(FALSE);
			}
			if (pos==-1 || pos==1)
			{
				pos=subdir.Find( _T("\\") );
				while (pos!=-1)
				{
					m_Segments.push_back(subdir.Left(pos));
					subdir=subdir.Mid(pos+1);
					pos=subdir.Find( _T("\\") );
				}
				if ( subdir!=_T("") )
					m_Segments.push_back(subdir);			
			}
			else
				ASSERT(FALSE);
		}
		break;
	default:
		ASSERT(FALSE);
	}	
}
예제 #19
0
BOOL PASCAL GetStatus64(LPCTSTR lpszFileName, CFileStatus64& rStatus)
{
	// attempt to fully qualify path first
	if (!AfxFullPath(rStatus.m_szFullName, lpszFileName))
	{
		rStatus.m_szFullName[0] = _MPT('\0');
		return FALSE;
	}

	WIN32_FIND_DATA findFileData;
	HANDLE hFind = FindFirstFile((LPTSTR)lpszFileName, &findFileData);
	if (hFind == INVALID_HANDLE_VALUE)
		return FALSE;
	VERIFY(FindClose(hFind));

	// strip attribute of NORMAL bit, our API doesn't have a "normal" bit.
	rStatus.m_attribute = (BYTE)
		(findFileData.dwFileAttributes & ~FILE_ATTRIBUTE_NORMAL);

	rStatus.m_size = ((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;

	// convert times as appropriate
	TRY
	{
		rStatus.m_ctime = CTime(findFileData.ftCreationTime);
		rStatus.m_has_ctime = true;
	}
	CATCH_ALL(e)
	{
		rStatus.m_has_ctime = false;
	}
	END_CATCH_ALL;

	TRY
	{
		rStatus.m_atime = CTime(findFileData.ftLastAccessTime);
		rStatus.m_has_atime = true;
	}
	CATCH_ALL(e)
	{
		rStatus.m_has_atime = false;
	}
	END_CATCH_ALL;

	TRY
	{
		rStatus.m_mtime = CTime(findFileData.ftLastWriteTime);
		rStatus.m_has_mtime = true;
	}
	CATCH_ALL(e)
	{
		rStatus.m_has_mtime = false;
	}
	END_CATCH_ALL;

	if (!rStatus.m_has_ctime || rStatus.m_ctime.GetTime() == 0)
	{
		if (rStatus.m_has_mtime)
		{
			rStatus.m_ctime = rStatus.m_mtime;
			rStatus.m_has_ctime = true;
		}
		else
			rStatus.m_has_ctime = false;
	}


	if (!rStatus.m_has_atime || rStatus.m_atime.GetTime() == 0)
	{
		if (rStatus.m_has_mtime)
		{
			rStatus.m_atime = rStatus.m_mtime;
			rStatus.m_has_atime = true;
		}
		else
			rStatus.m_has_atime = false;
	}

	if (!rStatus.m_has_mtime || rStatus.m_mtime.GetTime() == 0)
	{
		if (rStatus.m_has_ctime)
		{
			rStatus.m_mtime = rStatus.m_ctime;
			rStatus.m_has_mtime = true;
		}
		else
			rStatus.m_has_mtime = false;
	}

	return TRUE;
}
예제 #20
0
CString CServerPath::FormatFilename(CString fn, bool omitPath /*=false*/) const
{
	if (m_bEmpty)
		return fn;

	if (fn == _MPT(""))
		return _MPT("");

	CString path;
	tConstIter iter;
	switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
	{
	case FZ_SERVERTYPE_FTP:
		switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
		{
		case FZ_SERVERTYPE_SUB_FTP_MVS:
		case FZ_SERVERTYPE_SUB_FTP_BS2000:
			if (omitPath && m_Prefix == _T("."))
				return fn;

			path = _MPT("'");
			for (iter = m_Segments.begin(); iter != m_Segments.end(); ++iter)
				path += *iter + _T(".");
			if (m_Prefix != _T("."))
			{
				path.TrimRight(_MPT('.'));
				path += _T("(") + fn + _T(")");
			}
			else
				path += fn;
			path += _MPT("'");
			break;
		case FZ_SERVERTYPE_SUB_FTP_VMS:
			if (omitPath)
				return fn;

			path = m_Prefix + _MPT("[");
			for (iter = m_Segments.begin(); iter != m_Segments.end(); ++iter)
				path += *iter + _T(".");
			path.TrimRight( _T(".") );
			path += _MPT("]");
			path += fn;
			break;
		case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
			if (omitPath)
				return fn;
			for (iter=m_Segments.begin(); iter!=m_Segments.end(); ++iter)
				path+=*iter + _T(".");
			path += fn;
			break;
		default:
			if (omitPath)
				return fn;
			if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
				path=_MPT("/");
			for (iter = m_Segments.begin(); iter != m_Segments.end(); ++iter)
				path+=*iter + _T("/");
			path += fn;
			break;
		}
		break;
	case FZ_SERVERTYPE_LOCAL:
		if (omitPath)
			return fn;
		path=m_Prefix;
		if (!m_Segments.empty())
			path+=_MPT("\\");
		for (iter=m_Segments.begin(); iter!=m_Segments.end(); ++iter)
			path+=*iter + _T("\\");
		path += fn;
		break;
	default:
		ASSERT(FALSE);
	}
	return path;
}
예제 #21
0
BOOL CServerPath::SetPath(CString &newpath, BOOL bIsFile /*=FALSE*/)
{
	CString file;
	CString path=newpath;

	path.TrimLeft( _T(" ") );
	path.TrimRight( _T(" ") );
	if (path != _MPT(""))
		m_bEmpty = FALSE;
	else
		m_bEmpty = TRUE;
	if (!(m_nServerType & FZ_SERVERTYPE_HIGHMASK))
		m_nServerType = FZ_SERVERTYPE_FTP;
	if (!(m_nServerType&FZ_SERVERTYPE_SUBMASK) && (m_nServerType&FZ_SERVERTYPE_HIGHMASK)==FZ_SERVERTYPE_FTP)
	{
		int pos1 = path.Find( _T(":[") );
		if (pos1!=-1 && pos1!=(path.GetLength()-2))
		{
			if (!bIsFile && path.Right(1)==_T("]"))
				m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
			else if (bIsFile && path.ReverseFind(']')>(pos1+1))
				m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
		}
		if (newpath.GetLength() >= 3 && _istalpha(newpath[0]) && newpath[1] == _MPT(':') && (newpath[2] == _MPT('\\') || newpath[2] == _MPT('/')))
			m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
		else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
			m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
		else if (path.GetLength() >= 2 && path[0] != _MPT('/') && path.Right(1) == _T("."))
			m_nServerType |= FZ_SERVERTYPE_SUB_FTP_UNKNOWN;
	}
	m_Segments.clear();
	m_Prefix = _MPT("");
	switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
	{
		case FZ_SERVERTYPE_FTP:
			switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
			{
			case FZ_SERVERTYPE_SUB_FTP_MVS:
			case FZ_SERVERTYPE_SUB_FTP_BS2000:
				{
					path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
					path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
					path.TrimLeft(_MPT('\''));
					path.TrimRight(_MPT('\''));
					path.TrimLeft(_MPT('.'));
					while (path.Replace(_T(".."), _T(".")));

					int pos = path.Find(_T("."));
					while (pos != -1)
					{
						m_Segments.push_back(path.Left(pos));
						path = path.Mid(pos + 1);
						pos = path.Find( _T(".") );
					}
					if (path != _MPT(""))
						m_Segments.push_back(path);
					else
						m_Prefix = _T(".");

					if (bIsFile)
					{
						if (m_Segments.empty())
							return FALSE;
						file = m_Segments.back();
						m_Segments.pop_back();

						if (file.Right(1) == _T("."))
							return FALSE;

						int pos = file.Find(_MPT('('));
						int pos2 = file.Find(_MPT(')'));
						if (pos != -1)
						{
							if (!pos || pos2 != file.GetLength() - 2)
								return FALSE;
							m_Prefix = _T("");
							m_Segments.push_back(file.Left(pos));
							file = file.Mid(pos + 1, pos2 - pos - 1);
						}
						else if (pos2 != -1)
							return FALSE;
					}
				}
				break;
			case FZ_SERVERTYPE_SUB_FTP_VMS:
				{
					int pos1=path.Find( _T("[") );
					if (pos1==-1)
						return FALSE;
					if (bIsFile)
					{
						int rpos=path.ReverseFind(_MPT(']'));
						if (rpos==-1)
							return FALSE;
						else if (rpos!=(path.GetLength()-1) )
						{
							file=file.Mid(rpos+1);
							path=path.Left(rpos+1);
						}
						else
							return FALSE;
					}
					if (path.Right(1)!=_MPT("]"))
						return FALSE;
					path.TrimRight( _T("]") );
					if (pos1)
						m_Prefix=path.Left(pos1);
					path=path.Mid(pos1+1);
					int pos=path.Find( _T(".") );
					while(pos!=-1)
					{
						m_Segments.push_back(path.Left(pos));
						path=path.Mid(pos+1);
						pos=path.Find( _T(".") );
					}
					if (path!=_MPT(""))
						m_Segments.push_back(path);
				}
				break;
			case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
				while (path.Replace(_MPT('.'), _MPT('/')));
			default:
				path.Replace( _T("\\"), _T("/") );
				while(path.Replace( _T("//"), _T("/") ));
				path.TrimLeft( _T("/") );
				if (bIsFile)
				{
					if (path.Right(1)!= _T("/") )
					{
						int rpos=path.ReverseFind(_MPT('/'));
						if (rpos==-1)
						{
							newpath=path;
							m_bEmpty=TRUE;
							return TRUE;
						}
						file=path.Mid(rpos+1);
						path=path.Left(rpos);
					}
					else
						return FALSE;
				}
				path.TrimRight( _T("/") );
				int pos=path.Find( _T("/") );
				while(pos!=-1)
				{
					m_Segments.push_back(path.Left(pos));
					path=path.Mid(pos+1);
					pos=path.Find( _T("/") );
				}
				if (path!=_MPT(""))
					m_Segments.push_back(path);
				break;
			}
			break;
		case FZ_SERVERTYPE_LOCAL:
		{
			if (bIsFile)
			{
				if (path.Right(1)!= _T("\\") )
				{
					int rpos=path.ReverseFind(_MPT('\\'));
					if (rpos==-1)
						return FALSE;
					
					file=path.Mid(rpos+1);
					path=path.Left(rpos);
				}
				else
					return FALSE;
			}
			path.TrimRight( _T("\\") );
			while (path.Replace( _T("\\\\"), _T("\\") ));
			int pos=path.Find( _T(":\\") );
			if (pos==-1 || pos!=1)
				return FALSE;
			else
			{
				m_Prefix=path.Left(pos+1);
				path=path.Mid(pos+2);
			}
			pos=path.Find( _T("\\") );
			while (pos!=-1)
			{
				m_Segments.push_back(path.Left(pos));
				path=path.Mid(pos+1);
				pos=path.Find( _T("\\") );
			}
			if (path!=_MPT(""))
				m_Segments.push_back(path);
		}
		break;
	}
	if (bIsFile)
		newpath = file;
	return TRUE;
}
예제 #22
0
int CFileZillaApi::List(const CServerPath& parent, CString dirname, int nListMode /*=FZ_LIST_USECACHE*/)
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (IsConnected()==FZ_REPLY_NOTCONNECTED)
		return FZ_REPLY_NOTCONNECTED;
#ifndef MPEXT_NO_CACHE
	if ( (nListMode&(FZ_LIST_FORCECACHE|FZ_LIST_REALCHANGE))==(FZ_LIST_FORCECACHE|FZ_LIST_REALCHANGE) )
		return FZ_REPLY_INVALIDPARAM;
	if (nListMode&FZ_LIST_FORCECACHE)
		nListMode|=FZ_LIST_USECACHE;
#endif
	if (dirname==_MPT("") || parent.IsEmpty())
		return FZ_REPLY_INVALIDPARAM;

#ifndef MPEXT_NO_CACHE
	//Check if current dir is cached
	if (nListMode&FZ_LIST_USECACHE && !(nListMode&FZ_LIST_REALCHANGE))
	{
		t_server server;
		BOOL res=m_pMainThread->GetCurrentServer(server);
		if (res)
		{
			t_directory *directory=new t_directory;
			CDirectoryCache cache;
			res=cache.Lookup(parent,dirname,server,*directory);
			if (res)
			{
				BOOL bExact=TRUE;
				if (nListMode & FZ_LIST_EXACT)
					for (int i=0;i<directory->num;i++)
						if (directory->direntry[i].bUnsure || (directory->direntry[i].size==-1 && !directory->direntry[i].dir))
						{
							bExact=FALSE;
							break;
						}
				if (bExact)
				{
					m_pMainThread->SetWorkingDir(directory);
					delete directory;
					return FZ_REPLY_OK;
				}
			}
			delete directory;
		}
	}
#endif

	if (m_pMainThread->IsBusy())
		return FZ_REPLY_BUSY;
#ifndef MPEXT_NO_CACHE
	if (nListMode&FZ_LIST_FORCECACHE)
		return FZ_REPLY_ERROR;
#endif

	t_command command;
	command.id=FZ_COMMAND_LIST;
	command.path=parent;
	command.param1=dirname;
	command.param4=nListMode;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
}
예제 #23
0
CServerPath::CServerPath(CString path, int nServerType)
{
	m_nServerType = nServerType;
	path.TrimLeft( _T(" ") );
	path.TrimRight( _T(" ") );
	if (path == _MPT(""))
	{
		m_bEmpty = TRUE;
		return;
	}
	else
		m_bEmpty = FALSE;

	switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
	{
	case FZ_SERVERTYPE_FTP:
		switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
		{
		case FZ_SERVERTYPE_SUB_FTP_MVS:
		case FZ_SERVERTYPE_SUB_FTP_BS2000:
			{
				path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
				path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
				path.TrimLeft(_MPT('\''));
				path.TrimRight(_MPT('\''));
				path.TrimLeft(_MPT('.'));
				while (path.Replace(_T(".."), _T(".")));

				int pos = path.Find(_T("."));
				while (pos != -1)
				{
					m_Segments.push_back(path.Left(pos));
					path = path.Mid(pos + 1);
					pos = path.Find( _T(".") );
				}
				if (path != _T(""))
					m_Segments.push_back(path);
				else
					m_Prefix = _T(".");
			}
			break;
		case FZ_SERVERTYPE_SUB_FTP_VMS:
			{
				int pos1 = path.Find( _T("[") );
				if (pos1 == -1 || path.Right(1) != _T("]"))
				{
					ASSERT(FALSE);
					m_bEmpty = TRUE;
					return;
				}
				path.TrimRight( _T("]") );
				if (pos1)
					m_Prefix = path.Left(pos1);
				path = path.Mid(pos1 + 1);
				int pos = path.Find( _T(".") );
				while (pos != -1)
				{
					m_Segments.push_back(path.Left(pos));
					path = path.Mid(pos+1);
					pos = path.Find( _T(".") );
				}
				if (path != _MPT(""))
					m_Segments.push_back(path);
			}
			break;
		case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
			while (path.Replace(_MPT('.'), _MPT('/')));
		default:
			path.Replace( _T("\\"), _T("/") );
			while (path.Replace( _T("//"), _T("/") ));
			path.TrimLeft( _T("/") );
			path.TrimRight( _T("/") );
			int pos = path.Find( _T("/") );
			while (pos != -1)
			{
				m_Segments.push_back(path.Left(pos));
				path = path.Mid(pos+1);
				pos = path.Find( _T("/") );
			}
			if (path != _MPT(""))
				m_Segments.push_back(path);
			break;
		}
		break;
	case FZ_SERVERTYPE_LOCAL:
		{
			path.TrimRight( _T("\\") );
			while (path.Replace( _T("\\\\"), _T("\\") ));
			int pos = path.Find( _T("\\") );
			if (pos == -1)
			{
				m_Prefix = path;
				return;
			}
			ASSERT(pos == 2);
			m_Prefix = path.Left(pos);
			path = path.Mid(pos + 1);
			pos = path.Find( _T("\\") );
			while (pos != -1)
			{
				m_Segments.push_back(path.Left(pos));
				path=path.Mid(pos + 1);
				pos=path.Find( _T("\\") );
			}
			if (path != _MPT(""))
				m_Segments.push_back(path);
		}
		break;
	default:
		ASSERT(FALSE);
	}
}
예제 #24
0
BOOL CServerPath::ChangePath(CString &subdir, BOOL bIsFile /*=FALSE*/)
{
	CServerPath newpath = *this;
	CString dir = subdir;
	if (!(newpath.m_nServerType&FZ_SERVERTYPE_HIGHMASK))
		newpath.m_nServerType = FZ_SERVERTYPE_FTP;
	
	dir.TrimLeft(_T(" "));
	dir.TrimRight(_T(" "));

	if ( dir==_T("") )
	{
		if (newpath.IsEmpty() || bIsFile)
			return FALSE;
		else
		{
			*this=newpath;
			return TRUE;
		}
	}

	switch (newpath.m_nServerType&FZ_SERVERTYPE_HIGHMASK)
	{
	case FZ_SERVERTYPE_FTP:
		switch(newpath.m_nServerType&FZ_SERVERTYPE_SUBMASK)
		{
		case FZ_SERVERTYPE_SUB_FTP_MVS:
		case FZ_SERVERTYPE_SUB_FTP_BS2000:
			subdir.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
			subdir.TrimRight(FTP_MVS_DOUBLE_QUOTA);

			if (subdir.Left(1) == _MPT("'"))
			{
				if (subdir.Right(1) != _MPT("'"))
					return FALSE;

				if (!newpath.SetPath(subdir, bIsFile))
					return FALSE;
			}
			else if (subdir.Right(1) == _MPT("'"))
				return FALSE;
			else if (!newpath.IsEmpty())
			{
				if (m_Prefix != _T("."))
					return FALSE;

				subdir.TrimLeft(_MPT('.'));
				while (subdir.Replace(_T(".."), _T(".")));

				int pos = subdir.Find(_MPT('.'));
				while (pos != -1)
				{
					newpath.m_Segments.push_back(subdir.Left(pos));
					subdir = subdir.Mid(pos + 1);
				}
				if (subdir != _T(""))
				{
					newpath.m_Segments.push_back(subdir);
					newpath.m_Prefix = _T("");
				}
				else
					newpath.m_Prefix = _T(".");

				if (bIsFile)
				{
					if (newpath.m_Prefix == _T("."))
						return false;

					if (newpath.m_Segments.empty())
						return false;
					subdir = newpath.m_Segments.back();
					newpath.m_Segments.pop_back();

					int pos = subdir.Find(_MPT('('));
					int pos2 = subdir.Find(_MPT(')'));
					if (pos != -1)
					{
						if (!pos || pos2 != subdir.GetLength() - 2)
							return false;
						newpath.m_Segments.push_back(subdir.Left(pos));
						subdir = subdir.Mid(pos + 1, pos2 - pos - 1);
					}
					else if (pos2 != -1)
						return false;
					else
						newpath.m_Prefix = _T(".");
				}
			}
			else if (!newpath.SetPath(subdir, bIsFile))
				return FALSE;
			break;
		case FZ_SERVERTYPE_SUB_FTP_VMS:
			{
				int pos1=dir.Find( _T("[") );
				if (pos1==-1)
				{
					int pos2=dir.ReverseFind(_MPT(']'));
					if (pos2!=-1)
						return FALSE;
					if (bIsFile)
					{
						if (newpath.IsEmpty())
							return FALSE;
						subdir=dir;
						*this=newpath;
						return TRUE;
					}
					while ( dir.Replace( _T(".."), _T(".") ) );
				}
				else
				{
					int pos2=dir.ReverseFind(_MPT(']'));
					if (pos2==-1)
						return FALSE;
					if (bIsFile && pos2==(dir.GetLength()-1))
						return FALSE;
					if (!bIsFile && pos2!=(dir.GetLength()-1))
						return FALSE;
					if (pos2<=pos1)
						return FALSE;
					if (bIsFile)
						subdir=dir.Mid(pos2+2);
					dir=dir.Left(pos2);
					if (pos1)
						newpath.m_Prefix=dir.Left(pos1);
					else
						newpath.m_Prefix=_MPT("");
					newpath.m_Segments.clear();
					dir=dir.Mid(pos1+1);
					pos1=dir.Find( _T("[") );
					pos2=dir.Find( _T("]") );
					if (pos1!=-1 || pos2!=-1)
						return FALSE;
				}
				int pos=dir.Find( _T(".") );
				while(pos!=-1)
				{
					newpath.m_Segments.push_back(dir.Left(pos));
					dir=dir.Mid(pos+1);
					pos=dir.Find( _T(".") );
				}
				if (dir!=_MPT(""))
					newpath.m_Segments.push_back(dir);
			}
			break;
		case FZ_SERVERTYPE_SUB_FTP_WINDOWS:
			{
				dir.Replace( _T("\\"), _T("/") );
				while(dir.Replace( _T("//"), _T("/") ));
				if (dir.GetLength() >= 2 && dir[1] == _MPT(':'))
					newpath.m_Segments.clear();
				else if (dir[0]==_MPT('/'))
				{
					CString firstSegment;
					if (newpath.m_Segments.empty())
						firstSegment = _MPT("C:");
					else
						firstSegment = newpath.m_Segments.front();
					newpath.m_Segments.clear();
					newpath.m_Segments.push_back(firstSegment);
					dir.TrimLeft( _T("/") );
				}

				if (newpath.IsEmpty())
					return FALSE;
	
				if (dir.Right(1)==_T("/") && bIsFile)
					return FALSE;
				dir.TrimRight( _T("/") );

				int pos=dir.ReverseFind(_MPT('/'));
				if (bIsFile)
					if (pos==-1)
					{
						subdir=dir;
						newpath.m_bEmpty=FALSE;
						*this=newpath;
						return TRUE;
					}
					else
					{
						subdir=dir.Mid(pos+1);
						dir=dir.Left(pos);
						dir.TrimRight( _T("/") );
					}
			
				pos=dir.Find( _T("/") );
				while(pos!=-1)
				{
					newpath.m_Segments.push_back(dir.Left(pos));
					dir=dir.Mid(pos+1);
					pos=dir.Find( _T("/") );
				}
				if (dir!=_MPT(""))
					newpath.m_Segments.push_back(dir);
				break;
			}
		case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
			dir.Replace(_MPT('.'), _MPT('/'));
			dir = _T("/") + dir;
		default:
			dir.Replace( _T("\\"), _T("/") );
			while(dir.Replace( _T("//"), _T("/") ));
			if (dir[0]==_MPT('/'))
			{
				newpath.m_Segments.clear();
				if (dir!="/")
					dir.TrimLeft( _T("/") );
			}
			else
				if (newpath.IsEmpty())
					return FALSE;
			if (dir.Right(1)==_T("/") && bIsFile)
				return FALSE;
			dir.TrimRight( _T("/") );

			int pos=dir.ReverseFind(_MPT('/'));
			if (bIsFile)
				if (pos==-1)
				{
					subdir=dir;
					newpath.m_bEmpty=FALSE;
					*this=newpath;
					return TRUE;
				}
				else
				{
					subdir=dir.Mid(pos+1);
					dir=dir.Left(pos);
					dir.TrimRight( _T("/") );
				}
			
			pos=dir.Find( _T("/") );
			while(pos!=-1)
			{
				newpath.m_Segments.push_back(dir.Left(pos));
				dir=dir.Mid(pos+1);
				pos=dir.Find( _T("/") );
			}
			if (dir!=_MPT(""))
				newpath.m_Segments.push_back(dir);
			break;
		}
		break;
	case FZ_SERVERTYPE_LOCAL:
		{
			if (dir.Right(1)==_T("\\") && bIsFile)
				return FALSE;
			dir.TrimRight( _T("\\") );
			while (dir.Replace( _T("\\\\"), _T("\\") ));
			if ( dir.Left(1) == _T("\\") )
				newpath.m_Segments.clear();
			else
				if (newpath.IsEmpty())
					return FALSE;
			dir.TrimLeft( _T("\\") );
			if (bIsFile)
			{
				int pos=dir.ReverseFind(_MPT('\\'));
				if (pos==-1)
				{
					if (dir.Find( _T(":") )!=-1)
						return FALSE;
					subdir=dir;
					newpath.m_bEmpty=FALSE;
					*this=newpath;
					return TRUE;
				}
				else
				{
					if (dir.Find( _T(":"), pos+1)!=-1)
						return FALSE;
					subdir=dir.Mid(pos+1);
					dir=dir.Left(pos);
				}
			}
			int pos=dir.Find( _T(":") );
		
			if (pos==1) //dir is absolute path
			{
				newpath.m_Segments.clear();
				newpath.m_Prefix=dir.Left(pos+1);
				dir=dir.Mid(pos+1);
				dir.TrimLeft( _T("\\") );
				if (dir.Find( _T(":") )!=-1)
					return FALSE;
			}
			if (pos==-1 || pos==1)
			{
				pos=dir.Find( _T("\\") );
				while (pos!=-1)
				{
					newpath.m_Segments.push_back(dir.Left(pos));
					dir=dir.Mid(pos+1);
					pos=dir.Find( _T("\\") );
				}
				if (dir!=_MPT(""))
					newpath.m_Segments.push_back(dir);
			}
			else
				return FALSE;
		}
		break;
	default:
		return FALSE;
	}
	newpath.m_bEmpty=FALSE;
	*this=newpath;
	return TRUE;
}