From ab668c6cadab34fa4a070e420f76fe1607e6c52b Mon Sep 17 00:00:00 2001 From: jwinterm Date: Wed, 16 Dec 2015 21:19:33 -0800 Subject: [PATCH] Got wallet generation started...kinda. --- core/src/com/jw/lightwallet/LightWallet.java | 8 +- .../jw/lightwallet/screens/CreateScreen.java | 65 ++++++++++++-- .../jw/lightwallet/utils/CreateWallet.java | 84 +++++++++++++++++++ 3 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 core/src/com/jw/lightwallet/utils/CreateWallet.java diff --git a/core/src/com/jw/lightwallet/LightWallet.java b/core/src/com/jw/lightwallet/LightWallet.java index 8314e06..fe4e3fd 100644 --- a/core/src/com/jw/lightwallet/LightWallet.java +++ b/core/src/com/jw/lightwallet/LightWallet.java @@ -11,7 +11,10 @@ import com.jw.lightwallet.screens.MainScreen; import com.jw.lightwallet.screens.WizardScreen; public class LightWallet extends Game { - public static final String LOG = LightWallet.class.getSimpleName(); // Logging constant + + public static final String LOG = LightWallet.class.getSimpleName(); // Logging constant + + public String dir; // Set screen methods public MainScreen getMainScreen(){ @@ -35,6 +38,9 @@ public class LightWallet extends Game { // Initialize logger Gdx.app.log(LightWallet.LOG, "Launching application"); + // Get directory where program launched + dir = System.getProperty("user.dir"); + // Check if config file exists, if not launch setup wizard File f = new File("lightwallet.conf"); if(f.exists() && !f.isDirectory()) { diff --git a/core/src/com/jw/lightwallet/screens/CreateScreen.java b/core/src/com/jw/lightwallet/screens/CreateScreen.java index decd7ed..5b9b2ed 100644 --- a/core/src/com/jw/lightwallet/screens/CreateScreen.java +++ b/core/src/com/jw/lightwallet/screens/CreateScreen.java @@ -2,6 +2,7 @@ package com.jw.lightwallet.screens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; @@ -9,7 +10,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextField; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.jw.lightwallet.LightWallet; +import com.jw.lightwallet.utils.CreateWallet; public class CreateScreen extends AbstractScreen { @@ -21,23 +24,31 @@ public class CreateScreen extends AbstractScreen { Image logo; Texture logotex; + Table textcontainer; String instruction; Label instructionlabel; - Table textcontainer; - + + Table inputtable; Label namelabel; TextField nametext; + String name; Label pwlabel; TextField pwtext; + String pw; Label pwrptlabel; TextField pwrpttext; + String pwrpt; + Table buttontable; TextButton createbutton; TextButton gobackbutton; + + CreateWallet createwallet; public CreateScreen(final LightWallet game) { super(game); + System.out.print("CreateScreen creating."); uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); padvalue = 20; @@ -48,7 +59,7 @@ public class CreateScreen extends AbstractScreen { screenlayout = new Table(); logo = new Image(new Texture(Gdx.files.internal("logo.png"))); - + //logo.scaleBy(0.02f); instruction = "Please enter a name for your wallet in the \"Wallet name\" field. This is typically wallet.bin, " + "but you can make it whatever you like (as long as it is alphanumberic and periods only). " @@ -60,9 +71,53 @@ public class CreateScreen extends AbstractScreen { textcontainer = new Table(); textcontainer.add(instructionlabel).width(600); - screenlayout.add(logo).pad(10).center().row(); + inputtable = new Table(); + namelabel = new Label("Wallet name: ", uiSkin); + nametext = new TextField("", uiSkin); + pwlabel = new Label("Password: ", uiSkin); + pwtext = new TextField("", uiSkin); + pwtext.setPasswordMode(true); + pwtext.setPasswordCharacter((char) 42); + pwrptlabel = new Label("Repeat password: ", uiSkin); + pwrpttext = new TextField("", uiSkin); + pwrpttext.setPasswordMode(true); + pwrpttext.setPasswordCharacter((char) 42); + inputtable.add(namelabel).width(200); + inputtable.add(nametext).width(400).row(); + inputtable.add(pwlabel).width(200); + inputtable.add(pwtext).width(400).row(); + inputtable.add(pwrptlabel).width(200); + inputtable.add(pwrpttext).width(400).row(); + + buttontable = new Table(); + createbutton = new TextButton("Create!", uiSkin); + createbutton.addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + name = nametext.getText(); + pw = pwtext.getText(); + pwrpt = pwrpttext.getText(); + if (name.length() > 0 && pw.equals(pwrpt)) { + System.out.println(name + ", " + pw + ", " + pwrpt); + createwallet = new CreateWallet(name, pw); + } + //game.setScreen(game.getCreateScreen()); + } + }); + gobackbutton = new TextButton("Cancel", uiSkin); + gobackbutton.addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + game.setScreen(game.getWizardScreen()); + } + }); + buttontable.add(createbutton).width(150); + buttontable.add(gobackbutton).width(150); + + screenlayout.add(logo).pad(10).width(200).height(50).center().row(); screenlayout.add(textcontainer).pad(padvalue).row(); - //screenlayout.add(buttontable).pad(padvalue).row(); + screenlayout.add(inputtable).pad(padvalue).row(); + screenlayout.add(buttontable).pad(padvalue).row(); screenlayout.setFillParent(true); stage.addActor(screenlayout); diff --git a/core/src/com/jw/lightwallet/utils/CreateWallet.java b/core/src/com/jw/lightwallet/utils/CreateWallet.java new file mode 100644 index 0000000..9e418cf --- /dev/null +++ b/core/src/com/jw/lightwallet/utils/CreateWallet.java @@ -0,0 +1,84 @@ +package com.jw.lightwallet.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; + +public class CreateWallet { + + String name; + String pw; + + + public CreateWallet(String name, String pw) { + + this.name = name; + this.pw = pw; + + System.out.println("Starting creator"); + String s = null; + System.out.println("Working Directory = " + + System.getProperty("user.dir")); + + try { + + Process tr = Runtime.getRuntime().exec("E:\\src\\lightWallet\\simplewallet.exe --generate-new-wallet jj --password jj"); + Writer wr = new OutputStreamWriter( tr.getOutputStream() ); + BufferedReader rd = new BufferedReader( new InputStreamReader( tr.getInputStream() ) ); + System.out.println("Here is the standard output of the command:\n"); + while (true) { + String str = rd.readLine(); + System.out.println( str ); + if (str.contains("Japanese")) { + break; + } + } + wr.write( "0\n" ); + wr.flush(); + String str = rd.readLine(); + System.out.println( str ); + System.out.println("Here is the standard output of the command:\n"); + while ((s = rd.readLine()) != null) { + System.out.println(s); + } + + wr.write( "exit\n" ); + wr.flush(); + /* + // run the Unix "ps -ef" command + // using the Runtime exec method: + Process p = Runtime.getRuntime().exec("E:\\src\\lightWallet\\simplewallet.exe --generate-new-wallet jj --password jj"); + + BufferedReader stdInput = new BufferedReader(new + InputStreamReader(p.getInputStream())); + + BufferedReader stdError = new BufferedReader(new + InputStreamReader(p.getErrorStream())); + + + // read the output from the command + System.out.println("Here is the standard output of the command:\n"); + while ((s = stdInput.readLine()) != null) { + System.out.println(s); + } + + // read any errors from the attempted command + System.out.println("Here is the standard error of the command (if any):\n"); + while ((s = stdError.readLine()) != null) { + System.out.println(s); + }*/ + + + + System.exit(0); + } + catch (IOException e) { + System.out.println("exception happened - here's what I know: "); + e.printStackTrace(); + System.exit(-1); + } + } + +}