PathFunctions.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "stdafx.h"
  15. #include "pathfunctions.h"
  16. void PathRemoveArgs(CString &path)
  17. {
  18. path.TrimLeft( _T(" ") );
  19. path.TrimRight( _T(" ") );
  20. if (path==_MPT(""))
  21. return;
  22. BOOL quoted=FALSE;
  23. if (path[0]==_MPT('\"'))
  24. quoted=TRUE;
  25. int pos=path.ReverseFind(_MPT('\\'));
  26. if (pos==-1)
  27. pos=quoted?1:0;
  28. int i;
  29. for (i=pos;i<path.GetLength();i++)
  30. {
  31. if (path[i]==_MPT('\"'))
  32. break;
  33. if (path[i]==_MPT(' ') && !quoted)
  34. break;
  35. }
  36. path = path.Left(i+1);
  37. path.TrimRight(_MPT(' '));
  38. }
  39. void PathUnquoteSpaces(CString &path)
  40. {
  41. int pos;
  42. while ((pos=path.Find(_MPT('\"')))!=-1)
  43. path.SetAt(pos,_MPT(' '));
  44. path.TrimLeft( _T(" ") );
  45. path.TrimRight( _T(" ") );
  46. }
  47. CString PathFindExtension(CString path)
  48. {
  49. int pos=path.ReverseFind(_MPT('.'));
  50. if (pos==-1)
  51. return _MPT("");
  52. return path.Mid(pos);
  53. }
  54. void PathRemoveFileSpec(CString &path)
  55. {
  56. CFileStatus64 status;
  57. if (GetStatus64(path,status))
  58. {
  59. if (status.m_attribute&0x10)
  60. {
  61. path.TrimRight( _T("\\") );
  62. path=path+_MPT("\\");
  63. return;
  64. }
  65. else
  66. path.TrimRight( _T("\\") );
  67. }
  68. if (path.Right(1)!=_MPT("\\"))
  69. {
  70. path.TrimRight( _T("\\") );
  71. int pos=path.ReverseFind(_MPT('\\'));
  72. if (pos==-1)
  73. path=_MPT("");
  74. else
  75. path=path.Left(pos+1);
  76. }
  77. }
  78. CString PathAppend(CString path, LPCTSTR sub)
  79. {
  80. ASSERT(sub);
  81. if (path.Right(1) != _T("\\"))
  82. path += _T("\\");
  83. path += sub;
  84. return path;
  85. }