1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-22 09:27:39 +00:00

Flesh out MemoryMount into a writable mount

This moves MemoryMount to the main core module, and converts it to be a
"proper" WritableMount. It's still naively implemented - definitely
would be good to flesh out our tests in the future - but enough for what
we need it for.

We also do the following:
 - Remove the FileEntry.path variable, and instead pass the path around
   as a variable.
 - Clean up BinaryReadableHandle to use ByteBuffers in a more idiomatic
   way.
 - Add a couple more tests to our FS tests. These are in a bit of an odd
   place, where we want both Lua tests (for emulator compliance) and
   Java tests (for testing different implementations) - something to
   think about in the future.
This commit is contained in:
Jonathan Coates
2023-09-29 22:14:54 +01:00
parent e7a1065bfc
commit 96b6947ef2
20 changed files with 616 additions and 228 deletions

View File

@@ -58,7 +58,7 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
var hasAny = false;
String existingNamespace = null;
var newRoot = new FileEntry("", new ResourceLocation(namespace, subPath));
var newRoot = new FileEntry(new ResourceLocation(namespace, subPath));
for (var file : manager.listResources(subPath, s -> true).keySet()) {
existingNamespace = file.getNamespace();
@@ -86,24 +86,23 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
}
private FileEntry createEntry(String path) {
return new FileEntry(path, new ResourceLocation(namespace, subPath + "/" + path));
return new FileEntry(new ResourceLocation(namespace, subPath + "/" + path));
}
@Override
public byte[] getFileContents(FileEntry file) throws IOException {
protected byte[] getFileContents(String path, FileEntry file) throws IOException {
var resource = manager.getResource(file.identifier).orElse(null);
if (resource == null) throw new FileOperationException(file.path, NO_SUCH_FILE);
if (resource == null) throw new FileOperationException(path, NO_SUCH_FILE);
try (var stream = resource.open()) {
return stream.readAllBytes();
}
}
protected static class FileEntry extends ArchiveMount.FileEntry<FileEntry> {
protected static final class FileEntry extends ArchiveMount.FileEntry<FileEntry> {
final ResourceLocation identifier;
FileEntry(String path, ResourceLocation identifier) {
super(path);
FileEntry(ResourceLocation identifier) {
this.identifier = identifier;
}
}

View File

@@ -4,6 +4,7 @@
package dan200.computercraft.shared.computer.menu;
import dan200.computercraft.core.apis.handles.ByteBufferChannel;
import dan200.computercraft.core.apis.transfer.TransferredFile;
import dan200.computercraft.core.apis.transfer.TransferredFiles;
import dan200.computercraft.shared.computer.upload.FileSlice;
@@ -22,7 +23,6 @@ import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* The default concrete implementation of {@link ServerInputHandler}.
@@ -156,7 +156,7 @@ public class ServerInputState<T extends AbstractContainerMenu & ComputerMenu> im
computer.queueEvent(TransferredFiles.EVENT, new Object[]{
new TransferredFiles(
toUpload.stream().map(x -> new TransferredFile(x.getName(), x.getBytes())).collect(Collectors.toList()),
toUpload.stream().map(x -> new TransferredFile(x.getName(), new ByteBufferChannel(x.getBytes()))).toList(),
() -> {
if (player.isAlive() && player.containerMenu == owner) {
PlatformHelper.get().sendToPlayer(UploadResultMessage.consumed(owner), player);