diff options
Diffstat (limited to 'debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io')
8 files changed, 0 insertions, 1289 deletions
diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.cpp deleted file mode 100644 index 893f98c0..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "libplatform/impl.h" - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -namespace { - const File::Size __maxChunkSize = 1024*1024; -} - -/////////////////////////////////////////////////////////////////////////////// - -File::File( std::string name_, Mode mode_, FileProvider* provider_ ) - : _name ( name_ ) - , _isOpen ( false ) - , _mode ( mode_ ) - , _size ( 0 ) - , _position ( 0 ) - , _provider ( provider_ ? *provider_ : standard() ) - , name ( _name ) - , isOpen ( _isOpen ) - , mode ( _mode ) - , size ( _size ) - , position ( _position ) -{ -} - -/////////////////////////////////////////////////////////////////////////////// - -File::~File() -{ - close(); - delete &_provider; -} - -/////////////////////////////////////////////////////////////////////////////// - -void -File::setMode( Mode mode_ ) -{ - _mode = mode_; -} - -void -File::setName( const std::string& name_ ) -{ - _name = name_; -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -File::open( std::string name_, Mode mode_ ) -{ - if( _isOpen ) - return true; - - if( !name_.empty() ) - setName( name_ ); - if( mode_ != MODE_UNDEFINED ) - setMode( mode_ ); - - if( _provider.open( _name, _mode )) - return true; - - FileSystem::getFileSize( _name, _size ); - - _isOpen = true; - return false; -} - -bool -File::seek( Size pos ) -{ - if( !_isOpen ) - return true; - - if( _provider.seek( pos )) - return true; - _position = pos; - return false; -} - -bool -File::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) -{ - nin = 0; - - if( !_isOpen ) - return true; - - if( _provider.read( buffer, size, nin, maxChunkSize )) - return true; - - _position += nin; - if( _position > _size ) - _size = _position; - - return false; -} - -bool -File::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) -{ - nout = 0; - - if( !_isOpen ) - return true; - - if( _provider.write( buffer, size, nout, maxChunkSize )) - return true; - - _position += nout; - if( _position > _size ) - _size = _position; - - return false; -} - -bool -File::close() -{ - if( !_isOpen ) - return false; - if( _provider.close() ) - return true; - - _isOpen = false; - return false; -} - -/////////////////////////////////////////////////////////////////////////////// - -CustomFileProvider::CustomFileProvider( const MP4FileProvider& provider ) - : _handle( NULL ) -{ - memcpy( &_call, &provider, sizeof(MP4FileProvider) ); -} - -bool -CustomFileProvider::open( std::string name, Mode mode ) -{ - MP4FileMode fm; - switch( mode ) { - case MODE_READ: fm = FILEMODE_READ; break; - case MODE_MODIFY: fm = FILEMODE_MODIFY; break; - case MODE_CREATE: fm = FILEMODE_CREATE; break; - - case MODE_UNDEFINED: - default: - fm = FILEMODE_UNDEFINED; - break; - } - - _handle = _call.open( name.c_str(), fm ); - return _handle == NULL; -} - -bool -CustomFileProvider::seek( Size pos ) -{ - return _call.seek( _handle, pos ); -} - -bool -CustomFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) -{ - return _call.read( _handle, buffer, size, &nin, maxChunkSize ); -} - -bool -CustomFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) -{ - return _call.write( _handle, buffer, size, &nout, maxChunkSize ); -} - -bool -CustomFileProvider::close() -{ - return _call.close( _handle ); -} - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.h deleted file mode 100644 index 67bb2b6d..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File.h +++ /dev/null @@ -1,208 +0,0 @@ -#ifndef MP4V2_PLATFORM_IO_FILE_H -#define MP4V2_PLATFORM_IO_FILE_H - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -class MP4V2_EXPORT FileProvider -{ -public: - static FileProvider& standard(); - -public: - //! file operation mode flags - enum Mode { - MODE_UNDEFINED, //!< undefined - MODE_READ, //!< file may be read - MODE_MODIFY, //!< file may be read/written - MODE_CREATE, //!< file will be created/truncated for read/write - }; - - //! type used to represent all file sizes and offsets - typedef int64_t Size; - -public: - virtual ~FileProvider() { } - - virtual bool open( std::string name, Mode mode ) = 0; - virtual bool seek( Size pos ) = 0; - virtual bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ) = 0; - virtual bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) = 0; - virtual bool close() = 0; - -protected: - FileProvider() { } -}; - -/////////////////////////////////////////////////////////////////////////////// -/// -/// File implementation. -/// -/// File objects model real filesystem files in a 1:1 releationship and always -/// treated as binary; there are no translations of text content performed. -/// -/// The interface represents all sizes with a signed 64-bit value, thus -/// the limit to this interface is 63-bits of size, roughly 9.22 million TB. -/// -/////////////////////////////////////////////////////////////////////////////// - -class MP4V2_EXPORT File : public FileProvider -{ -public: - /////////////////////////////////////////////////////////////////////////// - //! - //! Constructor. - //! - //! A new file object is constructed but not opened. - //! - //! @param name filename of file object, or empty-string. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! @param mode bitmask specifying mode flags. - //! See #Mode for bit constants. - //! @param provider a fileprovider instance. If NULL a standard file - //! provider will be used otherwise the supplied provider must be - //! new-allocated and will be delete'd via ~File(). - //! - /////////////////////////////////////////////////////////////////////////// - - explicit File( std::string name = "", Mode mode = MODE_UNDEFINED, FileProvider* = NULL ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Destructor. - //! - //! File object is destroyed. If the file is opened it is closed prior - //! to destruction. - //! - /////////////////////////////////////////////////////////////////////////// - - ~File(); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Open file. - //! - //! @param name filename of file object, or empty-string to use #name. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - bool open( std::string name = "", Mode mode = MODE_UNDEFINED ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Closes file. - //! - //! If the file has not been opened or is not considered the - //! owner of a filehandle, no action is taken. - //! - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - bool close(); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Set current file position in bytes. - //! - //! @param pos new file position in bytes. - //! - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - bool seek( Size pos ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Binary stream read. - //! - //! The function reads up to a maximum <b>size</b> bytes from file, - //! storing them in <b>buffer</b>. The number of bytes actually read are - //! returned in <b>nin</b>. - //! - //! @param buffer storage for data read from file. - //! @param size maximum number of bytes to read from file. - //! @param nin output indicating number of bytes read from file. - //! @param maxChunkSize maximum chunk size for reads issued to operating - //! system or 0 for default. - //! - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - bool read( void* buffer, Size size, Size& nin, Size maxChunkSize = 0 ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Binary stream write. - //! - //! The function writes up to a maximum <b>size</b> bytes from - //! <b>buffer</b> to file. The number of bytes actually written are - //! returned in <b>nout</b>. - //! - //! @param buffer data to be written out to file. - //! @param size maximum number of bytes to read from file. - //! @param nout output indicating number of bytes written to file. - //! @param maxChunkSize maximum chunk size for writes issued to operating - //! system or 0 for default. - //! - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize = 0 ); - -private: - std::string _name; - bool _isOpen; - Mode _mode; - Size _size; - Size _position; - FileProvider& _provider; - -public: - const std::string& name; //!< read-only: file pathname or empty-string if not applicable - const bool& isOpen; //!< read-only: true if file is open - const Mode& mode; //!< read-only: file mode - const Size& size; //!< read-only: file size - const Size& position; //!< read-only: file position - -public: - void setName( const std::string& name ); - void setMode( Mode mode ); -}; - -/////////////////////////////////////////////////////////////////////////////// - -class CustomFileProvider : public FileProvider -{ -public: - CustomFileProvider( const MP4FileProvider& ); - - bool open( std::string name, Mode mode ); - bool seek( Size pos ); - bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ); - bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ); - bool close(); - -private: - MP4FileProvider _call; - void* _handle; -}; - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io - -#endif // MP4V2_PLATFORM_IO_FILE_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.cpp deleted file mode 100644 index 073b0261..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "libplatform/impl.h" - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -void -FileSystem::pathnameCleanup( string& name ) -{ - string bad; - - // fold repeating directory separators - bad = DIR_SEPARATOR; - bad += DIR_SEPARATOR; - for( string::size_type pos = name.find( bad ); - pos != string::npos; - pos = name.find( bad, pos ) ) - { - name.replace( pos, bad.length(), DIR_SEPARATOR ); - } - - // replace occurances of /./ with / - bad = DIR_SEPARATOR; - bad += '.'; - bad += DIR_SEPARATOR; - for( string::size_type pos = name.find( bad ); - pos != string::npos; - pos = name.find( bad, pos ) ) - { - name.replace( pos, bad.length(), DIR_SEPARATOR ); - } -} - -/////////////////////////////////////////////////////////////////////////////// - -void -FileSystem::pathnameOnlyExtension( string& name ) -{ - // compute basename - string::size_type dot_pos = name.rfind( '.' ); - string::size_type slash_pos = name.rfind( DIR_SEPARATOR ); - - // dot_pos must be after slash_pos - if( slash_pos != string::npos && dot_pos < slash_pos ) - dot_pos = string::npos; - - // return empty-string if no dot - if( dot_pos == string::npos ) { - name.resize( 0 ); - return; - } - - name = name.substr( dot_pos + 1 ); - pathnameCleanup( name ); -} - -/////////////////////////////////////////////////////////////////////////////// - -void -FileSystem::pathnameStripExtension( string& name ) -{ - pathnameCleanup( name ); - - // compute basename - string::size_type dot_pos = name.rfind( '.' ); - string::size_type slash_pos = name.rfind( DIR_SEPARATOR ); - - // dot_pos must be after slash_pos - if( slash_pos != string::npos && dot_pos < slash_pos ) - dot_pos = string::npos; - - // chop extension - if( dot_pos != string::npos ) - name.resize( dot_pos ); -} - -/////////////////////////////////////////////////////////////////////////////// - -void -FileSystem::pathnameTemp( string& name, string dir, string prefix, string suffix ) -{ - ostringstream buf; - - if( !dir.empty() ) { - buf << dir; - - // add dir separator if needed - // TODO there's a platform specific bug here, if someone passes in a pathname ending - // in '\', which would be legitimate on Windows. - if( dir[dir.length()-1] != '/' ) - buf << '/'; - } - - buf << prefix; - buf << setfill('0') << setw(8) << number::random32(); - buf << suffix; - - name = buf.str(); -} - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.h b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.h deleted file mode 100644 index b348752a..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem.h +++ /dev/null @@ -1,215 +0,0 @@ -#ifndef MP4V2_PLATFORM_IO_FILESYSTEM_H -#define MP4V2_PLATFORM_IO_FILESYSTEM_H - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// -/// -/// General file-system abstraction. -/// -/// FileSystem abstracts operations on files and directories. -/// -/////////////////////////////////////////////////////////////////////////////// -class MP4V2_EXPORT FileSystem -{ -public: - static string DIR_SEPARATOR; //!< separator string used in file pathnames - static string PATH_SEPARATOR; //!< separator string used in search-paths - - /////////////////////////////////////////////////////////////////////////// - //! - //! Query file presence. - //! Check if <b>name</b> exists. - //! @param name filename to query. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! @return true if present, false otherwise. - //! - /////////////////////////////////////////////////////////////////////////// - - static bool exists( std::string name ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Query directory type. - //! Check if <b>name</b> exists and is a directory. - //! @param name pathname to query. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! @return true if directory, false otherwise. - //! - /////////////////////////////////////////////////////////////////////////// - - static bool isDirectory( std::string name ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Query file type. - //! Check if <b>name</b> exists and is a file. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! @param name filename to query. - //! @return true if file, false otherwise. - //! - /////////////////////////////////////////////////////////////////////////// - - static bool isFile( std::string name ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Query file size. - //! Check if <b>name</b> exists and is a file. - //! @param name filename to query. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! @param size output indicating file size in bytes. - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - static bool getFileSize( std::string name, File::Size& size ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Rename file or directory. - //! - //! Rename <b>oldname</b> to <b>newname</b>. - //! If <b>newname</b> exists, it is first removed. - //! Both <b>oldname</b> and <b>newname</b> must be of the same type; - //! that is, both must be either files or directories and must reside on - //! the same filesystem. - //! - //! @param oldname existing pathname to rename. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! @param newname new pathname. - //! On Windows, this should be a UTF-8 encoded string. - //! On other platforms, it should be an 8-bit encoding that is - //! appropriate for the platform, locale, file system, etc. - //! (prefer to use UTF-8 when possible). - //! - //! @return true on failure, false on success. - //! - /////////////////////////////////////////////////////////////////////////// - - static bool rename( std::string oldname, std::string newname ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Generate temporary pathname. - //! - //! @param name output containing generated pathname. - //! @param dir relative or absolute directory of pathname. - //! @param prefix text prepended to base pathname. - //! @param suffix text appended to base pathname. - //! - /////////////////////////////////////////////////////////////////////////// - - static void pathnameTemp( string& name, string dir = ".", string prefix = "tmp", string suffix = "" ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Cleanup pathname. - //! - //! Redundant (repeating) directory-separators are folded into a single - //! directory-separator. - //! - //! Redundant /./ are folded into a single directory-separator. - //! - //! @param name pathname to modify. - //! - /////////////////////////////////////////////////////////////////////////// - - static void pathnameCleanup( string& name ); - -#if 0 -TODO-KB: implement - /////////////////////////////////////////////////////////////////////////// - //! - //! Remove everything after the last directory component. - //! - //! A pathname cleanup is always performed. See pathnameCleanup(). - //! If no directory component is present then "." is assumed. - //! - //! @param name pathname to modify. - //! @param trailing when true all results are suffixed with exactly one - //! directory-separator, otherwise the result is guaranteed to not - //! end in a directory-separator. - //! - /////////////////////////////////////////////////////////////////////////// - static void pathnameOnlyDirectory( string& name, bool trailing = true ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Remove everything except the file component of pathname. - //! - //! A pathname cleanup is always performed. See pathnameCleanup(). - //! If no file component exists then an empty-string is output. - //! A file component may include an extension. - //! - //! @param name pathname to modify. - //! - /////////////////////////////////////////////////////////////////////////// - static void pathnameOnlyFile( string& name ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Remove everything except file basename. - //! - //! A pathname cleanup is always performed. See pathnameCleanup(). - //! A basename is considered to be everything before the last '.' - //! in the file component of a pathname. - //! If no file extension exists then an empty-string is output. - //! - //! @param name pathname to modify. - //! - /////////////////////////////////////////////////////////////////////////// - static void pathnameOnlyBasename( string& name ); -#endif - - /////////////////////////////////////////////////////////////////////////// - //! - //! Remove everything except file extension. - //! - //! A pathname cleanup is always performed. See pathnameCleanup(). - //! A file extension is considered to everything <b>after</b> - //! the last '.' in the file component of a pathname. - //! If no file extension exists then an empty-string is output. - //! - //! @param name pathname to modify. - //! - /////////////////////////////////////////////////////////////////////////// - - static void pathnameOnlyExtension( string& name ); - - /////////////////////////////////////////////////////////////////////////// - //! - //! Remove file extension from pathname. - //! - //! A pathname cleanup is always performed. See pathnameCleanup(). - //! A file extension is considered to everything <b>after</b> - //! the last '.' in the file component of a pathname. - //! The last '.' is also removed. - //! - //! @param name pathname to modify. - //! - /////////////////////////////////////////////////////////////////////////// - - static void pathnameStripExtension( string& name ); -}; - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io - -#endif // MP4V2_PLATFORM_IO_FILESYSTEM_H diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_posix.cpp deleted file mode 100644 index 46cf9337..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_posix.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "libplatform/impl.h" -#include <sys/stat.h> - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::exists( string path_ ) -{ - struct stat buf; - return stat( path_.c_str(), &buf ) == 0; -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::isDirectory( string path_ ) -{ - struct stat buf; - if( stat( path_.c_str(), &buf )) - return false; - return S_ISDIR( buf.st_mode ); -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::isFile( string path_ ) -{ - struct stat buf; - if( stat( path_.c_str(), &buf )) - return false; - return S_ISREG( buf.st_mode ); -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::getFileSize( string path_, File::Size& size_ ) -{ - size_ = 0; - struct stat buf; - if( stat( path_.c_str(), &buf )) - return true; - size_ = buf.st_size; - return false; -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::rename( string from, string to ) -{ - return ::rename( from.c_str(), to.c_str() ) != 0; -} - -/////////////////////////////////////////////////////////////////////////////// - -string FileSystem::DIR_SEPARATOR = "/"; -string FileSystem::PATH_SEPARATOR = ":"; - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_win32.cpp deleted file mode 100644 index 4a213819..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/FileSystem_win32.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "src/impl.h" -#include "libplatform/impl.h" /* for platform_win32_impl.h which declares Utf8ToFilename */ -#include <windows.h> - -namespace mp4v2 { - using namespace impl; -} - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -static DWORD getAttributes ( string path_ ); - -/** - * Call GetFileAttributesW throw exceptions for errors - * - * @param path_ the path to get attributes for - * - * @retval INVALID_FILE_ATTRIBUTES @p path_ doesn't exist - * @retval anything else the attributes of @p path_ - */ -static DWORD -getAttributes ( string path_ ) -{ - win32::Utf8ToFilename filename(path_); - - if (!filename.IsUTF16Valid()) - { - // throw an exception to avoid changing the - // signature of this function and dealing with all - // the places it's called. - ostringstream msg; - msg << "can't convert file to UTF-16(" << filename.utf8 << ")"; - throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__); - } - - DWORD attributes = ::GetFileAttributesW(filename); - if( attributes == INVALID_FILE_ATTRIBUTES ) - { - DWORD last_err = GetLastError(); - - // Distinguish between an error and the path not existing - if ((last_err == ERROR_FILE_NOT_FOUND) || (last_err == ERROR_PATH_NOT_FOUND)) - { - return attributes; - } - - // Anything else is an error - ostringstream msg; - msg << "GetFileAttributes(" << filename.utf8 << ") failed (" << last_err << ")"; - throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__); - } - - // path exists so return its attributes - return attributes; -} - -bool -FileSystem::exists( string path_ ) -{ - return( getAttributes(path_) != INVALID_FILE_ATTRIBUTES ); -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::isDirectory( string path_ ) -{ - DWORD attributes = getAttributes( path_ ); - if( attributes == INVALID_FILE_ATTRIBUTES ) - return false; - - return ( ( attributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY ); -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::isFile( string path_ ) -{ - DWORD attributes = getAttributes( path_ ); - if( attributes == INVALID_FILE_ATTRIBUTES ) - return false; - - return ( ( attributes & FILE_ATTRIBUTE_DIRECTORY ) != FILE_ATTRIBUTE_DIRECTORY ); -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::getFileSize( string path_, File::Size& size_ ) -{ - win32::Utf8ToFilename filename(path_); - - if (!filename.IsUTF16Valid()) - { - // The logging is done - return true; - } - - size_ = 0; - WIN32_FILE_ATTRIBUTE_DATA data = {0}; - if( !GetFileAttributesExW( filename, GetFileExInfoStandard, (LPVOID)&data ) ) - { - log.errorf("%s: GetFileAttributesExW(%s) failed (%d)",__FUNCTION__,filename.utf8.c_str(), - GetLastError()); - return true; - } - - size_ = ( (File::Size)data.nFileSizeHigh << 32 ) | data.nFileSizeLow; - return false; -} - -/////////////////////////////////////////////////////////////////////////////// - -bool -FileSystem::rename( string from, string to ) -{ - win32::Utf8ToFilename from_file(from); - win32::Utf8ToFilename to_file(to); - - if (!from_file.IsUTF16Valid() || !to_file.IsUTF16Valid()) - { - return true; - } - - if (!::MoveFileExW( from_file, to_file, - MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ) ) - { - log.errorf("%s: MoveFileExW(%s,%s) failed (%d)",__FUNCTION__,from_file.utf8.c_str(),to_file.utf8.c_str(), - GetLastError()); - return true; - } - - return false; -} - -/////////////////////////////////////////////////////////////////////////////// - -string FileSystem::DIR_SEPARATOR = "\\"; -string FileSystem::PATH_SEPARATOR = ";"; - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_posix.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_posix.cpp deleted file mode 100644 index b6fb214a..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_posix.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "libplatform/impl.h" - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -class StandardFileProvider : public FileProvider -{ -public: - StandardFileProvider(); - - bool open( std::string name, Mode mode ); - bool seek( Size pos ); - bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ); - bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ); - bool close(); - -private: - bool _seekg; - bool _seekp; - std::fstream _fstream; -}; - -/////////////////////////////////////////////////////////////////////////////// - -StandardFileProvider::StandardFileProvider() - : _seekg ( false ) - , _seekp ( false ) -{ -} - -bool -StandardFileProvider::open( std::string name, Mode mode ) -{ - ios::openmode om = ios::binary; - switch( mode ) { - case MODE_UNDEFINED: - case MODE_READ: - default: - om |= ios::in; - _seekg = true; - _seekp = false; - break; - - case MODE_MODIFY: - om |= ios::in | ios::out; - _seekg = true; - _seekp = true; - break; - - case MODE_CREATE: - om |= ios::in | ios::out | ios::trunc; - _seekg = true; - _seekp = true; - break; - } - - _fstream.open( name.c_str(), om ); - return _fstream.fail(); -} - -bool -StandardFileProvider::seek( Size pos ) -{ - if( _seekg ) - _fstream.seekg( pos, ios::beg ); - if( _seekp ) - _fstream.seekp( pos, ios::beg ); - return _fstream.fail(); -} - -bool -StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) -{ - _fstream.read( (char*)buffer, size ); - if( _fstream.fail() ) - return true; - nin = _fstream.gcount(); - return false; -} - -bool -StandardFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) -{ - _fstream.write( (const char*)buffer, size ); - if( _fstream.fail() ) - return true; - nout = size; - return false; -} - -bool -StandardFileProvider::close() -{ - _fstream.close(); - return _fstream.fail(); -} - -/////////////////////////////////////////////////////////////////////////////// - -FileProvider& -FileProvider::standard() -{ - return *new StandardFileProvider(); -} - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io diff --git a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_win32.cpp b/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_win32.cpp deleted file mode 100644 index d9101ea3..00000000 --- a/debian/mp4v2/mp4v2-2.0.0~dfsg0/libplatform/io/File_win32.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include "src/impl.h" -#include "libplatform/impl.h" /* for platform_win32_impl.h which declares Utf8ToFilename */ -#include <windows.h> - -namespace mp4v2 { - using namespace impl; -} - -/** - * Set this to 1 to compile in extra debugging - */ -#define EXTRA_DEBUG 0 - -/** - * @def LOG_PRINTF - * - * call log.printf if EXTRA_DEBUG is defined to 1. Do - * nothing otherwise - */ -#if EXTRA_DEBUG -#define LOG_PRINTF(X) log.printf X -#else -#define LOG_PRINTF(X) -#endif - -namespace mp4v2 { namespace platform { namespace io { - -/////////////////////////////////////////////////////////////////////////////// - -class StandardFileProvider : public FileProvider -{ -public: - StandardFileProvider(); - - bool open( std::string name, Mode mode ); - bool seek( Size pos ); - bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ); - bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ); - bool close(); - -private: - HANDLE _handle; - - /** - * The UTF-8 encoded file name - */ - std::string _name; -}; - -/////////////////////////////////////////////////////////////////////////////// - -StandardFileProvider::StandardFileProvider() - : _handle( INVALID_HANDLE_VALUE ) -{ -} - -/** - * Open a file - * - * @param name the name of a file to open - * @param mode the mode to open @p name - * - * @retval false successfully opened @p name - * @retval true error opening @p name - */ -bool -StandardFileProvider::open( std::string name, Mode mode ) -{ - DWORD access = 0; - DWORD share = 0; - DWORD crdisp = 0; - DWORD flags = FILE_ATTRIBUTE_NORMAL; - - switch( mode ) { - case MODE_UNDEFINED: - case MODE_READ: - default: - access |= GENERIC_READ; - share |= FILE_SHARE_READ; - crdisp |= OPEN_EXISTING; - break; - - case MODE_MODIFY: - access |= GENERIC_READ | GENERIC_WRITE; - share |= FILE_SHARE_READ; - crdisp |= OPEN_EXISTING; - break; - - case MODE_CREATE: - access |= GENERIC_READ | GENERIC_WRITE; - share |= FILE_SHARE_READ; - crdisp |= CREATE_ALWAYS; - break; - } - - win32::Utf8ToFilename filename(name); - - if (!filename.IsUTF16Valid()) - { - // The logging is done - return true; - } - - ASSERT(LPCWSTR(filename)); - _handle = CreateFileW( filename, access, share, NULL, crdisp, flags, NULL ); - if (_handle == INVALID_HANDLE_VALUE) - { - log.errorf("%s: CreateFileW(%s) failed (%d)",__FUNCTION__,filename.utf8.c_str(),GetLastError()); - return true; - } - - /* - ** Make a copy of the name for future log messages, etc. - */ - log.verbose2f("%s: CreateFileW(%s) succeeded",__FUNCTION__,filename.utf8.c_str()); - - _name = filename.utf8; - return false; -} - -/** - * Seek to an offset in the file - * - * @param pos the offset from the beginning of the file to - * seek to - * - * @retval false successfully seeked to @p pos - * @retval true error seeking to @p pos - */ -bool -StandardFileProvider::seek( Size pos ) -{ - LARGE_INTEGER n; - - ASSERT(_handle != INVALID_HANDLE_VALUE); - - n.QuadPart = pos; - if (!SetFilePointerEx( _handle, n, NULL, FILE_BEGIN )) - { - log.errorf("%s: SetFilePointerEx(%s,%" PRId64 ") failed (%d)",__FUNCTION__,_name.c_str(), - pos,GetLastError()); - return true; - } - - return false; -} - -/** - * Read from the file - * - * @param buffer populated with at most @p size bytes from - * the file - * - * @param size the maximum number of bytes to read - * - * @param nin the - * - * @retval false successfully read from the file - * @retval true error reading from the file - */ -bool -StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize ) -{ - DWORD nread = 0; - - ASSERT(_handle != INVALID_HANDLE_VALUE); - - // ReadFile takes a DWORD for number of bytes to read so - // make sure we're not asking for more than fits. - // MAXDWORD from WinNT.h. - ASSERT(size <= MAXDWORD); - if( ReadFile( _handle, buffer, (DWORD)(size & MAXDWORD), &nread, NULL ) == 0 ) - { - log.errorf("%s: ReadFile(%s,%d) failed (%d)",__FUNCTION__,_name.c_str(), - (DWORD)(size & MAXDWORD),GetLastError()); - return true; - } - LOG_PRINTF((MP4_LOG_VERBOSE3,"%s: ReadFile(%s,%d) succeeded: read %d byte(s)",__FUNCTION__, - _name.c_str(),(DWORD)(size & MAXDWORD),nread)); - nin = nread; - return false; -} - -/** - * Write to the file - * - * @param buffer the data to write - * - * @param size the number of bytes of @p buffer to write - * - * @param nout populated with the number of bytes actually - * written if the function succeeds - * - * @retval false successfully wrote to the file - * @retval true error writing to the file - */ -bool -StandardFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) -{ - DWORD nwrote = 0; - - ASSERT(_handle != INVALID_HANDLE_VALUE); - - // ReadFile takes a DWORD for number of bytes to read so - // make sure we're not asking for more than fits. - // MAXDWORD from WinNT.h. - ASSERT(size <= MAXDWORD); - if( WriteFile( _handle, buffer, (DWORD)(size & MAXDWORD), &nwrote, NULL ) == 0 ) - { - log.errorf("%s: WriteFile(%s,%d) failed (%d)",__FUNCTION__,_name.c_str(), - (DWORD)(size & MAXDWORD),GetLastError()); - return true; - } - log.verbose2f("%s: WriteFile(%s,%d) succeeded: wrote %d byte(s)",__FUNCTION__, - _name.c_str(),(DWORD)(size & MAXDWORD),nwrote); - nout = nwrote; - return false; -} - -/** - * Close the file - * - * @retval false successfully closed the file - * @retval true error closing the file - */ -bool -StandardFileProvider::close() -{ - BOOL retval; - - retval = CloseHandle( _handle ); - if (!retval) - { - log.errorf("%s: CloseHandle(%s) failed (%d)",__FUNCTION__, - _name.c_str(),GetLastError()); - } - - // Whether we succeeded or not, clear the handle and - // forget the name - _handle = INVALID_HANDLE_VALUE; - _name.clear(); - - // CloseHandle return 0/false to indicate failure, but - // we return 0/false to indicate success, so negate. - return !retval; -} - -/////////////////////////////////////////////////////////////////////////////// - -FileProvider& -FileProvider::standard() -{ - return *new StandardFileProvider(); -} - -/////////////////////////////////////////////////////////////////////////////// - -}}} // namespace mp4v2::platform::io |