1
0

MoreItems.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "main.h"
  2. #include "MoreItems.h"
  3. static const wchar_t g_noentry[] = L"No Entry";
  4. wchar_t *strFile;
  5. size_t cbFile;
  6. wchar_t *strTitle;
  7. size_t cbTitle;
  8. char *strCurtain;
  9. size_t cbCurtain;
  10. int length;
  11. int index;
  12. unsigned long starttime; // Start time in MS (0, begin of file)
  13. unsigned long endtime; // End time in MS (0, end of file)
  14. moreitems *Next; // Next Item in linked list
  15. moreitems::moreitems()
  16. : strFile(0), cbFile(0), strTitle(0), cbTitle(0),
  17. strCurtain(0), cbCurtain(0), length(0), index(0),
  18. starttime(0), endtime(0), Next(0)
  19. {
  20. }
  21. moreitems::~moreitems()
  22. {
  23. // recursive, find the _tail and remove it, work back to _head
  24. delete Next; Next = NULL;
  25. delete[] strFile; strFile=NULL;
  26. delete[] strTitle;
  27. delete[] strCurtain;
  28. }
  29. const wchar_t *moreitems::GetHiddenFilename(int index)
  30. {
  31. if (this->index == index)
  32. return strFile;
  33. if (Next == NULL)
  34. return g_noentry;
  35. return Next->GetHiddenFilename(index);
  36. }
  37. int moreitems::SetRange(int index, unsigned long start, unsigned long end)
  38. {
  39. if (this->index == index)
  40. {
  41. this->starttime = start;
  42. this->endtime = end;
  43. return 1;
  44. }
  45. if (Next == NULL)
  46. return 0;
  47. return Next->SetRange(index,start,end);
  48. }
  49. unsigned long moreitems::GetStart(int index)
  50. {
  51. if (this->index == index)
  52. {
  53. return this->starttime;
  54. }
  55. if (Next == NULL)
  56. return 0;
  57. return Next->GetStart(index);
  58. }
  59. unsigned long moreitems::GetEnd(int index)
  60. {
  61. if (this->index == index)
  62. {
  63. return this->endtime;
  64. }
  65. if (Next == NULL)
  66. return 0;
  67. return Next->GetEnd(index);
  68. }
  69. int moreitems::AddHiddenItem(const wchar_t *filename, const wchar_t *title, int length, int index, char *curtain)
  70. {
  71. // Linked list _head
  72. moreitems *additem = this;
  73. if (additem && index == 1)
  74. {
  75. // List empty
  76. // Use placeholder
  77. }
  78. else
  79. {
  80. // Found items, walk to the end
  81. while (additem && additem->Next) additem = additem->Next;
  82. if (additem)
  83. {
  84. additem->Next = new moreitems;
  85. additem = additem->Next;
  86. }
  87. }
  88. if (additem)
  89. {
  90. additem->cbFile = lstrlenW(filename) + 1;
  91. additem->strFile = new wchar_t[additem->cbFile];
  92. StringCchCopyW(additem->strFile , additem->cbFile, filename);
  93. additem->cbTitle = (int)lstrlenW(title) + 1;
  94. additem->strTitle = new wchar_t[additem->cbFile];
  95. StringCchCopyW(additem->strTitle, additem->cbTitle, title);
  96. if (curtain && *curtain)
  97. {
  98. additem->cbCurtain = (int)strlen(curtain) + 1;
  99. additem->strCurtain = new char[additem->cbCurtain];
  100. StringCchCopyA(additem->strCurtain, additem->cbCurtain, curtain);
  101. }
  102. else
  103. {
  104. additem->cbCurtain = 0;
  105. additem->strCurtain = NULL;
  106. }
  107. additem->length = length;
  108. additem->index = index;
  109. return 1;
  110. }
  111. return 0;
  112. }
  113. const char *moreitems::GetHiddenCurtain(int index)
  114. {
  115. moreitems *where = this;
  116. while ( where )
  117. {
  118. if ( where->index == index && where->cbCurtain ) return where->strCurtain;
  119. where = where->Next;
  120. }
  121. return NULL;
  122. }