Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/archive.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 #include <functional> | |
| 3 #include "filesystem.h" | |
| 4 | |
| 5 namespace foobar2000_io { | |
| 6 class archive; | |
| 7 | |
| 8 //! Callback passed to archive listing methods. \n | |
| 9 //! For backwards compatibility, this inherits with abort_callback as well. \n | |
| 10 //! When implementiong, you must override abort_callback methods redirecting them to your abort_callback. \n | |
| 11 //! It is recommended to use lambda-based archive_list helper instead of implementing this interface. | |
| 12 class NOVTABLE archive_callback : public abort_callback { | |
| 13 public: | |
| 14 virtual bool on_entry(archive * owner,const char * url,const t_filestats & p_stats,const service_ptr_t<file> & p_reader) = 0; | |
| 15 }; | |
| 16 | |
| 17 //! Interface for archive reader services. When implementing, derive from archive_impl rather than from deriving from archive directly. | |
| 18 class NOVTABLE archive : public filesystem { | |
| 19 FB2K_MAKE_SERVICE_INTERFACE(archive,filesystem); | |
| 20 public: | |
| 21 typedef std::function<void(const char* url, const t_filestats& stats, file::ptr reader) > list_func_t; | |
| 22 | |
| 23 //! Lists archive contents. \n | |
| 24 //! May be called with any path, not only path accepted by is_our_archive. \n | |
| 25 //! It is strongly recommended to use the lambda_based archive_list() helper instead of calling this directly. | |
| 26 //! @param p_reader Optional reader to use, if the caller already has one. Implementation will open the file if no reader is supplied. | |
| 27 //! @param p_want_readers Flag to tell if the callback wants a reader object for each file in the archive, or just wants to list contents. | |
| 28 virtual void archive_list(const char * p_path,const service_ptr_t<file> & p_reader,archive_callback & p_callback,bool p_want_readers) = 0; | |
| 29 | |
| 30 //! Helper implemented on top of the other archive_list, uses lambda instead of callback, avoids having to implement archive_callback. | |
| 31 void archive_list(const char * path, file::ptr, list_func_t, bool wantReaders, abort_callback&); | |
| 32 | |
| 33 //! Optional method to weed out unsupported formats prior to calling archive_list. \n | |
| 34 //! Use this to suppress calls to archive_list() to avoid spurious exceptions being thrown. \n | |
| 35 //! Implemented via archive_v2. | |
| 36 bool is_our_archive( const char * path ); | |
| 37 }; | |
| 38 | |
| 39 //! \since 1.5 | |
| 40 //! New 1.5 series API, though allowed to implement/call in earlier versions. \n | |
| 41 //! Suppresses spurious C++ exceptions on all files not recognized as archives by this instance. | |
| 42 class NOVTABLE archive_v2 : public archive { | |
| 43 FB2K_MAKE_SERVICE_INTERFACE(archive_v2, archive) | |
| 44 public: | |
| 45 | |
| 46 //! Optional method to weed out unsupported formats prior to calling archive_list. \n | |
| 47 //! Use this to suppress calls to archive_list() to avoid spurious exceptions being thrown. | |
| 48 virtual bool is_our_archive( const char * path ) = 0; | |
| 49 }; | |
| 50 | |
| 51 //! \since 1.6 | |
| 52 //! New 1.6 series API, though allowed to implement/call in earlier versions. | |
| 53 class NOVTABLE archive_v3 : public archive_v2 { | |
| 54 FB2K_MAKE_SERVICE_INTERFACE(archive_v3, archive_v2) | |
| 55 public: | |
| 56 //! Determine supported archive file types. \n | |
| 57 //! Returns a list of extensions, colon delimited, e.g.: "zip,rar,7z" | |
| 58 virtual void list_extensions(pfc::string_base & out) = 0; | |
| 59 }; | |
| 60 //! \since 2.1 | |
| 61 class NOVTABLE archive_v4 : public archive_v3 { | |
| 62 FB2K_MAKE_SERVICE_INTERFACE(archive_v4, archive_v3) | |
| 63 public: | |
| 64 virtual fb2k::arrayRef archive_list_v4( fsItemFilePtr item, file::ptr readerOptional, abort_callback & a) = 0; | |
| 65 }; | |
| 66 | |
| 67 //! Root class for archive implementations. Derive from this instead of from archive directly. | |
| 68 class NOVTABLE archive_impl : public service_multi_inherit<archive_v4, filesystem_v3> { | |
| 69 protected: | |
| 70 //do not override these | |
| 71 bool get_canonical_path(const char * path,pfc::string_base & out) override; | |
| 72 bool is_our_path(const char * path) override; | |
| 73 bool get_display_path(const char * path,pfc::string_base & out) override; | |
| 74 void remove(const char * path,abort_callback & p_abort) override; | |
| 75 void move(const char * src,const char * dst,abort_callback & p_abort) override; | |
| 76 void move_overwrite(const char* src, const char* dst, abort_callback& abort) override; | |
| 77 bool is_remote(const char * src) override; | |
| 78 bool relative_path_create(const char * file_path,const char * playlist_path,pfc::string_base & out) override; | |
| 79 bool relative_path_parse(const char * relative_path,const char * playlist_path,pfc::string_base & out) override; | |
| 80 void open(service_ptr_t<file> & p_out,const char * path, t_open_mode mode,abort_callback & p_abort) override; | |
| 81 void create_directory(const char * path,abort_callback &) override; | |
| 82 void make_directory(const char* path, abort_callback& abort, bool* didCreate = nullptr) override; | |
| 83 void list_directory(const char* p_path, directory_callback& p_out, abort_callback& p_abort) override; | |
| 84 void list_directory_ex(const char* p_path, directory_callback& p_out, unsigned listMode, abort_callback& p_abort) override; | |
| 85 void list_directory_v3(const char* path, directory_callback_v3& callback, unsigned listMode, abort_callback& p_abort) override; | |
| 86 t_filestats2 get_stats2(const char* p_path, uint32_t s2flags, abort_callback& p_abort) override; | |
| 87 virtual void get_stats(const char* p_path, t_filestats& p_stats, bool& p_is_writeable, abort_callback& p_abort) override; | |
| 88 void list_extensions(pfc::string_base & out) override { out = get_archive_type(); } | |
| 89 bool supports_content_types() override { return false; } | |
| 90 char pathSeparator() override { return '/'; } | |
| 91 void extract_filename_ext(const char * path, pfc::string_base & outFN) override; | |
| 92 bool get_display_name_short(const char* in, pfc::string_base& out) override; | |
| 93 fb2k::arrayRef archive_list_v4( fsItemFilePtr item, file::ptr readerOptional, abort_callback & a ) override; | |
| 94 protected: | |
| 95 //override these | |
| 96 virtual const char * get_archive_type()=0;//eg. "zip", must be lowercase | |
| 97 virtual t_filestats2 get_stats2_in_archive(const char * p_archive,const char * p_file,unsigned s2flags,abort_callback & p_abort) = 0; | |
| 98 virtual void open_archive(service_ptr_t<file> & p_out,const char * archive,const char * file, abort_callback & p_abort) = 0;//opens for reading | |
| 99 public: | |
| 100 //override these | |
| 101 // virtual void archive_list(const char * path,const service_ptr_t<file> & p_reader,archive_callback & p_out,bool p_want_readers) = 0; | |
| 102 // virtual bool is_our_archive( const char * path ) = 0; | |
| 103 | |
| 104 static bool g_is_unpack_path(const char * path); | |
| 105 static bool g_parse_unpack_path(const char * path,pfc::string_base & archive,pfc::string_base & file); | |
| 106 static bool g_parse_unpack_path_ex(const char * path,pfc::string_base & archive,pfc::string_base & file, pfc::string_base & type); | |
| 107 static void g_make_unpack_path(pfc::string_base & path,const char * archive,const char * file,const char * type); | |
| 108 void make_unpack_path(pfc::string_base & path,const char * archive,const char * file); | |
| 109 | |
| 110 | |
| 111 }; | |
| 112 | |
| 113 template<typename T> | |
| 114 class archive_factory_t : public service_factory_single_t<T> {}; | |
| 115 } |
