Commit a1d8aadc authored by chris.crook's avatar chris.crook

> adding load / save

parent 590901d0
...@@ -12,16 +12,37 @@ import java.io.FileWriter; ...@@ -12,16 +12,37 @@ import java.io.FileWriter;
import java.util.Scanner; import java.util.Scanner;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
// file info and load
String filename1 = "magicwords"; String filename1 = "magicwords";
String filename2 = "appdatatxt"; String filename2 = "appdatatxt";
File file1; File file1;
File file2; File file2;
// generic variables and stuff
int sizeoverride = 1000;
String tempload = "";
String [] [] magicwords = new String [sizeoverride] [5]; // storage of the login info
int size = 0;
boolean tempbool = true;
int tempint = 0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt"); file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt"); file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt");
for (int i = 0; i < sizeoverride; i ++){
magicwords [i] [0] = "END";
}
try{
FileWriter stream = new FileWriter(file1, true);
stream.append(""); //opens and test-loads an append
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_SHORT).show();
}
try{ try{
Scanner reader = new Scanner(file1); Scanner reader = new Scanner(file1);
String temp = ""; String temp = "";
...@@ -29,36 +50,65 @@ public class MainActivity extends AppCompatActivity { ...@@ -29,36 +50,65 @@ public class MainActivity extends AppCompatActivity {
while (reader.hasNextLine()){ while (reader.hasNextLine()){
temp = temp + reader.nextLine(); temp = temp + reader.nextLine();
} }
Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
} catch(Exception e){ } catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
try{ }
FileWriter stream = new FileWriter(file1, false); tempload = openandload();
stream.write(" "); if (tempload.equals("&&&")){
stream.close(); // this means that the load failed
}
} catch(Exception e){ else{
Toast.makeText(getApplicationContext(), "write error", Toast.LENGTH_LONG).show(); // load successful
if (tempload.equals("")){
// dont add a '#' to the start
} }
else{
tempload += "#";
}
tempload += "adminname&adminuser&adminpassword&ADMIN";
String [] temploadarray = tempload.split("%");
size = temploadarray.length;
for (int i = 0; i < size; i++){
magicwords [i] [0] = temploadarray [i]; // splits by user
}
for (int i = 0; i < size; i++){
String [] sort = temploadarray [i].split("&");
magicwords [i] [1] = sort [0];
magicwords [i] [2] = sort [1];
magicwords [i] [3] = sort [2];
magicwords [i] [4] = sort [3];
}
/*for (int i = 0; i < sizeoverride; i++){
if (magicwords [i] [0].equals("END")){
// end marker found
tempint = i;
break;
}
System.out.println(size + "");
System.out.println(tempint + "");
}*/
} }
} }
public void openandload(View view){ public String openandload(){
try{ try{
Scanner reader = new Scanner(file1); Scanner reader = new Scanner(file1);
String temp = ""; String temp = "";
while (reader.hasNextLine()){ while (reader.hasNextLine()){
temp = temp + reader.nextLine(); temp = temp + reader.nextLine();
} }
Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
return temp;
} catch(Exception e){ } catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show();
return "&&&";
} }
} }
public void saveandclose(View view){ public void saveandclose(){
try{ try{
FileWriter stream = new FileWriter(file1, false); FileWriter stream = new FileWriter(file1, false);
stream.write(" "); stream.write(" ");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment