Import.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include <Bild.h>
  3. #include <Text.h>
  4. #include <Fenster.h>
  5. #include <DateiSystem.h>
  6. #include <Schrift.h>
  7. #include <Fortschritt.h>
  8. #pragma comment( lib, "gdiplus.lib" )
  9. using namespace Framework;
  10. Bild *ladeBild( Text *zPfad )
  11. {
  12. Text *txt = zPfad->getTeilText( zPfad->positionVon( '.', zPfad->anzahlVon( '.' ) - 1 ) );
  13. if( !( txt->istGleich( ".bmp" ) || txt->istGleich( ".jpg" ) || txt->istGleich( ".gif" ) || txt->istGleich( ".png" ) ) )
  14. {
  15. WMessageBox( 0, new Text( "Error" ), new Text( "Die Angegebene Datei ist keine gueltige Bilddatei!" ), MB_ICONERROR );
  16. txt->release();
  17. return 0;
  18. }
  19. txt->release();
  20. wchar_t *name = new wchar_t[ zPfad->getLength() + 1 ];
  21. for( int i = 0; i < zPfad->getLength(); i++ )
  22. name[ i ] = (wchar_t)zPfad->getText()[ i ];
  23. name[ zPfad->getLength() ] = '\0';
  24. Gdiplus::Bitmap bitmap( name );
  25. Gdiplus::Color pix;
  26. delete[]name;
  27. Bild *ret = new Bild();
  28. ret->neuBild( bitmap.GetWidth(), bitmap.GetHeight(), 0 );
  29. int *buff = ret->getBuffer();
  30. for( unsigned int i = 0; i < bitmap.GetWidth() * bitmap.GetHeight(); i++ )
  31. {
  32. bitmap.GetPixel( i % bitmap.GetWidth(), i / bitmap.GetWidth(), &pix );
  33. buff[ i ] = pix.GetValue();
  34. }
  35. return ret;
  36. }
  37. int countVerzeichnis( Text *pfad )
  38. {
  39. int ret = 0;
  40. WIN32_FIND_DATA FData;
  41. pfad->ersetzen( '/', '\\' );
  42. if( pfad->positionVon( '\\', pfad->anzahlVon( '\\' ) - 1 ) != pfad->getLength() - 1 )
  43. pfad->append( "\\" );
  44. pfad->append( "*" );
  45. HANDLE hSearch = FindFirstFile( pfad->getText(), &FData );
  46. pfad->remove( pfad->getLength() - 1 );
  47. BOOL MoreFiles = FALSE;
  48. int cnt_dir = 0, cnt_file = 0;
  49. if( hSearch == INVALID_HANDLE_VALUE )
  50. return 0;
  51. do
  52. {
  53. Text *txt = new Text( FData.cFileName );
  54. if( FData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
  55. {
  56. if( !( txt->istGleich( ".." ) || txt->istGleich( "." ) ) )
  57. {
  58. txt->insert( 0, pfad->getText() );
  59. ret += countVerzeichnis( txt->getThis() );
  60. }
  61. }
  62. else
  63. {
  64. txt->insert( 0, pfad->getText() );
  65. Text *end = txt->getTeilText( txt->positionVon( '.', txt->anzahlVon( '.' ) - 1 ) );
  66. if( end->istGleich( ".bmp" ) || end->istGleich( ".jpg" ) || end->istGleich( ".gif" ) || end->istGleich( ".png" ) )
  67. ret++;
  68. end->release();
  69. }
  70. txt->release();
  71. MoreFiles = FindNextFile( hSearch, &FData );
  72. } while( MoreFiles );
  73. FindClose( hSearch );
  74. pfad->release();
  75. return ret;
  76. }
  77. void ladeVerzeichnis( Text *pfad, Schrift *zSchrift, LTDBDatei *zDatei, FBalken *fb1, FBalken *fb2 )
  78. {
  79. WIN32_FIND_DATA FData;
  80. pfad->ersetzen( '/', '\\' );
  81. if( pfad->positionVon( '\\', pfad->anzahlVon( '\\' ) - 1 ) != pfad->getLength() - 1 )
  82. pfad->append( "\\" );
  83. pfad->append( "*" );
  84. HANDLE hSearch = FindFirstFile( pfad->getText(), &FData );
  85. pfad->remove( pfad->getLength() - 1 );
  86. BOOL MoreFiles = FALSE;
  87. int cnt_dir = 0, cnt_file = 0;
  88. if( hSearch == INVALID_HANDLE_VALUE )
  89. return;
  90. do
  91. {
  92. Text *txt = new Text( FData.cFileName );
  93. if( FData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
  94. {
  95. if( !( txt->istGleich( ".." ) || txt->istGleich( "." ) ) )
  96. {
  97. txt->insert( 0, pfad->getText() );
  98. ladeVerzeichnis( txt->getThis(), zSchrift, zDatei, fb1, fb2 );
  99. }
  100. }
  101. else
  102. {
  103. txt->insert( 0, pfad->getText() );
  104. Text *end = txt->getTeilText( txt->positionVon( '.', txt->anzahlVon( '.' ) - 1 ) );
  105. if( end->istGleich( ".bmp" ) || end->istGleich( ".jpg" ) || end->istGleich( ".gif" ) || end->istGleich( ".png" ) )
  106. {
  107. zDatei->speichern( fb1, ladeBild( txt ), txt->getTeilText( txt->positionVon( '\\', txt->anzahlVon( '\\' ) - 1 ) + 1 ) );
  108. fb2->aktionPlus();
  109. }
  110. end->release();
  111. }
  112. txt->release();
  113. MoreFiles = FindNextFile( hSearch, &FData );
  114. } while( MoreFiles );
  115. FindClose( hSearch );
  116. pfad->release();
  117. }