public KDevice FindDevice( IMediaDevice device )
 {
     foreach( KDevice Device in Devices )
         if( Device.Device == device )
             return Device;
     return null;
 }
Exemple #2
0
 public KDevice(Kernel kernel, string name, string[] aliases, IMediaDevice device)
 {
     Kernel        = kernel;
     Name          = name;
     Aliases       = aliases;
     Device        = device;
     ReadOnly      = device.IsReadOnly;
     IsBlockDevice = false;
 }
Exemple #3
0
		public KDevice( Kernel kernel, string name, string[] aliases, IMediaDevice device )
		{
			Kernel = kernel;
			Name = name;
			Aliases = aliases;
			Device = device;
			ReadOnly = device.IsReadOnly;
			IsBlockDevice = false;
		}
Exemple #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SongPlayer(IMediaDevice mediaDevice)
        {
            _mediaDevice = mediaDevice;

            _queue       = new FairQueue();
            _songLibrary = new SongLibrary();
            _songLibrary.StatusChanged += OnLibraryStatusChanged;

            _updateThread = new Thread(new ThreadStart(Update));
            _updateThread.Start();
        }
Exemple #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SongPlayer(IMediaDevice mediaDevice)
        {
            _mediaDevice = mediaDevice;

            _queue = new FairQueue();
            _songLibrary = new SongLibrary();
            _songLibrary.StatusChanged += OnLibraryStatusChanged;

            _updateThread = new Thread(new ThreadStart(Update));
            _updateThread.Start();
        }
Exemple #6
0
 public KDevice FindDevice(IMediaDevice device)
 {
     foreach (KDevice Device in Devices)
     {
         if (Device.Device == device)
         {
             return(Device);
         }
     }
     return(null);
 }
Exemple #7
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();
        }
Exemple #8
0
        /// <summary>
        /// Get <see cref="GameInformation"/> from the given UMD device.
        /// </summary>
        /// <param name="device">The device containing the game.</param>
        /// <returns>A <see cref="GameInformation"/> instance representing the game, or <c>null</c> if an error occurred.</returns>
        public static GameInformation GetUmdGameInformation(IMediaDevice device)
        {
            IMediaFolder folder  = device.Root;
            IMediaFile   umdData = folder["UMD_DATA.BIN"] as IMediaFile;

            //[4 alpha country code]-[4 digit game id]|16 digit binhex|0001|G
            // Get code from SFO
            string uniqueId;

            using (StreamReader reader = new StreamReader(umdData.OpenRead()))
            {
                string   line = reader.ReadToEnd().Trim();
                string[] ps   = line.Split('|');
                uniqueId = ps[1];
            }

            IMediaFile sfoData = folder.FindFile(@"PSP_GAME\PARAM.SFO");

            GameParameters gameParams;

            using (Stream stream = sfoData.OpenRead())
                gameParams = ReadSfo(stream);

            // Only accept games
            if ((gameParams.Category != GameCategory.MemoryStickGame) &&
                (gameParams.Category != GameCategory.UmdGame))
            {
                return(null);
            }

            Stream     icon       = null;
            Stream     background = null;
            IMediaFile iconData   = folder.FindFile(@"PSP_GAME\ICON0.PNG");

            if (iconData != null)
            {
                icon = iconData.OpenRead();
            }
            IMediaFile bgData = folder.FindFile(@"PSP_GAME\PIC1.PNG");

            if (bgData != null)
            {
                background = bgData.OpenRead();
            }

            return(new GameInformation(GameType.UmdGame, folder, gameParams, icon, background, uniqueId));
        }
Exemple #9
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();
        }
Exemple #10
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();
        }
Exemple #11
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();
        }
Exemple #12
0
 public TurnOffDevice(IMediaDevice device)
 {
     _mediaDevice = device;
 }
Exemple #13
0
 public bool Equals(IMediaDevice other) => other != null && other is AudioDevice && other.uniqueID == uniqueID;
Exemple #14
0
        /// <summary>
        /// Get <see cref="GameInformation"/> from the given UMD device.
        /// </summary>
        /// <param name="device">The device containing the game.</param>
        /// <returns>A <see cref="GameInformation"/> instance representing the game, or <c>null</c> if an error occurred.</returns>
        public static GameInformation GetUmdGameInformation( IMediaDevice device )
        {
            IMediaFolder folder = device.Root;
            IMediaFile umdData = folder[ "UMD_DATA.BIN" ] as IMediaFile;

            //[4 alpha country code]-[4 digit game id]|16 digit binhex|0001|G
            // Get code from SFO
            string uniqueId;
            using( StreamReader reader = new StreamReader( umdData.OpenRead() ) )
            {
                string line = reader.ReadToEnd().Trim();
                string[] ps = line.Split( '|' );
                uniqueId = ps[ 1 ];
            }

            IMediaFile sfoData = folder.FindFile( @"PSP_GAME\PARAM.SFO" );

            GameParameters gameParams;
            using( Stream stream = sfoData.OpenRead() )
                gameParams = ReadSfo( stream );

            // Only accept games
            if( ( gameParams.Category != GameCategory.MemoryStickGame ) &&
                ( gameParams.Category != GameCategory.UmdGame ) )
                return null;

            Stream icon = null;
            Stream background = null;
            IMediaFile iconData = folder.FindFile( @"PSP_GAME\ICON0.PNG" );
            if( iconData != null )
                icon = iconData.OpenRead();
            IMediaFile bgData = folder.FindFile( @"PSP_GAME\PIC1.PNG" );
            if( bgData != null )
                background = bgData.OpenRead();

            return new GameInformation( GameType.UmdGame, folder, gameParams, icon, background, uniqueId );
        }
