Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.io.Writer;
- import java.util.ArrayList;
- /**
- * The Main Handler class which controls main functions of the program like...
- **/
- public class DBHandler {
- /**
- * The FileReader Object
- **/
- private FileReader fileReader = null; //-- initialisierung in einer init()-Methode oder Konstruktor
- /**
- * Check Variable to look if smth exists
- **/
- private boolean doesExist; //--boolean sind von Grund auf schon false
- /**
- * Important Benchmark Files
- **/
- private File Ofile = new File(System.getProperty("user.home") + File.separator + "benchInit.bat");
- private File Ofile2 = new File(System.getProperty("user.home") + File.separator + "benchRead.bat");
- private File OfileD = new File(System.getProperty("user.home") + File.separator + "filename.txt");
- private File OfileTemp = new File(System.getProperty("user.home") + File.separator + "tempfile.bat");
- private File OfileTemp2 = new File(System.getProperty("user.home") + File.separator + "tempfile2.bat");
- private File OfileTempPortBat = new File(System.getProperty("user.home") + File.separator + "porttempfile.bat");
- private File OfileTempPort = new File(System.getProperty("user.home") + File.separator + "porttemp.txt");
- /**
- * Decode Integer var for...
- **/
- private int decodeKey = //hidden; //--hidden? :D
- /**
- * Decode Fragment var for...
- **/
- private int[] decodeFragment = //hidden;
- /**
- * Standart OS Type set to 32b
- **/
- private int osType = 32;
- /**
- * Standart default Path String
- **/
- private String defaultPath = "defaultPath";
- /**
- * Check if the request repeat itself
- **/
- private boolean repeatRequested;
- //-- USW das machst du mit allen variablen
- static boolean noRegData = false;
- static boolean noRegDataPort = false;
- static boolean gotData = false;
- static String postProcessDefPath = "default";
- static int firstRun = 0;
- static int globalPort = 6789;
- // --------------------------------------------------- //
- /**
- * Constructor which initializes creation stuff
- **/
- public DBHandler(){
- getInitBatch();
- }
- private void instanciate(String requestedPath){
- //detect 64-bit systems for future optimizing purposes
- if(System.getProperty("os.arch").equals("amd64")){
- osType = 64;
- }
- //create batchfiles, that convert registry keys related to this program
- //into a .txt file, that can be read by the buffered filereader.
- //If there is no registry info, create firstrun default registry data.
- try {
- try {
- //--system outs entfernen!
- <<System.out.println("Instanciation request initiated.");
- doesExist = !Ofile.createNewFile();
- <<if(doesExist){
- <<System.out.println("Instanciation not required. Savefile localized.");
- <<}else{
- <<System.out.println("Instanciation required and Completed!");
- <<}
- } catch (IOException e) {
- e.printStackTrace();
- }
- fr = new FileReader(Ofile);
- } catch (FileNotFoundException e) {
- <<System.out.println("Instanciation of Savefile failed!");
- doesExist = false;
- e.printStackTrace();
- }
- <<System.out.println("Instanciation Request Successfully executed.");
- if(!doesExist){
- <<System.out.println("Writing default values to new Savefile Instance.");
- writeInitBatch(osType, requestedPath);
- }
- <<System.out.println("Reading default values from Savefile Instance.");
- getInitBatch();
- }
- private void writeInitBatch(int osArch, String defPath){
- //function to create the default program initiation batchfile to write to registry data.
- try (Writer writer = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(Ofile), "utf-8"))) {
- writer.write("@echo off");
- ((BufferedWriter) writer).newLine();
- writer.write("REG ADD HKCU\\SOFTWARE /v BenchmarkInitialized /t REG_SZ /d 1");
- ((BufferedWriter) writer).newLine();
- writer.write("REG ADD HKCU\\SOFTWARE /v BenchmarkDefDBPath /t REG_SZ /d " + defPath);
- ((BufferedWriter) writer).newLine();
- writer.write("exit");
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- Runtime.getRuntime().exec("cmd /c start C:\\Users\\%USERNAME%\\benchInit.bat");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement