/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
 */
package com.opcturkey.kepserverexdesktopclient;

import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.time.Clock.system;
import static java.time.InstantSource.system;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
 *
 * @author yunus
 */
public class SecuritySettings extends javax.swing.JFrame  {

    private BufferedImage icon1;

    /**
     * Creates new form SecuritySettings
     */
    public SecuritySettings() {
        initComponents();
            String what;
                
                      try  {
            try (BufferedReader bufferedReader = new BufferedReader(new FileReader("tempdatafile2.ini"))) {
                what=bufferedReader.readLine();
                
                if("01101110 01101111 01110100".equals(what)){
                    jButton1.setText("Enable Password Protection");
                   
                    
                }else{
                    jButton1.setText("Disable Password Protection"); 
                      
                }
            }
          
          
    
           
         

          
    
      
      }catch(IOException e){
          
      }
          
         try {
             this.icon1 = ImageIO.read(new File("C:\\Users\\yunus\\Documents\\NetBeansProjects\\KepServerExDesktopClient\\src\\main\\java\\com\\opcturkey\\kepserverexdesktopclient\\resources\\robotic-arm.png"));
             setIconImage(icon1);  } catch (IOException ex) {
             Logger.getLogger(loginCreditChangerDetails.class.getName()).log(Level.SEVERE, null, ex);
         }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Security Settings");

        jButton1.setText("Enable Password Protection");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Enability:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(240, 240, 240)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(141, 141, 141)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)))
                .addContainerGap(193, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1)
                .addGap(61, 61, 61)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jLabel2))
                .addContainerGap(210, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 6, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

 WelcomeScreen wsws = new WelcomeScreen();
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
   
        if(jButton1.getText()=="Enable Password Protection"){
            jButton1.setText("Disable Password Protection"); 
             
           
            try {
                Path path = Paths.get("tempdatafile2.ini");
              Path path2 = Paths.get("tempdatafile.ini");
              File file = new File("tempdatafile2.ini");
              File file2 = new File("tempdatafile.ini");
              
                if(file.isHidden() || file2.isHidden()){
                    Files.setAttribute(path, "dos:hidden", false,LinkOption.NOFOLLOW_LINKS );
              Files.setAttribute(path2, "dos:hidden", false,LinkOption.NOFOLLOW_LINKS );
                }
                
                PrintWriter printWriter = new PrintWriter("tempdatafile2.ini");
              printWriter.println("01110000 01100001 01110011 01110011");
              
              
              
              printWriter.close();
              
              Files.setAttribute(path, "dos:hidden", true,LinkOption.NOFOLLOW_LINKS );
              Files.setAttribute(path2, "dos:hidden", true,LinkOption.NOFOLLOW_LINKS );
              
                 System.exit(0);
              // WelcomeScreen WelcomeScreen1 = new WelcomeScreen();WelcomeScreen1.show();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(SecuritySettings.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(SecuritySettings.class.getName()).log(Level.SEVERE, null, ex);
            }
      
              
             
            
           
             
                    //jButton5.setEnabled(true);
        }else{
            jButton1.setText("Enable Password Protection");
                    
            try {
                Path path = Paths.get("tempdatafile2.ini");
              Path path2 = Paths.get("tempdatafile.ini");
              File file = new File("tempdatafile2.ini");
              File file2 = new File("tempdatafile.ini");
              
                if(file.isHidden() || file2.isHidden()){
                    Files.setAttribute(path, "dos:hidden", false,LinkOption.NOFOLLOW_LINKS );
              Files.setAttribute(path2, "dos:hidden", false,LinkOption.NOFOLLOW_LINKS );
                }
                
                PrintWriter printWriter = new PrintWriter("tempdatafile2.ini");
              printWriter.println("01101110 01101111 01110100");
              
              
              
              printWriter.close();
              
              
              
                 System.exit(0);
              // WelcomeScreen WelcomeScreen1 = new WelcomeScreen();WelcomeScreen1.show();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(SecuritySettings.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(SecuritySettings.class.getName()).log(Level.SEVERE, null, ex);
            } 
             
            
            
        }
 
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SecuritySettings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SecuritySettings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SecuritySettings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SecuritySettings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SecuritySettings().setVisible(true);
              }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables


}
