structures.cpp 2.9 KB

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