Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// \file graphics_skin_manager.cpp
  3. /// \author Sergey Zubkov <seZubkov@gmail.com>
  4. /// \date 04/05/2010
  5. /// Copyright
  6. ////////////////////////////////////////////////////////////////////////////////
  7. #include "graphics_skin_manager.h"
  8. #include "graphics_interfaces.h"
  9.  
  10. #include <windows.h>
  11. //! Для распаковки скинов.
  12. #include <zlib/unzip.h>
  13.  
  14. namespace est_api
  15. {
  16. namespace g_interface
  17. {
  18.     std::vector<std::wstring> skin_manager::get_list_skins()
  19.     {
  20.         std::vector<std::wstring> list_skin;
  21.         //
  22.         WIN32_FIND_DATA find_data;
  23.  
  24.         HANDLE h_file_find =
  25.             ::FindFirstFile( (this->skin_path_ + _Text("*.*")).c_str(), &find_data );
  26.        
  27.         if ( h_file_find == INVALID_HANDLE_VALUE )
  28.         {
  29.             return list_skin;
  30.         }
  31.  
  32.         // Перебираем все файлы.
  33.         do
  34.         {
  35.             if ( wcsstr(find_data.cFileName, skin_file_extention.c_str()) != NULL )
  36.             {
  37.                 list_skin.push_back(find_data.cFileName);
  38.                 //
  39.                 continue;
  40.             }
  41.         }
  42.         while ( ::FindNextFile(h_file_find, &find_data) == TRUE );
  43.        
  44.         //
  45.         FindClose(h_file_find);
  46.        
  47.         //
  48.         return list_skin;
  49.     }
  50.  
  51.     bool skin_manager::set_skin_directory(const std::wstring & skin_path)
  52.     {
  53.         this->skin_path_ = skin_path;
  54.  
  55.         // Проверка на существование директории.
  56.         return true;
  57.     }
  58.  
  59.     bool skin_manager::load_skin(const std::wstring & skin_name)
  60.     {
  61.         unsigned long file_size = 0; char * file_buff = NULL;
  62.  
  63.         this->read_file_from_skin(
  64.             L"\\zip_test.zip", L"black_skin_.json", file_size, (void**)&file_buff);
  65.         //
  66.         return false;
  67.     }
  68.  
  69.     bool skin_manager::read_file_from_skin(
  70.         const std::wstring & skin_file_name, const std::wstring & file_name,
  71.         unsigned long & file_size, void ** buffer
  72.         )
  73.     {
  74.         // Открываем Zip - архив со скином.
  75.         HZIP zip_h_file = OpenZip(skin_file_name.c_str(), NULL);
  76.  
  77.         // Не смогли открыть архив, выходим.
  78.         if ( zip_h_file == NULL )
  79.         {
  80.             return false;
  81.         }
  82.                
  83.         int index_item = 0; ZIPENTRY ze;
  84.         // Ищем нужный файл.
  85.         ZRESULT z_result = FindZipItem(
  86.             zip_h_file, file_name.c_str(), true, &index_item, &ze);
  87.  
  88.         // Не нашли нужный файл в архиве.
  89.         if ( z_result != ZR_OK )
  90.         {
  91.             return false;
  92.         }
  93.  
  94.         // Выделяем память под файл.
  95.         try
  96.         {
  97.             *buffer = (unsigned char *)new unsigned char [ze.unc_size];
  98.         }
  99.         catch(std::bad_alloc & e)
  100.         {
  101.             *buffer = NULL;
  102.             //
  103.             return false;
  104.         }
  105.  
  106.         // Копируем файл в память.
  107.         z_result = UnzipItem(zip_h_file, index_item, *buffer, ze.unc_size);
  108.  
  109.         // Зкарываем архив.
  110.         CloseZip(zip_h_file);
  111.  
  112.         return true;
  113.     }
  114.  
  115.     const std::vector<element_rectangle> & skin_converter::grid_to_rectangle(
  116.         const std::vector<element_grid> &el_grid, const long & x_size,const long & y_size
  117.         )
  118.     {
  119.         el_grid.
  120.     }
  121.  
  122. } // namespace graphics
  123. } // namespace est_api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement