mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-31 21:52:59 +00:00
Merge branch 'mc-1.14.x' into mc-1.15.x
This commit is contained in:
@@ -10,12 +10,18 @@ import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
import dan200.computercraft.api.lua.ILuaAPI;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.core.computer.BasicEnvironment;
|
||||
import dan200.computercraft.core.computer.Computer;
|
||||
import dan200.computercraft.core.computer.ComputerSide;
|
||||
import dan200.computercraft.core.computer.MainThread;
|
||||
import dan200.computercraft.core.filesystem.FileMount;
|
||||
import dan200.computercraft.core.filesystem.FileSystemException;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.*;
|
||||
@@ -78,7 +84,7 @@ public class ComputerTestDelegate
|
||||
ComputerCraft.logPeripheralErrors = true;
|
||||
|
||||
Terminal term = new Terminal( 78, 20 );
|
||||
IWritableMount mount = new FileMount( new File( "test-files/mount" ), Long.MAX_VALUE );
|
||||
IWritableMount mount = new FileMount( new File( "test-files/mount" ), 10_000_000 );
|
||||
|
||||
// Remove any existing files
|
||||
List<String> children = new ArrayList<>();
|
||||
@@ -89,10 +95,11 @@ public class ComputerTestDelegate
|
||||
try( WritableByteChannel channel = mount.openForWrite( "startup.lua" );
|
||||
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-rom/mcfly.lua', nil, _ENV)('test-rom/spec') cct_test.finish()" );
|
||||
}
|
||||
|
||||
computer = new Computer( new BasicEnvironment( mount ), term, 0 );
|
||||
computer.getEnvironment().setPeripheral( ComputerSide.TOP, new FakeModem() );
|
||||
computer.addApi( new ILuaAPI()
|
||||
{
|
||||
@Override
|
||||
@@ -114,7 +121,7 @@ public class ComputerTestDelegate
|
||||
try
|
||||
{
|
||||
computer.getAPIEnvironment().getFileSystem().mount(
|
||||
"test-rom", "test",
|
||||
"test-rom", "test-rom",
|
||||
BasicEnvironment.createMount( ComputerTestDelegate.class, "test-rom", "test" )
|
||||
);
|
||||
}
|
||||
@@ -416,4 +423,33 @@ public class ComputerTestDelegate
|
||||
{
|
||||
return name.replace( "\0", " -> " );
|
||||
}
|
||||
|
||||
private static class FakeModem extends WirelessModemPeripheral
|
||||
{
|
||||
FakeModem()
|
||||
{
|
||||
super( new ModemState(), true );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@SuppressWarnings( "ConstantConditions" )
|
||||
public World getWorld()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
{
|
||||
return Vec3d.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( @Nullable IPeripheral other )
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class BasicEnvironment implements IComputerEnvironment
|
||||
while( baseFile != null && !wholeFile.exists() )
|
||||
{
|
||||
baseFile = baseFile.getParentFile();
|
||||
wholeFile = new File( baseFile, "resources/" + fallback + "/" + path );
|
||||
wholeFile = new File( baseFile, "src/" + fallback + "/resources/" + path );
|
||||
}
|
||||
|
||||
if( !wholeFile.exists() ) throw new IllegalStateException( "Cannot find ROM mount at " + file );
|
||||
|
||||
@@ -16,6 +16,10 @@ import java.io.IOException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -25,10 +29,11 @@ public class JarMountTest
|
||||
{
|
||||
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
|
||||
|
||||
private static final FileTime MODIFY_TIME = FileTime.from( Instant.EPOCH.plus( 2, ChronoUnit.DAYS ) );
|
||||
|
||||
@BeforeAll
|
||||
public static void before() throws IOException
|
||||
{
|
||||
if( ZIP_FILE.exists() ) return;
|
||||
ZIP_FILE.getParentFile().mkdirs();
|
||||
|
||||
try( ZipOutputStream stream = new ZipOutputStream( new FileOutputStream( ZIP_FILE ) ) )
|
||||
@@ -36,7 +41,7 @@ public class JarMountTest
|
||||
stream.putNextEntry( new ZipEntry( "dir/" ) );
|
||||
stream.closeEntry();
|
||||
|
||||
stream.putNextEntry( new ZipEntry( "dir/file.lua" ) );
|
||||
stream.putNextEntry( new ZipEntry( "dir/file.lua" ).setLastModifiedTime( MODIFY_TIME ) );
|
||||
stream.write( "print('testing')".getBytes( StandardCharsets.UTF_8 ) );
|
||||
stream.closeEntry();
|
||||
}
|
||||
@@ -83,4 +88,21 @@ public class JarMountTest
|
||||
|
||||
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileAttributes() throws IOException
|
||||
{
|
||||
BasicFileAttributes attributes = new JarMount( ZIP_FILE, "dir" ).getAttributes( "file.lua" );
|
||||
assertFalse( attributes.isDirectory() );
|
||||
assertEquals( "print('testing')".length(), attributes.size() );
|
||||
assertEquals( MODIFY_TIME, attributes.lastModifiedTime() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directoryAttributes() throws IOException
|
||||
{
|
||||
BasicFileAttributes attributes = new JarMount( ZIP_FILE, "dir" ).getAttributes( "" );
|
||||
assertTrue( attributes.isDirectory() );
|
||||
assertEquals( 0, attributes.size() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user