Patcher.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "Patcher.h"
  2. #include <Text.h>
  3. #include "../Global/Variablen.h"
  4. #include <Globals.h>
  5. typedef UpdaterV *( *GetUpdater )( KSGClient::PatchServerClient * );
  6. // Inhalt der Patcher Klasse aus Patcher.h
  7. // Konstruktor
  8. Patcher::Patcher()
  9. : ReferenceCounter()
  10. {
  11. updater = 0;
  12. updateDll = 0;
  13. läuft = 0;
  14. }
  15. // Destruktor
  16. Patcher::~Patcher()
  17. {
  18. if( updater )
  19. updater->release();
  20. if( updateDll )
  21. FreeLibrary( updateDll );
  22. }
  23. // nicht constant
  24. bool Patcher::update( int dateiGruppe, bool *abbruch, FBalken *fortschritt, TextFeld *status, Text *zError )
  25. {
  26. if( läuft )
  27. {
  28. zError->setText( "Es kann nur ein Update zur Zeit herruntergeladen werden." );
  29. fortschritt->release();
  30. if( status )
  31. status->release();
  32. return 0;
  33. }
  34. läuft = 1;
  35. if( !updater )
  36. {
  37. if( !updateDll )
  38. updateDll = Framework::getDLLRegister()->ladeDLL( "update.dll", "data/bin/update.dll" );
  39. if( !updateDll )
  40. {
  41. updater = 0;
  42. zError->setText( "Die DLL Datei 'data/bin/update.dll' wurde nicht gefunden." );
  43. }
  44. else
  45. {
  46. GetUpdater getUpdater = (GetUpdater)GetProcAddress( updateDll, "getUpdater" );
  47. if( !getUpdater )
  48. {
  49. updater = 0;
  50. zError->setText( "Der Einstiegspunkt 'getUpdater' konnte in der DLL Datei 'data/bin/update.dll' nicht gefunden." );
  51. }
  52. else
  53. {
  54. KSGClient::PatchServerClient *patchClient = mainClient->createPatchServerClient();
  55. if( !patchClient )
  56. {
  57. updater = 0;
  58. zError->setText( mainClient->getLetzterFehler() );
  59. }
  60. else
  61. updater = getUpdater( patchClient );
  62. }
  63. }
  64. }
  65. if( !updater )
  66. {
  67. fortschritt->release();
  68. if( status )
  69. status->release();
  70. läuft = 0;
  71. return 0;
  72. }
  73. UpdateParams p;
  74. p.abbruch = abbruch;
  75. p.dateiGruppe = dateiGruppe;
  76. p.zFortschritt = fortschritt;
  77. p.zStatus = status;
  78. int ret = updater->update( &p );
  79. fortschritt->release();
  80. if( status )
  81. status->release();
  82. if( ret == 1 )
  83. zError->setText( updater->getError() );
  84. läuft = 0;
  85. return ret != 1;
  86. }
  87. // constant
  88. bool Patcher::läuftPatch() const
  89. {
  90. return läuft;
  91. }
  92. int Patcher::getDownload() const
  93. {
  94. return updater ? updater->getDownload() : 0;
  95. }