Exemple #15
0
        public int realIoOpen(int fileName, int flags, int mode, bool async)
        {
            string path = _kernel.ReadString(( uint )fileName);

            if (string.IsNullOrEmpty(path) == true)
            {
                return(-1);
            }
            IMediaItem item = _kernel.FindPath(path);

            if (item is IMediaFolder)
            {
                // Block access?
                Debug.Assert(item.Device is IUmdDevice);
                IUmdDevice umd    = ( IUmdDevice )item.Device;
                Stream     stream = umd.OpenImageStream();
                if (stream == null)
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open image stream '{0}'", path);

                    if (async == true)
                    {
                        KFile fakehandle = new KFile(_kernel, false);
                        fakehandle.Result       = 0x80010002;
                        fakehandle.PendingClose = true;
                        _kernel.AddHandle(fakehandle);
                        return(( int )fakehandle.UID);
                    }

                    return(-1);
                }

                KDevice dev = _kernel.FindDevice(umd);
                Debug.Assert(dev != null);

                KFile handle = new KFile(_kernel, dev, item, stream);
                handle.IsBlockAccess = true;
                _kernel.AddHandle(handle);

                handle.Result = handle.UID;

                Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened block access on {0} with ID {1:X}", path, handle.UID);

                return(( int )handle.UID);
            }
            else
            {
                IMediaFile file = ( IMediaFile )item;
                if (file == null)
                {
                    // Create if needed
                    if ((flags & 0x0200) != 0)
                    {
                        string       newName;
                        IMediaFolder parent;
                        if (path.IndexOf('/') >= 0)
                        {
                            string parentPath = path.Substring(0, path.LastIndexOf('/'));
                            newName = path.Substring(path.LastIndexOf('/') + 1);
                            parent  = ( IMediaFolder )_kernel.FindPath(parentPath);
                        }
                        else
                        {
                            newName = path;
                            parent  = _kernel.CurrentPath;
                        }
                        if (parent == null)
                        {
                            Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find parent to create file '{0}' in on open", path);

                            if (async == true)
                            {
                                KFile fakehandle = new KFile(_kernel, false);
                                fakehandle.Result       = 0x80010002;
                                fakehandle.PendingClose = true;
                                _kernel.AddHandle(fakehandle);
                                return(( int )fakehandle.UID);
                            }

                            return(-1);
                        }
                        file = parent.CreateFile(newName);
                    }
                    else
                    {
                        Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find path '{0}'", path);

                        if (async == true)
                        {
                            KFile fakehandle = new KFile(_kernel, false);
                            fakehandle.Result       = 0x80010002;
                            fakehandle.PendingClose = true;
                            _kernel.AddHandle(fakehandle);
                            return(( int )fakehandle.UID);
                        }

                        return(unchecked (( int )0x8002012f));
                    }
                }

                /*
                 *	#define PSP_O_RDONLY	0x0001
                 #define PSP_O_WRONLY	0x0002
                 #define PSP_O_RDWR		(PSP_O_RDONLY | PSP_O_WRONLY)
                 #define PSP_O_NBLOCK	0x0004
                 #define PSP_O_DIROPEN	0x0008	// Internal use for dopen
                 #define PSP_O_APPEND	0x0100
                 #define PSP_O_CREAT		0x0200
                 #define PSP_O_TRUNC		0x0400
                 #define	PSP_O_EXCL		0x0800
                 #define PSP_O_NOWAIT	0x8000*/
                MediaFileMode fileMode = MediaFileMode.Normal;
                if ((flags & 0x0100) == 0x0100)
                {
                    fileMode = MediaFileMode.Append;
                }
                if ((flags & 0x0400) == 0x0400)
                {
                    fileMode = MediaFileMode.Truncate;
                }
                MediaFileAccess fileAccess = MediaFileAccess.ReadWrite;
                if ((flags & 0x0001) == 0x0001)
                {
                    fileAccess = MediaFileAccess.Read;
                }
                if ((flags & 0x0002) == 0x0002)
                {
                    fileAccess = MediaFileAccess.Write;
                }
                if ((flags & 0x0003) == 0x0003)
                {
                    fileAccess = MediaFileAccess.ReadWrite;
                }

                if ((flags & 0x0800) != 0)
                {
                    // Exclusive O_EXCL
                    //int x = 1;
                }
                if ((flags & 0x8000) != 0)
                {
                    // Non-blocking O_NOWAIT
                    //int x = 1;
                }
                if ((flags & 0x0004) != 0)
                {
                    // ? O_NBLOCK
                    //int x = 1;
                }

                Stream stream = file.Open(fileMode, fileAccess);
                if (stream == null)
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open stream on file '{0}' for mode {1} access {2}", path, fileMode, fileAccess);
                    return(-1);
                }

                IMediaDevice device = file.Device;
                KDevice      dev    = _kernel.FindDevice(file.Device);
                Debug.Assert(dev != null);

                KFile handle = new KFile(_kernel, dev, file, stream);
                _kernel.AddHandle(handle);

                handle.Result = handle.UID;

                Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened file {0} with ID {1:X}", path, handle.UID);

                return(( int )handle.UID);
            }
        }
        private async void onDeviceAdded(DeviceInformation args)
        {
            // Examples of e.Value.Properties
            // System.Devices.ContainerId: e0acfce3-b225-4b5d-80d5-c240553ff32e
            // ([]) System.Devices.CompatibleIds: urn:schemas-upnp-org:device:MediaRenderer:1
            // ([]) System.Devices.IpAddress: 192.168.0.18
            // {A45C254E-DF1C-4EFD-8020-67D146A850E0},15: http://192.168.0.18:54797/e0acfce3-b225-4b5d-80d5-c240553ff32e.xml

            Guid ContainerId;

            string[] CompatibleIds      = null;
            string[] IpAddress          = null;
            string   DeviceLocationInfo = null;

            foreach (var prop in args.Properties)
            {
                switch (prop.Key)
                {
                case "System.Devices.ContainerId":
                    ContainerId = (Guid)prop.Value;
                    break;

                case "System.Devices.CompatibleIds":
                    CompatibleIds = prop.Value as string[];
                    break;

                case "System.Devices.IpAddress":
                    IpAddress = prop.Value as string[];
                    break;

                case "{A45C254E-DF1C-4EFD-8020-67D146A850E0} 15":
                    DeviceLocationInfo = prop.Value as string;
                    break;

                default:
                    break;
                }
            }

            //Check if Deive is a server or a renderer
            if ((CompatibleIds?.Count() ?? 0) > 0 && !string.IsNullOrEmpty(DeviceLocationInfo))
            {
                MediaDeviceType mediaDeviceType;

                switch (CompatibleIds[0])
                {
                case "urn:schemas-upnp-org:device:MediaServer:1":
                    mediaDeviceType = MediaDeviceType.MediaServer;
                    break;

                case "urn:schemas-upnp-org:device:MediaRenderer:1":
                    mediaDeviceType = MediaDeviceType.MediaRenderer;
                    break;

                default:
                    mediaDeviceType = MediaDeviceType.Unknown;
                    break;
                }

                IMediaDevice mediaDevice = await loadMediaDeviceAsync(DeviceLocationInfo, mediaDeviceType);

                devices[args.Id] = mediaDevice;

                if (mediaDeviceType == MediaDeviceType.MediaServer)
                {
                    //Assign MediaServer
                    mediaServer = mediaDevice as MediaServer;
                }

                //await getRaumfeldZones();
            }
        }
