@@ -20,41 +20,20 @@ public interface IFileSystem
2020 /// <returns>The contents of the file</returns>
2121 public string ReadAllText ( string filepath ) ;
2222
23- /// <summary>
24- /// Reads all text from a file.
25- /// </summary>
26- /// <param name="file">The file</param>
27- /// <returns>The contents of the file</returns>
28- public string ReadAllText ( IFile file ) ;
29-
3023 /// <summary>
3124 /// Reads all text from a file, as a list of lines.
3225 /// </summary>
3326 /// <param name="filepath">The path to the file</param>
3427 /// <returns>The contents of the file</returns>
3528 public string [ ] ReadAllLines ( string filepath ) ;
3629
37- /// <summary>
38- /// Reads all text from a file, as a list of lines.
39- /// </summary>
40- /// <param name="file">The file</param>
41- /// <returns>The contents of the file</returns>
42- public string [ ] ReadAllLines ( IFile file ) ;
43-
4430 /// <summary>
4531 /// Reads the very first line of a file.
4632 /// </summary>
4733 /// <param name="filepath">The path to the file</param>
4834 /// <returns>The first line of the file</returns>
4935 public string ReadLine ( string filepath ) ;
5036
51- /// <summary>
52- /// Reads the very first line of a file.
53- /// </summary>
54- /// <param name="file">The file</param>
55- /// <returns>The first line of the file</returns>
56- public string ReadLine ( IFile file ) ;
57-
5837 /// <summary>
5938 /// Reads a specific amount of characters from a file buffer.
6039 /// </summary>
@@ -64,15 +43,6 @@ public interface IFileSystem
6443 /// <returns>A span of characters</returns>
6544 public Span < char > ReadCharacters ( string filepath , ulong amount , long offset = 0 ) ;
6645
67- /// <summary>
68- /// Reads a specific amount of characters from a file buffer.
69- /// </summary>
70- /// <param name="file">The file</param>
71- /// <param name="amount">The amount of characters to read</param>
72- /// <param name="offset">The index from which to start reading the characters</param>
73- /// <returns>A span of characters</returns>
74- public Span < char > ReadCharacters ( IFile file , ulong amount , long offset = 0 ) ;
75-
7646 #endregion
7747
7848 #region Writing
@@ -85,14 +55,6 @@ public interface IFileSystem
8555 /// <param name="data">The text to write</param>
8656 public void WriteAllText ( string filepath , string data ) ;
8757
88- /// <summary>
89- /// Writes text to a file, creating it if necessary. If the file exists,
90- /// it will be overwritten.
91- /// </summary>
92- /// <param name="file">The file</param>
93- /// <param name="data">The text to write</param>
94- public void WriteAllText ( IFile file , string data ) ;
95-
9658 /// <summary>
9759 /// Writes lines of text to a file, creating it if necessary.
9860 /// If the file exists, it will be overwritten.
@@ -101,14 +63,6 @@ public interface IFileSystem
10163 /// <param name="data">The lines of text to write</param>
10264 public void WriteAllLines ( string filepath , string [ ] data ) ;
10365
104- /// <summary>
105- /// Writes lines of text to a file, creating it if necessary.
106- /// If the file exists, it will be overwritten.
107- /// </summary>
108- /// <param name="file">The file</param>
109- /// <param name="data">The lines of text to write</param>
110- public void WriteAllLines ( IFile file , string [ ] data ) ;
111-
11266 #endregion
11367
11468 #region Appending
@@ -120,27 +74,13 @@ public interface IFileSystem
12074 /// <param name="data">The text to append</param>
12175 public void AppendAllText ( string filepath , string data ) ;
12276
123- /// <summary>
124- /// Appends all the text to the end of a file.
125- /// </summary>
126- /// <param name="file">The file</param>
127- /// <param name="data">The text to append</param>
128- public void AppendAllText ( IFile file , string data ) ;
129-
13077 /// <summary>
13178 /// Appends all the specified lines of text to the end of a file.
13279 /// </summary>
13380 /// <param name="filepath">The path to the file</param>
13481 /// <param name="data">The lines to append</param>
13582 public void AppendAllLines ( string filepath , string [ ] data ) ;
13683
137- /// <summary>
138- /// Appends all the specified lines of text to the end of a file.
139- /// </summary>
140- /// <param name="file">The file</param>
141- /// <param name="data">The lines to append</param>
142- public void AppendAllLines ( IFile file , string [ ] data ) ;
143-
14484 #endregion
14585
14686 #region Sharding Toolkit
@@ -154,20 +94,44 @@ public interface IFileSystem
15494 /// <returns><c>true</c> if in use by another plugin</returns>
15595 public bool InUse ( string filepath ) ;
15696
97+ #endregion
98+
99+ #region Locking
100+
157101 /// <summary>
158- /// Checks if a file is in use by another plugin.
159- /// A result of <c>false</c> does not mean the file is strictly
160- /// not in use - it only means no other plugin is using it.
102+ /// Locks a file, to prevent it from being accessed by other plugins.
161103 /// </summary>
162- /// <param name="filepath">The file</param>
163- /// <returns><c>true</c> if in use by another plugin</returns>
164- public bool InUse ( IFile filepath ) ;
104+ /// <param name="filepath">The path to the file to lock</param>
105+ public void Lock ( string filepath ) ;
165106
166- #endregion
107+ /// <summary>
108+ /// Unlocks a previously locked file.
109+ /// </summary>
110+ /// <param name="filepath">The path to the file</param>
111+ public void Unlock ( string filepath ) ;
167112
168- #region Locking
113+ /// <summary>
114+ /// Checks if a file is locked.
115+ /// </summary>
116+ /// <param name="filepath">The path to the file</param>
117+ /// <param name="lockOwnerIsCaller"><c>true</c> if the caller is the owner of the lock placed on this file</param>
118+ /// <returns><c>true</c> if the file is locked, no matter who owns the lock</returns>
119+ public bool IsLocked ( string filepath , out bool lockOwnerIsCaller ) ;
120+
121+ /// <summary>
122+ /// Checks if a file is locked by the caller.
123+ /// </summary>
124+ /// <param name="filepath">The path to the file</param>
125+ /// <returns><c>true</c> if the file is locked and the lock owner is the caller</returns>
126+ public bool IsLockedByMe ( string filepath ) => IsLocked ( filepath , out var byMe ) && byMe ;
169127
170- // todo: this shit
128+ /// <summary>
129+ /// Checks if a file is considered "lockable" (allows locking)
130+ /// by WriterSharp.
131+ /// </summary>
132+ /// <param name="filepath">The path to the file</param>
133+ /// <returns><c>true</c> if it can be locked</returns>
134+ public bool IsLockable ( string filepath ) ;
171135
172136 #endregion
173137
0 commit comments