Internet Cache.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /******************************************************************************/
  2. struct InternetCache
  3. {
  4. struct SrcFile
  5. {
  6. C PakFile *pf; // from Pak File
  7. DataSource *ds; // from Data Source
  8. void clear() {pf=null; ds=null;}
  9. SrcFile() {clear();}
  10. };
  11. // manage
  12. void del (); // delete manually
  13. void create(C Str &db_name, const_mem_addr Threads *threads=null, const_mem_addr Cipher *cipher=null, COMPRESS_TYPE compress=COMPRESS_LZ4, Int image_mip_maps=-1); // create, 'db_name'=file name where the database will be located, 'threads'=worker threads that will import the images (if null then importing will be done on the main thread), 'cipher'=database file encryption, 'compress'=database file compression, 'image_mip_maps'=number of mip maps to be created when importing images (-1..Inf, -1=keep original value, 0=autodetect)
  14. // operations
  15. ImagePtr getImage(C Str &url ); // get image from the internet, image may be empty at start if it's not yet downloaded, it will be automatically updated once it completes downloading
  16. Bool getFile (C Str &url, SrcFile &file); // get file from the internet, 'file' will contain a way to access this file, false is returned if file is not yet available and will be downloaded
  17. void changed (C Str &url ); // notify the cache that the file on the internet has just been changed and needs updating
  18. void flush ( ); // flush updated files to disk, warning: this may update the Pak file, because of which existing file references 'SrcFile' obtained through 'getFile' will become invalid
  19. ~InternetCache() {del();}
  20. InternetCache() {_image_mip_maps=0; _compress=COMPRESS_NONE; _threads=null;}
  21. #if !EE_PRIVATE
  22. private:
  23. #endif
  24. struct ImportImage : SrcFile
  25. {
  26. Bool done; // if finished importing
  27. ImagePtr image_ptr; // image into which import
  28. Image image_temp; // temp image which will have the data
  29. ImportImage() {done=false;}
  30. };
  31. const_mem_addr struct Downloaded : PakFileData
  32. {
  33. Mems<Byte> file_data;
  34. };
  35. COMPRESS_TYPE _compress;
  36. Int _image_mip_maps;
  37. Threads *_threads;
  38. Pak _pak;
  39. Memb<Downloaded> _downloaded; // use 'Memb' to have const_mem_addr needed for threads and pointing to 'data'
  40. Download _downloading[6];
  41. Memc<Str> _to_download, _verified, _to_verify;
  42. Memx<ImportImage> _import_images; // use 'Memx' to have const_mem_addr needed for threads
  43. #if EE_PRIVATE
  44. Bool busy ()C;
  45. void enable();
  46. void update();
  47. void import(ImportImage &ii);
  48. #endif
  49. };
  50. /******************************************************************************/