-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathFileExtensions.cs
More file actions
103 lines (96 loc) · 3.92 KB
/
Copy pathFileExtensions.cs
File metadata and controls
103 lines (96 loc) · 3.92 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Runtime.Versioning;
namespace BytecodeApi.Extensions;
/// <summary>
/// Provides <see langword="static" /> methods that extend the <see cref="File" /> class.
/// </summary>
public static class FileExtensions
{
extension(File)
{
/// <summary>
/// Sends the specified file to the recycle bin.
/// </summary>
/// <param name="path">A <see cref="string" /> representing the path to a file.</param>
[SupportedOSPlatform("windows")]
public static void SendToRecycleBin(string path)
{
Check.ArgumentNull(path);
Check.FileNotFound(path);
new FileInfo(path).SendToRecycleBin();
}
/// <summary>
/// Deletes the :Zone.Identifier alternate data stream for the specified file.
/// </summary>
/// <param name="path">A <see cref="string" /> representing the path to a file.</param>
/// <returns>
/// <see langword="true" />, if the :Zone.Identifier alternate data stream was present and could be deleted;
/// otherwise, <see langword="false" />.
/// </returns>
[SupportedOSPlatform("windows")]
public static bool Unblock(string path)
{
Check.ArgumentNull(path);
Check.FileNotFound(path);
return new FileInfo(path).Unblock();
}
//TODO:FEATURE: Icon GetIcon(string path)
/// <summary>
/// Shows the properties dialog for the specified file.
/// </summary>
/// <param name="path">A <see cref="string" /> representing the path to a file.</param>
[SupportedOSPlatform("windows")]
public static void ShowPropertiesDialog(string path)
{
Check.ArgumentNull(path);
Check.FileNotFound(path);
new FileInfo(path).ShowPropertiesDialog();
}
/// <summary>
/// Compares the contents of two files. Returns <see langword="true" />, if both files are of equal size and equal binary content.
/// </summary>
/// <param name="path">A <see cref="string" /> representing the path to a file.</param>
/// <param name="otherPath">A <see cref="string" /> representing the path to the other file to compare.</param>
/// <returns>
/// <see langword="true" />, if both files are of equal size and equal binary content;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool CompareContents(string path, string otherPath)
{
Check.ArgumentNull(path);
Check.FileNotFound(path);
Check.ArgumentNull(otherPath);
Check.FileNotFound(otherPath);
return new FileInfo(path).CompareContents(new(otherPath));
}
/// <summary>
/// Searches the file for the first occurrence of <paramref name="sequence" />. If not found, returns -1.
/// </summary>
/// <param name="path">A <see cref="string" /> representing the path to a file.</param>
/// <param name="sequence">The <see cref="byte" />[] to search for.</param>
/// <returns>
/// The index of the first occurrence of <paramref name="sequence" /> and -1, if not found.
/// </returns>
public static long FindSequence(string path, byte[] sequence)
{
return FindSequence(path, sequence, 0);
}
/// <summary>
/// Searches the file for the first occurrence of <paramref name="sequence" /> starting from <paramref name="startIndex" />. If not found, returns -1.
/// </summary>
/// <param name="path">A <see cref="string" /> representing the path to a file.</param>
/// <param name="sequence">The <see cref="byte" />[] to search for.</param>
/// <param name="startIndex">The zero-based starting position to start searching from.</param>
/// <returns>
/// The index of the first occurrence of <paramref name="sequence" /> and -1, if not found.
/// </returns>
public static long FindSequence(string path, byte[] sequence, int startIndex)
{
Check.ArgumentNull(path);
Check.FileNotFound(path);
Check.ArgumentNull(sequence);
Check.ArgumentEx.ArrayElementsRequired(sequence);
Check.ArgumentOutOfRangeEx.GreaterEqual0(startIndex);
return new FileInfo(path).FindSequence(sequence, startIndex);
}
}
}