public override bool CanCreateStream(PlaylistItem playlistItem)
        {
            //The behaviour is not loaded for utilities so we can't check whether it's enabled.
            //if (this.Behaviour == null || !this.Behaviour.Enabled)
            //{
            //    return false;
            //}
            var fileName  = default(string);
            var entryName = default(string);

            return(ArchiveUtils.ParseUrl(playlistItem.FileName, out fileName, out entryName));
        }
        public override IBassStream CreateInteractiveStream(PlaylistItem playlistItem, IEnumerable <IBassStreamAdvice> advice, BassFlags flags)
        {
            var fileName  = default(string);
            var entryName = default(string);

            if (!ArchiveUtils.ParseUrl(playlistItem.FileName, out fileName, out entryName))
            {
                //This shouldn't happen as CanCreateStream would have returned false.
                return(BassStream.Empty);
            }
            var index = default(int);

            if (!ArchiveUtils.GetEntryIndex(fileName, entryName, out index))
            {
                //The associated entry was not found.
                return(BassStream.Empty);
            }
            if (this.Output != null && this.Output.PlayFromMemory)
            {
                Logger.Write(this, LogLevel.Warn, "This provider cannot play from memory.");
            }
retry:
            var channelHandle = BassZipStream.CreateStream(fileName, index, Flags: flags);

            if (channelHandle == 0)
            {
                switch (ArchiveError.GetLastError())
                {
                case ArchiveError.E_PASSWORD_REQUIRED:
                    Logger.Write(this, LogLevel.Warn, "Invalid password for \"{0}\".", fileName);
                    if (this.PasswordBehaviour != null)
                    {
                        var cancelled = this.PasswordBehaviour.WasCancelled(fileName);
                        this.PasswordBehaviour.Reset(fileName);
                        if (!cancelled)
                        {
                            goto retry;
                        }
                    }
                    break;
                }
            }
            return(this.CreateInteractiveStream(channelHandle, advice, flags));
        }
예제 #3
0
        protected virtual async Task Create(IntPtr archive, string path, List <T> items)
        {
            var count          = default(int);
            var metaDataSource = this.MetaDataSourceFactory.Create();

            if (Archive.GetEntryCount(archive, out count))
            {
                for (var a = 0; a < count; a++)
                {
                    var entry = default(Archive.ArchiveEntry);
                    if (Archive.GetEntry(archive, out entry, a))
                    {
                        if (!this.Output.IsSupported(entry.path))
                        {
                            continue;
                        }
                        var fileName = ArchiveUtils.CreateUrl(path, entry.path);
                        var item     = new T()
                        {
                            //An archive is a virtual directory I suppose? Not sure if this will cause any problems.
                            DirectoryName = path,
                            FileName      = fileName
                        };
                        if (this.MetaData.Value)
                        {
                            try
                            {
retry:
                                using (var fileAbstraction = ArchiveFileAbstraction.Create(path, entry.path, a))
                                {
                                    if (fileAbstraction.IsOpen)
                                    {
                                        item.MetaDatas = (
                                            await metaDataSource.GetMetaData(fileAbstraction).ConfigureAwait(false)
                                            ).ToList();
                                        switch (fileAbstraction.Result)
                                        {
                                        case ArchiveEntry.RESULT_PASSWORD_REQUIRED:
                                            Logger.Write(this, LogLevel.Warn, "Invalid password for \"{0}\".", path);
                                            if (this.PasswordBehaviour != null && !this.PasswordBehaviour.WasCancelled(path))
                                            {
                                                this.PasswordBehaviour.Reset(path);
                                                goto retry;
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.Write(this, LogLevel.Debug, "Failed to read meta data from file \"{0}\": {1}", path, e.Message);
                            }
                        }
                        this.EnsureMetaData(a, entry, item);
                        items.Add(item);
                    }
                    else
                    {
                        //TODO: Warn.
                    }
                }
            }
            else
            {
                //TODO: Warn.
            }
        }