Exemple #17
0
 public DecreaseVolume(IMediaDevice device)
 {
     _mediaDevice = device;
 }
Exemple #18
0
        public IMediaItem FindPath(string path)
        {
            // Hack for ToE and maybe others
            path = path.Replace("host0:UMD", "umd0:");

            int colonPos = path.IndexOf(':');

            if (colonPos >= 0)
            {
                // Absolute path
                string  deviceName = path.Substring(0, colonPos);
                KDevice kdevice;
                if (this.DeviceLookup.TryGetValue(deviceName, out kdevice) == false)
                {
                    Log.WriteLine(Verbosity.Critical, Feature.Bios, "FindPath({0}): unable to find device {1}", path, deviceName);
                    return(null);
                }
                IMediaDevice device = kdevice.Device;
                if (device.State == MediaState.Present)
                {
                    path = path.Substring(colonPos + 1);
                    if (path.StartsWith("/sce_lbn") == true)
                    {
                        Debug.Assert(device is IUmdDevice);
                        IUmdDevice umd = ( IUmdDevice )device;

                        // Lookup LBN/etc
                        //0x0_size0xbb141
                        path = path.Substring(8);
                        int    sep   = path.LastIndexOf('_');
                        string slbn  = path.Substring(0, sep);
                        string ssize = path.Substring(sep + 5);
                        long   lbn;
                        long   size;
                        if (slbn.StartsWith("0x"))
                        {
                            lbn = long.Parse(slbn.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            lbn = long.Parse(slbn);
                        }
                        if (ssize.StartsWith("0x"))
                        {
                            size = long.Parse(ssize.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            size = long.Parse(ssize);
                        }
                        return(umd.Lookup(lbn, size));
                    }
                    else
                    {
                        return(device.Root.Find(path));
                    }
                }
                else
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "FindPath: device {0} is ejected, cannot access {1}", device.Description, path);
                    return(null);
                }
            }
            else
            {
                // Relative path
                Debug.Assert(this.CurrentPath != null);
                return(this.CurrentPath.Find(path));
            }
        }