31 PFC_DECLARE_EXCEPTION(exception_io_data_truncation, exception_io_data,
"Unsupported format or corrupted file");
35 PFC_DECLARE_EXCEPTION(exception_io_object_is_remote, exception_io,
"This operation is not supported on remote objects");
51 PFC_DECLARE_EXCEPTION(exception_io_no_data, exception_io,
"The process receiving or sending data has terminated");
55 PFC_DECLARE_EXCEPTION(exception_io_write_protected, exception_io_denied,
"The media is write protected");
84 #define WIN32_IO_OP(X) {SetLastError(NO_ERROR); if (!(X)) exception_io_from_win32(GetLastError());} 109 virtual t_filesize skip(t_filesize p_bytes,
abort_callback & p_abort);
113 virtual void skip_object(t_filesize p_bytes,
abort_callback & p_abort);
118 template<
typename T>
inline void read_object_t(
T& p_object,
abort_callback & p_abort) {pfc::assert_raw_type<T>(); read_object(&p_object,
sizeof(p_object),p_abort);}
144 template<
typename t_outArray>
146 pfc::assert_raw_type<typename t_outArray::t_item>();
147 const t_size itemWidth =
sizeof(
typename t_outArray::t_item);
148 out.set_size(pfc::max_t<t_size>(1,256 / itemWidth));
t_size done = 0;
150 t_size delta = out.get_size() - done;
151 t_size delta2 =
read(out.get_ptr() + done, delta * itemWidth, abort ) / itemWidth;
153 if (delta2 != delta)
break;
154 out.set_size(out.get_size() << 1);
180 template<
typename T>
inline void write_object_t(
const T & p_object,
abort_callback & p_abort) {pfc::assert_raw_type<T>(); write_object(&p_object,
sizeof(p_object),p_abort);}
191 void write_string(
const char * p_string,
abort_callback & p_abort);
198 void write_string_raw(
const char * p_string,
abort_callback & p_abort);
214 seek_from_beginning = 0,
216 seek_from_current = 1,
234 virtual void resize(t_filesize p_size,
abort_callback & p_abort) = 0;
251 virtual bool can_seek() = 0;
274 virtual bool is_remote() = 0;
299 void ensure_seekable();
319 t_filesize skip_seek(t_filesize p_bytes,
abort_callback & p_abort);
331 virtual bool get_static_info(
class file_info & p_out) = 0;
333 virtual bool is_dynamic_info_enabled()=0;
335 virtual bool get_dynamic_info(
class file_info & p_out) = 0;
342 virtual size_t get_cache_block_size() = 0;
343 virtual void suggest_grow_cache(
size_t suggestSize) = 0;
348 static void g_decodeInitCache(file::ptr & theFile,
abort_callback & abort,
size_t blockSize);
367 void seek(t_filesize p_position,
abort_callback & p_abort) {
throw exception_io_object_not_seekable();}
384 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(
filesystem);
396 virtual bool get_canonical_path(
const char * p_path,
pfc::string_base & p_out)=0;
397 virtual bool is_our_path(
const char * p_path)=0;
398 virtual bool get_display_path(
const char * p_path,
pfc::string_base & p_out)=0;
401 virtual void remove(
const char * p_path,
abort_callback & p_abort)=0;
402 virtual void move(
const char * p_src,
const char * p_dst,
abort_callback & p_abort)=0;
404 virtual bool is_remote(
const char * p_src) = 0;
413 virtual void create_directory(
const char * p_path,
abort_callback & p_abort) = 0;
419 virtual bool supports_content_types() = 0;
428 static filesystem::ptr g_get_interface(
const char * path);
429 static bool g_is_remote(
const char * p_path);
430 static bool g_is_recognized_and_remote(
const char * p_path);
431 static bool g_is_remote_safe(
const char * p_path) {
return g_is_recognized_and_remote(p_path);}
432 static bool g_is_remote_or_unrecognized(
const char * p_path);
433 static bool g_is_recognized_path(
const char * p_path);
442 static bool g_exists(
const char * p_path,
abort_callback & p_abort);
443 static bool g_exists_writeable(
const char * p_path,
abort_callback & p_abort);
445 static void g_remove(
const char * p_path,
abort_callback & p_abort);
447 static void g_remove_timeout(
const char * p_path,
double p_timeout,
abort_callback & p_abort);
449 static void g_move(
const char * p_src,
const char * p_dst,
abort_callback & p_abort);
451 static void g_move_timeout(
const char * p_src,
const char * p_dst,
double p_timeout,
abort_callback & p_abort);
453 static void g_link(
const char * p_src,
const char * p_dst,
abort_callback & p_abort);
454 static void g_link_timeout(
const char * p_src,
const char * p_dst,
double p_timeout,
abort_callback & p_abort);
456 static void g_copy(
const char * p_src,
const char * p_dst,
abort_callback & p_abort);
457 static void g_copy_timeout(
const char * p_src,
const char * p_dst,
double p_timeout,
abort_callback & p_abort);
458 static void g_copy_directory(
const char * p_src,
const char * p_dst,
abort_callback & p_abort);
460 static bool g_relative_path_create(
const char * p_file_path,
const char * p_playlist_path,
pfc::string_base & out);
461 static bool g_relative_path_parse(
const char * p_relative_path,
const char * p_playlist_path,
pfc::string_base & out);
463 static void g_create_directory(
const char * p_path,
abort_callback & p_abort);
466 static FILE * streamio_open(
const char * p_path,
const char * p_flags);
470 static file::ptr g_open_tempmem();
474 static bool g_is_valid_directory(
const char * path,
abort_callback & p_abort);
475 static bool g_is_empty_directory(
const char * path,
abort_callback & p_abort);
477 void remove_object_recur(
const char * path,
abort_callback & abort);
478 void remove_directory_content(
const char * path,
abort_callback & abort);
479 static void g_remove_object_recur(
const char * path,
abort_callback & abort);
480 static void g_remove_object_recur_timeout(
const char * path,
double timeout,
abort_callback & abort);
483 void copy_directory(
const char * p_src,
const char * p_dst,
abort_callback & p_abort);
531 bool is_our_path(
const char * path);
534 void move(
const char * src,
const char * dst,
abort_callback & p_abort);
535 bool is_remote(
const char * src);
536 bool relative_path_create(
const char * file_path,
const char * playlist_path,
pfc::string_base & out);
537 bool relative_path_parse(
const char * relative_path,
const char * playlist_path,
pfc::string_base & out);
544 virtual const char * get_archive_type()=0;
552 static bool g_is_unpack_path(
const char * path);
555 static void g_make_unpack_path(
pfc::string_base & path,
const char * archive,
const char * file,
const char * type);
556 void make_unpack_path(
pfc::string_base & path,
const char * archive,
const char * file);
569 return *
reinterpret_cast<t_filetimestamp*
>(&ft);
590 template<
typename t_list>
593 directory_callback_retrieveList(t_list & p_list,
bool p_getFiles,
bool p_getSubDirectories) : m_list(p_list), m_getFiles(p_getFiles), m_getSubDirectories(p_getSubDirectories) {}
596 if (p_is_subdirectory ? m_getSubDirectories : m_getFiles) {
597 m_list.add_item(p_url);
606 template<
typename t_list>
612 if (p_is_subdirectory) m_directories += p_url;
613 else m_files += p_url;
625 try { owner->
list_directory(path,*
this,p_abort); }
catch(exception_io) {}
627 m_list.add_item(path);
635 template<
typename t_list>
640 template<
typename t_list>
645 template<
typename t_list>
650 template<
typename t_list>
665 return temp.toString();
671 return temp.toString();
676 bool matchProtocol(
const char * fullString,
const char * protocolName);
void read(const service_ptr_t< file > &p_file, abort_callback &p_abort, pfc::string_base &p_out, bool &is_utf8)
void write_string_nullterm(const char *p_string, abort_callback &p_abort)
t_filesize get_size(HANDLE p_handle)
bool matchContentType(const char *fullString, const char *ourType)
service_ptr_t< file > file_ptr
static void listFilesRecur(const char *p_path, t_list &p_out, abort_callback &p_abort)
t_seek_mode
Seeking mode constants. Note: these are purposedly defined to same values as standard C SEEK_* consta...
virtual void on_idle(abort_callback &p_abort)
Optional, called by owner thread before sleeping.
t_int64 t_sfilesize
Type used for file size related variables when a signed value is needed.
t_filesize m_size
Size of the file.
void set_eof(abort_callback &p_abort)
Truncates the file at current read/write cursor position.
const char * stringToPtr(T const &val)
t_filetimestamp filetimestamp_from_system_timer()
A class providing abstraction for an open file object, with reading/writing/seeking methods...
static const t_filetimestamp filetimestamp_1second_increment
PFC_NORETURN void win32_file_write_failure(DWORD p_code, const char *path)
Opens an existing file for writing; if the file does not exist, the operation will fail...
This class is used to signal underlying worker code whether user has decided to abort a potentially t...
void seek(HANDLE p_handle, t_sfilesize p_position, file::t_seek_mode p_mode)
bool get_content_type(pfc::string_base &p_out)
virtual bool relative_path_create(const char *file_path, const char *playlist_path, pfc::string_base &out)
pfc::string_simple m_path
static bool g_is_remote_safe(const char *p_path)
static void g_get_canonical_path(const char *path, pfc::string_base &out)
const char * get_item(t_size n) const
PFC_NORETURN void exception_io_from_win32(DWORD p_code)
bool extract_native_path_ex(const char *p_fspath, pfc::string_base &p_native)
bool operator==(const t_filestats ¶m) const
int compare(t1 const &p1, t2 const &p2)
t_filesize get_position(abort_callback &p_abort)
pfc::string getPathDisplay(const T &source)
bool _extract_native_path_ptr(const char *&p_fspath)
void read_bendian_t(T &p_object, abort_callback &p_abort)
Helper template built around read_object. Reads single raw object from the stream; corrects byte orde...
t_size read(void *p_buffer, t_size p_bytes, abort_callback &p_abort)
const char * operator[](t_size n) const
void order_native_to_le_t(T ¶m)
static int sortfunc(const pfc::rcptr_t< const t_entry > &p1, const pfc::rcptr_t< const t_entry > &p2)
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
void check() const
Checks if user has requested the operation to be aborted, and throws exception_aborted if so...
static void listDirectories(const char *p_path, t_list &p_out, abort_callback &p_abort)
bool is_native_filesystem(const char *p_fspath)
static void g_open_read(service_ptr_t< file > &p_out, const char *path, abort_callback &p_abort)
static void g_open_timeout(service_ptr_t< file > &p_out, const char *p_path, t_open_mode p_mode, double p_timeout, abort_callback &p_abort)
Attempts to open file at specified path; if the operation fails with sharing violation error...
void order_be_to_native_t(T ¶m)
Extension for cached file access - allows callers to know that they're dealing with a cache layer...
directory_callback_retrieveListRecur(t_list &p_list)
PFC_DECLARE_EXCEPTION(exception_aborted, pfc::exception,"User abort")
Extension for shoutcast dynamic metadata handling.
directory_callback_retrieveList(t_list &p_list, bool p_getFiles, bool p_getSubDirectories)
static const t_filestats filestats_invalid
Invalid/unknown file stats constant. See: t_filestats.
t_open_mode
Enumeration specifying how to open a file. See: filesystem::open(), filesystem::g_open().
file_readonly_t< file > file_readonly
file_ptr fileOpenWriteNew(const char *p_path, abort_callback &p_abort, double p_timeout=0)
virtual bool is_in_memory()
Hint, returns whether the file is already fully buffered into memory.
Generic interface to read data from a nonseekable stream. Also see: stream_writer, file. Error handling: all methods may throw exception_io or one of derivatives on failure; exception_aborted when abort_callback is signaled.
pfc::list_t< pfc::rcptr_t< t_entry > > m_data
Interface for archive reader services. When implementing, derive from archive_impl rather than from d...
static void g_list_directory(const char *p_path, directory_callback &p_out, abort_callback &p_abort)
const t_filetimestamp filetimestamp_invalid
Invalid/unknown file timestamp constant. Also see: t_filetimestamp.
Contains various I/O related structures and interfaces.
Main interface class for information about some playable object.
void read_lendian_t(T &p_object, abort_callback &p_abort)
Helper template built around read_object. Reads single raw object from the stream; corrects byte orde...
t_filesize get_size(abort_callback &p_abort)
void order_le_to_native_t(T ¶m)
string_simple_t< char > string_simple
const t_filestats & get_item_stats(t_size n) const
string8_fastalloc string_formatter
bool on_entry(filesystem *p_owner, abort_callback &p_abort, const char *p_url, bool p_is_subdirectory, const t_filestats &p_stats)
t_entry(const char *p_path, const t_filestats &p_stats)
bool matchProtocol(const char *fullString, const char *protocolName)
void seek(t_filesize p_position, abort_callback &p_abort)
Generic interface to write data to a nonseekable stream. Also see: stream_reader, file...
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
t_filetimestamp m_timestamp
Time of last file modification.
bool extract_native_path(const char *p_fspath, pfc::string_base &p_native)
Opens an existing file for reading; if the file does not exist, the operation will fail...
void write(const void *p_buffer, t_size p_bytes, abort_callback &p_abort)
void purgeOldFiles(const char *directory, t_filetimestamp period, abort_callback &abort)
Root class for archive implementations. Derive from this instead of from archive directly.
bool on_entry(filesystem *owner, abort_callback &p_abort, const char *path, bool isSubdir, const t_filestats &)
void write(const service_ptr_t< file > &p_file, abort_callback &p_abort, const char *p_string, bool is_utf8)
void generate_temp_location_for_file(pfc::string_base &p_out, const char *p_origpath, const char *p_extension, const char *p_magic)
void read_till_eof(t_outArray &out, abort_callback &abort)
virtual bool relative_path_parse(const char *relative_path, const char *playlist_path, pfc::string_base &out)
void substituteProtocol(pfc::string_base &out, const char *fullString, const char *protocolName)
void resize(t_filesize p_size, abort_callback &p_abort)
Entrypoint service for all filesystem operations. Implementation: standard implementations for local ...
void write_lendian_t(const T &p_object, abort_callback &p_abort)
Helper template. Writes single raw object to the stream; corrects byte order assuming stream uses lit...
t_uint64 t_filetimestamp
Type used for file timestamp related variables. 64-bit value representing the number of 100-nanosecon...
virtual void list_directory(const char *p_path, directory_callback &p_out, abort_callback &p_abort)=0
bool on_entry(filesystem *p_owner, abort_callback &p_abort, const char *p_url, bool p_is_subdirectory, const t_filestats &p_stats)
bool operator!=(const t_filestats ¶m) const
void write_bendian_t(const T &p_object, abort_callback &p_abort)
Helper template. Writes single raw object to the stream; corrects byte order assuming stream uses big...
static void g_get_display_path(const char *path, pfc::string_base &out)
static void listFilesAndDirectories(const char *p_path, t_list &p_files, t_list &p_directories, abort_callback &p_abort)
t_filetimestamp import_filetimestamp(FILETIME ft)
t_uint64 t_filesize
Type used for file size related variables.
const bool m_getSubDirectories
void write_object_t(const T &p_object, abort_callback &p_abort)
Helper template. Writes single raw object to the stream.
file_ptr fileOpenReadExisting(const char *p_path, abort_callback &p_abort, double p_timeout=0)
void sort_t(t_compare p_compare)
Implementation helper - contains dummy implementations of methods that modify the file...
New EXPERIMENTAL string class, allowing efficient copies and returning from functions. Does not implement the string_base interface so you still need string8 in many cases. Safe to pass between DLLs, but since a reference is used, objects possibly created by other DLLs must be released before owning DLLs are unloaded.
virtual t_filetimestamp get_timestamp(abort_callback &p_abort)
Retrieves last modification time of the file.
void write_string(const T &val, abort_callback &p_abort)
Stores file stats (size and timestamp).
void write_object(const void *p_buffer, t_size p_bytes, abort_callback &p_abort)
Helper. Same as write(), provided for consistency.
void read_object_t(T &p_object, abort_callback &p_abort)
Helper template built around read_object. Reads single raw object from the stream.
static void listFiles(const char *p_path, t_list &p_out, abort_callback &p_abort)
void reopen(abort_callback &)
pfc::string getPathCanonical(const T &source)
directory_callback_impl(bool p_recur)
file_ptr fileOpen(const char *p_path, filesystem::t_open_mode p_mode, abort_callback &p_abort, double p_timeout)
Opens a new file for writing; if the file exists, its contents will be wiped.
void order_native_to_be_t(T ¶m)
directory_callback_retrieveListEx(t_list &p_files, t_list &p_directories)
file_ptr fileOpenWriteExisting(const char *p_path, abort_callback &p_abort, double p_timeout=0)