structures.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. AFX_COMDAT int _afxInitDataA[] = { -1, 0, 0, 0 };
  16. AFX_COMDAT CStringDataA* _afxDataNilA = (CStringDataA*)&_afxInitDataA;
  17. AFX_COMDAT LPCSTR _afxPchNilA = (LPCSTR)(((BYTE*)&_afxInitDataA)+sizeof(CStringDataA));
  18. t_directory::t_directory()
  19. {
  20. direntry=0;
  21. num=0;
  22. #ifndef MPEXT_NO_CACHE
  23. bCached=FALSE;
  24. #endif
  25. }
  26. t_directory::~t_directory()
  27. {
  28. if (direntry)
  29. delete [] direntry;
  30. }
  31. t_directory& t_directory::operator=(const t_directory &a)
  32. {
  33. if (&a==this)
  34. return *this;
  35. if (direntry)
  36. delete [] direntry;
  37. direntry=0;
  38. path=a.path;
  39. num=a.num;
  40. server=a.server;
  41. if (num)
  42. direntry=new t_directory::t_direntry[num];
  43. for (int i=0;i<num;i++)
  44. direntry[i]=a.direntry[i];
  45. #ifndef MPEXT_NO_CACHE
  46. bCached=a.bCached;
  47. #endif
  48. return *this;
  49. }
  50. t_directory::t_direntry::t_direntry()
  51. {
  52. dir=FALSE;
  53. size=0;
  54. bUnsure=TRUE;
  55. bLink=FALSE;
  56. EntryTime=CTime::GetCurrentTime();
  57. }
  58. t_directory::t_direntry::t_date::t_date()
  59. {
  60. year=month=day=hour=minute=second=0;
  61. hasdate=hastime=hasseconds=utc=FALSE;
  62. }
  63. void t_directory::Merge(const t_directory &directory, CTime MergeTime)
  64. {
  65. std::list<t_direntry> AddList;
  66. if (!num)
  67. {
  68. if (!directory.num)
  69. return;
  70. for (int i=0; i<directory.num; i++)
  71. if (directory.direntry[i].EntryTime>=MergeTime)
  72. AddList.push_back(directory.direntry[i]);
  73. }
  74. else
  75. {
  76. ASSERT(num>0 && directory.num>=0);
  77. int i;
  78. CTime oldestTime=CTime::GetCurrentTime();
  79. for (i=0; i<num; i++)
  80. if (direntry[i].EntryTime<oldestTime)
  81. oldestTime=direntry[i].EntryTime;
  82. for (i=0;i<directory.num;i++)
  83. {
  84. int j;
  85. for (j=0; j<num; j++)
  86. {
  87. if (directory.direntry[i].lName==direntry[j].lName)
  88. {
  89. if (directory.direntry[i].dir != direntry[j].dir)
  90. break;
  91. if (directory.direntry[i].EntryTime > direntry[j].EntryTime)
  92. direntry[j]=directory.direntry[i];
  93. break;
  94. }
  95. }
  96. if (j==num && directory.direntry[i].EntryTime>=oldestTime)
  97. AddList.push_back(directory.direntry[i]);
  98. }
  99. }
  100. if (AddList.empty())
  101. return;
  102. t_direntry *tmp=direntry;
  103. direntry=new t_direntry[num + AddList.size()];
  104. int i;
  105. for (i=0; i<num; i++)
  106. direntry[i] = tmp[i];
  107. for (std::list<t_direntry>::iterator iter=AddList.begin(); iter!=AddList.end(); iter++, i++)
  108. direntry[i] = *iter;
  109. num+=AddList.size();
  110. delete [] tmp;
  111. }