Patcher.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #include "Patcher.h"
  2. #include <Datei.h>
  3. #include <Text.h>
  4. #include <InitDatei.h>
  5. #include <Text.h>
  6. #include <GSLDateiV.h>
  7. typedef UpdaterV *( *GetUpdater )( KSGClient::PatchServerClient * );
  8. typedef GSL::GSLDateiV *( *GetGSLDatei )( );
  9. // Inhalt der Patcher Klasse aus Patcher.h
  10. // Konstruktor
  11. Patcher::Patcher( FBalken *fortschritt, TextFeld *status, Knopf *play, bool *close, KSGClient::PatchServerClient *client )
  12. : Thread()
  13. {
  14. if( !client )
  15. {
  16. updater = 0;
  17. MessageBox( 0, "Es steht kein Patch Client zur Verfügung.", "Fehler", MB_ICONERROR );
  18. }
  19. else
  20. {
  21. // Dll Laden
  22. updateDll = LoadLibrary( "data/bin/update.dll" );
  23. if( !updateDll )
  24. {
  25. updater = 0;
  26. MessageBox( 0, "Die DLL Datei 'data/bin/update.dll' wurde nicht gefunden.", "Fehler", MB_ICONERROR );
  27. }
  28. else
  29. {
  30. GetUpdater getUpdater = (GetUpdater)GetProcAddress( updateDll, "getUpdater" );
  31. if( !getUpdater )
  32. {
  33. updater = 0;
  34. MessageBox( 0, "Der Einstiegspunkt 'getUpdater' konnte in der DLL Datei 'data/bin/update.dll' nicht gefunden.", "Fehler", MB_ICONERROR );
  35. }
  36. else
  37. updater = getUpdater( client );
  38. }
  39. if( !updater )
  40. client->release();
  41. }
  42. // Initialisierung
  43. this->fortschritt = fortschritt;
  44. this->status = status;
  45. this->play = play;
  46. this->close = close;
  47. ret = 0;
  48. }
  49. // Destruktor
  50. Patcher::~Patcher()
  51. {
  52. if( run )
  53. {
  54. *close = 1;
  55. warteAufPatch( 5000 );
  56. }
  57. if( run )
  58. ende();
  59. fortschritt->release();
  60. status->release();
  61. play->release();
  62. if( updater )
  63. updater->release();
  64. FreeLibrary( updateDll );
  65. }
  66. // nicht constant
  67. void Patcher::startPatch()
  68. {
  69. start();
  70. }
  71. void Patcher::thread()
  72. {
  73. if( !updater )
  74. {
  75. status->lockZeichnung();
  76. status->setText( "Es ist ein schwerer Fehler aufgetreten!" );
  77. status->unlockZeichnung();
  78. run = 0;
  79. return;
  80. }
  81. status->lockZeichnung();
  82. status->setText( "Suche nach Updates . . ." );
  83. status->unlockZeichnung();
  84. Text dgPfad;
  85. int gruppe = updater->getNextDateiGruppe( &dgPfad ); // Nächste Dateigruppe die geupdatet werden muss
  86. while( gruppe )
  87. {
  88. if( gruppe == -1 )
  89. { // error
  90. status->lockZeichnung();
  91. status->setText( "Es ist ein schwerer Fehler aufgetreten!" );
  92. status->unlockZeichnung();
  93. MessageBox( 0, updater->getError(), "Fehler", MB_ICONERROR );
  94. run = 0;
  95. return;
  96. }
  97. bool clientGruppe = !dgPfad.getLength();
  98. if( !clientGruppe )
  99. { // Das Spiel kann bereits gestartet werden
  100. play->addStyle( Knopf::Style::Sichtbar );
  101. ret = 2;
  102. }
  103. status->lockZeichnung();
  104. status->setText( "Update für '" );
  105. if( !clientGruppe )
  106. status->zText()->append( dgPfad.getText() );
  107. else
  108. status->zText()->append( "Client" );
  109. status->zText()->append( "'. . ." );
  110. status->unlockZeichnung();
  111. UpdateParams params;
  112. params.abbruch = close;
  113. params.dateiGruppe = gruppe;
  114. params.zFortschritt = fortschritt;
  115. params.zStatus = 0;
  116. int res = updater->update( &params );
  117. if( res == 3 )
  118. { // es gibt Dateien, die der Patcher (wegen momentaner Benutzung) nicht pätchen konnte
  119. status->lockZeichnung();
  120. status->setText( "Klicke auf Play, um die verbleibenen Änderungen zu übernehmen." );
  121. status->unlockZeichnung();
  122. play->addStyle( Knopf::Style::Sichtbar );
  123. ret = 1;
  124. run = 0;
  125. return;
  126. }
  127. if( res == 2 )
  128. break;
  129. if( res == 1 )
  130. MessageBox( 0, updater->getError(), "Fehler", MB_ICONERROR );
  131. status->lockZeichnung();
  132. status->setText( "Suche nach Updates . . ." );
  133. status->unlockZeichnung();
  134. gruppe = updater->getNextDateiGruppe( &dgPfad );
  135. }
  136. status->lockZeichnung();
  137. status->setText( "Alle ausgewählten Dateien sind aktuell." );
  138. status->unlockZeichnung();
  139. play->addStyle( Knopf::Style::Sichtbar );
  140. ret = 2;
  141. HMODULE sDll = LoadLibrary( "data/bin/GSL.dll" );
  142. if( sDll )
  143. {
  144. GetGSLDatei getGSLDatei = (GetGSLDatei)GetProcAddress( sDll, "getGSLDatei" );
  145. if( getGSLDatei )
  146. {
  147. GSL::GSLDateiV *sDatei = getGSLDatei();
  148. sDatei->setDatei( "data/sounds/popup.gsl" );
  149. sDatei->leseDaten();
  150. GSL::GSLSoundV *sound = sDatei->getSound( "info.wav" );
  151. sDatei->release();
  152. sound->setVolume( 0xFFFF, 0xFFFF );
  153. sound->playSound();
  154. sound->warteAufSound( 3000 );
  155. sound->stopSound();
  156. sound->release();
  157. }
  158. FreeLibrary( sDll );
  159. }
  160. run = 0;
  161. }
  162. // constant
  163. bool Patcher::läuftPatch() const
  164. {
  165. return run;
  166. }
  167. int Patcher::getReturn() const
  168. {
  169. return ret;
  170. }
  171. void Patcher::warteAufPatch( int zeit )
  172. {
  173. warteAufThread( zeit );
  174. }
  175. int Patcher::getDownload() const
  176. {
  177. return updater ? updater->getDownload() : 0;
  178. }