Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.47 KB | None | 0 0
  1. package main;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10. import java.io.OutputStreamWriter;
  11. import java.io.Writer;
  12. import java.util.ArrayList;
  13.  
  14. /**
  15. * The Main Handler class which controls main functions of the program like...
  16. **/
  17. public class DBHandler {   
  18.     /**
  19.     * The FileReader Object
  20.     **/
  21.     private FileReader fileReader = null; //-- initialisierung in einer init()-Methode oder Konstruktor
  22.     /**
  23.     * Check Variable to look if smth exists
  24.     **/
  25.     private boolean doesExist; //--boolean sind von Grund auf schon false
  26.     /**
  27.     * Important Benchmark Files
  28.     **/
  29.     private File Ofile = new File(System.getProperty("user.home") + File.separator + "benchInit.bat");
  30.     private File Ofile2 = new File(System.getProperty("user.home") + File.separator + "benchRead.bat");
  31.     private File OfileD = new File(System.getProperty("user.home") + File.separator + "filename.txt");
  32.     private File OfileTemp = new File(System.getProperty("user.home") + File.separator + "tempfile.bat");
  33.     private File OfileTemp2 = new File(System.getProperty("user.home") + File.separator + "tempfile2.bat");
  34.     private File OfileTempPortBat = new File(System.getProperty("user.home") + File.separator + "porttempfile.bat");
  35.     private File OfileTempPort = new File(System.getProperty("user.home") + File.separator + "porttemp.txt");
  36.     /**
  37.     * Decode Integer var for...
  38.     **/
  39.     private int decodeKey = //hidden; //--hidden? :D
  40.     /**
  41.     * Decode Fragment var for...
  42.     **/
  43.     private int[] decodeFragment = //hidden;
  44.     /**
  45.     * Standart OS Type set to 32b
  46.     **/
  47.     private int osType = 32;
  48.     /**
  49.     * Standart default Path String
  50.     **/
  51.     private String defaultPath = "defaultPath";
  52.     /**
  53.     * Check if the request repeat itself
  54.     **/
  55.     private boolean repeatRequested;
  56.    
  57. //-- USW das machst du mit allen variablen
  58.  
  59.     static boolean noRegData = false;
  60.     static boolean noRegDataPort = false;
  61.     static boolean gotData = false;
  62.     static String postProcessDefPath = "default";
  63.     static int firstRun = 0;
  64.     static int globalPort = 6789;
  65.  
  66. // --------------------------------------------------- //
  67.    
  68.     /**
  69.     * Constructor which initializes creation stuff
  70.     **/
  71.     public DBHandler(){
  72.         getInitBatch();
  73.     }
  74.    
  75.     private void instanciate(String requestedPath){
  76.        
  77.         //detect 64-bit systems for future optimizing purposes
  78.        
  79.         if(System.getProperty("os.arch").equals("amd64")){
  80.            
  81.             osType = 64;
  82.            
  83.         }
  84.        
  85.         //create batchfiles, that convert registry keys related to this program
  86.         //into a .txt file, that can be read by the buffered filereader.
  87.         //If there is no registry info, create firstrun default registry data.
  88.        
  89.         try {
  90.             try {
  91. //--system outs entfernen!
  92.                 <<System.out.println("Instanciation request initiated.");
  93.                 doesExist = !Ofile.createNewFile();
  94.                 <<if(doesExist){
  95.                     <<System.out.println("Instanciation not required. Savefile localized.");
  96.                 <<}else{
  97.                     <<System.out.println("Instanciation required and Completed!");
  98.                 <<}
  99.             } catch (IOException e) {
  100.                 e.printStackTrace();
  101.             }
  102.             fr = new FileReader(Ofile);
  103.         } catch (FileNotFoundException e) {
  104.             <<System.out.println("Instanciation of Savefile failed!");
  105.             doesExist = false;
  106.             e.printStackTrace();
  107.         }
  108.         <<System.out.println("Instanciation Request Successfully executed.");
  109.         if(!doesExist){
  110.             <<System.out.println("Writing default values to new Savefile Instance.");
  111.             writeInitBatch(osType, requestedPath);
  112.         }
  113.        
  114.             <<System.out.println("Reading default values from Savefile Instance.");
  115.             getInitBatch();
  116.        
  117.     }
  118.    
  119.     private void writeInitBatch(int osArch, String defPath){
  120.        
  121.         //function to create the default program initiation batchfile to write to registry data.
  122.        
  123.     try (Writer writer = new BufferedWriter(new OutputStreamWriter(
  124.                   new FileOutputStream(Ofile), "utf-8"))) {
  125.        writer.write("@echo off");
  126.        ((BufferedWriter) writer).newLine();
  127.        writer.write("REG ADD HKCU\\SOFTWARE /v BenchmarkInitialized /t REG_SZ /d 1");
  128.        ((BufferedWriter) writer).newLine();
  129.        writer.write("REG ADD HKCU\\SOFTWARE /v BenchmarkDefDBPath /t REG_SZ /d " + defPath);
  130.        ((BufferedWriter) writer).newLine();
  131.        writer.write("exit");
  132.     } catch (IOException e) {
  133.         e.printStackTrace();
  134.     }
  135.    
  136.     try {
  137.         Runtime.getRuntime().exec("cmd /c start C:\\Users\\%USERNAME%\\benchInit.bat");
  138.     } catch (IOException e) {
  139.         e.printStackTrace();
  140.     }
  141.    
  142.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement