mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-15 22:34:54 +00:00
Some API cleanup
- Remove *Stream methods on IMount/IWritableMount, and make the channel ones the primary. - Fix location of AbstractTurtleUpgrade - Make IComputerAccess.getAvailablePeripheral and .getMainThreadMonitor mandatory. - IComputerAccess throws a specialised NotAttachedException
This commit is contained in:
parent
fb440b0d2e
commit
044d2b2b06
@ -112,31 +112,6 @@ public final class ComputerCraftAPI
|
|||||||
return getInstance().createResourceMount( domain, subPath );
|
return getInstance().createResourceMount( domain, subPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a file system mount to a resource folder, and returns it.
|
|
||||||
*
|
|
||||||
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
|
||||||
* resource folder onto a computer's file system.
|
|
||||||
*
|
|
||||||
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
|
||||||
* resources with the same domain and path.
|
|
||||||
*
|
|
||||||
* @param klass The mod class to which the files belong.
|
|
||||||
* @param domain The domain under which to look for resources. eg: "mymod".
|
|
||||||
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
|
||||||
* @return The mount, or {@code null} if it could be created for some reason.
|
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
|
||||||
* @see IMount
|
|
||||||
* @deprecated Use {@link #createResourceMount(String, String)} instead.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
@Deprecated
|
|
||||||
public static IMount createResourceMount( Class<?> klass, @Nonnull String domain, @Nonnull String subPath )
|
|
||||||
{
|
|
||||||
return getInstance().createResourceMount( domain, subPath );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
|
* Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
|
||||||
*
|
*
|
||||||
|
@ -11,8 +11,6 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -22,10 +20,10 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* Ready made implementations of this interface can be created using
|
* Ready made implementations of this interface can be created using
|
||||||
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
||||||
* {@link ComputerCraftAPI#createResourceMount(Class, String, String)}, or you're free to implement it yourselves!
|
* {@link ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
|
||||||
*
|
*
|
||||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, IMount)
|
||||||
* @see IWritableMount
|
* @see IWritableMount
|
||||||
*/
|
*/
|
||||||
@ -67,18 +65,6 @@ public interface IMount
|
|||||||
*/
|
*/
|
||||||
long getSize( @Nonnull String path ) throws IOException;
|
long getSize( @Nonnull String path ) throws IOException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a file with a given path, and returns an {@link InputStream} representing its contents.
|
|
||||||
*
|
|
||||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
|
||||||
* @return A stream representing the contents of the file.
|
|
||||||
* @throws IOException If the file does not exist, or could not be opened.
|
|
||||||
* @deprecated Use {@link #openChannelForRead(String)} instead
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
@Deprecated
|
|
||||||
InputStream openForRead( @Nonnull String path ) throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
|
* Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
|
||||||
*
|
*
|
||||||
@ -89,8 +75,5 @@ public interface IMount
|
|||||||
* @throws IOException If the file does not exist, or could not be opened.
|
* @throws IOException If the file does not exist, or could not be opened.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
default ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
|
||||||
{
|
|
||||||
return Channels.newChannel( openForRead( path ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import net.minecraft.world.World;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,18 +44,6 @@ public interface IWritableMount extends IMount
|
|||||||
*/
|
*/
|
||||||
void delete( @Nonnull String path ) throws IOException;
|
void delete( @Nonnull String path ) throws IOException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
|
|
||||||
*
|
|
||||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
|
||||||
* @return A stream for writing to
|
|
||||||
* @throws IOException If the file could not be opened for writing.
|
|
||||||
* @deprecated Use {@link #openChannelForWrite(String)} instead.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
@Deprecated
|
|
||||||
OutputStream openForWrite( @Nonnull String path ) throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
|
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
|
||||||
*
|
*
|
||||||
@ -66,22 +53,7 @@ public interface IWritableMount extends IMount
|
|||||||
* @throws IOException If the file could not be opened for writing.
|
* @throws IOException If the file could not be opened for writing.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
WritableByteChannel openForWrite( @Nonnull String path ) throws IOException;
|
||||||
{
|
|
||||||
return Channels.newChannel( openForWrite( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
|
|
||||||
*
|
|
||||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
|
||||||
* @return A stream for writing to.
|
|
||||||
* @throws IOException If the file could not be opened for writing.
|
|
||||||
* @deprecated Use {@link #openChannelForAppend(String)} instead.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
@Deprecated
|
|
||||||
OutputStream openForAppend( @Nonnull String path ) throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
|
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
|
||||||
@ -92,10 +64,7 @@ public interface IWritableMount extends IMount
|
|||||||
* @throws IOException If the file could not be opened for writing.
|
* @throws IOException If the file could not be opened for writing.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
WritableByteChannel openForAppend( @Nonnull String path ) throws IOException;
|
||||||
{
|
|
||||||
return Channels.newChannel( openForAppend( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
|
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
|
||||||
|
@ -79,7 +79,7 @@ public interface IMedia
|
|||||||
* @see IMount
|
* @see IMount
|
||||||
* @see dan200.computercraft.api.filesystem.IWritableMount
|
* @see dan200.computercraft.api.filesystem.IWritableMount
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
|
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
|
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
|
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
|
||||||
|
@ -14,7 +14,6 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,9 +30,9 @@ public interface IComputerAccess
|
|||||||
* @param mount The mount object to mount on the computer.
|
* @param mount The mount object to mount on the computer.
|
||||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||||
* @see #mount(String, IMount, String)
|
* @see #mount(String, IMount, String)
|
||||||
* @see #mountWritable(String, IWritableMount)
|
* @see #mountWritable(String, IWritableMount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
@ -53,9 +52,9 @@ public interface IComputerAccess
|
|||||||
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
||||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, IMount)
|
||||||
* @see #mountWritable(String, IWritableMount)
|
* @see #mountWritable(String, IWritableMount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
@ -71,9 +70,9 @@ public interface IComputerAccess
|
|||||||
* @param mount The mount object to mount on the computer.
|
* @param mount The mount object to mount on the computer.
|
||||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, IMount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
* @see IMount
|
* @see IMount
|
||||||
@ -92,9 +91,9 @@ public interface IComputerAccess
|
|||||||
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
||||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, IMount)
|
||||||
* @see #unmount(String)
|
* @see #unmount(String)
|
||||||
* @see IMount
|
* @see IMount
|
||||||
@ -114,8 +113,8 @@ public interface IComputerAccess
|
|||||||
* @param location The desired location in the computers file system of the directory to unmount.
|
* @param location The desired location in the computers file system of the directory to unmount.
|
||||||
* This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
|
* This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
|
||||||
* {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
|
* {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @throws RuntimeException If the mount does not exist, or was mounted by another peripheral.
|
* @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
|
||||||
* @see #mount(String, IMount)
|
* @see #mount(String, IMount)
|
||||||
* @see #mountWritable(String, IWritableMount)
|
* @see #mountWritable(String, IWritableMount)
|
||||||
*/
|
*/
|
||||||
@ -146,7 +145,7 @@ public interface IComputerAccess
|
|||||||
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().
|
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().
|
||||||
*
|
*
|
||||||
* You may supply {@code null} to indicate that no arguments are to be supplied.
|
* You may supply {@code null} to indicate that no arguments are to be supplied.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see IPeripheral#callMethod
|
* @see IPeripheral#callMethod
|
||||||
*/
|
*/
|
||||||
void queueEvent( @Nonnull String event, @Nullable Object[] arguments );
|
void queueEvent( @Nonnull String event, @Nullable Object[] arguments );
|
||||||
@ -159,7 +158,7 @@ public interface IComputerAccess
|
|||||||
* which peripheral the event came.
|
* which peripheral the event came.
|
||||||
*
|
*
|
||||||
* @return A string unique to the computer, but not globally.
|
* @return A string unique to the computer, but not globally.
|
||||||
* @throws RuntimeException If the peripheral has been detached.
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
String getAttachmentName();
|
String getAttachmentName();
|
||||||
@ -170,14 +169,12 @@ public interface IComputerAccess
|
|||||||
* This may include other peripherals on the wired network or peripherals on other sides of the computer.
|
* This may include other peripherals on the wired network or peripherals on other sides of the computer.
|
||||||
*
|
*
|
||||||
* @return All reachable peripherals
|
* @return All reachable peripherals
|
||||||
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
* @see #getAttachmentName()
|
* @see #getAttachmentName()
|
||||||
* @see #getAvailablePeripheral(String)
|
* @see #getAvailablePeripheral(String)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
default Map<String, IPeripheral> getAvailablePeripherals()
|
Map<String, IPeripheral> getAvailablePeripherals();
|
||||||
{
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a reachable peripheral with the given attachment name. This is a equivalent to
|
* Get a reachable peripheral with the given attachment name. This is a equivalent to
|
||||||
@ -188,10 +185,7 @@ public interface IComputerAccess
|
|||||||
* @see #getAvailablePeripherals()
|
* @see #getAvailablePeripherals()
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default IPeripheral getAvailablePeripheral( @Nonnull String name )
|
IPeripheral getAvailablePeripheral( @Nonnull String name );
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@link IWorkMonitor} for tasks your peripheral might execute on the main (server) thread.
|
* Get a {@link IWorkMonitor} for tasks your peripheral might execute on the main (server) thread.
|
||||||
@ -205,10 +199,8 @@ public interface IComputerAccess
|
|||||||
* thread.
|
* thread.
|
||||||
*
|
*
|
||||||
* @return The work monitor for the main thread, or {@code null} if this computer does not have one.
|
* @return The work monitor for the main thread, or {@code null} if this computer does not have one.
|
||||||
|
* @throws NotAttachedException If the peripheral has been detached.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
default IWorkMonitor getMainThreadMonitor()
|
IWorkMonitor getMainThreadMonitor();
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when performing operations on {@link IComputerAccess} when the current peripheral is no longer attached to
|
||||||
|
* the computer.
|
||||||
|
*/
|
||||||
|
public class NotAttachedException extends IllegalStateException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1221244785535553536L;
|
||||||
|
|
||||||
|
public NotAttachedException()
|
||||||
|
{
|
||||||
|
super( "You are not attached to this Computer" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotAttachedException( String s )
|
||||||
|
{
|
||||||
|
super( s );
|
||||||
|
}
|
||||||
|
}
|
@ -3,10 +3,8 @@
|
|||||||
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
*/
|
*/
|
||||||
package dan200.computercraft.api;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IItemProvider;
|
import net.minecraft.util.IItemProvider;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
@ -13,7 +13,6 @@ import dan200.computercraft.core.filesystem.FileSystem;
|
|||||||
import dan200.computercraft.core.filesystem.FileSystemException;
|
import dan200.computercraft.core.filesystem.FileSystemException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -123,7 +122,7 @@ public abstract class ComputerAccess implements IComputerAccess
|
|||||||
m_environment.queueEvent( event, arguments );
|
m_environment.queueEvent( event, arguments );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IWorkMonitor getMainThreadMonitor()
|
public IWorkMonitor getMainThreadMonitor()
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,8 @@ import dan200.computercraft.api.lua.ILuaAPI;
|
|||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||||
|
import dan200.computercraft.api.peripheral.NotAttachedException;
|
||||||
import dan200.computercraft.core.computer.ComputerSide;
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.core.tracking.TrackingField;
|
import dan200.computercraft.core.tracking.TrackingField;
|
||||||
|
|
||||||
@ -122,53 +124,35 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
@Override
|
@Override
|
||||||
public synchronized String mount( @Nonnull String desiredLoc, @Nonnull IMount mount, @Nonnull String driveName )
|
public synchronized String mount( @Nonnull String desiredLoc, @Nonnull IMount mount, @Nonnull String driveName )
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.mount( desiredLoc, mount, driveName );
|
return super.mount( desiredLoc, mount, driveName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized String mountWritable( @Nonnull String desiredLoc, @Nonnull IWritableMount mount, @Nonnull String driveName )
|
public synchronized String mountWritable( @Nonnull String desiredLoc, @Nonnull IWritableMount mount, @Nonnull String driveName )
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.mountWritable( desiredLoc, mount, driveName );
|
return super.mountWritable( desiredLoc, mount, driveName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void unmount( String location )
|
public synchronized void unmount( String location )
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
|
|
||||||
super.unmount( location );
|
super.unmount( location );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getID()
|
public int getID()
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
return super.getID();
|
return super.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueEvent( @Nonnull final String event, final Object[] arguments )
|
public void queueEvent( @Nonnull final String event, final Object[] arguments )
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
super.queueEvent( event, arguments );
|
super.queueEvent( event, arguments );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,10 +160,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
@Override
|
@Override
|
||||||
public String getAttachmentName()
|
public String getAttachmentName()
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
return m_side;
|
return m_side;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,10 +168,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, IPeripheral> getAvailablePeripherals()
|
public Map<String, IPeripheral> getAvailablePeripherals()
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, IPeripheral> peripherals = new HashMap<>();
|
Map<String, IPeripheral> peripherals = new HashMap<>();
|
||||||
for( PeripheralWrapper wrapper : m_peripherals )
|
for( PeripheralWrapper wrapper : m_peripherals )
|
||||||
@ -208,10 +186,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
@Override
|
@Override
|
||||||
public IPeripheral getAvailablePeripheral( @Nonnull String name )
|
public IPeripheral getAvailablePeripheral( @Nonnull String name )
|
||||||
{
|
{
|
||||||
if( !m_attached )
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
{
|
|
||||||
throw new RuntimeException( "You are not attached to this Computer" );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( PeripheralWrapper wrapper : m_peripherals )
|
for( PeripheralWrapper wrapper : m_peripherals )
|
||||||
{
|
{
|
||||||
@ -222,6 +197,14 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IWorkMonitor getMainThreadMonitor()
|
||||||
|
{
|
||||||
|
if( !m_attached ) throw new NotAttachedException();
|
||||||
|
return super.getMainThreadMonitor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IAPIEnvironment m_environment;
|
private final IAPIEnvironment m_environment;
|
||||||
|
@ -9,12 +9,15 @@ import dan200.computercraft.api.filesystem.IFileSystem;
|
|||||||
import dan200.computercraft.api.lua.IComputerSystem;
|
import dan200.computercraft.api.lua.IComputerSystem;
|
||||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.apis.ComputerAccess;
|
import dan200.computercraft.core.apis.ComputerAccess;
|
||||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||||
import dan200.computercraft.core.filesystem.FileSystem;
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link IComputerAccess}/{@link IComputerSystem} for usage by externally registered APIs.
|
* Implementation of {@link IComputerAccess}/{@link IComputerSystem} for usage by externally registered APIs.
|
||||||
@ -54,4 +57,19 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem
|
|||||||
{
|
{
|
||||||
return environment.getLabel();
|
return environment.getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public Map<String, IPeripheral> getAvailablePeripherals()
|
||||||
|
{
|
||||||
|
// TODO: Should this return peripherals on the current computer?
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IPeripheral getAvailablePeripheral( @Nonnull String name )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -115,8 +114,7 @@ public class ComboMount implements IMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||||
{
|
{
|
||||||
@ -128,19 +126,4 @@ public class ComboMount implements IMount
|
|||||||
}
|
}
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new FileOperationException( path, "No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
|
||||||
{
|
|
||||||
IMount part = m_parts[i];
|
|
||||||
if( part.exists( path ) && !part.isDirectory( path ) )
|
|
||||||
{
|
|
||||||
return part.openChannelForRead( path );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -42,15 +41,7 @@ public class EmptyMount implements IMount
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
{
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new FileOperationException( path, "No such file" );
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@ import dan200.computercraft.api.filesystem.FileOperationException;
|
|||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -199,21 +200,7 @@ public class FileMount implements IWritableMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
if( created() )
|
|
||||||
{
|
|
||||||
File file = getRealPath( path );
|
|
||||||
if( file.exists() && !file.isDirectory() ) return new FileInputStream( file );
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
if( created() )
|
if( created() )
|
||||||
{
|
{
|
||||||
@ -299,23 +286,7 @@ public class FileMount implements IWritableMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public WritableByteChannel openForWrite( @Nonnull String path ) throws IOException
|
||||||
public OutputStream openForWrite( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newOutputStream( openChannelForWrite( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public OutputStream openForAppend( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newOutputStream( openChannelForAppend( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
create();
|
create();
|
||||||
File file = getRealPath( path );
|
File file = getRealPath( path );
|
||||||
@ -336,7 +307,7 @@ public class FileMount implements IWritableMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
public WritableByteChannel openForAppend( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
if( !created() )
|
if( !created() )
|
||||||
{
|
{
|
||||||
|
@ -165,7 +165,7 @@ public class FileSystem
|
|||||||
{
|
{
|
||||||
if( m_mount.exists( path ) && !m_mount.isDirectory( path ) )
|
if( m_mount.exists( path ) && !m_mount.isDirectory( path ) )
|
||||||
{
|
{
|
||||||
return m_mount.openChannelForRead( path );
|
return m_mount.openForRead( path );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -245,7 +245,7 @@ public class FileSystem
|
|||||||
m_writableMount.makeDirectory( dir );
|
m_writableMount.makeDirectory( dir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_writableMount.openChannelForWrite( path );
|
return m_writableMount.openForWrite( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( AccessDeniedException e )
|
catch( AccessDeniedException e )
|
||||||
@ -275,7 +275,7 @@ public class FileSystem
|
|||||||
m_writableMount.makeDirectory( dir );
|
m_writableMount.makeDirectory( dir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_writableMount.openChannelForWrite( path );
|
return m_writableMount.openForWrite( path );
|
||||||
}
|
}
|
||||||
else if( m_mount.isDirectory( path ) )
|
else if( m_mount.isDirectory( path ) )
|
||||||
{
|
{
|
||||||
@ -283,7 +283,7 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return m_writableMount.openChannelForAppend( path );
|
return m_writableMount.openForAppend( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( AccessDeniedException e )
|
catch( AccessDeniedException e )
|
||||||
|
@ -9,9 +9,6 @@ import dan200.computercraft.api.filesystem.IFileSystem;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -55,7 +52,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -70,7 +67,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
public WritableByteChannel openForWrite( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -84,7 +81,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
public WritableByteChannel openForAppend( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -96,30 +93,6 @@ public class FileSystemWrapperMount implements IFileSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newInputStream( openChannelForRead( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public OutputStream openForWrite( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newOutputStream( openChannelForWrite( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public OutputStream openForAppend( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newOutputStream( openChannelForAppend( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getRemainingSpace() throws IOException
|
public long getRemainingSpace() throws IOException
|
||||||
{
|
{
|
||||||
|
@ -181,15 +181,7 @@ public class JarMount implements IMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newInputStream( openChannelForRead( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
FileEntry file = get( path );
|
FileEntry file = get( path );
|
||||||
if( file != null && !file.isDirectory() )
|
if( file != null && !file.isDirectory() )
|
||||||
|
@ -223,15 +223,7 @@ public final class ResourceMount implements IMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newInputStream( openChannelForRead( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
FileEntry file = get( path );
|
FileEntry file = get( path );
|
||||||
if( file != null && !file.isDirectory() )
|
if( file != null && !file.isDirectory() )
|
||||||
|
@ -9,7 +9,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -52,19 +51,11 @@ public class SubMount implements IMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
return m_parent.openForRead( getFullPath( path ) );
|
return m_parent.openForRead( getFullPath( path ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return m_parent.openChannelForRead( getFullPath( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFullPath( String path )
|
private String getFullPath( String path )
|
||||||
{
|
{
|
||||||
if( path.isEmpty() )
|
if( path.isEmpty() )
|
||||||
|
@ -374,7 +374,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
|||||||
m_computer.queueEvent( event, arguments );
|
m_computer.queueEvent( event, arguments );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IWorkMonitor getMainThreadMonitor()
|
public IWorkMonitor getMainThreadMonitor()
|
||||||
{
|
{
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.turtle.upgrades;
|
package dan200.computercraft.shared.turtle.upgrades;
|
||||||
|
|
||||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import dan200.computercraft.api.client.TransformedModel;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package dan200.computercraft.shared.turtle.upgrades;
|
package dan200.computercraft.shared.turtle.upgrades;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import dan200.computercraft.api.client.TransformedModel;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.turtle.*;
|
import dan200.computercraft.api.turtle.*;
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
package dan200.computercraft.shared.turtle.upgrades;
|
package dan200.computercraft.shared.turtle.upgrades;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import dan200.computercraft.api.client.TransformedModel;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package dan200.computercraft.shared.turtle.upgrades;
|
package dan200.computercraft.shared.turtle.upgrades;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import dan200.computercraft.api.client.TransformedModel;
|
||||||
import dan200.computercraft.api.turtle.*;
|
import dan200.computercraft.api.turtle.*;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
||||||
|
@ -86,7 +86,7 @@ public class ComputerTestDelegate
|
|||||||
for( String child : children ) mount.delete( child );
|
for( String child : children ) mount.delete( child );
|
||||||
|
|
||||||
// And add our startup file
|
// And add our startup file
|
||||||
try( WritableByteChannel channel = mount.openChannelForWrite( "startup.lua" );
|
try( WritableByteChannel channel = mount.openForWrite( "startup.lua" );
|
||||||
Writer writer = Channels.newWriter( channel, StandardCharsets.UTF_8.newEncoder(), -1 ) )
|
Writer writer = Channels.newWriter( channel, StandardCharsets.UTF_8.newEncoder(), -1 ) )
|
||||||
{
|
{
|
||||||
writer.write( "loadfile('test/mcfly.lua', nil, _ENV)('test/spec') cct_test.finish()" );
|
writer.write( "loadfile('test/mcfly.lua', nil, _ENV)('test/spec') cct_test.finish()" );
|
||||||
|
@ -13,14 +13,14 @@ import org.junit.jupiter.api.Test;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@SuppressWarnings( "deprecation" )
|
|
||||||
public class JarMountTest
|
public class JarMountTest
|
||||||
{
|
{
|
||||||
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
|
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
|
||||||
@ -63,9 +63,9 @@ public class JarMountTest
|
|||||||
{
|
{
|
||||||
IMount mount = new JarMount( ZIP_FILE, "dir/file.lua" );
|
IMount mount = new JarMount( ZIP_FILE, "dir/file.lua" );
|
||||||
byte[] contents;
|
byte[] contents;
|
||||||
try( InputStream stream = mount.openForRead( "" ) )
|
try( ReadableByteChannel stream = mount.openForRead( "" ) )
|
||||||
{
|
{
|
||||||
contents = ByteStreams.toByteArray( stream );
|
contents = ByteStreams.toByteArray( Channels.newInputStream( stream ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
||||||
@ -76,9 +76,9 @@ public class JarMountTest
|
|||||||
{
|
{
|
||||||
IMount mount = new JarMount( ZIP_FILE, "dir" );
|
IMount mount = new JarMount( ZIP_FILE, "dir" );
|
||||||
byte[] contents;
|
byte[] contents;
|
||||||
try( InputStream stream = mount.openForRead( "file.lua" ) )
|
try( ReadableByteChannel stream = mount.openForRead( "file.lua" ) )
|
||||||
{
|
{
|
||||||
contents = ByteStreams.toByteArray( stream );
|
contents = ByteStreams.toByteArray( Channels.newInputStream( stream ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
||||||
|
@ -6,9 +6,15 @@
|
|||||||
package dan200.computercraft.core.filesystem;
|
package dan200.computercraft.core.filesystem;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
|
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.*;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,10 +67,9 @@ public class MemoryMount implements IWritableMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public WritableByteChannel openForWrite( @Nonnull final String path )
|
||||||
public OutputStream openForWrite( @Nonnull final String path )
|
|
||||||
{
|
{
|
||||||
return new ByteArrayOutputStream()
|
return Channels.newChannel( new ByteArrayOutputStream()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
@ -72,13 +77,12 @@ public class MemoryMount implements IWritableMount
|
|||||||
super.close();
|
super.close();
|
||||||
files.put( path, toByteArray() );
|
files.put( path, toByteArray() );
|
||||||
}
|
}
|
||||||
};
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public WritableByteChannel openForAppend( @Nonnull final String path ) throws IOException
|
||||||
public OutputStream openForAppend( @Nonnull final String path ) throws IOException
|
|
||||||
{
|
{
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream()
|
ByteArrayOutputStream stream = new ByteArrayOutputStream()
|
||||||
{
|
{
|
||||||
@ -93,7 +97,7 @@ public class MemoryMount implements IWritableMount
|
|||||||
byte[] current = files.get( path );
|
byte[] current = files.get( path );
|
||||||
if( current != null ) stream.write( current );
|
if( current != null ) stream.write( current );
|
||||||
|
|
||||||
return stream;
|
return Channels.newChannel( stream );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -131,10 +135,9 @@ public class MemoryMount implements IWritableMount
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ReadableByteChannel openForRead( @Nonnull String path )
|
||||||
public InputStream openForRead( @Nonnull String path )
|
|
||||||
{
|
{
|
||||||
return new ByteArrayInputStream( files.get( path ) );
|
return new ArrayByteChannel( files.get( path ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryMount addFile( String file, String contents )
|
public MemoryMount addFile( String file, String contents )
|
||||||
|
Loading…
Reference in New Issue
Block a user