blob: 77f71d84d63d7f63596fa0e4ba45a9d489bf78ae [file] [log] [blame] [raw]
Florian Nückec231f612013-10-25 02:33:08 +02001package li.cil.oc.api.detail;
2
Florian Nücke2312b282015-10-13 21:39:58 +02003import li.cil.oc.api.network.EnvironmentHost;
Florian Nückec231f612013-10-25 02:33:08 +02004import li.cil.oc.api.fs.FileSystem;
Florian Nückea7d21192013-11-09 20:56:21 +01005import li.cil.oc.api.fs.Label;
Florian Nücke730c8f02013-11-01 01:12:55 +01006import li.cil.oc.api.network.ManagedEnvironment;
Florian Nückec231f612013-10-25 02:33:08 +02007
8public interface FileSystemAPI {
Florian Nückebb9f0732014-03-03 15:12:28 +01009 /**
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ückec231f612013-10-25 02:33:08 +020030 FileSystem fromClass(Class<?> clazz, String domain, String root);
31
Florian Nückebb9f0732014-03-03 15:12:28 +010032 /**
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ückec231f612013-10-25 02:33:08 +020055 FileSystem fromSaveDirectory(String root, long capacity, boolean buffered);
56
Florian Nückebb9f0732014-03-03 15:12:28 +010057 /**
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ückec231f612013-10-25 02:33:08 +020068 FileSystem fromMemory(long capacity);
69
Florian Nückebb9f0732014-03-03 15:12:28 +010070 /**
71 * Creates a new file system based on a read-only ComputerCraft mount.
Florian Nücke1ddb6842014-05-28 13:13:05 +020072 * <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ückebb9f0732014-03-03 15:12:28 +010078 *
79 * @param mount the mount to wrap with a file system.
80 * @return a file system wrapping the specified mount.
81 */
Florian Nücke1ddb6842014-05-28 13:13:05 +020082 FileSystem fromComputerCraft(Object mount);
Florian Nückec231f612013-10-25 02:33:08 +020083
Florian Nückebb9f0732014-03-03 15:12:28 +010084 /**
Florian Nücke4cb81b32015-06-28 19:20:15 +020085 * 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ückebb9f0732014-03-03 15:12:28 +010094 * 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ückedd41cb42014-03-09 17:13:19 +0100102 * <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ücke20239782015-04-22 15:21:43 +0200109 * <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ückedd41cb42014-03-09 17:13:19 +0100120 *
Florian Nücke0005aac2014-09-19 20:14:22 +0200121 * @param fileSystem the file system to wrap.
122 * @param label the label of the file system.
Florian Nückeb464e812014-09-19 20:17:37 +0200123 * @param host the tile entity containing the file system.
Florian Nücke0005aac2014-09-19 20:14:22 +0200124 * @param accessSound the name of the sound effect to play when the file
Florian Nücke20239782015-04-22 15:21:43 +0200125 * 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ückedd41cb42014-03-09 17:13:19 +0100129 * @return the network node wrapping the file system.
130 */
Florian Nücke20239782015-04-22 15:21:43 +0200131 ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound, int speed);
Florian Nückedd41cb42014-03-09 17:13:19 +0100132
133 /**
Florian Nücke20239782015-04-22 15:21:43 +0200134 * 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ückef4b07c72014-03-10 01:48:44 +0100139 *
Florian Nücke0005aac2014-09-19 20:14:22 +0200140 * @param fileSystem the file system to wrap.
141 * @param label the read-only label of the file system.
Florian Nückeb464e812014-09-19 20:17:37 +0200142 * @param host the tile entity containing the file system.
Florian Nücke0005aac2014-09-19 20:14:22 +0200143 * @param accessSound the name of the sound effect to play when the file
Florian Nücke20239782015-04-22 15:21:43 +0200144 * 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ückef4b07c72014-03-10 01:48:44 +0100148 * @return the network node wrapping the file system.
149 */
Florian Nücke20239782015-04-22 15:21:43 +0200150 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ückeb464e812014-09-19 20:17:37 +0200162 ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound);
Florian Nückef4b07c72014-03-10 01:48:44 +0100163
164 /**
Florian Nücke20239782015-04-22 15:21:43 +0200165 * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
Florian Nückebb9f0732014-03-03 15:12:28 +0100166 */
Florian Nücke20239782015-04-22 15:21:43 +0200167 @Deprecated
Florian Nückebb9f0732014-03-03 15:12:28 +0100168 ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label);
Florian Nückea7d21192013-11-09 20:56:21 +0100169
Florian Nückebb9f0732014-03-03 15:12:28 +0100170 /**
Florian Nücke20239782015-04-22 15:21:43 +0200171 * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
Florian Nückebb9f0732014-03-03 15:12:28 +0100172 */
Florian Nücke20239782015-04-22 15:21:43 +0200173 @Deprecated
Florian Nückebb9f0732014-03-03 15:12:28 +0100174 ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label);
Florian Nückea7d21192013-11-09 20:56:21 +0100175
Florian Nückebb9f0732014-03-03 15:12:28 +0100176 /**
Florian Nücke20239782015-04-22 15:21:43 +0200177 * @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
Florian Nückebb9f0732014-03-03 15:12:28 +0100178 */
Florian Nücke20239782015-04-22 15:21:43 +0200179 @Deprecated
Florian Nückebb9f0732014-03-03 15:12:28 +0100180 ManagedEnvironment asManagedEnvironment(FileSystem fileSystem);
Florian Nückec231f612013-10-25 02:33:08 +0200181}