|
| 1 | +using System; |
| 2 | + |
| 3 | + |
| 4 | +namespace WriterSharp.PluginApi.FileSystem |
| 5 | +{ |
| 6 | + |
| 7 | + /// <summary> |
| 8 | + /// A type-safe, flexible, sharded file-system for WriterSharp plugins to use for |
| 9 | + /// maximum safety, instead of the defaults. |
| 10 | + /// </summary> |
| 11 | + public interface IFileSystem |
| 12 | + { |
| 13 | + |
| 14 | + #region Reading |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Reads all text from a file. |
| 18 | + /// </summary> |
| 19 | + /// <param name="filepath">The path to the file</param> |
| 20 | + /// <returns>The contents of the file</returns> |
| 21 | + public string ReadAllText(string filepath); |
| 22 | + |
| 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 | + |
| 30 | + /// <summary> |
| 31 | + /// Reads all text from a file, as a list of lines. |
| 32 | + /// </summary> |
| 33 | + /// <param name="filepath">The path to the file</param> |
| 34 | + /// <returns>The contents of the file</returns> |
| 35 | + public string[] ReadAllLines(string filepath); |
| 36 | + |
| 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 | + |
| 44 | + /// <summary> |
| 45 | + /// Reads the very first line of a file. |
| 46 | + /// </summary> |
| 47 | + /// <param name="filepath">The path to the file</param> |
| 48 | + /// <returns>The first line of the file</returns> |
| 49 | + public string ReadLine(string filepath); |
| 50 | + |
| 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 | + |
| 58 | + /// <summary> |
| 59 | + /// Reads a specific amount of characters from a file buffer. |
| 60 | + /// </summary> |
| 61 | + /// <param name="filepath">The path to the file</param> |
| 62 | + /// <param name="amount">The amount of characters to read</param> |
| 63 | + /// <param name="offset">The index from which to start reading the characters</param> |
| 64 | + /// <returns>A span of characters</returns> |
| 65 | + public Span<char> ReadCharacters(string filepath, ulong amount, long offset = 0); |
| 66 | + |
| 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 | + |
| 76 | + #endregion |
| 77 | + |
| 78 | + #region Writing |
| 79 | + |
| 80 | + /// <summary> |
| 81 | + /// Writes text to a file, creating it if necessary. If the file exists, |
| 82 | + /// it will be overwritten. |
| 83 | + /// </summary> |
| 84 | + /// <param name="filepath">The path to the file</param> |
| 85 | + /// <param name="data">The text to write</param> |
| 86 | + public void WriteAllText(string filepath, string data); |
| 87 | + |
| 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 | + |
| 96 | + /// <summary> |
| 97 | + /// Writes lines of text to a file, creating it if necessary. |
| 98 | + /// If the file exists, it will be overwritten. |
| 99 | + /// </summary> |
| 100 | + /// <param name="filepath">The path to the file</param> |
| 101 | + /// <param name="data">The lines of text to write</param> |
| 102 | + public void WriteAllLines(string filepath, string[] data); |
| 103 | + |
| 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 | + |
| 112 | + #endregion |
| 113 | + |
| 114 | + #region Appending |
| 115 | + |
| 116 | + /// <summary> |
| 117 | + /// Appends all the text to the end of a file. |
| 118 | + /// </summary> |
| 119 | + /// <param name="filepath">The path to the file</param> |
| 120 | + /// <param name="data">The text to append</param> |
| 121 | + public void AppendAllText(string filepath, string data); |
| 122 | + |
| 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 | + |
| 130 | + /// <summary> |
| 131 | + /// Appends all the specified lines of text to the end of a file. |
| 132 | + /// </summary> |
| 133 | + /// <param name="filepath">The path to the file</param> |
| 134 | + /// <param name="data">The lines to append</param> |
| 135 | + public void AppendAllLines(string filepath, string[] data); |
| 136 | + |
| 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 | + |
| 144 | + #endregion |
| 145 | + |
| 146 | + #region Sharding Toolkit |
| 147 | + |
| 148 | + /// <summary> |
| 149 | + /// Checks if a file is in use by another plugin. |
| 150 | + /// A result of <c>false</c> does not mean the file is strictly |
| 151 | + /// not in use - it only means no other plugin is using it. |
| 152 | + /// </summary> |
| 153 | + /// <param name="filepath">The path to the file</param> |
| 154 | + /// <returns><c>true</c> if in use by another plugin</returns> |
| 155 | + public bool InUse(string filepath); |
| 156 | + |
| 157 | + /// <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. |
| 161 | + /// </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); |
| 165 | + |
| 166 | + #endregion |
| 167 | + |
| 168 | + #region Locking |
| 169 | + |
| 170 | + // todo: this shit |
| 171 | + |
| 172 | + #endregion |
| 173 | + |
| 174 | + } |
| 175 | + |
| 176 | +} |
0 commit comments