Patcher.cpp 5.2 KB

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