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" : "" ) ); }
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(); }
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(); }
public void Cleanup() { _root = null; }
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; }
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; }
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; }
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; }