-
-
Notifications
You must be signed in to change notification settings - Fork 741
/
Copy pathSound.cs
79 lines (74 loc) · 3.03 KB
/
Sound.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.IO;
namespace Discord
{
/// <summary>
/// An sound that will be uploaded to Discord.
/// </summary>
public struct Sound : IDisposable
{
private bool _isDisposed;
/// <summary>
/// Gets the stream to be uploaded to Discord.
/// </summary>
#pragma warning disable IDISP008
public Stream Stream { get; }
#pragma warning restore IDISP008
/// <summary>
/// Create the sound with a <see cref="System.IO.Stream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="System.IO.Stream" /> to create the sound with. Note that this must be some type of stream
/// with the contents of a file in it.
/// </param>
public Sound(Stream stream)
{
_isDisposed = false;
Stream = stream;
}
/// <summary>
/// Create the sound from a file path.
/// </summary>
/// <remarks>
/// This file path is NOT validated and is passed directly into a
/// <see cref="File.OpenRead"/>.
/// </remarks>
/// <param name="path">The path to the file.</param>
/// <exception cref="System.ArgumentException">
/// <paramref name="path" /> is a zero-length string, contains only white space, or contains one or more invalid
/// characters as defined by <see cref="Path.GetInvalidPathChars"/>.
/// </exception>
/// <exception cref="System.ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
/// <exception cref="PathTooLongException">
/// The specified path, file name, or both exceed the system-defined maximum length. For example, on
/// Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260
/// characters.
/// </exception>
/// <exception cref="System.NotSupportedException"><paramref name="path" /> is in an invalid format.</exception>
/// <exception cref="DirectoryNotFoundException">
/// The specified <paramref name="path"/> is invalid, (for example, it is on an unmapped drive).
/// </exception>
/// <exception cref="System.UnauthorizedAccessException">
/// <paramref name="path" /> specified a directory.-or- The caller does not have the required permission.
/// </exception>
/// <exception cref="FileNotFoundException">The file specified in <paramref name="path" /> was not found.
/// </exception>
/// <exception cref="IOException">An I/O error occurred while opening the file. </exception>
public Sound(string path)
{
_isDisposed = false;
Stream = File.OpenRead(path);
}
/// <inheritdoc/>
public void Dispose()
{
if (!_isDisposed)
{
#pragma warning disable IDISP007
Stream?.Dispose();
#pragma warning restore IDISP007
_isDisposed = true;
}
}
}
}