diff --git a/LeagueProfiles/.classpath b/LeagueProfiles/.classpath new file mode 100644 index 0000000..07ca123 --- /dev/null +++ b/LeagueProfiles/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/LeagueProfiles/.gitignore b/LeagueProfiles/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/LeagueProfiles/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/LeagueProfiles/.project b/LeagueProfiles/.project new file mode 100644 index 0000000..655442b --- /dev/null +++ b/LeagueProfiles/.project @@ -0,0 +1,17 @@ + + + LeagueProfiles + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/LeagueProfiles/.settings/org.eclipse.jdt.core.prefs b/LeagueProfiles/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..54e493c --- /dev/null +++ b/LeagueProfiles/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/LeagueProfiles/src/proc/ProfileManager.java b/LeagueProfiles/src/proc/ProfileManager.java new file mode 100644 index 0000000..9f55fe7 --- /dev/null +++ b/LeagueProfiles/src/proc/ProfileManager.java @@ -0,0 +1,311 @@ +package proc; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.util.ArrayList; + +public class ProfileManager { + + + + // Paths n stuff + private static String LOL_PATH = ""; + //this one may vary a lot from patch to patch + private static final String VIDEO_CONFIG_PATH ="/RADS/solutions/lol_game_client_sln/releases/0.0.1.39/deploy/DATA/menu/hud"; + + private static final String MOUSE_KEYBOARD_PATH="/Config/input.ini"; + + private static final String GAME_SETTINGS_PATH = "/Config/game.cfg"; + + + //Atributes + + private ArrayList profiles; + + + public ProfileManager() + { + File archive = new File( "profiles.txt" ); + File archiveP = new File( "path.txt" ); + if( archive.exists( ) && archiveP.exists() ) + { + try + { + //Profiles + FileInputStream fis = new FileInputStream("profiles.txt"); + ObjectInputStream ois = new ObjectInputStream(fis); + profiles = (ArrayList) ois.readObject(); + ois.close(); + //Path + FileInputStream fisa = new FileInputStream("path.txt"); + ObjectInputStream oisa = new ObjectInputStream(fisa); + LOL_PATH = (String) oisa.readObject(); + oisa.close(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + else + { + profiles = new ArrayList( ); + LOL_PATH = ""; + } + } + + + + /** + * Returns the list of profile names. + * @return + */ + public ArrayList getProfiles() throws Exception + { + if (profiles.isEmpty()) + { + throw new Exception("There are no profiles registered."); + } + else + { + return profiles; + } + + } + + /** + * Creates a new profile based on a new name. + * NOTE: The profile is created with the settings that are actually active + * for the League of Legends installation. + * @param profileName + */ + public void createNewProfile(String profileName) throws Exception + { + //First part: Namecheck + boolean found = false; + for(int i = 0; i 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); + } + } + + public static void delete(File file) + throws IOException{ + + if(file.isDirectory()){ + + //directory is empty, then delete it + if(file.list().length==0){ + + file.delete(); + System.out.println("Directory is deleted : " + + file.getAbsolutePath()); + + }else{ + + //list all the directory contents + String files[] = file.list(); + + for (String temp : files) { + //construct the file structure + File fileDelete = new File(file, temp); + + //recursive delete + delete(fileDelete); + } + + //check the directory again, if empty then delete it + if(file.list().length==0){ + file.delete(); + System.out.println("Directory is deleted : " + + file.getAbsolutePath()); + } + } + + }else{ + //if file, then delete it + file.delete(); + System.out.println("File is deleted : " + file.getAbsolutePath()); + } + } + + public void saveData() throws Exception + { + if(profiles.isEmpty()) + { + FileOutputStream foso = new FileOutputStream("path.txt"); + ObjectOutputStream ooso = new ObjectOutputStream(foso); + ooso.writeObject(LOL_PATH); + ooso.close(); + } + else + { + FileOutputStream fos = new FileOutputStream("profiles.txt"); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(profiles); + oos.close(); + + FileOutputStream fosa = new FileOutputStream("path.txt"); + ObjectOutputStream oosa = new ObjectOutputStream(fosa); + oosa.writeObject(LOL_PATH); + oosa.close(); + } + } + + + +// public static void main(String[] args) +// { +// try{ +// ProfileManager pm = new ProfileManager(); +// pm.setGamePath("C:/League of Legends"); +// pm.createNewProfile("Satanasa"); +// pm.createNewProfile("Abejitas"); +// pm.deleteProfile("Satanasa"); +// +// File f = new File("Satanas"); +// System.out.println(f.exists()); +// pm.saveData(); +// +// } +// catch(Exception e) +// { +// e.printStackTrace(); +// } +// } + +} diff --git a/LeagueProfiles/src/ui/MidPanel.java b/LeagueProfiles/src/ui/MidPanel.java new file mode 100644 index 0000000..d0d324d --- /dev/null +++ b/LeagueProfiles/src/ui/MidPanel.java @@ -0,0 +1,151 @@ +package ui; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; + +public class MidPanel extends JPanel implements ActionListener { + + private Ui ui; + + private JList list; + + private JButton addButton; + + private JButton delButton; + + private JButton useButton; + + private JScrollPane listScroller; + + public MidPanel(Ui ui) + { + + this.ui = ui; + setLayout(new BorderLayout()); + + // + list = new JList(); //data has type Object[] + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setLayoutOrientation(JList.VERTICAL_WRAP); + //list.setVisibleRowCount(-1); + + + listScroller = new JScrollPane(); + listScroller.setViewportView(list); + + + + addButton = new JButton("Add New Profile"); + addButton.setActionCommand("ADD"); + addButton.addActionListener(this); + + delButton = new JButton("Delete Selected Profile"); + delButton.setActionCommand("DEL"); + delButton.addActionListener(this); + + useButton = new JButton("Use Selected Profile"); + useButton.setActionCommand("USE"); + useButton.addActionListener(this); + + add(listScroller, BorderLayout.CENTER); + updateProfiles(); + GridLayout g = new GridLayout(3, 1); + JPanel p =new JPanel(g); + + p.add(addButton); + p.add(useButton); + p.add(delButton); + add(p, BorderLayout.EAST); + + + + } + + public void updateProfiles() + { + try{ + ArrayList al = ui.getProfiles(); + String[] arra = new String[al.size()]; + al.toArray(arra); // fill the array + list.setListData(arra); + } + catch(Exception e) + { + ArrayList a= new ArrayList(); + a.add("No Profiles Found"); + String[] array = new String[a.size()]; + a.toArray(array); // fill the array + list.setListData(array); + JOptionPane.showMessageDialog(this, "There are no profiles yet."); + + } + } + + + + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + String command = arg0.getActionCommand( ); + + if( "ADD".equals(command) ) + { + String name = JOptionPane.showInputDialog(this,"Enter a name for the new profile", "Add a Profile"); + if (name != null) + { + try + { + ui.createProfile(name); + JOptionPane.showMessageDialog(this, "Profile "+ name +" was created."); + updateProfiles(); + } + catch(Exception e) + { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + } + } + else if ("DEL".equals(command)) + { + String selectedProfile =(String) list.getSelectedValue(); + try{ + ui.deleteProfile(selectedProfile); + updateProfiles(); + JOptionPane.showMessageDialog(this, "Profile "+selectedProfile+" was deleted."); + } + catch(Exception e) + { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + + } + else + { + String selectedProfile =(String) list.getSelectedValue(); + try{ + ui.useProfile(selectedProfile); + JOptionPane.showMessageDialog(this, "Profile "+selectedProfile+" is now active."); + } + catch(Exception e) + { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + } + + } + + + +} diff --git a/LeagueProfiles/src/ui/TopPanel.java b/LeagueProfiles/src/ui/TopPanel.java new file mode 100644 index 0000000..c3d21a0 --- /dev/null +++ b/LeagueProfiles/src/ui/TopPanel.java @@ -0,0 +1,94 @@ +package ui; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +public class TopPanel extends JPanel implements ActionListener { + + private Ui pm; + + private JButton button; + + private JFileChooser fc; + + private JLabel label; + + + public TopPanel(Ui pm) + { + this.pm = pm; + setLayout(new BorderLayout()); + this.setName("League of Legends path"); + + + button = new JButton("Browse"); + button.setActionCommand("BROWSE"); + button.addActionListener(this); + + + + if (getPath().isEmpty()) + { + label = new JLabel("Select a path please"); + } + else + { + label = new JLabel(getPath()); + } + label.setEnabled(false); + + add(button, BorderLayout.EAST); + add(label, BorderLayout.CENTER); + + + + + } + + public String getPath() + { + return pm.getPath(); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + String command = arg0.getActionCommand( ); + + if( "BROWSE".equals( command ) ) + { + fc = new JFileChooser( "C:/" ); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fc.setDialogTitle( "League of Legends Path, eg: C:/RiotGames/League of Legends" ); + int result = fc.showOpenDialog( this ); + if( result == JFileChooser.APPROVE_OPTION ) + { + File file = fc.getSelectedFile( ); + String path = file.getAbsolutePath( ); + + + File propFile = new File(path, "lol.launcher.exe"); + + if (propFile.exists()) { + pm.setPath(path); + label.setText(path); + label.setToolTipText("LoL game directory."); + JOptionPane.showMessageDialog(this, "Path was set."); + } else { + JOptionPane.showMessageDialog(this, "Path was not set."); + } + + } + } + + } + +} diff --git a/LeagueProfiles/src/ui/Ui.java b/LeagueProfiles/src/ui/Ui.java new file mode 100644 index 0000000..3ff06ba --- /dev/null +++ b/LeagueProfiles/src/ui/Ui.java @@ -0,0 +1,107 @@ +package ui; + +import java.awt.BorderLayout; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +import proc.ProfileManager; + +public class Ui extends JFrame { + + private ProfileManager profileManager; + + private TopPanel topPanel; + + private MidPanel midPanel; + + public Ui( ProfileManager pm ) + { + setTitle("LeagueProfiles"); + setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + + profileManager = pm; + topPanel = new TopPanel(this); + midPanel = new MidPanel(this); + JPanel signature = new JPanel(new BorderLayout()); + JLabel label = new JLabel("LeagueProfiles-2014"); + label.setEnabled(false); + add(midPanel, BorderLayout.CENTER); + add(topPanel, BorderLayout.NORTH); + add(signature, BorderLayout.SOUTH); + + signature.add(label, BorderLayout.CENTER); + //To pack or not to pack + setSize(400, 200); + //pack(); + + } + + public void dispose() + { + try + { + profileManager.saveData( ); + super.dispose( ); + } + catch( Exception e ) + { + setVisible( true ); + int respuesta = JOptionPane.showConfirmDialog( this, "Problems saving:\n" + e.getMessage( ) + "\n¿Still want to close?", "Error", JOptionPane.YES_NO_OPTION ); + if( respuesta == JOptionPane.YES_OPTION ) + { + super.dispose( ); + } + } + } + + public void setPath(String path) + { + profileManager.setGamePath(path); + } + + public ArrayList getProfiles() throws Exception + { + return profileManager.getProfiles(); + } + + public void deleteProfile(String profileName) throws Exception + { + profileManager.deleteProfile(profileName); + } + + public void createProfile(String profileName) throws Exception + { + profileManager.createNewProfile(profileName); + } + + public void useProfile(String profileName) throws Exception + { + profileManager.useProfile(profileName); + } + + public String getPath() + { + return profileManager.getPath(); + } + + public static void main( String[] args ) + { + ProfileManager pms = null; + try + { + pms = new ProfileManager( ); + } + catch(Exception e ) + { + e.printStackTrace( ); + System.exit( 1 ); + } + Ui id = new Ui( pms ); + id.setVisible( true ); + } + +}