mirror of
https://github.com/Wurst-Imperium/Wurst7.git
synced 2024-09-20 01:12:13 +02:00
Add JSOn format to export button
This commit is contained in:
parent
78a1e5960d
commit
41a7d9612d
@ -122,7 +122,7 @@ public final class AltsFile
|
||||
}
|
||||
}
|
||||
|
||||
private JsonObject createJson(AltManager alts)
|
||||
public static JsonObject createJson(AltManager alts)
|
||||
{
|
||||
JsonObject json = new JsonObject();
|
||||
|
||||
|
@ -13,6 +13,7 @@ import java.awt.HeadlessException;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
import net.wurstclient.util.SwingUtils;
|
||||
@ -37,13 +38,27 @@ public final class ExportAltsFileChooser extends JFileChooser
|
||||
|
||||
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
fileChooser.setAcceptAllFileFilterUsed(false);
|
||||
fileChooser.addChoosableFileFilter(
|
||||
new FileNameExtensionFilter("TXT file (username:password)", "txt"));
|
||||
|
||||
FileNameExtensionFilter txtFilter =
|
||||
new FileNameExtensionFilter("TXT file (username:password)", "txt");
|
||||
fileChooser.addChoosableFileFilter(txtFilter);
|
||||
|
||||
FileNameExtensionFilter jsonFilter =
|
||||
new FileNameExtensionFilter("JSON file", "json");
|
||||
fileChooser.addChoosableFileFilter(jsonFilter);
|
||||
|
||||
if(fileChooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION)
|
||||
return;
|
||||
|
||||
System.out.println(fileChooser.getSelectedFile().getAbsolutePath());
|
||||
String path = fileChooser.getSelectedFile().getAbsolutePath();
|
||||
FileFilter fileFilter = fileChooser.getFileFilter();
|
||||
|
||||
if(fileFilter == txtFilter && !path.endsWith(".txt"))
|
||||
path += ".txt";
|
||||
else if(fileFilter == jsonFilter && !path.endsWith(".json"))
|
||||
path += ".json";
|
||||
|
||||
System.out.println(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,8 @@ import java.util.List;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
@ -29,15 +31,11 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.wurstclient.WurstClient;
|
||||
import net.wurstclient.altmanager.Alt;
|
||||
import net.wurstclient.altmanager.AltManager;
|
||||
import net.wurstclient.altmanager.AltRenderer;
|
||||
import net.wurstclient.altmanager.ExportAltsFileChooser;
|
||||
import net.wurstclient.altmanager.ImportAltsFileChooser;
|
||||
import net.wurstclient.altmanager.LoginManager;
|
||||
import net.wurstclient.altmanager.NameGenerator;
|
||||
import net.wurstclient.altmanager.*;
|
||||
import net.wurstclient.util.ListWidget;
|
||||
import net.wurstclient.util.MultiProcessingUtils;
|
||||
import net.wurstclient.util.json.JsonException;
|
||||
import net.wurstclient.util.json.JsonUtils;
|
||||
|
||||
public final class AltManagerScreen extends Screen
|
||||
{
|
||||
@ -258,17 +256,12 @@ public final class AltManagerScreen extends Screen
|
||||
|
||||
process.waitFor();
|
||||
|
||||
List<String> lines = new ArrayList<>();
|
||||
if(path.getFileName().toString().endsWith(".json"))
|
||||
exportAsJSON(path);
|
||||
else
|
||||
exportAsTXT(path);
|
||||
|
||||
for(Alt alt : altManager.getList())
|
||||
if(alt.isCracked())
|
||||
lines.add(alt.getEmail());
|
||||
else
|
||||
lines.add(alt.getEmail() + ":" + alt.getPassword());
|
||||
|
||||
Files.write(path, lines);
|
||||
|
||||
}catch(IOException | InterruptedException e)
|
||||
}catch(IOException | InterruptedException | JsonException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -287,11 +280,7 @@ public final class AltManagerScreen extends Screen
|
||||
|
||||
try
|
||||
{
|
||||
Path path = Paths.get(response);
|
||||
if(!path.getFileName().toString().endsWith(".txt"))
|
||||
path = path.resolveSibling(path.getFileName() + ".txt");
|
||||
|
||||
return path;
|
||||
return Paths.get(response);
|
||||
|
||||
}catch(InvalidPathException e)
|
||||
{
|
||||
@ -301,6 +290,25 @@ public final class AltManagerScreen extends Screen
|
||||
}
|
||||
}
|
||||
|
||||
private void exportAsJSON(Path path) throws IOException, JsonException
|
||||
{
|
||||
JsonObject json = AltsFile.createJson(altManager);
|
||||
JsonUtils.toJson(json, path);
|
||||
}
|
||||
|
||||
private void exportAsTXT(Path path) throws IOException
|
||||
{
|
||||
List<String> lines = new ArrayList<>();
|
||||
|
||||
for(Alt alt : altManager.getList())
|
||||
if(alt.isCracked())
|
||||
lines.add(alt.getEmail());
|
||||
else
|
||||
lines.add(alt.getEmail() + ":" + alt.getPassword());
|
||||
|
||||
Files.write(path, lines);
|
||||
}
|
||||
|
||||
private void confirmGenerate(boolean confirmed)
|
||||
{
|
||||
if(confirmed)
|
||||
|
Loading…
Reference in New Issue
Block a user