ServerPath.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. // ServerPath.cpp: Implementierung der Klasse CServerPath.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ServerPath.h"
  19. #include "structures.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char THIS_FILE[]=__FILE__;
  23. #define new DEBUG_NEW
  24. #endif
  25. #define FTP_MVS_DOUBLE_QUOTA (TCHAR)0xDC
  26. //////////////////////////////////////////////////////////////////////
  27. // Konstruktion/Destruktion
  28. //////////////////////////////////////////////////////////////////////
  29. CServerPath::CServerPath()
  30. {
  31. m_nServerType = 0;
  32. m_bEmpty = TRUE;
  33. }
  34. CServerPath::CServerPath(int nServerType)
  35. {
  36. m_nServerType = nServerType;
  37. m_bEmpty = TRUE;
  38. }
  39. CServerPath::CServerPath(CString path)
  40. {
  41. m_nServerType = FZ_SERVERTYPE_FTP;
  42. path.TrimLeft( _T(" ") );
  43. path.TrimRight( _T(" ") );
  44. if (path == _MPT(""))
  45. {
  46. m_bEmpty = TRUE;
  47. return;
  48. }
  49. else
  50. m_bEmpty = FALSE;
  51. int pos1 = path.Find( _T(":[") );
  52. if (pos1 != -1 && path.Right(1) == _MPT("]") && pos1 != (path.GetLength()-1))
  53. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
  54. else if (path.GetLength() >= 3 && _istalpha(path[0]) && path[1] == _MPT(':') && (path[2] == _MPT('\\') || path[2] == _MPT('/')))
  55. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
  56. else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
  57. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  58. else if (path.GetLength() > 2 && path[0] == _MPT('\'') && path.Right(1) == _T("'") && path.Find(_MPT('/')) == -1 && path.Find(_MPT('\\')) == -1)
  59. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  60. else if (path.GetLength() >= 2 && path[0] != _MPT('/') && path.Right(1) == _T("."))
  61. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_UNKNOWN;
  62. *this = CServerPath(path, m_nServerType);
  63. }
  64. CServerPath::CServerPath(CString path, int nServerType)
  65. {
  66. m_nServerType = nServerType;
  67. path.TrimLeft( _T(" ") );
  68. path.TrimRight( _T(" ") );
  69. if (path == _MPT(""))
  70. {
  71. m_bEmpty = TRUE;
  72. return;
  73. }
  74. else
  75. m_bEmpty = FALSE;
  76. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  77. {
  78. case FZ_SERVERTYPE_FTP:
  79. switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
  80. {
  81. case FZ_SERVERTYPE_SUB_FTP_MVS:
  82. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  83. {
  84. path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  85. path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  86. path.TrimLeft(_MPT('\''));
  87. path.TrimRight(_MPT('\''));
  88. path.TrimLeft(_MPT('.'));
  89. while (path.Replace(_T(".."), _T(".")));
  90. int pos = path.Find(_T("."));
  91. while (pos != -1)
  92. {
  93. m_Segments.push_back(path.Left(pos));
  94. path = path.Mid(pos + 1);
  95. pos = path.Find( _T(".") );
  96. }
  97. if (path != _T(""))
  98. m_Segments.push_back(path);
  99. else
  100. m_Prefix = _T(".");
  101. }
  102. break;
  103. case FZ_SERVERTYPE_SUB_FTP_VMS:
  104. {
  105. int pos1 = path.Find( _T("[") );
  106. if (pos1 == -1 || path.Right(1) != _T("]"))
  107. {
  108. ASSERT(FALSE);
  109. m_bEmpty = TRUE;
  110. return;
  111. }
  112. path.TrimRight( _T("]") );
  113. if (pos1)
  114. m_Prefix = path.Left(pos1);
  115. path = path.Mid(pos1 + 1);
  116. int pos = path.Find( _T(".") );
  117. while (pos != -1)
  118. {
  119. m_Segments.push_back(path.Left(pos));
  120. path = path.Mid(pos+1);
  121. pos = path.Find( _T(".") );
  122. }
  123. if (path != _MPT(""))
  124. m_Segments.push_back(path);
  125. }
  126. break;
  127. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  128. while (path.Replace(_MPT('.'), _MPT('/')));
  129. default:
  130. path.Replace( _T("\\"), _T("/") );
  131. while (path.Replace( _T("//"), _T("/") ));
  132. path.TrimLeft( _T("/") );
  133. path.TrimRight( _T("/") );
  134. int pos = path.Find( _T("/") );
  135. while (pos != -1)
  136. {
  137. m_Segments.push_back(path.Left(pos));
  138. path = path.Mid(pos+1);
  139. pos = path.Find( _T("/") );
  140. }
  141. if (path != _MPT(""))
  142. m_Segments.push_back(path);
  143. break;
  144. }
  145. break;
  146. case FZ_SERVERTYPE_LOCAL:
  147. {
  148. path.TrimRight( _T("\\") );
  149. while (path.Replace( _T("\\\\"), _T("\\") ));
  150. int pos = path.Find( _T("\\") );
  151. if (pos == -1)
  152. {
  153. m_Prefix = path;
  154. return;
  155. }
  156. ASSERT(pos == 2);
  157. m_Prefix = path.Left(pos);
  158. path = path.Mid(pos + 1);
  159. pos = path.Find( _T("\\") );
  160. while (pos != -1)
  161. {
  162. m_Segments.push_back(path.Left(pos));
  163. path=path.Mid(pos + 1);
  164. pos=path.Find( _T("\\") );
  165. }
  166. if (path != _MPT(""))
  167. m_Segments.push_back(path);
  168. }
  169. break;
  170. default:
  171. ASSERT(FALSE);
  172. }
  173. }
  174. CServerPath::CServerPath(const CServerPath &path)
  175. {
  176. m_nServerType = path.m_nServerType;
  177. m_Prefix = path.m_Prefix;
  178. m_bEmpty = path.m_bEmpty;
  179. m_Segments = path.m_Segments;
  180. }
  181. CServerPath::~CServerPath()
  182. {
  183. }
  184. void CServerPath::SetServer(const t_server &server)
  185. {
  186. m_nServerType=server.nServerType;
  187. }
  188. BOOL CServerPath::SetPath(CString &newpath, BOOL bIsFile /*=FALSE*/)
  189. {
  190. CString file;
  191. CString path=newpath;
  192. path.TrimLeft( _T(" ") );
  193. path.TrimRight( _T(" ") );
  194. if (path != _MPT(""))
  195. m_bEmpty = FALSE;
  196. else
  197. m_bEmpty = TRUE;
  198. if (!(m_nServerType & FZ_SERVERTYPE_HIGHMASK))
  199. m_nServerType = FZ_SERVERTYPE_FTP;
  200. if (!(m_nServerType&FZ_SERVERTYPE_SUBMASK) && (m_nServerType&FZ_SERVERTYPE_HIGHMASK)==FZ_SERVERTYPE_FTP)
  201. {
  202. int pos1 = path.Find( _T(":[") );
  203. if (pos1!=-1 && pos1!=(path.GetLength()-2))
  204. {
  205. if (!bIsFile && path.Right(1)==_T("]"))
  206. m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
  207. else if (bIsFile && path.ReverseFind(']')>(pos1+1))
  208. m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
  209. }
  210. if (newpath.GetLength() >= 3 && _istalpha(newpath[0]) && newpath[1] == _MPT(':') && (newpath[2] == _MPT('\\') || newpath[2] == _MPT('/')))
  211. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
  212. else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
  213. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  214. else if (path.GetLength() >= 2 && path[0] != _MPT('/') && path.Right(1) == _T("."))
  215. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_UNKNOWN;
  216. }
  217. m_Segments.clear();
  218. m_Prefix = _MPT("");
  219. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  220. {
  221. case FZ_SERVERTYPE_FTP:
  222. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  223. {
  224. case FZ_SERVERTYPE_SUB_FTP_MVS:
  225. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  226. {
  227. path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  228. path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  229. path.TrimLeft(_MPT('\''));
  230. path.TrimRight(_MPT('\''));
  231. path.TrimLeft(_MPT('.'));
  232. while (path.Replace(_T(".."), _T(".")));
  233. int pos = path.Find(_T("."));
  234. while (pos != -1)
  235. {
  236. m_Segments.push_back(path.Left(pos));
  237. path = path.Mid(pos + 1);
  238. pos = path.Find( _T(".") );
  239. }
  240. if (path != _MPT(""))
  241. m_Segments.push_back(path);
  242. else
  243. m_Prefix = _T(".");
  244. if (bIsFile)
  245. {
  246. if (m_Segments.empty())
  247. return FALSE;
  248. file = m_Segments.back();
  249. m_Segments.pop_back();
  250. if (file.Right(1) == _T("."))
  251. return FALSE;
  252. int pos = file.Find(_MPT('('));
  253. int pos2 = file.Find(_MPT(')'));
  254. if (pos != -1)
  255. {
  256. if (!pos || pos2 != file.GetLength() - 2)
  257. return FALSE;
  258. m_Prefix = _T("");
  259. m_Segments.push_back(file.Left(pos));
  260. file = file.Mid(pos + 1, pos2 - pos - 1);
  261. }
  262. else if (pos2 != -1)
  263. return FALSE;
  264. }
  265. }
  266. break;
  267. case FZ_SERVERTYPE_SUB_FTP_VMS:
  268. {
  269. int pos1=path.Find( _T("[") );
  270. if (pos1==-1)
  271. return FALSE;
  272. if (bIsFile)
  273. {
  274. int rpos=path.ReverseFind(_MPT(']'));
  275. if (rpos==-1)
  276. return FALSE;
  277. else if (rpos!=(path.GetLength()-1) )
  278. {
  279. file=file.Mid(rpos+1);
  280. path=path.Left(rpos+1);
  281. }
  282. else
  283. return FALSE;
  284. }
  285. if (path.Right(1)!=_MPT("]"))
  286. return FALSE;
  287. path.TrimRight( _T("]") );
  288. if (pos1)
  289. m_Prefix=path.Left(pos1);
  290. path=path.Mid(pos1+1);
  291. int pos=path.Find( _T(".") );
  292. while(pos!=-1)
  293. {
  294. m_Segments.push_back(path.Left(pos));
  295. path=path.Mid(pos+1);
  296. pos=path.Find( _T(".") );
  297. }
  298. if (path!=_MPT(""))
  299. m_Segments.push_back(path);
  300. }
  301. break;
  302. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  303. while (path.Replace(_MPT('.'), _MPT('/')));
  304. default:
  305. path.Replace( _T("\\"), _T("/") );
  306. while(path.Replace( _T("//"), _T("/") ));
  307. path.TrimLeft( _T("/") );
  308. if (bIsFile)
  309. {
  310. if (path.Right(1)!= _T("/") )
  311. {
  312. int rpos=path.ReverseFind(_MPT('/'));
  313. if (rpos==-1)
  314. {
  315. newpath=path;
  316. m_bEmpty=TRUE;
  317. return TRUE;
  318. }
  319. file=path.Mid(rpos+1);
  320. path=path.Left(rpos);
  321. }
  322. else
  323. return FALSE;
  324. }
  325. path.TrimRight( _T("/") );
  326. int pos=path.Find( _T("/") );
  327. while(pos!=-1)
  328. {
  329. m_Segments.push_back(path.Left(pos));
  330. path=path.Mid(pos+1);
  331. pos=path.Find( _T("/") );
  332. }
  333. if (path!=_MPT(""))
  334. m_Segments.push_back(path);
  335. break;
  336. }
  337. break;
  338. case FZ_SERVERTYPE_LOCAL:
  339. {
  340. if (bIsFile)
  341. {
  342. if (path.Right(1)!= _T("\\") )
  343. {
  344. int rpos=path.ReverseFind(_MPT('\\'));
  345. if (rpos==-1)
  346. return FALSE;
  347. file=path.Mid(rpos+1);
  348. path=path.Left(rpos);
  349. }
  350. else
  351. return FALSE;
  352. }
  353. path.TrimRight( _T("\\") );
  354. while (path.Replace( _T("\\\\"), _T("\\") ));
  355. int pos=path.Find( _T(":\\") );
  356. if (pos==-1 || pos!=1)
  357. return FALSE;
  358. else
  359. {
  360. m_Prefix=path.Left(pos+1);
  361. path=path.Mid(pos+2);
  362. }
  363. pos=path.Find( _T("\\") );
  364. while (pos!=-1)
  365. {
  366. m_Segments.push_back(path.Left(pos));
  367. path=path.Mid(pos+1);
  368. pos=path.Find( _T("\\") );
  369. }
  370. if (path!=_MPT(""))
  371. m_Segments.push_back(path);
  372. }
  373. break;
  374. }
  375. if (bIsFile)
  376. newpath = file;
  377. return TRUE;
  378. }
  379. const CString CServerPath::GetPath() const
  380. {
  381. if (m_bEmpty)
  382. return _MPT("");
  383. CString path;
  384. tConstIter iter;
  385. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  386. {
  387. case FZ_SERVERTYPE_FTP:
  388. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  389. {
  390. case FZ_SERVERTYPE_SUB_FTP_MVS:
  391. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  392. path = _MPT("'");
  393. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  394. {
  395. if (iter != m_Segments.begin())
  396. path += _T(".");
  397. path += *iter;
  398. }
  399. path += m_Prefix + _MPT("'");
  400. break;
  401. case FZ_SERVERTYPE_SUB_FTP_VMS:
  402. path = m_Prefix + _MPT("[");
  403. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  404. path += *iter + _T(".");
  405. path.TrimRight( _T(".") );
  406. path += _MPT("]");
  407. break;
  408. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  409. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  410. path+=*iter + _T(".");
  411. break;
  412. default:
  413. if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
  414. path=_MPT("/");
  415. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  416. path+=*iter + _T("/");
  417. break;
  418. }
  419. break;
  420. case FZ_SERVERTYPE_LOCAL:
  421. path=m_Prefix;
  422. if (!m_Segments.empty())
  423. path+=_MPT("\\");
  424. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  425. path+=*iter + _T("\\");
  426. break;
  427. default:
  428. ASSERT(FALSE);
  429. }
  430. return path;
  431. }
  432. CServerPath& CServerPath::operator=(const CServerPath &op)
  433. {
  434. if (this == &op)
  435. return *this;
  436. m_Segments.clear();
  437. m_nServerType = op.m_nServerType;
  438. m_Prefix = op.m_Prefix;
  439. m_bEmpty = op.m_bEmpty;
  440. m_Segments = op.m_Segments;
  441. return *this;
  442. }
  443. const bool CServerPath::operator==(const CServerPath &op) const
  444. {
  445. if (this == &op)
  446. return true;
  447. if (m_bEmpty != op.m_bEmpty)
  448. return false;
  449. if (m_Prefix != op.m_Prefix)
  450. return false;
  451. if (m_nServerType != op.m_nServerType)
  452. return false;
  453. tConstIter iter1 = m_Segments.begin();
  454. tConstIter iter2 = op.m_Segments.begin();
  455. while (iter1 != m_Segments.end())
  456. {
  457. if (iter2 == op.m_Segments.end())
  458. return false;
  459. if (*iter1 != *iter2)
  460. return false;
  461. iter1++;
  462. iter2++;
  463. }
  464. if (iter2 != op.m_Segments.end())
  465. return false;
  466. return true;
  467. }
  468. const BOOL operator==(const CServerPath &a, const CString &b)
  469. {
  470. CServerPath path(b);
  471. return a==path;
  472. }
  473. const bool CServerPath::operator!=(const CServerPath &op) const
  474. {
  475. if (!this)
  476. return false;
  477. if (*this == op)
  478. return false;
  479. else
  480. return true;
  481. }
  482. CString CServerPath::GetLastSegment() const
  483. {
  484. if (!HasParent())
  485. return _T("");
  486. if (m_Segments.empty())
  487. return _T("");
  488. else
  489. return m_Segments.back();
  490. }
  491. CServerPath CServerPath::GetParent() const
  492. {
  493. ASSERT(HasParent());
  494. CServerPath path;
  495. path = *this;
  496. path.m_Segments.pop_back();
  497. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000))
  498. path.m_Prefix = _T(".");
  499. return path;
  500. }
  501. BOOL CServerPath::HasParent() const
  502. {
  503. if (!m_Segments.empty())
  504. return TRUE;
  505. else
  506. return FALSE;
  507. }
  508. BOOL CServerPath::IsSubdirOf(const CServerPath &path, BOOL bCompareNoCase /*=FALSE*/) const
  509. {
  510. if (this==&path)
  511. return FALSE;
  512. if (m_bEmpty || path.m_bEmpty)
  513. return FALSE;
  514. if (m_Prefix != path.m_Prefix)
  515. return FALSE;
  516. if (m_nServerType!=path.m_nServerType)
  517. return FALSE;
  518. tConstIter iter1 = m_Segments.begin();
  519. tConstIter iter2 = path.m_Segments.begin();
  520. while (iter1 != m_Segments.end())
  521. {
  522. if (iter2==path.m_Segments.end())
  523. return TRUE;
  524. if (bCompareNoCase)
  525. {
  526. CString Segment1 = *iter1;
  527. CString Segment2 = *iter2;
  528. Segment1.MakeLower();
  529. Segment2.MakeLower();
  530. if (Segment1 != Segment2)
  531. return FALSE;
  532. }
  533. else
  534. if (*iter1 != *iter2)
  535. return FALSE;
  536. iter1++;
  537. iter2++;
  538. }
  539. return FALSE;
  540. }
  541. BOOL CServerPath::IsParentOf(const CServerPath &path, BOOL bCompareNoCase /*=FALSE*/) const
  542. {
  543. if (!this)
  544. return FALSE;
  545. return path.IsSubdirOf(*this, bCompareNoCase);
  546. }
  547. const BOOL CServerPath::IsEmpty() const
  548. {
  549. return m_bEmpty;
  550. }
  551. BOOL CServerPath::SetSafePath(CString path)
  552. {
  553. m_bEmpty = TRUE;
  554. m_Prefix = _MPT("");
  555. m_Segments.clear();
  556. int pos1 = path.Find( _T(" ") );
  557. int pos2 = 0;
  558. if (pos1 <= pos2)
  559. return FALSE;
  560. m_nServerType = _ttoi(path.Mid(pos2,pos1));
  561. pos2 = pos1 + 1;
  562. pos1=path.Find(_T(" "), pos2);
  563. if (pos1<=pos2)
  564. return FALSE;
  565. int len = _ttoi(path.Mid(pos2,pos1));
  566. pos2=pos1+1;
  567. if (len)
  568. {
  569. m_Prefix=path.Mid(pos2,len);
  570. pos2+=len+1;
  571. }
  572. while (pos2<path.GetLength())
  573. {
  574. pos1=path.Find(_T(" "), pos2);
  575. if (pos1<=pos2)
  576. return FALSE;
  577. int len=_ttoi(path.Mid(pos2,pos1));
  578. pos2=pos1+1;
  579. if (len)
  580. {
  581. m_Segments.push_back(path.Mid(pos2,len));
  582. pos2+=len+1;
  583. }
  584. }
  585. m_bEmpty=FALSE;
  586. return TRUE;
  587. }
  588. CString CServerPath::GetSafePath() const
  589. {
  590. if (m_bEmpty)
  591. return _T("");
  592. CString safepath;
  593. safepath.Format(_T("%d %d "), m_nServerType, m_Prefix.GetLength());
  594. if (m_Prefix!=_MPT(""))
  595. safepath+=m_Prefix+_MPT(" ");
  596. tConstIter iter = m_Segments.begin();
  597. while(iter!=m_Segments.end())
  598. {
  599. CString len;
  600. len.Format(_T("%d "), iter->GetLength());
  601. safepath+=len;
  602. safepath+=*iter;
  603. iter++;
  604. if (iter!=m_Segments.end())
  605. safepath+=_MPT(" ");
  606. }
  607. return safepath;
  608. }
  609. CString CServerPath::GetSubdirsOf(const CServerPath &path) const
  610. {
  611. ASSERT(IsParentOf(path));
  612. CServerPath subdirs=path;
  613. CString ret;
  614. while(IsParentOf(subdirs))
  615. {
  616. CString tmp;
  617. tmp.Format(_T(" %d %s"), subdirs.GetLastSegment().GetLength(),subdirs.GetLastSegment());
  618. ret += tmp;
  619. subdirs = subdirs.GetParent();
  620. }
  621. ret.TrimLeft( _T(" ") );
  622. return ret;
  623. }
  624. BOOL CServerPath::AddSubdirs(CString subdirs)
  625. {
  626. // Do nothing if subdirs is empty
  627. if (subdirs == _T(""))
  628. return TRUE;
  629. int pos1;
  630. int pos2 = 0;
  631. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && m_Prefix != _T("."))
  632. return FALSE;
  633. while (pos2 < subdirs.GetLength())
  634. {
  635. pos1 = subdirs.Find(_T(" "), pos2);
  636. if (pos1 <= pos2)
  637. return FALSE;
  638. int len = _ttoi(subdirs.Mid(pos2, pos1));
  639. pos2 = pos1 + 1;
  640. if (len)
  641. {
  642. m_Segments.push_back(subdirs.Mid(pos2, len));
  643. pos2 += len + 1;
  644. }
  645. }
  646. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && !m_Segments.empty())
  647. {
  648. if (m_Segments.back().Right(1) == _T("."))
  649. {
  650. m_Segments.back().TrimRight(_MPT('.'));
  651. m_Prefix = _T(".");
  652. }
  653. else
  654. m_Prefix = _T("");
  655. }
  656. return TRUE;
  657. }
  658. BOOL CServerPath::AddSubdir(CString subdir)
  659. {
  660. subdir.TrimLeft( _T(" ") );
  661. subdir.TrimRight( _T(" ") );
  662. if (subdir == _MPT(""))
  663. return FALSE;
  664. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && m_Prefix != _T("."))
  665. return FALSE;
  666. m_Segments.push_back(subdir);
  667. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && !m_Segments.empty())
  668. {
  669. if (m_Segments.back().Right(1) == _T("."))
  670. {
  671. m_Segments.back().TrimRight(_MPT('.'));
  672. m_Prefix = _T(".");
  673. }
  674. else
  675. m_Prefix = _T("");
  676. }
  677. m_bEmpty = FALSE;
  678. return TRUE;
  679. }
  680. CServerPath::CServerPath(CString subdir, const CServerPath &parent)
  681. {
  682. *this=parent;
  683. subdir.TrimLeft( _T(" ") );
  684. subdir.TrimRight( _T(" ") );
  685. if ( subdir==_T("") )
  686. {
  687. if (IsEmpty())
  688. ASSERT(FALSE);
  689. else
  690. return;
  691. }
  692. if (!(m_nServerType&FZ_SERVERTYPE_HIGHMASK))
  693. m_nServerType=FZ_SERVERTYPE_FTP;
  694. m_bEmpty = FALSE;
  695. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  696. {
  697. case FZ_SERVERTYPE_FTP:
  698. switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
  699. {
  700. case FZ_SERVERTYPE_SUB_FTP_MVS:
  701. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  702. {
  703. subdir.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  704. subdir.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  705. if (subdir.Left(1) == _MPT("'"))
  706. {
  707. if (subdir.Right(1) == _MPT("'"))
  708. {
  709. if (!SetPath(subdir))
  710. m_bEmpty = true;
  711. }
  712. else
  713. m_bEmpty = true;
  714. }
  715. else if (subdir.Right(1) == _MPT("'"))
  716. m_bEmpty = true;
  717. else if (!m_bEmpty)
  718. {
  719. if (m_Prefix != _T("."))
  720. m_bEmpty = true;
  721. else
  722. {
  723. subdir.TrimLeft(_MPT('.'));
  724. while (subdir.Replace(_T(".."), _T(".")));
  725. int pos = subdir.Find(_MPT('.'));
  726. while (pos != -1)
  727. {
  728. m_Segments.push_back(subdir.Left(pos));
  729. subdir = subdir.Mid(pos + 1);
  730. }
  731. if (subdir != _T(""))
  732. {
  733. m_Prefix = _T("");
  734. m_Segments.push_back(subdir);
  735. }
  736. }
  737. }
  738. else if (!SetPath(subdir))
  739. m_bEmpty = true;
  740. }
  741. break;
  742. case FZ_SERVERTYPE_SUB_FTP_VMS:
  743. {
  744. int pos1=subdir.Find( _T("[") );
  745. if (pos1==-1)
  746. {
  747. ASSERT( subdir.Right(1)!=_T("]") );
  748. while ( subdir.Replace( _T(".."), _T(".") ) );
  749. }
  750. else
  751. {
  752. if (subdir.Right(1)!=_MPT("]"))
  753. ASSERT(FALSE);
  754. subdir=subdir.Left(subdir.GetLength()-1);
  755. if (pos1)
  756. m_Prefix=subdir.Left(pos1);
  757. else
  758. m_Prefix=_MPT("");
  759. m_Segments.clear();
  760. subdir=subdir.Mid(pos1+1);
  761. pos1=subdir.Find( _T("[") );
  762. int pos2=subdir.Find( _T("]") );
  763. if (pos1!=-1 || pos2!=-1)
  764. ASSERT(FALSE);
  765. }
  766. int pos=subdir.Find( _T(".") );
  767. while(pos!=-1)
  768. {
  769. m_Segments.push_back(subdir.Left(pos));
  770. subdir=subdir.Mid(pos+1);
  771. pos=subdir.Find( _T(".") );
  772. }
  773. if (subdir!=_MPT(""))
  774. m_Segments.push_back(subdir);
  775. }
  776. break;
  777. case FZ_SERVERTYPE_SUB_FTP_WINDOWS:
  778. {
  779. subdir.Replace( _T("\\"), _T("/") );
  780. while(subdir.Replace( _T("//"), _T("/") ));
  781. if (subdir.GetLength() >= 2 && subdir[1] == _MPT(':'))
  782. m_Segments.clear();
  783. else if (subdir[0]==_MPT('/'))
  784. {
  785. CString firstSegment;
  786. if (m_Segments.empty())
  787. firstSegment = _MPT("C:");
  788. else
  789. firstSegment = m_Segments.front();
  790. m_Segments.clear();
  791. m_Segments.push_back(firstSegment);
  792. subdir.TrimLeft( _T("/") );
  793. }
  794. subdir.TrimRight( _T("/") );
  795. int pos = subdir.Find( _T("/") );
  796. while(pos!=-1)
  797. {
  798. m_Segments.push_back(subdir.Left(pos));
  799. subdir=subdir.Mid(pos+1);
  800. pos=subdir.Find( _T("/") );
  801. }
  802. if (subdir!=_MPT(""))
  803. m_Segments.push_back(subdir);
  804. break;
  805. }
  806. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  807. subdir.Replace(_MPT('.'), _MPT('/'));
  808. default:
  809. subdir.Replace( _T("\\"), _T("/") );
  810. while(subdir.Replace( _T("//"), _T("/") ));
  811. if (subdir[0]==_MPT('/'))
  812. {
  813. m_Segments.clear();
  814. subdir.TrimLeft( _T("/") );
  815. }
  816. subdir.TrimRight( _T("/") );
  817. int pos=subdir.Find( _T("/") );
  818. while(pos!=-1)
  819. {
  820. m_Segments.push_back(subdir.Left(pos));
  821. subdir=subdir.Mid(pos+1);
  822. pos=subdir.Find( _T("/") );
  823. }
  824. if (subdir!=_MPT(""))
  825. m_Segments.push_back(subdir);
  826. break;
  827. }
  828. break;
  829. case FZ_SERVERTYPE_LOCAL:
  830. {
  831. subdir.TrimRight( _T("\\") );
  832. while (subdir.Replace( _T("\\\\"), _T("\\") ));
  833. subdir.TrimLeft( _T("\\") );
  834. int pos=subdir.Find( _T(":") );
  835. if (pos==1) //subdir is absolute path
  836. {
  837. m_Segments.clear();
  838. m_Prefix=subdir.Left(pos+1);
  839. subdir=subdir.Mid(pos+1);
  840. subdir.TrimLeft( _T("\\") );
  841. if (subdir.Find( _T(":") )!=-1)
  842. ASSERT(FALSE);
  843. }
  844. if (pos==-1 || pos==1)
  845. {
  846. pos=subdir.Find( _T("\\") );
  847. while (pos!=-1)
  848. {
  849. m_Segments.push_back(subdir.Left(pos));
  850. subdir=subdir.Mid(pos+1);
  851. pos=subdir.Find( _T("\\") );
  852. }
  853. if ( subdir!=_T("") )
  854. m_Segments.push_back(subdir);
  855. }
  856. else
  857. ASSERT(FALSE);
  858. }
  859. break;
  860. default:
  861. ASSERT(FALSE);
  862. }
  863. }
  864. BOOL CServerPath::ChangePath(CString &subdir, BOOL bIsFile /*=FALSE*/)
  865. {
  866. CServerPath newpath = *this;
  867. CString dir = subdir;
  868. if (!(newpath.m_nServerType&FZ_SERVERTYPE_HIGHMASK))
  869. newpath.m_nServerType = FZ_SERVERTYPE_FTP;
  870. dir.TrimLeft(_T(" "));
  871. dir.TrimRight(_T(" "));
  872. if ( dir==_T("") )
  873. {
  874. if (newpath.IsEmpty() || bIsFile)
  875. return FALSE;
  876. else
  877. {
  878. *this=newpath;
  879. return TRUE;
  880. }
  881. }
  882. switch (newpath.m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  883. {
  884. case FZ_SERVERTYPE_FTP:
  885. switch(newpath.m_nServerType&FZ_SERVERTYPE_SUBMASK)
  886. {
  887. case FZ_SERVERTYPE_SUB_FTP_MVS:
  888. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  889. subdir.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  890. subdir.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  891. if (subdir.Left(1) == _MPT("'"))
  892. {
  893. if (subdir.Right(1) != _MPT("'"))
  894. return FALSE;
  895. if (!newpath.SetPath(subdir, bIsFile))
  896. return FALSE;
  897. }
  898. else if (subdir.Right(1) == _MPT("'"))
  899. return FALSE;
  900. else if (!newpath.IsEmpty())
  901. {
  902. if (m_Prefix != _T("."))
  903. return FALSE;
  904. subdir.TrimLeft(_MPT('.'));
  905. while (subdir.Replace(_T(".."), _T(".")));
  906. int pos = subdir.Find(_MPT('.'));
  907. while (pos != -1)
  908. {
  909. newpath.m_Segments.push_back(subdir.Left(pos));
  910. subdir = subdir.Mid(pos + 1);
  911. }
  912. if (subdir != _T(""))
  913. {
  914. newpath.m_Segments.push_back(subdir);
  915. newpath.m_Prefix = _T("");
  916. }
  917. else
  918. newpath.m_Prefix = _T(".");
  919. if (bIsFile)
  920. {
  921. if (newpath.m_Prefix == _T("."))
  922. return false;
  923. if (newpath.m_Segments.empty())
  924. return false;
  925. subdir = newpath.m_Segments.back();
  926. newpath.m_Segments.pop_back();
  927. int pos = subdir.Find(_MPT('('));
  928. int pos2 = subdir.Find(_MPT(')'));
  929. if (pos != -1)
  930. {
  931. if (!pos || pos2 != subdir.GetLength() - 2)
  932. return false;
  933. newpath.m_Segments.push_back(subdir.Left(pos));
  934. subdir = subdir.Mid(pos + 1, pos2 - pos - 1);
  935. }
  936. else if (pos2 != -1)
  937. return false;
  938. else
  939. newpath.m_Prefix = _T(".");
  940. }
  941. }
  942. else if (!newpath.SetPath(subdir, bIsFile))
  943. return FALSE;
  944. break;
  945. case FZ_SERVERTYPE_SUB_FTP_VMS:
  946. {
  947. int pos1=dir.Find( _T("[") );
  948. if (pos1==-1)
  949. {
  950. int pos2=dir.ReverseFind(_MPT(']'));
  951. if (pos2!=-1)
  952. return FALSE;
  953. if (bIsFile)
  954. {
  955. if (newpath.IsEmpty())
  956. return FALSE;
  957. subdir=dir;
  958. *this=newpath;
  959. return TRUE;
  960. }
  961. while ( dir.Replace( _T(".."), _T(".") ) );
  962. }
  963. else
  964. {
  965. int pos2=dir.ReverseFind(_MPT(']'));
  966. if (pos2==-1)
  967. return FALSE;
  968. if (bIsFile && pos2==(dir.GetLength()-1))
  969. return FALSE;
  970. if (!bIsFile && pos2!=(dir.GetLength()-1))
  971. return FALSE;
  972. if (pos2<=pos1)
  973. return FALSE;
  974. if (bIsFile)
  975. subdir=dir.Mid(pos2+2);
  976. dir=dir.Left(pos2);
  977. if (pos1)
  978. newpath.m_Prefix=dir.Left(pos1);
  979. else
  980. newpath.m_Prefix=_MPT("");
  981. newpath.m_Segments.clear();
  982. dir=dir.Mid(pos1+1);
  983. pos1=dir.Find( _T("[") );
  984. pos2=dir.Find( _T("]") );
  985. if (pos1!=-1 || pos2!=-1)
  986. return FALSE;
  987. }
  988. int pos=dir.Find( _T(".") );
  989. while(pos!=-1)
  990. {
  991. newpath.m_Segments.push_back(dir.Left(pos));
  992. dir=dir.Mid(pos+1);
  993. pos=dir.Find( _T(".") );
  994. }
  995. if (dir!=_MPT(""))
  996. newpath.m_Segments.push_back(dir);
  997. }
  998. break;
  999. case FZ_SERVERTYPE_SUB_FTP_WINDOWS:
  1000. {
  1001. dir.Replace( _T("\\"), _T("/") );
  1002. while(dir.Replace( _T("//"), _T("/") ));
  1003. if (dir.GetLength() >= 2 && dir[1] == _MPT(':'))
  1004. newpath.m_Segments.clear();
  1005. else if (dir[0]==_MPT('/'))
  1006. {
  1007. CString firstSegment;
  1008. if (newpath.m_Segments.empty())
  1009. firstSegment = _MPT("C:");
  1010. else
  1011. firstSegment = newpath.m_Segments.front();
  1012. newpath.m_Segments.clear();
  1013. newpath.m_Segments.push_back(firstSegment);
  1014. dir.TrimLeft( _T("/") );
  1015. }
  1016. if (newpath.IsEmpty())
  1017. return FALSE;
  1018. if (dir.Right(1)==_T("/") && bIsFile)
  1019. return FALSE;
  1020. dir.TrimRight( _T("/") );
  1021. int pos=dir.ReverseFind(_MPT('/'));
  1022. if (bIsFile)
  1023. if (pos==-1)
  1024. {
  1025. subdir=dir;
  1026. newpath.m_bEmpty=FALSE;
  1027. *this=newpath;
  1028. return TRUE;
  1029. }
  1030. else
  1031. {
  1032. subdir=dir.Mid(pos+1);
  1033. dir=dir.Left(pos);
  1034. dir.TrimRight( _T("/") );
  1035. }
  1036. pos=dir.Find( _T("/") );
  1037. while(pos!=-1)
  1038. {
  1039. newpath.m_Segments.push_back(dir.Left(pos));
  1040. dir=dir.Mid(pos+1);
  1041. pos=dir.Find( _T("/") );
  1042. }
  1043. if (dir!=_MPT(""))
  1044. newpath.m_Segments.push_back(dir);
  1045. break;
  1046. }
  1047. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  1048. dir.Replace(_MPT('.'), _MPT('/'));
  1049. dir = _T("/") + dir;
  1050. default:
  1051. dir.Replace( _T("\\"), _T("/") );
  1052. while(dir.Replace( _T("//"), _T("/") ));
  1053. if (dir[0]==_MPT('/'))
  1054. {
  1055. newpath.m_Segments.clear();
  1056. if (dir!="/")
  1057. dir.TrimLeft( _T("/") );
  1058. }
  1059. else
  1060. if (newpath.IsEmpty())
  1061. return FALSE;
  1062. if (dir.Right(1)==_T("/") && bIsFile)
  1063. return FALSE;
  1064. dir.TrimRight( _T("/") );
  1065. int pos=dir.ReverseFind(_MPT('/'));
  1066. if (bIsFile)
  1067. if (pos==-1)
  1068. {
  1069. subdir=dir;
  1070. newpath.m_bEmpty=FALSE;
  1071. *this=newpath;
  1072. return TRUE;
  1073. }
  1074. else
  1075. {
  1076. subdir=dir.Mid(pos+1);
  1077. dir=dir.Left(pos);
  1078. dir.TrimRight( _T("/") );
  1079. }
  1080. pos=dir.Find( _T("/") );
  1081. while(pos!=-1)
  1082. {
  1083. newpath.m_Segments.push_back(dir.Left(pos));
  1084. dir=dir.Mid(pos+1);
  1085. pos=dir.Find( _T("/") );
  1086. }
  1087. if (dir!=_MPT(""))
  1088. newpath.m_Segments.push_back(dir);
  1089. break;
  1090. }
  1091. break;
  1092. case FZ_SERVERTYPE_LOCAL:
  1093. {
  1094. if (dir.Right(1)==_T("\\") && bIsFile)
  1095. return FALSE;
  1096. dir.TrimRight( _T("\\") );
  1097. while (dir.Replace( _T("\\\\"), _T("\\") ));
  1098. if ( dir.Left(1) == _T("\\") )
  1099. newpath.m_Segments.clear();
  1100. else
  1101. if (newpath.IsEmpty())
  1102. return FALSE;
  1103. dir.TrimLeft( _T("\\") );
  1104. if (bIsFile)
  1105. {
  1106. int pos=dir.ReverseFind(_MPT('\\'));
  1107. if (pos==-1)
  1108. {
  1109. if (dir.Find( _T(":") )!=-1)
  1110. return FALSE;
  1111. subdir=dir;
  1112. newpath.m_bEmpty=FALSE;
  1113. *this=newpath;
  1114. return TRUE;
  1115. }
  1116. else
  1117. {
  1118. if (dir.Find( _T(":"), pos+1)!=-1)
  1119. return FALSE;
  1120. subdir=dir.Mid(pos+1);
  1121. dir=dir.Left(pos);
  1122. }
  1123. }
  1124. int pos=dir.Find( _T(":") );
  1125. if (pos==1) //dir is absolute path
  1126. {
  1127. newpath.m_Segments.clear();
  1128. newpath.m_Prefix=dir.Left(pos+1);
  1129. dir=dir.Mid(pos+1);
  1130. dir.TrimLeft( _T("\\") );
  1131. if (dir.Find( _T(":") )!=-1)
  1132. return FALSE;
  1133. }
  1134. if (pos==-1 || pos==1)
  1135. {
  1136. pos=dir.Find( _T("\\") );
  1137. while (pos!=-1)
  1138. {
  1139. newpath.m_Segments.push_back(dir.Left(pos));
  1140. dir=dir.Mid(pos+1);
  1141. pos=dir.Find( _T("\\") );
  1142. }
  1143. if (dir!=_MPT(""))
  1144. newpath.m_Segments.push_back(dir);
  1145. }
  1146. else
  1147. return FALSE;
  1148. }
  1149. break;
  1150. default:
  1151. return FALSE;
  1152. }
  1153. newpath.m_bEmpty=FALSE;
  1154. *this=newpath;
  1155. return TRUE;
  1156. }
  1157. BOOL CServerPath::SetPath(CString newpath)
  1158. {
  1159. return SetPath(newpath, FALSE);
  1160. }
  1161. const bool CServerPath::MatchNoCase(const CServerPath &op) const
  1162. {
  1163. if (this==&op)
  1164. return TRUE;
  1165. if (m_bEmpty!=op.m_bEmpty)
  1166. return FALSE;
  1167. if (m_Prefix!=op.m_Prefix)
  1168. return FALSE;
  1169. if (m_nServerType!=op.m_nServerType)
  1170. return FALSE;
  1171. tConstIter iter1=m_Segments.begin();
  1172. tConstIter iter2=op.m_Segments.begin();
  1173. while (iter1!=m_Segments.end())
  1174. {
  1175. if (iter2==op.m_Segments.end())
  1176. return FALSE;
  1177. CString Segment1=*iter1;
  1178. CString Segment2=*iter2;
  1179. Segment1.MakeLower();
  1180. Segment2.MakeLower();
  1181. if (Segment1!=Segment2)
  1182. return FALSE;
  1183. iter1++;
  1184. iter2++;
  1185. }
  1186. if (iter2!=op.m_Segments.end())
  1187. return FALSE;
  1188. return TRUE;
  1189. }
  1190. CString CServerPath::FormatFilename(CString fn, bool omitPath /*=false*/) const
  1191. {
  1192. if (m_bEmpty)
  1193. return fn;
  1194. if (fn == _MPT(""))
  1195. return _MPT("");
  1196. CString path;
  1197. tConstIter iter;
  1198. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  1199. {
  1200. case FZ_SERVERTYPE_FTP:
  1201. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  1202. {
  1203. case FZ_SERVERTYPE_SUB_FTP_MVS:
  1204. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  1205. if (omitPath && m_Prefix == _T("."))
  1206. return fn;
  1207. path = _MPT("'");
  1208. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  1209. path += *iter + _T(".");
  1210. if (m_Prefix != _T("."))
  1211. {
  1212. path.TrimRight(_MPT('.'));
  1213. path += _T("(") + fn + _T(")");
  1214. }
  1215. else
  1216. path += fn;
  1217. path += _MPT("'");
  1218. break;
  1219. case FZ_SERVERTYPE_SUB_FTP_VMS:
  1220. if (omitPath)
  1221. return fn;
  1222. path = m_Prefix + _MPT("[");
  1223. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  1224. path += *iter + _T(".");
  1225. path.TrimRight( _T(".") );
  1226. path += _MPT("]");
  1227. path += fn;
  1228. break;
  1229. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  1230. if (omitPath)
  1231. return fn;
  1232. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  1233. path+=*iter + _T(".");
  1234. path += fn;
  1235. break;
  1236. default:
  1237. if (omitPath)
  1238. return fn;
  1239. if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
  1240. path=_MPT("/");
  1241. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  1242. path+=*iter + _T("/");
  1243. path += fn;
  1244. break;
  1245. }
  1246. break;
  1247. case FZ_SERVERTYPE_LOCAL:
  1248. if (omitPath)
  1249. return fn;
  1250. path=m_Prefix;
  1251. if (!m_Segments.empty())
  1252. path+=_MPT("\\");
  1253. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  1254. path+=*iter + _T("\\");
  1255. path += fn;
  1256. break;
  1257. default:
  1258. ASSERT(FALSE);
  1259. }
  1260. return path;
  1261. }