ServerPath.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. //---------------------------------------------------------------------------
  2. #include "stdafx.h"
  3. #include "ServerPath.h"
  4. #include "structures.h"
  5. #define FTP_MVS_DOUBLE_QUOTA (TCHAR)0xDC
  6. //////////////////////////////////////////////////////////////////////
  7. // Konstruktion/Destruktion
  8. //////////////////////////////////////////////////////////////////////
  9. CServerPath::CServerPath()
  10. {
  11. m_nServerType = 0;
  12. m_bEmpty = TRUE;
  13. }
  14. CServerPath::CServerPath(int nServerType)
  15. {
  16. m_nServerType = nServerType;
  17. m_bEmpty = TRUE;
  18. }
  19. CServerPath::CServerPath(CString path, bool trim)
  20. {
  21. m_nServerType = FZ_SERVERTYPE_FTP;
  22. if (trim)
  23. {
  24. path.TrimLeft( L" " );
  25. path.TrimRight( L" " );
  26. }
  27. if (path == L"")
  28. {
  29. m_bEmpty = TRUE;
  30. return;
  31. }
  32. else
  33. m_bEmpty = FALSE;
  34. int pos1 = path.Find( L":[" );
  35. if (pos1 != -1 && path.Right(1) == L"]" && pos1 != (path.GetLength()-1))
  36. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
  37. else if (path.GetLength() >= 3 && _istalpha(path[0]) && path[1] == L':' && (path[2] == L'\\' || path[2] == L'/'))
  38. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
  39. else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
  40. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  41. else if (path.GetLength() > 2 && path[0] == L'\'' && path.Right(1) == L"'" && path.Find(L'/') == -1 && path.Find(L'\\') == -1)
  42. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  43. *this = CServerPath(path, m_nServerType, trim);
  44. }
  45. CServerPath::CServerPath(CString path, int nServerType, bool trim)
  46. {
  47. m_nServerType = nServerType;
  48. if (trim)
  49. {
  50. path.TrimLeft( L" " );
  51. path.TrimRight( L" " );
  52. }
  53. if (path == L"")
  54. {
  55. m_bEmpty = TRUE;
  56. return;
  57. }
  58. else
  59. m_bEmpty = FALSE;
  60. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  61. {
  62. case FZ_SERVERTYPE_FTP:
  63. switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
  64. {
  65. case FZ_SERVERTYPE_SUB_FTP_MVS:
  66. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  67. {
  68. path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  69. path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  70. path.TrimLeft(L'\'');
  71. path.TrimRight(L'\'');
  72. path.TrimLeft(L'.');
  73. while (path.Replace(L"..", L"."));
  74. int pos = path.Find(L".");
  75. while (pos != -1)
  76. {
  77. m_Segments.push_back(path.Left(pos));
  78. path = path.Mid(pos + 1);
  79. pos = path.Find( L"." );
  80. }
  81. if (path != L"")
  82. m_Segments.push_back(path);
  83. else
  84. m_Prefix = L".";
  85. }
  86. break;
  87. case FZ_SERVERTYPE_SUB_FTP_VMS:
  88. {
  89. int pos1 = path.Find( L"[" );
  90. if (pos1 == -1 || path.Right(1) != L"]")
  91. {
  92. DebugAssert(FALSE);
  93. m_bEmpty = TRUE;
  94. return;
  95. }
  96. path.TrimRight( L"]" );
  97. if (pos1)
  98. m_Prefix = path.Left(pos1);
  99. path = path.Mid(pos1 + 1);
  100. int pos = path.Find( L"." );
  101. while (pos != -1)
  102. {
  103. m_Segments.push_back(path.Left(pos));
  104. path = path.Mid(pos+1);
  105. pos = path.Find( L"." );
  106. }
  107. if (path != L"")
  108. m_Segments.push_back(path);
  109. }
  110. break;
  111. default:
  112. path.Replace( L"\\", L"/" );
  113. while (path.Replace( L"//", L"/" ));
  114. path.TrimLeft( L"/" );
  115. path.TrimRight( L"/" );
  116. int pos = path.Find( L"/" );
  117. while (pos != -1)
  118. {
  119. m_Segments.push_back(path.Left(pos));
  120. path = path.Mid(pos+1);
  121. pos = path.Find( L"/" );
  122. }
  123. if (path != L"")
  124. m_Segments.push_back(path);
  125. break;
  126. }
  127. break;
  128. case FZ_SERVERTYPE_LOCAL:
  129. {
  130. path.TrimRight( L"\\" );
  131. while (path.Replace( L"\\\\", L"\\" ));
  132. int pos = path.Find( L"\\" );
  133. if (pos == -1)
  134. {
  135. m_Prefix = path;
  136. return;
  137. }
  138. DebugAssert(pos == 2);
  139. m_Prefix = path.Left(pos);
  140. path = path.Mid(pos + 1);
  141. pos = path.Find( L"\\" );
  142. while (pos != -1)
  143. {
  144. m_Segments.push_back(path.Left(pos));
  145. path=path.Mid(pos + 1);
  146. pos=path.Find( L"\\" );
  147. }
  148. if (path != L"")
  149. m_Segments.push_back(path);
  150. }
  151. break;
  152. default:
  153. DebugAssert(FALSE);
  154. }
  155. }
  156. CServerPath::CServerPath(const CServerPath &path)
  157. {
  158. m_nServerType = path.m_nServerType;
  159. m_Prefix = path.m_Prefix;
  160. m_bEmpty = path.m_bEmpty;
  161. m_Segments = path.m_Segments;
  162. }
  163. CServerPath::~CServerPath()
  164. {
  165. }
  166. void CServerPath::SetServer(const t_server &server)
  167. {
  168. m_nServerType=server.nServerType;
  169. }
  170. BOOL CServerPath::SetPath(CString &newpath, BOOL bIsFile /*=FALSE*/)
  171. {
  172. CString file;
  173. CString path=newpath;
  174. path.TrimLeft( L" " );
  175. path.TrimRight( L" " );
  176. if (path != L"")
  177. m_bEmpty = FALSE;
  178. else
  179. m_bEmpty = TRUE;
  180. if (!(m_nServerType & FZ_SERVERTYPE_HIGHMASK))
  181. m_nServerType = FZ_SERVERTYPE_FTP;
  182. if (!(m_nServerType&FZ_SERVERTYPE_SUBMASK) && (m_nServerType&FZ_SERVERTYPE_HIGHMASK)==FZ_SERVERTYPE_FTP)
  183. {
  184. int pos1 = path.Find( L":[" );
  185. if (pos1!=-1 && pos1!=(path.GetLength()-2))
  186. {
  187. if (!bIsFile && path.Right(1)==L"]")
  188. m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
  189. else if (bIsFile && path.ReverseFind(']')>(pos1+1))
  190. m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
  191. }
  192. if (newpath.GetLength() >= 3 && _istalpha(newpath[0]) && newpath[1] == L':' && (newpath[2] == L'\\' || newpath[2] == L'/'))
  193. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
  194. else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
  195. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  196. }
  197. m_Segments.clear();
  198. m_Prefix = L"";
  199. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  200. {
  201. case FZ_SERVERTYPE_FTP:
  202. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  203. {
  204. case FZ_SERVERTYPE_SUB_FTP_MVS:
  205. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  206. {
  207. path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  208. path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  209. path.TrimLeft(L'\'');
  210. path.TrimRight(L'\'');
  211. path.TrimLeft(L'.');
  212. while (path.Replace(L"..", L"."));
  213. int pos = path.Find(L".");
  214. while (pos != -1)
  215. {
  216. m_Segments.push_back(path.Left(pos));
  217. path = path.Mid(pos + 1);
  218. pos = path.Find( L"." );
  219. }
  220. if (path != L"")
  221. m_Segments.push_back(path);
  222. else
  223. m_Prefix = L".";
  224. if (bIsFile)
  225. {
  226. if (m_Segments.empty())
  227. return FALSE;
  228. file = m_Segments.back();
  229. m_Segments.pop_back();
  230. if (file.Right(1) == L".")
  231. return FALSE;
  232. int pos = file.Find(L'(');
  233. int pos2 = file.Find(L')');
  234. if (pos != -1)
  235. {
  236. if (!pos || pos2 != file.GetLength() - 2)
  237. return FALSE;
  238. m_Prefix = L"";
  239. m_Segments.push_back(file.Left(pos));
  240. file = file.Mid(pos + 1, pos2 - pos - 1);
  241. }
  242. else if (pos2 != -1)
  243. return FALSE;
  244. }
  245. }
  246. break;
  247. case FZ_SERVERTYPE_SUB_FTP_VMS:
  248. {
  249. int pos1=path.Find( L"[" );
  250. if (pos1==-1)
  251. return FALSE;
  252. if (bIsFile)
  253. {
  254. int rpos=path.ReverseFind(L']');
  255. if (rpos==-1)
  256. return FALSE;
  257. else if (rpos!=(path.GetLength()-1) )
  258. {
  259. file=file.Mid(rpos+1);
  260. path=path.Left(rpos+1);
  261. }
  262. else
  263. return FALSE;
  264. }
  265. if (path.Right(1)!=L"]")
  266. return FALSE;
  267. path.TrimRight( L"]" );
  268. if (pos1)
  269. m_Prefix=path.Left(pos1);
  270. path=path.Mid(pos1+1);
  271. int pos=path.Find( L"." );
  272. while(pos!=-1)
  273. {
  274. m_Segments.push_back(path.Left(pos));
  275. path=path.Mid(pos+1);
  276. pos=path.Find( L"." );
  277. }
  278. if (path!=L"")
  279. m_Segments.push_back(path);
  280. }
  281. break;
  282. default:
  283. path.Replace( L"\\", L"/" );
  284. while(path.Replace( L"//", L"/" ));
  285. path.TrimLeft( L"/" );
  286. if (bIsFile)
  287. {
  288. if (path.Right(1)!= L"/" )
  289. {
  290. int rpos=path.ReverseFind(L'/');
  291. if (rpos==-1)
  292. {
  293. newpath=path;
  294. m_bEmpty=TRUE;
  295. return TRUE;
  296. }
  297. file=path.Mid(rpos+1);
  298. path=path.Left(rpos);
  299. }
  300. else
  301. return FALSE;
  302. }
  303. path.TrimRight( L"/" );
  304. int pos=path.Find( L"/" );
  305. while(pos!=-1)
  306. {
  307. m_Segments.push_back(path.Left(pos));
  308. path=path.Mid(pos+1);
  309. pos=path.Find( L"/" );
  310. }
  311. if (path!=L"")
  312. m_Segments.push_back(path);
  313. break;
  314. }
  315. break;
  316. case FZ_SERVERTYPE_LOCAL:
  317. {
  318. if (bIsFile)
  319. {
  320. if (path.Right(1)!= L"\\" )
  321. {
  322. int rpos=path.ReverseFind(L'\\');
  323. if (rpos==-1)
  324. return FALSE;
  325. file=path.Mid(rpos+1);
  326. path=path.Left(rpos);
  327. }
  328. else
  329. return FALSE;
  330. }
  331. path.TrimRight( L"\\" );
  332. while (path.Replace( L"\\\\", L"\\" ));
  333. int pos=path.Find( L":\\" );
  334. if (pos==-1 || pos!=1)
  335. return FALSE;
  336. else
  337. {
  338. m_Prefix=path.Left(pos+1);
  339. path=path.Mid(pos+2);
  340. }
  341. pos=path.Find( L"\\" );
  342. while (pos!=-1)
  343. {
  344. m_Segments.push_back(path.Left(pos));
  345. path=path.Mid(pos+1);
  346. pos=path.Find( L"\\" );
  347. }
  348. if (path!=L"")
  349. m_Segments.push_back(path);
  350. }
  351. break;
  352. }
  353. if (bIsFile)
  354. newpath = file;
  355. return TRUE;
  356. }
  357. const CString CServerPath::GetPath() const
  358. {
  359. if (m_bEmpty)
  360. return L"";
  361. CString path;
  362. tConstIter iter;
  363. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  364. {
  365. case FZ_SERVERTYPE_FTP:
  366. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  367. {
  368. case FZ_SERVERTYPE_SUB_FTP_MVS:
  369. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  370. path = L"'";
  371. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  372. {
  373. if (iter != m_Segments.begin())
  374. path += L".";
  375. path += *iter;
  376. }
  377. path += m_Prefix + L"'";
  378. break;
  379. case FZ_SERVERTYPE_SUB_FTP_VMS:
  380. path = m_Prefix + L"[";
  381. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  382. path += *iter + L".";
  383. path.TrimRight( L"." );
  384. path += L"]";
  385. break;
  386. default:
  387. if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
  388. path=L"/";
  389. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  390. path+=*iter + L"/";
  391. break;
  392. }
  393. break;
  394. case FZ_SERVERTYPE_LOCAL:
  395. path=m_Prefix;
  396. if (!m_Segments.empty())
  397. path+=L"\\";
  398. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  399. path+=*iter + L"\\";
  400. break;
  401. default:
  402. DebugAssert(FALSE);
  403. }
  404. return path;
  405. }
  406. CServerPath& CServerPath::operator=(const CServerPath &op)
  407. {
  408. if (this == &op)
  409. return *this;
  410. m_Segments.clear();
  411. m_nServerType = op.m_nServerType;
  412. m_Prefix = op.m_Prefix;
  413. m_bEmpty = op.m_bEmpty;
  414. m_Segments = op.m_Segments;
  415. return *this;
  416. }
  417. const bool CServerPath::operator==(const CServerPath &op) const
  418. {
  419. if (this == &op)
  420. return true;
  421. if (m_bEmpty != op.m_bEmpty)
  422. return false;
  423. if (m_Prefix != op.m_Prefix)
  424. return false;
  425. // excluding FZ_SERVERTYPE_LAYERMASK from comparison,
  426. // as this part of server type is not set in TFileZillaIntf
  427. const int CompareMask = FZ_SERVERTYPE_HIGHMASK | FZ_SERVERTYPE_SUBMASK;
  428. if ((m_nServerType & CompareMask) != (op.m_nServerType & CompareMask))
  429. return false;
  430. tConstIter iter1 = m_Segments.begin();
  431. tConstIter iter2 = op.m_Segments.begin();
  432. while (iter1 != m_Segments.end())
  433. {
  434. if (iter2 == op.m_Segments.end())
  435. return false;
  436. if (*iter1 != *iter2)
  437. return false;
  438. iter1++;
  439. iter2++;
  440. }
  441. if (iter2 != op.m_Segments.end())
  442. return false;
  443. return true;
  444. }
  445. const BOOL operator==(const CServerPath &a, const CString &b)
  446. {
  447. CServerPath path(b);
  448. return a==path;
  449. }
  450. const bool CServerPath::operator!=(const CServerPath &op) const
  451. {
  452. if (!this)
  453. return false;
  454. if (*this == op)
  455. return false;
  456. else
  457. return true;
  458. }
  459. CString CServerPath::GetLastSegment() const
  460. {
  461. if (!HasParent())
  462. return L"";
  463. if (m_Segments.empty())
  464. return L"";
  465. else
  466. return m_Segments.back();
  467. }
  468. CServerPath CServerPath::GetParent() const
  469. {
  470. DebugAssert(HasParent());
  471. CServerPath path;
  472. path = *this;
  473. path.m_Segments.pop_back();
  474. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000))
  475. path.m_Prefix = L".";
  476. return path;
  477. }
  478. BOOL CServerPath::HasParent() const
  479. {
  480. if (!m_Segments.empty())
  481. return TRUE;
  482. else
  483. return FALSE;
  484. }
  485. const BOOL CServerPath::IsEmpty() const
  486. {
  487. return m_bEmpty;
  488. }
  489. CString CServerPath::GetSafePath() const
  490. {
  491. if (m_bEmpty)
  492. return L"";
  493. CString safepath;
  494. safepath.Format(L"%d %d ", m_nServerType, m_Prefix.GetLength());
  495. if (m_Prefix!=L"")
  496. safepath+=m_Prefix+L" ";
  497. tConstIter iter = m_Segments.begin();
  498. while(iter!=m_Segments.end())
  499. {
  500. CString len;
  501. len.Format(L"%d ", iter->GetLength());
  502. safepath+=len;
  503. safepath+=*iter;
  504. iter++;
  505. if (iter!=m_Segments.end())
  506. safepath+=L" ";
  507. }
  508. return safepath;
  509. }
  510. BOOL CServerPath::AddSubdir(CString subdir)
  511. {
  512. subdir.TrimLeft( L" " );
  513. subdir.TrimRight( L" " );
  514. if (subdir == L"")
  515. return FALSE;
  516. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && m_Prefix != L".")
  517. return FALSE;
  518. m_Segments.push_back(subdir);
  519. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && !m_Segments.empty())
  520. {
  521. if (m_Segments.back().Right(1) == L".")
  522. {
  523. m_Segments.back().TrimRight(L'.');
  524. m_Prefix = L".";
  525. }
  526. else
  527. m_Prefix = L"";
  528. }
  529. m_bEmpty = FALSE;
  530. return TRUE;
  531. }
  532. CServerPath::CServerPath(CString subdir, const CServerPath &parent)
  533. {
  534. *this=parent;
  535. subdir.TrimLeft( L" " );
  536. subdir.TrimRight( L" " );
  537. if ( subdir==L"" )
  538. {
  539. if (IsEmpty())
  540. DebugAssert(FALSE);
  541. else
  542. return;
  543. }
  544. if (!(m_nServerType&FZ_SERVERTYPE_HIGHMASK))
  545. m_nServerType=FZ_SERVERTYPE_FTP;
  546. m_bEmpty = FALSE;
  547. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  548. {
  549. case FZ_SERVERTYPE_FTP:
  550. switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
  551. {
  552. case FZ_SERVERTYPE_SUB_FTP_MVS:
  553. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  554. {
  555. subdir.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  556. subdir.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  557. if (subdir.Left(1) == L"'")
  558. {
  559. if (subdir.Right(1) == L"'")
  560. {
  561. if (!SetPath(subdir))
  562. m_bEmpty = true;
  563. }
  564. else
  565. m_bEmpty = true;
  566. }
  567. else if (subdir.Right(1) == L"'")
  568. m_bEmpty = true;
  569. else if (!m_bEmpty)
  570. {
  571. if (m_Prefix != L".")
  572. m_bEmpty = true;
  573. else
  574. {
  575. subdir.TrimLeft(L'.');
  576. while (subdir.Replace(L"..", L"."));
  577. int pos = subdir.Find(L'.');
  578. while (pos != -1)
  579. {
  580. m_Segments.push_back(subdir.Left(pos));
  581. subdir = subdir.Mid(pos + 1);
  582. pos = subdir.Find(L'.');
  583. }
  584. if (subdir != L"")
  585. {
  586. m_Prefix = L"";
  587. m_Segments.push_back(subdir);
  588. }
  589. }
  590. }
  591. else if (!SetPath(subdir))
  592. m_bEmpty = true;
  593. }
  594. break;
  595. case FZ_SERVERTYPE_SUB_FTP_VMS:
  596. {
  597. int pos1=subdir.Find( L"[" );
  598. if (pos1==-1)
  599. {
  600. DebugAssert( subdir.Right(1)!=L"]" );
  601. while ( subdir.Replace( L"..", L"." ) );
  602. }
  603. else
  604. {
  605. if (subdir.Right(1)!=L"]")
  606. DebugAssert(FALSE);
  607. subdir=subdir.Left(subdir.GetLength()-1);
  608. if (pos1)
  609. m_Prefix=subdir.Left(pos1);
  610. else
  611. m_Prefix=L"";
  612. m_Segments.clear();
  613. subdir=subdir.Mid(pos1+1);
  614. pos1=subdir.Find( L"[" );
  615. int pos2=subdir.Find( L"]" );
  616. if (pos1!=-1 || pos2!=-1)
  617. DebugAssert(FALSE);
  618. }
  619. int pos=subdir.Find( L"." );
  620. while(pos!=-1)
  621. {
  622. m_Segments.push_back(subdir.Left(pos));
  623. subdir=subdir.Mid(pos+1);
  624. pos=subdir.Find( L"." );
  625. }
  626. if (subdir!=L"")
  627. m_Segments.push_back(subdir);
  628. }
  629. break;
  630. case FZ_SERVERTYPE_SUB_FTP_WINDOWS:
  631. {
  632. subdir.Replace( L"\\", L"/" );
  633. while(subdir.Replace( L"//", L"/" ));
  634. if (subdir.GetLength() >= 2 && subdir[1] == L':')
  635. m_Segments.clear();
  636. else if (subdir[0]==L'/')
  637. {
  638. CString firstSegment;
  639. if (m_Segments.empty())
  640. firstSegment = L"C:";
  641. else
  642. firstSegment = m_Segments.front();
  643. m_Segments.clear();
  644. m_Segments.push_back(firstSegment);
  645. subdir.TrimLeft( L"/" );
  646. }
  647. subdir.TrimRight( L"/" );
  648. int pos = subdir.Find( L"/" );
  649. while(pos!=-1)
  650. {
  651. m_Segments.push_back(subdir.Left(pos));
  652. subdir=subdir.Mid(pos+1);
  653. pos=subdir.Find( L"/" );
  654. }
  655. if (subdir!=L"")
  656. m_Segments.push_back(subdir);
  657. break;
  658. }
  659. default:
  660. subdir.Replace( L"\\", L"/" );
  661. while(subdir.Replace( L"//", L"/" ));
  662. if (subdir[0]==L'/')
  663. {
  664. m_Segments.clear();
  665. subdir.TrimLeft( L"/" );
  666. }
  667. subdir.TrimRight( L"/" );
  668. int pos=subdir.Find( L"/" );
  669. while(pos!=-1)
  670. {
  671. m_Segments.push_back(subdir.Left(pos));
  672. subdir=subdir.Mid(pos+1);
  673. pos=subdir.Find( L"/" );
  674. }
  675. if (subdir!=L"")
  676. m_Segments.push_back(subdir);
  677. break;
  678. }
  679. break;
  680. case FZ_SERVERTYPE_LOCAL:
  681. {
  682. subdir.TrimRight( L"\\" );
  683. while (subdir.Replace( L"\\\\", L"\\" ));
  684. subdir.TrimLeft( L"\\" );
  685. int pos=subdir.Find( L":" );
  686. if (pos==1) //subdir is absolute path
  687. {
  688. m_Segments.clear();
  689. m_Prefix=subdir.Left(pos+1);
  690. subdir=subdir.Mid(pos+1);
  691. subdir.TrimLeft( L"\\" );
  692. if (subdir.Find( L":" )!=-1)
  693. DebugAssert(FALSE);
  694. }
  695. if (pos==-1 || pos==1)
  696. {
  697. pos=subdir.Find( L"\\" );
  698. while (pos!=-1)
  699. {
  700. m_Segments.push_back(subdir.Left(pos));
  701. subdir=subdir.Mid(pos+1);
  702. pos=subdir.Find( L"\\" );
  703. }
  704. if ( subdir!=L"" )
  705. m_Segments.push_back(subdir);
  706. }
  707. else
  708. DebugAssert(FALSE);
  709. }
  710. break;
  711. default:
  712. DebugAssert(FALSE);
  713. }
  714. }
  715. BOOL CServerPath::SetPath(CString newpath)
  716. {
  717. return SetPath(newpath, FALSE);
  718. }
  719. CString CServerPath::FormatFilename(CString fn, bool omitPath /*=false*/) const
  720. {
  721. if (m_bEmpty)
  722. return fn;
  723. if (fn == L"")
  724. return L"";
  725. CString path;
  726. tConstIter iter;
  727. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  728. {
  729. case FZ_SERVERTYPE_FTP:
  730. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  731. {
  732. case FZ_SERVERTYPE_SUB_FTP_MVS:
  733. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  734. if (omitPath && m_Prefix == L".")
  735. return fn;
  736. path = L"'";
  737. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  738. path += *iter + L".";
  739. if (m_Prefix != L".")
  740. {
  741. path.TrimRight(L'.');
  742. path += L"(" + fn + L")";
  743. }
  744. else
  745. path += fn;
  746. path += L"'";
  747. break;
  748. case FZ_SERVERTYPE_SUB_FTP_VMS:
  749. if (omitPath)
  750. return fn;
  751. path = m_Prefix + L"[";
  752. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  753. path += *iter + L".";
  754. path.TrimRight( L"." );
  755. path += L"]";
  756. path += fn;
  757. break;
  758. default:
  759. if (omitPath)
  760. return fn;
  761. if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
  762. path=L"/";
  763. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  764. path+=*iter + L"/";
  765. path += fn;
  766. break;
  767. }
  768. break;
  769. case FZ_SERVERTYPE_LOCAL:
  770. if (omitPath)
  771. return fn;
  772. path=m_Prefix;
  773. if (!m_Segments.empty())
  774. path+=L"\\";
  775. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  776. path+=*iter + L"\\";
  777. path += fn;
  778. break;
  779. default:
  780. DebugAssert(FALSE);
  781. }
  782. return path;
  783. }