Sync Screen offers user-options
This commit is contained in:
parent
d46e375501
commit
dfe25a9599
7 changed files with 144 additions and 76 deletions
|
@ -6,6 +6,7 @@ import ru.bclib.api.dataexchange.DataHandler;
|
|||
import ru.bclib.api.dataexchange.SyncFileHash;
|
||||
import ru.bclib.api.dataexchange.handler.autosync.AutoSync.NeedTransferPredicate;
|
||||
import ru.bclib.api.dataexchange.handler.autosync.SyncFolderDescriptor.SubFile;
|
||||
import ru.bclib.config.Config;
|
||||
import ru.bclib.util.ModUtil;
|
||||
import ru.bclib.util.Pair;
|
||||
import ru.bclib.util.ModUtil.ModInfo;
|
||||
|
@ -108,6 +109,7 @@ class AutoFileSyncEntry extends AutoSyncID {
|
|||
this.requestContent = requestContent;
|
||||
}
|
||||
|
||||
|
||||
public SyncFileHash getFileHash() {
|
||||
if (hash == null) {
|
||||
hash = SyncFileHash.create(modID, fileName, uniqueID);
|
||||
|
|
|
@ -3,6 +3,7 @@ package ru.bclib.api.dataexchange.handler.autosync;
|
|||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.bclib.api.dataexchange.DataHandler;
|
||||
import ru.bclib.config.Config;
|
||||
import ru.bclib.util.ModUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -134,4 +135,8 @@ public class AutoSyncID {
|
|||
return new AutoSyncID(modID, uID);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConfigFile(){
|
||||
return this.uniqueID.startsWith(Config.CONFIG_SYNC_PREFIX);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -330,7 +330,7 @@ public class HelloClient extends DataHandler.FromServer {
|
|||
//Files can only get placed within that folder
|
||||
|
||||
if ((filesToRequest.size() > 0 || filesToRemove.size() > 0) && ClientConfig.isAcceptingFiles()) {
|
||||
showDownloadConfigs(client, filesToRequest, filesToRemove);
|
||||
showSyncFilesScreen(client, filesToRequest, filesToRemove);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -350,40 +350,67 @@ public class HelloClient extends DataHandler.FromServer {
|
|||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
protected void showDownloadConfigs(Minecraft client, List<AutoSyncID> files, final List<AutoSyncID.ForDirectFileRequest> filesToRemove) {
|
||||
client.setScreen(new SyncFilesScreen((download) -> {
|
||||
protected void showSyncFilesScreen(Minecraft client, List<AutoSyncID> files, final List<AutoSyncID.ForDirectFileRequest> filesToRemove) {
|
||||
int configFiles = 0;
|
||||
int singleFiles = 0;
|
||||
int folderFiles = 0;
|
||||
int modFiles = 0;
|
||||
|
||||
for (AutoSyncID aid : files){
|
||||
if (aid.isConfigFile()){
|
||||
configFiles++;
|
||||
} else if (aid instanceof AutoSyncID.ForModFileRequest){
|
||||
modFiles++;
|
||||
} else if (aid instanceof AutoSyncID.ForDirectFileRequest){
|
||||
folderFiles++;
|
||||
} else {
|
||||
singleFiles++;
|
||||
}
|
||||
}
|
||||
|
||||
client.setScreen(new SyncFilesScreen(modFiles, configFiles, singleFiles, folderFiles, filesToRemove.size(), (downloadMods, downloadConfigs, downloadFiles, removeFiles) -> {
|
||||
Minecraft.getInstance()
|
||||
.setScreen((Screen) null);
|
||||
if (download) {
|
||||
if (downloadMods || downloadConfigs || downloadFiles) {
|
||||
BCLib.LOGGER.info("Updating local Files:");
|
||||
List<AutoSyncID.WithContentOverride> localChanges = new ArrayList<>(files.toArray().length);
|
||||
List<AutoSyncID> requestFiles = new ArrayList<>(files.toArray().length);
|
||||
|
||||
files.forEach(aid -> {
|
||||
if (aid instanceof WithContentOverride) {
|
||||
final WithContentOverride aidc = (WithContentOverride) aid;
|
||||
BCLib.LOGGER.info(" - " + aid + " (updating Content)");
|
||||
|
||||
SendFiles.writeSyncedFile(aid, aidc.contentWrapper.getRawContent(), aidc.localFile);
|
||||
if (aid.isConfigFile() && downloadConfigs){
|
||||
processOfferedFile(requestFiles, aid);
|
||||
} else if (aid instanceof AutoSyncID.ForModFileRequest && downloadMods){
|
||||
processOfferedFile(requestFiles, aid);
|
||||
} else if (downloadFiles){
|
||||
processOfferedFile(requestFiles, aid);
|
||||
}
|
||||
else {
|
||||
requestFiles.add(aid);
|
||||
BCLib.LOGGER.info(" - " + aid + " (requesting)");
|
||||
}
|
||||
});
|
||||
|
||||
filesToRemove.forEach(aid -> {
|
||||
BCLib.LOGGER.info(" - " + aid.relFile + " (removing)");
|
||||
|
||||
aid.relFile.delete();
|
||||
});
|
||||
|
||||
requestFileDownloads(requestFiles);
|
||||
}
|
||||
if (removeFiles) {
|
||||
filesToRemove.forEach(aid -> {
|
||||
BCLib.LOGGER.info(" - " + aid.relFile + " (removing)");
|
||||
aid.relFile.delete();
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private void processOfferedFile(List<AutoSyncID> requestFiles, AutoSyncID aid) {
|
||||
if (aid instanceof WithContentOverride) {
|
||||
final WithContentOverride aidc = (WithContentOverride) aid;
|
||||
BCLib.LOGGER.info(" - " + aid + " (updating Content)");
|
||||
|
||||
SendFiles.writeSyncedFile(aid, aidc.contentWrapper.getRawContent(), aidc.localFile);
|
||||
}
|
||||
else {
|
||||
requestFiles.add(aid);
|
||||
BCLib.LOGGER.info(" - " + aid + " (requesting)");
|
||||
}
|
||||
}
|
||||
|
||||
private void requestBCLibDownload(Consumer<Boolean> whenFinished) {
|
||||
BCLib.LOGGER.warning("Starting download of BCLib");
|
||||
whenFinished.accept(true);
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public abstract class Config {
|
||||
public static final String CONFIG_SYNC_PREFIX = "CONFIG_";
|
||||
protected final static Map<AutoSyncID, Config> autoSyncConfigs = new HashMap<>();
|
||||
protected final ConfigKeeper keeper;
|
||||
protected final boolean autoSync;
|
||||
|
@ -33,16 +34,12 @@ public abstract class Config {
|
|||
}
|
||||
|
||||
protected Config(String modID, String group, boolean autoSync, boolean diffContent) {
|
||||
if (autoSync) {
|
||||
BCLib.LOGGER.info("Added Config " + modID + "." + group + " to auto sync (contentDiff = " + diffContent + ")");
|
||||
}
|
||||
|
||||
this.keeper = new ConfigKeeper(modID, group);
|
||||
this.registerEntries();
|
||||
this.autoSync = autoSync;
|
||||
|
||||
if (autoSync) {
|
||||
final String uid = "CONFIG_" + modID + "_" + group;
|
||||
final String uid = CONFIG_SYNC_PREFIX + modID + "_" + group;
|
||||
final AutoSyncID aid = new AutoSyncID(BCLib.MOD_ID, uid);
|
||||
if (diffContent)
|
||||
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile(),this::compareForSync);
|
||||
|
@ -50,6 +47,7 @@ public abstract class Config {
|
|||
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile());
|
||||
|
||||
autoSyncConfigs.put(aid, this);
|
||||
BCLib.LOGGER.info("Added Config " + modID + "." + group + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ abstract class BCLibScreen extends GridScreen {
|
|||
}
|
||||
|
||||
protected void addTitle(){
|
||||
GridRow row = grid.addRow(VerticalAlignment.BOTTOM);
|
||||
GridRow row = grid.addRow(VerticalAlignment.CENTER);
|
||||
row.addFiller();
|
||||
row.addImage(BCLIB_LOGO_LOCATION, 24, GridValueType.CONSTANT, 24, 512, 512);
|
||||
row.addSpacer(4);
|
||||
|
|
|
@ -11,53 +11,88 @@ import ru.bclib.gui.gridlayout.GridRow;
|
|||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class SyncFilesScreen extends BCLibScreen {
|
||||
private final Component description;
|
||||
private final SyncFilesScreen.Listener listener;
|
||||
public SyncFilesScreen(SyncFilesScreen.Listener listener) {
|
||||
super(new TranslatableComponent("title.bclib.syncfiles"));
|
||||
|
||||
this.description = new TranslatableComponent("message.bclib.syncfiles");
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
protected void initLayout() {
|
||||
final int BUTTON_HEIGHT = 20;
|
||||
|
||||
grid.addRow().addMessage(this.description, this.font, Alignment.CENTER);
|
||||
|
||||
grid.addSpacerRow(10);
|
||||
|
||||
GridRow row = grid.addRow();
|
||||
GridCheckboxCell mods = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.mods"), true, BUTTON_HEIGHT, this.font);
|
||||
|
||||
grid.addSpacerRow();
|
||||
row = grid.addRow();
|
||||
GridCheckboxCell files = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.files"), true, BUTTON_HEIGHT, this.font);
|
||||
|
||||
grid.addSpacerRow();
|
||||
row = grid.addRow();
|
||||
GridCheckboxCell folder = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.folder"), true, BUTTON_HEIGHT, this.font);
|
||||
|
||||
grid.addSpacerRow(30);
|
||||
|
||||
row = grid.addRow();
|
||||
row.addFiller();
|
||||
row.addButton(CommonComponents.GUI_NO, BUTTON_HEIGHT, this.font, (button) -> {
|
||||
listener.proceed(false);
|
||||
});
|
||||
row.addSpacer();
|
||||
row.addButton(CommonComponents.GUI_YES, BUTTON_HEIGHT, this.font, (button) -> {
|
||||
listener.proceed(true);
|
||||
});
|
||||
row.addFiller();
|
||||
}
|
||||
|
||||
public boolean shouldCloseOnEsc() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface Listener {
|
||||
void proceed(boolean download);
|
||||
}
|
||||
private final Component description;
|
||||
private final SyncFilesScreen.Listener listener;
|
||||
private final boolean hasConfigFiles;
|
||||
private final boolean hasFiles;
|
||||
private final boolean hasMods;
|
||||
private final boolean shouldDelete;
|
||||
|
||||
public SyncFilesScreen(int modFiles, int configFiles, int singleFiles, int folderFiles, int deleteFiles, Listener listener) {
|
||||
super(new TranslatableComponent("title.bclib.syncfiles"));
|
||||
|
||||
this.description = new TranslatableComponent("message.bclib.syncfiles");
|
||||
this.listener = listener;
|
||||
|
||||
this.hasConfigFiles = configFiles>0;
|
||||
this.hasFiles = singleFiles+folderFiles>0;
|
||||
this.hasMods = modFiles>0;
|
||||
this.shouldDelete = deleteFiles>0;
|
||||
}
|
||||
|
||||
protected void initLayout() {
|
||||
final int BUTTON_HEIGHT = 20;
|
||||
|
||||
grid.addRow()
|
||||
.addMessage(this.description, this.font, Alignment.CENTER);
|
||||
|
||||
grid.addSpacerRow(10);
|
||||
|
||||
GridRow row;
|
||||
|
||||
|
||||
final GridCheckboxCell mods;
|
||||
if (hasMods) {
|
||||
row = grid.addRow();
|
||||
mods = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.mods"), true, BUTTON_HEIGHT, this.font);
|
||||
grid.addSpacerRow();
|
||||
} else mods=null;
|
||||
|
||||
final GridCheckboxCell configs;
|
||||
if (hasConfigFiles) {
|
||||
row = grid.addRow();
|
||||
configs = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.configs"), true, BUTTON_HEIGHT, this.font);
|
||||
grid.addSpacerRow();
|
||||
} else configs = null;
|
||||
|
||||
row = grid.addRow();
|
||||
|
||||
final GridCheckboxCell folder;
|
||||
if (hasFiles) {
|
||||
folder = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.folders"), true, BUTTON_HEIGHT, this.font);
|
||||
row.addSpacer();
|
||||
} else folder = null;
|
||||
|
||||
GridCheckboxCell delete;
|
||||
if (shouldDelete) {
|
||||
delete = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.delete"), true, BUTTON_HEIGHT, this.font);
|
||||
} else delete = null;
|
||||
|
||||
grid.addSpacerRow(30);
|
||||
|
||||
row = grid.addRow();
|
||||
row.addFiller();
|
||||
row.addButton(CommonComponents.GUI_NO, BUTTON_HEIGHT, this.font, (button) -> {
|
||||
listener.proceed(false, false, false, false);
|
||||
});
|
||||
row.addSpacer();
|
||||
row.addButton(CommonComponents.GUI_YES, BUTTON_HEIGHT, this.font, (button) -> {
|
||||
listener.proceed(
|
||||
mods!=null && mods.isChecked(),
|
||||
configs!=null && configs.isChecked(),
|
||||
folder != null && folder.isChecked(),
|
||||
delete !=null && delete.isChecked()
|
||||
);
|
||||
});
|
||||
row.addFiller();
|
||||
}
|
||||
|
||||
public boolean shouldCloseOnEsc() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface Listener {
|
||||
void proceed(boolean downloadMods, boolean downloadConfigs, boolean downloadFiles, boolean removeFiles);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
"title.bclib.syncfiles": "Mismatching Data",
|
||||
"message.bclib.syncfiles": "Some Content on the Server does not match the versions on the client.\nDo you want to replace the selected content with the data from the server?",
|
||||
"message.bclib.syncfiles.mods": "Synchronize Mods",
|
||||
"message.bclib.syncfiles.files": "Synchronize Configs",
|
||||
"message.bclib.syncfiles.folder": "Synchronize Folders",
|
||||
"message.bclib.syncfiles.configs": "Synchronize Configs",
|
||||
"message.bclib.syncfiles.folders": "Synchronize Folders and Files",
|
||||
"message.bclib.syncfiles.delete": "Delete unneeded",
|
||||
"title.bclib.confirmrestart": "Restart Required",
|
||||
"message.bclib.confirmrestart": "The requested files were processed. You need o restart Minecraft now."
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue