Added UploadedFileHandler to keep track of files that have already been uploaded
This commit is contained in:
@@ -6,8 +6,9 @@ import eu.crushedpixel.replaymod.events.*;
|
|||||||
import eu.crushedpixel.replaymod.localization.LocalizedResourcePack;
|
import eu.crushedpixel.replaymod.localization.LocalizedResourcePack;
|
||||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||||
import eu.crushedpixel.replaymod.registry.ReplayFileAppender;
|
|
||||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||||
|
import eu.crushedpixel.replaymod.registry.ReplayFileAppender;
|
||||||
|
import eu.crushedpixel.replaymod.registry.UploadedFileHandler;
|
||||||
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
|
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplaySender;
|
import eu.crushedpixel.replaymod.replay.ReplaySender;
|
||||||
import eu.crushedpixel.replaymod.settings.ReplaySettings;
|
import eu.crushedpixel.replaymod.settings.ReplaySettings;
|
||||||
@@ -36,7 +37,7 @@ public class ReplayMod {
|
|||||||
|
|
||||||
//TODO: Show the player whether he has already uploaded a replay
|
//TODO: Show the player whether he has already uploaded a replay
|
||||||
|
|
||||||
//TODO: Hinting to the b/v key feature (help page)
|
//TODO: help page
|
||||||
|
|
||||||
//TODO: Add "Miscellaneous" Replay Category
|
//TODO: Add "Miscellaneous" Replay Category
|
||||||
|
|
||||||
@@ -47,7 +48,6 @@ public class ReplayMod {
|
|||||||
//Rain isn't working
|
//Rain isn't working
|
||||||
//Incompatible with Shaders Mod
|
//Incompatible with Shaders Mod
|
||||||
//
|
//
|
||||||
//
|
|
||||||
|
|
||||||
public static final String MODID = "replaymod";
|
public static final String MODID = "replaymod";
|
||||||
public static final String VERSION = "0.0.1";
|
public static final String VERSION = "0.0.1";
|
||||||
@@ -63,6 +63,7 @@ public class ReplayMod {
|
|||||||
public static ReplaySender replaySender;
|
public static ReplaySender replaySender;
|
||||||
public static int TP_DISTANCE_LIMIT = 128;
|
public static int TP_DISTANCE_LIMIT = 128;
|
||||||
public static ReplayFileAppender replayFileAppender;
|
public static ReplayFileAppender replayFileAppender;
|
||||||
|
public static UploadedFileHandler uploadedFileHandler;
|
||||||
|
|
||||||
private static Field defaultResourcePacksField;
|
private static Field defaultResourcePacksField;
|
||||||
static {
|
static {
|
||||||
@@ -83,6 +84,8 @@ public class ReplayMod {
|
|||||||
config = new Configuration(event.getSuggestedConfigurationFile());
|
config = new Configuration(event.getSuggestedConfigurationFile());
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
|
uploadedFileHandler = new UploadedFileHandler(event.getModConfigurationDirectory());
|
||||||
|
|
||||||
replaySettings = new ReplaySettings();
|
replaySettings = new ReplaySettings();
|
||||||
replaySettings.readValues();
|
replaySettings.readValues();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package eu.crushedpixel.replaymod.api.client;
|
package eu.crushedpixel.replaymod.api.client;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import eu.crushedpixel.replaymod.ReplayMod;
|
||||||
import eu.crushedpixel.replaymod.api.client.holders.ApiError;
|
import eu.crushedpixel.replaymod.api.client.holders.ApiError;
|
||||||
import eu.crushedpixel.replaymod.api.client.holders.Category;
|
import eu.crushedpixel.replaymod.api.client.holders.Category;
|
||||||
import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
|
import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
|
||||||
@@ -31,6 +32,10 @@ public class FileUploader {
|
|||||||
private GuiUploadFile parent;
|
private GuiUploadFile parent;
|
||||||
|
|
||||||
public void uploadFile(GuiUploadFile gui, String auth, String filename, List<String> tags, File file, Category category) throws IOException, ApiException, RuntimeException {
|
public void uploadFile(GuiUploadFile gui, String auth, String filename, List<String> tags, File file, Category category) throws IOException, ApiException, RuntimeException {
|
||||||
|
boolean success = false;
|
||||||
|
String info = null;
|
||||||
|
|
||||||
|
try {
|
||||||
parent = gui;
|
parent = gui;
|
||||||
gui.onStartUploading();
|
gui.onStartUploading();
|
||||||
filesize = 0;
|
filesize = 0;
|
||||||
@@ -99,7 +104,7 @@ public class FileUploader {
|
|||||||
request.flush();
|
request.flush();
|
||||||
request.close();
|
request.close();
|
||||||
|
|
||||||
boolean success = false;
|
success = false;
|
||||||
int responseCode = con.getResponseCode();
|
int responseCode = con.getResponseCode();
|
||||||
InputStream is;
|
InputStream is;
|
||||||
if(responseCode == 200) {
|
if(responseCode == 200) {
|
||||||
@@ -109,8 +114,6 @@ public class FileUploader {
|
|||||||
is = con.getErrorStream();
|
is = con.getErrorStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
String info = null;
|
|
||||||
|
|
||||||
if(is != null) {
|
if(is != null) {
|
||||||
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
||||||
info = null;
|
info = null;
|
||||||
@@ -128,10 +131,17 @@ public class FileUploader {
|
|||||||
|
|
||||||
if(info == null) info = I18n.format("replaymod.gui.unknownerror");
|
if(info == null) info = I18n.format("replaymod.gui.unknownerror");
|
||||||
|
|
||||||
|
ReplayMod.uploadedFileHandler.markAsUploaded(file);
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
} catch(Exception e) {
|
||||||
|
success = false;
|
||||||
|
} finally {
|
||||||
parent.onFinishUploading(success, info);
|
parent.onFinishUploading(success, info);
|
||||||
|
|
||||||
uploading = false;
|
uploading = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public float getUploadProgress() {
|
public float getUploadProgress() {
|
||||||
if(!uploading || filesize == 0) return 0;
|
if(!uploading || filesize == 0) return 0;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package eu.crushedpixel.replaymod.gui.replayviewer;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.mojang.realmsclient.util.Pair;
|
import com.mojang.realmsclient.util.Pair;
|
||||||
|
import eu.crushedpixel.replaymod.ReplayMod;
|
||||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||||
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
|
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
|
||||||
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
|
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
|
||||||
@@ -11,6 +12,7 @@ import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
|||||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||||
|
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
@@ -166,7 +168,18 @@ public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
|||||||
this.drawDefaultBackground();
|
this.drawDefaultBackground();
|
||||||
this.replayGuiList.drawScreen(mouseX, mouseY, partialTicks);
|
this.replayGuiList.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
this.drawCenteredString(this.fontRendererObj, I18n.format("replaymod.gui.replayviewer"), this.width / 2, 20, 16777215);
|
this.drawCenteredString(this.fontRendererObj, I18n.format("replaymod.gui.replayviewer"), this.width / 2, 20, 16777215);
|
||||||
|
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
|
if(uploadButton.isMouseOver() && !uploadButton.enabled && loadButton.enabled) {
|
||||||
|
if(!AuthenticationHandler.isAuthenticated()) {
|
||||||
|
Point mouse = MouseUtils.getMousePos();
|
||||||
|
drawCenteredString(mc.fontRendererObj, I18n.format("replaymod.gui.viewer.noauth"), (int) mouse.getX(), (int) mouse.getY() + 4, Color.RED.getRGB());
|
||||||
|
} else if(currentFileUploaded) {
|
||||||
|
Point mouse = MouseUtils.getMousePos();
|
||||||
|
drawCenteredString(mc.fontRendererObj, I18n.format("replaymod.gui.viewer.alreadyuploaded"), (int) mouse.getX(), (int) mouse.getY() + 4, Color.RED.getRGB());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -243,12 +256,15 @@ public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean currentFileUploaded = false;
|
||||||
|
|
||||||
public void setButtonsEnabled(boolean b) {
|
public void setButtonsEnabled(boolean b) {
|
||||||
loadButton.enabled = b;
|
loadButton.enabled = b;
|
||||||
if(!b || !AuthenticationHandler.isAuthenticated()) {
|
if(!b || !AuthenticationHandler.isAuthenticated()) {
|
||||||
uploadButton.enabled = false;
|
uploadButton.enabled = false;
|
||||||
} else {
|
} else {
|
||||||
uploadButton.enabled = true;
|
currentFileUploaded = ReplayMod.uploadedFileHandler.isUploaded(replayFileList.get(replayGuiList.selected).first().first());
|
||||||
|
uploadButton.enabled = !currentFileUploaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
renameButton.enabled = b;
|
renameButton.enabled = b;
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package eu.crushedpixel.replaymod.registry;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
import net.minecraftforge.common.config.Property;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UploadedFileHandler {
|
||||||
|
|
||||||
|
private Configuration configuration;
|
||||||
|
|
||||||
|
public UploadedFileHandler(File confDir) {
|
||||||
|
try {
|
||||||
|
File confFile = new File(confDir, "uploaded");
|
||||||
|
confFile.createNewFile();
|
||||||
|
configuration = new Configuration(confFile);
|
||||||
|
configuration.load();
|
||||||
|
|
||||||
|
Property uploaded = configuration.get("uploaded", "hashes", new String[0]);
|
||||||
|
|
||||||
|
configuration.save();
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void markAsUploaded(File file) throws IOException {
|
||||||
|
String checksum = String.valueOf(FileUtils.checksumCRC32(file));
|
||||||
|
List<String> hashes = new ArrayList<String>(Arrays.asList(configuration.get("uploaded",
|
||||||
|
"hashes", new String[0]).getStringList()));
|
||||||
|
configuration.removeCategory(configuration.getCategory("uploaded"));
|
||||||
|
|
||||||
|
hashes.add(checksum);
|
||||||
|
|
||||||
|
configuration.get("uploaded", "hashes", hashes.toArray(new String[hashes.size()]));
|
||||||
|
configuration.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUploaded(File file) {
|
||||||
|
try {
|
||||||
|
String checksum = String.valueOf(FileUtils.checksumCRC32(file));
|
||||||
|
List<String> hashes = new ArrayList<String>(Arrays.asList(configuration.get("uploaded",
|
||||||
|
"hashes", new String[0]).getStringList()));
|
||||||
|
return hashes.contains(checksum);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,22 +22,22 @@ public class ReplaySettings {
|
|||||||
Configuration config = ReplayMod.config;
|
Configuration config = ReplayMod.config;
|
||||||
|
|
||||||
for(RecordingOptions o : RecordingOptions.values()) {
|
for(RecordingOptions o : RecordingOptions.values()) {
|
||||||
Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "recording", false);
|
Property p = getConfigSetting(config, o.name(), o.getValue(), "recording", false);
|
||||||
o.setValue(getValueObject(p));
|
o.setValue(getValueObject(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ReplayOptions o : ReplayOptions.values()) {
|
for(ReplayOptions o : ReplayOptions.values()) {
|
||||||
Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "replay", false);
|
Property p = getConfigSetting(config, o.name(), o.getValue(), "replay", false);
|
||||||
o.setValue(getValueObject(p));
|
o.setValue(getValueObject(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(RenderOptions o : RenderOptions.values()) {
|
for(RenderOptions o : RenderOptions.values()) {
|
||||||
Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "render", false);
|
Property p = getConfigSetting(config, o.name(), o.getValue(), "render", false);
|
||||||
o.setValue(getValueObject(p));
|
o.setValue(getValueObject(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(AdvancedOptions o : AdvancedOptions.values()) {
|
for(AdvancedOptions o : AdvancedOptions.values()) {
|
||||||
Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "advanced", true);
|
Property p = getConfigSetting(config, o.name(), o.getValue(), "advanced", true);
|
||||||
o.setValue(getValueObject(p));
|
o.setValue(getValueObject(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ replaymod.gui.login.connectionerror=Could not connect to ReplayMod.com
|
|||||||
replaymod.gui.viewer.rename.title=Rename Replay
|
replaymod.gui.viewer.rename.title=Rename Replay
|
||||||
replaymod.gui.viewer.rename.name=Replay Name
|
replaymod.gui.viewer.rename.name=Replay Name
|
||||||
replaymod.gui.viewer.replayfolder=Open Replay Folder...
|
replaymod.gui.viewer.replayfolder=Open Replay Folder...
|
||||||
|
replaymod.gui.viewer.noauth=Log in to upload a Replay
|
||||||
|
replaymod.gui.viewer.alreadyuploaded=This Replay has already been uploaded
|
||||||
|
|
||||||
replaymod.gui.viewer.delete.linea=Are you sure you want to delete this replay?
|
replaymod.gui.viewer.delete.linea=Are you sure you want to delete this replay?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user