Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 1 | package li.cil.oc.api.detail; |
| 2 | |
Florian Nücke | 2312b28 | 2015-10-13 21:39:58 +0200 | [diff] [blame] | 3 | import li.cil.oc.api.network.EnvironmentHost; |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 4 | import li.cil.oc.api.fs.FileSystem; |
Florian Nücke | a7d2119 | 2013-11-09 20:56:21 +0100 | [diff] [blame] | 5 | import li.cil.oc.api.fs.Label; |
Florian Nücke | 730c8f0 | 2013-11-01 01:12:55 +0100 | [diff] [blame] | 6 | import li.cil.oc.api.network.ManagedEnvironment; |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 7 | |
| 8 | public interface FileSystemAPI { |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 9 | /** |
| 10 | * Creates a new file system based on the location of a class. |
| 11 | * <p/> |
| 12 | * This can be used to wrap a folder in the assets folder of your mod's JAR. |
| 13 | * The actual path is built like this: |
| 14 | * <pre>"/assets/" + domain + "/" + root</pre> |
| 15 | * <p/> |
| 16 | * If the class is located in a JAR file, this will create a read-only file |
| 17 | * system based on that JAR file. If the class file is located in the native |
| 18 | * file system, this will create a read-only file system first trying from |
| 19 | * the actual location of the class file, and failing that by searching the |
| 20 | * class path (i.e. it'll look for a path constructed as described above). |
| 21 | * <p/> |
| 22 | * If the specified path cannot be located, the creation fails and this |
| 23 | * returns <tt>null</tt>. |
| 24 | * |
| 25 | * @param clazz the class whose containing JAR to wrap. |
| 26 | * @param domain the domain, usually your mod's ID. |
| 27 | * @param root an optional subdirectory. |
| 28 | * @return a file system wrapping the specified folder. |
| 29 | */ |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 30 | FileSystem fromClass(Class<?> clazz, String domain, String root); |
| 31 | |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 32 | /** |
| 33 | * Creates a new <em>writable</em> file system in the save folder. |
| 34 | * <p/> |
| 35 | * This will create a folder, if necessary, and create a writable virtual |
| 36 | * file system based in that folder. The actual path is based in a sub- |
| 37 | * folder of the save folder. The actual path is built like this: |
| 38 | * <pre>"saves/" + WORLD_NAME + "/opencomputers/" + root</pre> |
| 39 | * The first part may differ, in particular for servers. |
| 40 | * <p/> |
| 41 | * Usually the name will be the address of the node used to represent the |
| 42 | * file system. |
| 43 | * <p/> |
| 44 | * Note that by default file systems are "buffered", meaning that any |
| 45 | * changes made to them are only saved to disk when the world is saved. This |
| 46 | * ensured that the file system contents do not go "out of sync" when the |
| 47 | * game crashes, but introduces additional memory overhead, since all files |
| 48 | * in the file system have to be kept in memory. |
| 49 | * |
| 50 | * @param root the name of the file system. |
| 51 | * @param capacity the amount of space in bytes to allow being used. |
| 52 | * @param buffered whether data should only be written to disk when saving. |
| 53 | * @return a file system wrapping the specified folder. |
| 54 | */ |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 55 | FileSystem fromSaveDirectory(String root, long capacity, boolean buffered); |
| 56 | |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 57 | /** |
| 58 | * Creates a new <em>writable</em> file system that resides in memory. |
| 59 | * <p/> |
| 60 | * Any contents created and written on this file system will be lost when |
| 61 | * the node is removed from the network. |
| 62 | * <p/> |
| 63 | * This is used for computers' <tt>/tmp</tt> mount, for example. |
| 64 | * |
| 65 | * @param capacity the capacity of the file system. |
| 66 | * @return a file system residing in memory. |
| 67 | */ |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 68 | FileSystem fromMemory(long capacity); |
| 69 | |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 70 | /** |
| 71 | * Creates a new file system based on a read-only ComputerCraft mount. |
Florian Nücke | 1ddb684 | 2014-05-28 13:13:05 +0200 | [diff] [blame] | 72 | * <p/> |
| 73 | * This supports read-only and writable mounts from either CC 1.5x or |
| 74 | * CC 1.6x. The argument is kept untyped to avoid having the OC API |
| 75 | * depend on the CC API. |
| 76 | * <p/> |
| 77 | * If the passed type is unsupported, this will return <tt>null</tt>. |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 78 | * |
| 79 | * @param mount the mount to wrap with a file system. |
| 80 | * @return a file system wrapping the specified mount. |
| 81 | */ |
Florian Nücke | 1ddb684 | 2014-05-28 13:13:05 +0200 | [diff] [blame] | 82 | FileSystem fromComputerCraft(Object mount); |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 83 | |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 84 | /** |
Florian Nücke | 4cb81b3 | 2015-06-28 19:20:15 +0200 | [diff] [blame] | 85 | * Wrap a file system retrieved via one of the <tt>from???</tt> methods to |
| 86 | * make it read-only. |
| 87 | * |
| 88 | * @param fileSystem the file system to wrap. |
| 89 | * @return the specified file system wrapped to be read-only. |
| 90 | */ |
| 91 | FileSystem asReadOnly(final FileSystem fileSystem); |
| 92 | |
| 93 | /** |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 94 | * Creates a network node that makes the specified file system available via |
| 95 | * the common file system driver. |
| 96 | * <p/> |
| 97 | * This can be useful for providing some data if you don't wish to implement |
| 98 | * your own driver. Which will probably be most of the time. If you need |
| 99 | * more control over the node, implement your own, and connect this one to |
| 100 | * it. In that case you will have to forward any disk driver messages to the |
| 101 | * node, though. |
Florian Nücke | dd41cb4 | 2014-03-09 17:13:19 +0100 | [diff] [blame] | 102 | * <p/> |
| 103 | * The container parameter is used to give the file system some physical |
| 104 | * relation to the world, for example this is used by hard drives to send |
| 105 | * the disk event notifications to the client that are used to play disk |
| 106 | * access sounds. |
| 107 | * <p/> |
| 108 | * The container may be <tt>null</tt>, if no such context can be provided. |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 109 | * <p/> |
| 110 | * The access sound is the name of the sound effect to play when the file |
| 111 | * system is accessed, for example by listing a directory or reading from |
| 112 | * a file. It may be <tt>null</tt> to create a silent file system. |
| 113 | * <p/> |
| 114 | * The speed multiplier controls how fast read and write operations on the |
| 115 | * file system are. It must be a value in [1,6], and controls the access |
| 116 | * speed, with the default being one. |
| 117 | * For reference, floppies are using the default, hard drives scale with |
| 118 | * their tiers, i.e. a tier one hard drive uses speed two, tier three uses |
| 119 | * speed four. |
Florian Nücke | dd41cb4 | 2014-03-09 17:13:19 +0100 | [diff] [blame] | 120 | * |
Florian Nücke | 0005aac | 2014-09-19 20:14:22 +0200 | [diff] [blame] | 121 | * @param fileSystem the file system to wrap. |
| 122 | * @param label the label of the file system. |
Florian Nücke | b464e81 | 2014-09-19 20:17:37 +0200 | [diff] [blame] | 123 | * @param host the tile entity containing the file system. |
Florian Nücke | 0005aac | 2014-09-19 20:14:22 +0200 | [diff] [blame] | 124 | * @param accessSound the name of the sound effect to play when the file |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 125 | * system is accessed. This has to be the fully |
| 126 | * qualified resource name, e.g. |
| 127 | * <tt>opencomputers:floppy_access</tt>. |
| 128 | * @param speed the speed multiplier for this file system. |
Florian Nücke | dd41cb4 | 2014-03-09 17:13:19 +0100 | [diff] [blame] | 129 | * @return the network node wrapping the file system. |
| 130 | */ |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 131 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound, int speed); |
Florian Nücke | dd41cb4 | 2014-03-09 17:13:19 +0100 | [diff] [blame] | 132 | |
| 133 | /** |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 134 | * Creates a network node that makes the specified file system available via |
| 135 | * the common file system driver. |
| 136 | * <p/> |
| 137 | * Creates a file system with the a read-only label and the specified |
| 138 | * access sound and file system speed. |
Florian Nücke | f4b07c7 | 2014-03-10 01:48:44 +0100 | [diff] [blame] | 139 | * |
Florian Nücke | 0005aac | 2014-09-19 20:14:22 +0200 | [diff] [blame] | 140 | * @param fileSystem the file system to wrap. |
| 141 | * @param label the read-only label of the file system. |
Florian Nücke | b464e81 | 2014-09-19 20:17:37 +0200 | [diff] [blame] | 142 | * @param host the tile entity containing the file system. |
Florian Nücke | 0005aac | 2014-09-19 20:14:22 +0200 | [diff] [blame] | 143 | * @param accessSound the name of the sound effect to play when the file |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 144 | * system is accessed. This has to be the fully |
| 145 | * qualified resource name, e.g. |
| 146 | * <tt>opencomputers:floppy_access</tt>. |
| 147 | * @param speed the speed multiplier for this file system. |
Florian Nücke | f4b07c7 | 2014-03-10 01:48:44 +0100 | [diff] [blame] | 148 | * @return the network node wrapping the file system. |
| 149 | */ |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 150 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound, int speed); |
| 151 | |
| 152 | /** |
| 153 | * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}. |
| 154 | */ |
| 155 | @Deprecated |
| 156 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound); |
| 157 | |
| 158 | /** |
| 159 | * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}. |
| 160 | */ |
| 161 | @Deprecated |
Florian Nücke | b464e81 | 2014-09-19 20:17:37 +0200 | [diff] [blame] | 162 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound); |
Florian Nücke | f4b07c7 | 2014-03-10 01:48:44 +0100 | [diff] [blame] | 163 | |
| 164 | /** |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 165 | * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}. |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 166 | */ |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 167 | @Deprecated |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 168 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label); |
Florian Nücke | a7d2119 | 2013-11-09 20:56:21 +0100 | [diff] [blame] | 169 | |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 170 | /** |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 171 | * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}. |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 172 | */ |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 173 | @Deprecated |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 174 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label); |
Florian Nücke | a7d2119 | 2013-11-09 20:56:21 +0100 | [diff] [blame] | 175 | |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 176 | /** |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 177 | * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}. |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 178 | */ |
Florian Nücke | 2023978 | 2015-04-22 15:21:43 +0200 | [diff] [blame] | 179 | @Deprecated |
Florian Nücke | bb9f073 | 2014-03-03 15:12:28 +0100 | [diff] [blame] | 180 | ManagedEnvironment asManagedEnvironment(FileSystem fileSystem); |
Florian Nücke | c231f61 | 2013-10-25 02:33:08 +0200 | [diff] [blame] | 181 | } |