Update.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "../../Global/Initialisierung.h"
  2. #include <MausEreignis.h>
  3. #include "../../Global/Variablen.h"
  4. // Inhalt der UpdateGUI klasse aus UpdateGUI.h
  5. // Konstruktor
  6. Update::Update( FBalken *fb, int dg, std::function< void( bool ) > after )
  7. : Thread()
  8. {
  9. p = 0;
  10. this->fb = fb;
  11. updateAbbrechen = 0;
  12. this->dg = dg;
  13. this->after = after;
  14. }
  15. // Destruktor
  16. Update::~Update()
  17. {
  18. if( fb )
  19. fb->release();
  20. if( p )
  21. p->release();
  22. }
  23. // nicht constant
  24. void Update::setPatcher( Patcher *p )
  25. {
  26. this->p = p;
  27. }
  28. void Update::abbrechen()
  29. {
  30. updateAbbrechen = 1;
  31. }
  32. void Update::herunterladen()
  33. {
  34. if( isRunning() || !p )
  35. return;
  36. start();
  37. getThis();
  38. }
  39. void Update::thread()
  40. {
  41. int dgId = dg;
  42. Text err;
  43. if( !p->update( dgId, &updateAbbrechen, dynamic_cast<FBalken *>( fb->getThis() ), 0, &err ) )
  44. {
  45. updateAbbrechen = 1;
  46. if( nachLogin && nachLogin->zNachrichtenListe() )
  47. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), dynamic_cast<Text *>( err.getThis() ), new Text( "Ok" ) );
  48. }
  49. run = 0;
  50. }
  51. void Update::threadEnd()
  52. {
  53. __super::threadEnd();
  54. after( !updateAbbrechen );
  55. release();
  56. }
  57. // constant
  58. int Update::getDateiGruppe() const
  59. {
  60. return dg;
  61. }
  62. // inhalt der UpdateHandler Klasse aus UpdateGUI.h
  63. // Konstruktor
  64. UpdateHandler::UpdateHandler()
  65. : ReferenceCounter()
  66. {
  67. patcher = new Patcher();
  68. updates = new RCArray< Update >();
  69. }
  70. // Destruktor
  71. UpdateHandler::~UpdateHandler()
  72. {
  73. updates->release();
  74. patcher->release();
  75. }
  76. // privat
  77. void UpdateHandler::lock()
  78. {
  79. cs.lock();
  80. }
  81. void UpdateHandler::unlock()
  82. {
  83. cs.unlock();
  84. }
  85. // nicht constant
  86. bool UpdateHandler::add( Update *update )
  87. {
  88. lock();
  89. if( hat( update->getDateiGruppe() ) )
  90. {
  91. update->release();
  92. unlock();
  93. return 0;
  94. }
  95. int anz = updates->getEintragAnzahl();
  96. update->setPatcher( dynamic_cast<Patcher *>( patcher->getThis() ) );
  97. updates->add( update );
  98. unlock();
  99. return 1;
  100. }
  101. void UpdateHandler::remove( int dg )
  102. {
  103. lock();
  104. int anz = updates->getEintragAnzahl();
  105. for( int i = 0; i < anz; i++ )
  106. {
  107. if( updates->z( i )->getDateiGruppe() == dg )
  108. {
  109. updates->remove( i );
  110. break;
  111. }
  112. }
  113. unlock();
  114. }
  115. bool UpdateHandler::hat( int dg )
  116. {
  117. lock();
  118. bool ret = 0;
  119. int anz = updates->getEintragAnzahl();
  120. for( int i = 0; i < anz; i++ )
  121. {
  122. if( updates->z( i )->getDateiGruppe() == dg )
  123. {
  124. ret = 1;
  125. break;
  126. }
  127. }
  128. unlock();
  129. return ret;
  130. }