示例#1
0
        public MemoryStickDevice( IEmulationInstance emulator, ComponentParameters parameters, string hostPath, bool writeProtected, long capacity )
        {
            Debug.Assert( emulator != null );
            Debug.Assert( parameters != null );
            Debug.Assert( hostPath != null );
            Debug.Assert( Directory.Exists( hostPath ) == true );
            Debug.Assert( capacity > 0 );

            _emulator = emulator;
            _parameters = parameters;
            _hostPath = hostPath;
            _writeProtected = writeProtected;

            DirectoryInfo info = new DirectoryInfo( hostPath );
            _root = new MediaFolder( this, null, info );

            _capacity = capacity;
            long used = _root.Cache();
            _available = _capacity - used;
            if( _available < 0 )
            {
                // User gave a capacity that is too small for the size, fix it up
                while( _capacity < used )
                    _capacity *= 2;
                Log.WriteLine( Verbosity.Critical, Feature.Media, "MemoryStickDevice: user gave capacity {0} but {1} is used; changing capacity to {2}",
                    capacity, used, _capacity );
            }

            // Would be nice to do something with this that was official-like (serial number?)
            _description = string.Format( "Memory Stick ({0}MB){1}",
                _capacity / 1024 / 1024,
                ( _writeProtected == true ? " read-only" : "" ) );
        }
示例#2
0
        internal MediaFile( IMediaDevice device, MediaFolder parent, FileInfo info )
        {
            Debug.Assert( device != null );
            Debug.Assert( parent != null );
            Debug.Assert( info != null );

            _device = device;
            _parent = parent;
            _info = info;

            // Add to parent
            if( _parent != null )
                _parent.AddItemInternal( this );

            this.Refresh();
        }
示例#3
0
        internal MediaFolder( IMediaDevice device, MediaFolder parent, DirectoryInfo info )
        {
            Debug.Assert( device != null );
            Debug.Assert( info != null );

            _device = device;
            _parent = parent;
            _info = info;

            _items = new List<IMediaItem>();
            _itemLookup = new Dictionary<string, IMediaItem>();

            // Add to parent
            if( _parent != null )
                _parent.AddItemInternal( this );

            this.Refresh();
        }
示例#4
0
 public void Cleanup()
 {
     _root = null;
 }
示例#5
0
        public bool MoveTo( IMediaFolder destination )
        {
            try
            {
                if( _device.IsReadOnly == true )
                    return false;
                if( destination.Device.IsReadOnly == true )
                    return false;

                this.Refresh();

                _parent.RemoveItemInternal( this );
                _info.MoveTo( Path.Combine( destination.AbsolutePath, _info.Name ) );

                MediaFolder folder = destination as MediaFolder;
                Debug.Assert( folder != null, "Do not support inter-device moves yet" );
                folder.AddItemInternal( this );
                _parent = folder;
            }
            catch
            {
                return false;
            }
            return true;
        }
示例#6
0
 public void Cleanup()
 {
     _root = null;
 }
示例#7
0
        public bool Load( string path, bool minimalCache )
        {
            _hostPath = path;

            DirectoryInfo info = new DirectoryInfo( path );
            _root = new MediaFolder( this, null, info );

            long used = _root.Cache();
            _available = _capacity - used;
            if( _available < 0 )
            {
                // User gave a capacity that is too small for the size, fix it up
                while( _capacity < used )
                    _capacity *= 2;
                Log.WriteLine( Verbosity.Critical, Feature.Media, "UmdDevice: user gave capacity {0} but {1} is used; changing capacity to {2}",
                    _capacity, used, _capacity );
            }

            // Would be nice to do something with this that was official-like (serial number?)
            _description = string.Format( "UMD ({0}MB)",
                _capacity / 1024 / 1024 );

            return true;
        }
示例#8
0
        internal long Cache()
        {
            long sum = 0;

            foreach( DirectoryInfo info in _info.GetDirectories() )
            {
                MediaFolder folder = new MediaFolder( _device, this, info );
                sum += folder.Cache();
            }

            foreach( FileInfo info in _info.GetFiles() )
            {
                MediaFile file = new MediaFile( _device, this, info );
                sum += file.Length;
            }

            return sum;
        }
示例#9
0
        public IMediaFolder CreateFolder( string name )
        {
            if( _device.IsReadOnly == true )
                return null;

            Debug.Assert( name != null );
            Debug.Assert( name.Length > 0 );
            // TODO: Assert name is valid directory style via regex, here we just do / check
            Debug.Assert( name.IndexOfAny( new char[] { '/', '\\' } ) < 0 );

            DirectoryInfo info = Directory.CreateDirectory( Path.Combine( _info.FullName, name ) );

            MediaFolder folder = new MediaFolder( _device, this, info );
            return folder;
        }