Exemple #1
0
        internal MediaFolder( UmdDevice device, MediaFolder parent, string name, MediaItemAttributes attributes, DateTime timestamp )
        {
            Debug.Assert( device != null );

            _device = device;
            _parent = parent;

            _name = name;
            _attributes = attributes;
            _timestamp = timestamp;

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

            // Add to parent
            if( _parent != null )
                _parent.AddItemInternal( this );
        }
        protected MediaFolder ParseIsoFileSystem(string path, bool minimalCache)
        {
            Debug.Assert(path != null);
            Debug.Assert(File.Exists(path) == true);

            if (File.Exists(path) == false)
            {
                return(null);
            }

            using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    NativePrimaryDescriptor?npdv = NativePrimaryDescriptor.FromStream(reader);
                    Debug.Assert(npdv != null);
                    if (npdv == null)
                    {
                        return(null);
                    }
                    NativePrimaryDescriptor npd = npdv.Value;

                    List <NativePathEntry> npes = new List <NativePathEntry>();
                    stream.Seek(npd.PathTableStart * 2048, SeekOrigin.Begin);
                    while (stream.Position < (npd.PathTableStart * 2048) + npd.PathTableLength)
                    {
                        NativePathEntry npe = NativePathEntry.FromReader(reader);
                        if (npe == null)
                        {
                            continue;
                        }

                        npes.Add(npe);
                    }

                    List <MediaFolder> folders = new List <MediaFolder>(npes.Count);
                    for (int n = 0; n < npes.Count; n++)
                    {
                        NativePathEntry npe = npes[n];

                        MediaFolder current = null;
                        MediaFolder parent  = null;
                        if (npe.IsRoot == false)
                        {
                            parent = folders[npe.ParentEntry];
                        }

                        if (npe.Length == 0)
                        {
                            // Look in parent for length
                            if (parent != null)
                            {
                                NativePathEntry pe = npes[npe.ParentEntry];
                                npe.Length = pe.ChildLengths[npe.Name];
                            }
                            else
                            {
                                npe.Length = 2048;
                            }
                        }

                        int m = 0;
                        for (int s = 0; s < npe.Length / 2048; s++)
                        {
                            stream.Seek((npe.FirstSector + s) * 2048, SeekOrigin.Begin);
                            while (true)
                            {
                                NativeEntry?nev = NativeEntry.FromReader(reader);
                                if (nev == null)
                                {
                                    break;
                                }
                                NativeEntry ne = nev.Value;

                                if (m == 0)
                                {
                                    // '.' this dir
                                    MediaItemAttributes attributes = MediaItemAttributes.Normal;
                                    if ((ne.Flags & NativeEntryFlags.Hidden) == NativeEntryFlags.Hidden)
                                    {
                                        attributes |= MediaItemAttributes.Hidden;
                                    }
                                    current = new MediaFolder(this, parent, npe.Name, attributes, ne.Timestamp);
                                    folders.Add(current);
                                }
                                else if (m == 1)
                                {
                                    // '..' parent dir - ignored
                                }
                                else
                                {
                                    // Child
                                    if ((ne.Flags & NativeEntryFlags.Directory) == NativeEntryFlags.Directory)
                                    {
                                        // Directories are handled when it is their turn to be added
                                        // EXCEPT for size, which we need to get now and store back
                                        // At this time in the code, we have all dirs prior to the one whose length
                                        // we just got - since we have already added ourselves, we know we have its
                                        // parent too
                                        npe.ChildLengths.Add(ne.Name, ne.Length);
                                    }
                                    else
                                    {
                                        MediaItemAttributes attributes = MediaItemAttributes.Normal;
                                        if ((ne.Flags & NativeEntryFlags.Hidden) == NativeEntryFlags.Hidden)
                                        {
                                            attributes |= MediaItemAttributes.Hidden;
                                        }

                                        long lbn = ne.FirstSector /* * 2048*/;

                                        MediaFile file = new MediaFile(this, current, ne.Name, attributes, ne.Timestamp, lbn * 2048, ne.Length);

                                        //Log.WriteLine(Verbosity.Normal, Feature.Bios, "{0} = {1}", ne.Name, lbn);
                                        // Pretty sure this is wrong, but it shouldn't matter
                                        Debug.Assert(_lbnLookup.ContainsKey(lbn) == false);
                                        _lbnLookup[lbn] = file;
                                    }
                                }
                                m++;

                                if ((ne.Flags & NativeEntryFlags.LastEntry) == NativeEntryFlags.LastEntry)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    return(folders[0]);
                }
        }
Exemple #3
0
        public bool Load( string path, bool minimalCache )
        {
            _hostPath = path;

            FileInfo fi = new FileInfo( path );
            _capacity = fi.Length;

            _lbnLookup.Clear();

            _root = ParseIsoFileSystem( path, minimalCache );
            Debug.Assert( _root != null );
            _root.CalculateSize();

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

            _state = MediaState.Present;

            return true;
        }
        protected MediaFolder ParseIsoFileSystem( string path, bool minimalCache )
        {
            Debug.Assert( path != null );
            Debug.Assert( File.Exists( path ) == true );

            if( File.Exists( path ) == false )
                return null;

            using( FileStream stream = File.Open( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
            using( BinaryReader reader = new BinaryReader( stream ) )
            {
                NativePrimaryDescriptor? npdv = NativePrimaryDescriptor.FromStream( reader );
                Debug.Assert( npdv != null );
                if( npdv == null )
                    return null;
                NativePrimaryDescriptor npd = npdv.Value;

                List<NativePathEntry> npes = new List<NativePathEntry>();
                stream.Seek( npd.PathTableStart * 2048, SeekOrigin.Begin );
                while( stream.Position < ( npd.PathTableStart * 2048 ) + npd.PathTableLength )
                {
                    NativePathEntry npe = NativePathEntry.FromReader( reader );
                    if( npe == null )
                        continue;

                    npes.Add( npe );
                }

                List<MediaFolder> folders = new List<MediaFolder>( npes.Count );
                for( int n = 0; n < npes.Count; n++ )
                {
                    NativePathEntry npe = npes[ n ];

                    MediaFolder current = null;
                    MediaFolder parent = null;
                    if( npe.IsRoot == false )
                        parent = folders[ npe.ParentEntry ];

                    if( npe.Length == 0 )
                    {
                        // Look in parent for length
                        if( parent != null )
                        {
                            NativePathEntry pe = npes[ npe.ParentEntry ];
                            npe.Length = pe.ChildLengths[ npe.Name ];
                        }
                        else
                            npe.Length = 2048;
                    }

                    int m = 0;
                    for( int s = 0; s < npe.Length / 2048; s++ )
                    {
                        stream.Seek( ( npe.FirstSector + s ) * 2048, SeekOrigin.Begin );
                        while( true )
                        {
                            NativeEntry? nev = NativeEntry.FromReader( reader );
                            if( nev == null )
                                break;
                            NativeEntry ne = nev.Value;

                            if( m == 0 )
                            {
                                // '.' this dir
                                MediaItemAttributes attributes = MediaItemAttributes.Normal;
                                if( ( ne.Flags & NativeEntryFlags.Hidden ) == NativeEntryFlags.Hidden )
                                    attributes |= MediaItemAttributes.Hidden;
                                current = new MediaFolder( this, parent, npe.Name, attributes, ne.Timestamp );
                                folders.Add( current );
                            }
                            else if( m == 1 )
                            {
                                // '..' parent dir - ignored
                            }
                            else
                            {
                                // Child
                                if( ( ne.Flags & NativeEntryFlags.Directory ) == NativeEntryFlags.Directory )
                                {
                                    // Directories are handled when it is their turn to be added
                                    // EXCEPT for size, which we need to get now and store back
                                    // At this time in the code, we have all dirs prior to the one whose length
                                    // we just got - since we have already added ourselves, we know we have its
                                    // parent too
                                    npe.ChildLengths.Add( ne.Name, ne.Length );
                                }
                                else
                                {
                                    MediaItemAttributes attributes = MediaItemAttributes.Normal;
                                    if( ( ne.Flags & NativeEntryFlags.Hidden ) == NativeEntryFlags.Hidden )
                                        attributes |= MediaItemAttributes.Hidden;

                                    long lbn = ne.FirstSector/* * 2048*/;

                                    MediaFile file = new MediaFile( this, current, ne.Name, attributes, ne.Timestamp, lbn * 2048, ne.Length );

                                    //Log.WriteLine(Verbosity.Normal, Feature.Bios, "{0} = {1}", ne.Name, lbn);
                                    // Pretty sure this is wrong, but it shouldn't matter
                                    Debug.Assert( _lbnLookup.ContainsKey( lbn ) == false );
                                    _lbnLookup[ lbn ] = file;
                                }
                            }
                            m++;

                            if( ( ne.Flags & NativeEntryFlags.LastEntry ) == NativeEntryFlags.LastEntry )
                                break;
                        }
                    }
                }

                return folders[ 0 ];
            }
        }
Exemple #5
0
 public void Cleanup()
 {
     _root = null;
 }