////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : Installation. //This class is the PIMS installation program. In the installation the user is //asked for the initial username and password. The user also needs to specify //his home directory. The PIMS working files are then created in the directory // home/.pims. After this process the next installation program is called which //downloads the share prices from the net and initializes the prices file. The //Companies file is also initialized which contains the names of some 800 //companies registered in the NSE stock exchange. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; import java.io.*; import java.util.*; public class Installation extends JFrame implements ActionListener{ private String login; private String password; private TextField log; private TextField pass; private TextField ret_pass; private TextField home; private Button cancel; private Button next; private String logt; private String passt; private String homet; private boolean downloadOption; public Installation(boolean downloadOption)throws Exception{ login = ""; password = ""; this.downloadOption = downloadOption; installPIMS(); } private void installPIMS()throws Exception{ setSize(420, 300); setLocation(320,280); setBackground(Color.white); setTitle("PIMS Installation Wizard"); Container CP = getContentPane(); CP.setBackground(Color.white); CP.setLayout(new FlowLayout()); Panel pan1 = new Panel(); Panel pan2 = new Panel(); Panel pan3 = new Panel(); Panel pan4 = new Panel(); Panel pan5 = new Panel(); Panel pan6 = new Panel(); Label PIMS = new Label("PIMS: Personal Investment Management System"); pan1.add(PIMS); Label login = new Label("Enter the desired login:"); log = new TextField(15); pan2.add(login);pan2.add(log); Label password = new Label("Give initial password"); pass = new TextField(15); pass.setEchoChar('*'); pan3.add(password);pan3.add(pass); Label retype_password = new Label("Retype Password"); ret_pass = new TextField(15); ret_pass.setEchoChar('*'); pan4.add(retype_password);pan4.add(ret_pass); Label homel = new Label("Enter Home Directory(full path):"); home = new TextField(20); pan5.add(homel);pan5.add(home); cancel = new Button("Cancel"); cancel.addActionListener(this); next = new Button("Next"); next.addActionListener(this); pan6.add(cancel);pan6.add(next); CP.add(pan1); CP.add(pan2); CP.add(pan3); CP.add(pan4); CP.add(pan5); CP.add(pan6); setVisible(true); } private boolean initializeFiles()throws Exception{ Process P = java.lang.Runtime.getRuntime().exec("./removePrevious"); P.waitFor(); //Create the directory .pims in the home directory of the user. if(!(new File(homet+"/.pims")).mkdir())return(false); //Create the directory .pims/Investment which will contain the entrire Investment structure. if(!(new File(homet+"/.pims/Investment")).mkdir())return(false); if(!(new File(homet+"/.pims/Investment/portfolios")).createNewFile())return(false); //create the files neede for computation. if(!(new File(homet+"/.pims/prices")).createNewFile())return(false); if(!(new File(homet+"/.pims/log_file")).createNewFile())return(false); if(!(new File(homet+"/.pims/Companies")).createNewFile())return(false); if(!(new File(homet+"/.pims/alerts")).createNewFile())return(false); //Write the login and password into the log_file. FileWriter FW = new FileWriter(homet+"/.pims/log_file"); writeLine(FW, logt+":"+passt); FW.close(); //Write the home in the file user_home in the same directory FW = new FileWriter("./user_home"); writeLine(FW, homet); FW.close(); return(true); } public void writeLine(FileWriter fw, String Line)throws Exception{ int i=0; int length = Line.length(); char buffer[] = new char[length]; Line.getChars(0, length, buffer, 0); fw.write(buffer); fw.write('\n'); } public void actionPerformed(ActionEvent ae){ try{ String action = ae.getActionCommand(); logt = log.getText(); passt = pass.getText(); String ret_passt = ret_pass.getText(); homet = home.getText(); if(action.equals("Next")){ if(logt.equals("") || passt.equals("") || ret_passt.equals("") || homet.equals("")){ Error e = new Error("Login or Password not Entered."); return; } if(!passt.equals(ret_passt)){ new Error("Entered passwords do not match"); return; } //Call the function that writes into the initial files. if(!initializeFiles()){ new Error("Problem creating the installation files. Please check permissions of ~"); return; } //Files Installed. Now go to the next installation site. setVisible(false); new InstallNext(homet, downloadOption); } if(action.equals("Cancel"))System.exit(0); }catch(Exception e){} } public static void main(String args[])throws Exception{ if(args.length > 0 && args[0].equals("-d")) new Installation(false);//start the installation program. else new Installation(true);//start the installation program. } }