public void Test002(string archiveName, string entryPath, string password) { if (!this.Cleanup) { Assert.Ignore("Requires clean state."); } var fileName = Path.Combine(Location, "Media", archiveName); var index = Utils.GetEntryIndex(archiveName, entryPath); if (!Bass.Init(Bass.DefaultDevice)) { Assert.Fail(string.Format("Failed to initialize BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError))); } if (!BassZipStream.Init()) { Assert.Fail("Failed to initialize ZIPSTREAM."); } if (string.IsNullOrEmpty(password)) { Utils.PasswordHandler.Reset(); } else { Utils.PasswordHandler.Set(fileName, password, 5000); } try { var sourceChannel = BassZipStream.CreateStream(fileName, index); Assert.AreEqual(0, sourceChannel); Assert.AreEqual(ArchiveError.E_PASSWORD_REQUIRED, ArchiveError.GetLastError()); } finally { if (!BassZipStream.Free()) { Assert.Fail(string.Format("Failed to free ZIPSTREAM: {0}", Enum.GetName(typeof(Errors), Bass.LastError))); } if (!Bass.Free()) { Assert.Fail(string.Format("Failed to free BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError))); } } }
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)); }
public void Test001() { var fileName = Path.Combine(Location, "Media", "Missing.zip"); var archive = default(IntPtr); if (!Archive.Create(out archive)) { Assert.Fail("Failed to create archive."); } try { Assert.IsFalse(Archive.Open(archive, fileName)); Assert.AreEqual(ArchiveError.E_FILE_NOT_FOUND, ArchiveError.GetLastError()); } finally { Archive.Release(archive); } }