Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/files'
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCrayfish committed Oct 26, 2017
2 parents a9cea84 + 85d40c9 commit 15bdf1a
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/main/java/com/mrcrayfish/device/api/io/Folder.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.mrcrayfish.device.api.io;

import com.mrcrayfish.device.api.task.Callback;
import com.mrcrayfish.device.api.task.Task;
import com.mrcrayfish.device.api.task.TaskManager;
import com.mrcrayfish.device.core.Laptop;
import com.mrcrayfish.device.core.io.FileSystem;
import com.mrcrayfish.device.core.io.action.FileAction;
import com.mrcrayfish.device.core.io.task.TaskGetFiles;
import com.mrcrayfish.device.programs.system.component.FileBrowser;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
Expand Down Expand Up @@ -295,7 +299,7 @@ else if(getFile(file.name).isProtected())
*/
public boolean hasFile(String name)
{
return files.stream().anyMatch(file -> file.name.equalsIgnoreCase(name));
return synced && files.stream().anyMatch(file -> file.name.equalsIgnoreCase(name));
}

/**
Expand All @@ -319,7 +323,7 @@ public File getFile(String name)
*/
public boolean hasFolder(String name)
{
return files.stream().anyMatch(file -> file.isFolder() && file.name.equalsIgnoreCase(name));
return synced && files.stream().anyMatch(file -> file.isFolder() && file.name.equalsIgnoreCase(name));
}

/**
Expand All @@ -335,6 +339,40 @@ public Folder getFolder(String name)
return (Folder) files.stream().filter(file -> file.isFolder() && file.name.equalsIgnoreCase(name)).findFirst().orElse(null);
}

public void getFolder(String name, Callback<Folder> callback)
{
Folder folder = getFolder(name);

if(folder == null)
{
callback.execute(null, false);
return;
}

if(!folder.isSynced())
{
Task task = new TaskGetFiles(folder, Laptop.getPos());
task.setCallback((nbt, success) ->
{
if(success && nbt.hasKey("files", Constants.NBT.TAG_LIST))
{
NBTTagList files = nbt.getTagList("files", Constants.NBT.TAG_COMPOUND);
folder.syncFiles(files);
callback.execute(folder, true);
}
else
{
callback.execute(null, false);
}
});
TaskManager.sendTask(task);
}
else
{
callback.execute(folder, true);
}
}

/**
* Gets all the files in the folder.
*
Expand Down

0 comments on commit 15bdf1a

Please sign in to comment.