Skip to content

Commit b304b08

Browse files
committed
Fixed username thing
YES!!! I programmed something in Java!
1 parent bccce9e commit b304b08

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/io/github/coursesplus/installer/CoursesPlusInstaller.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@
2727
@SuppressWarnings("serial")
2828
public class CoursesPlusInstaller extends JFrame implements ActionListener {
2929
public static final String VERSION = "0.1";
30-
30+
3131
public static Logger logger;
32-
32+
3333
public static Dimension screenSize;
3434

3535
public static Font font;
3636
public static Font bigFont;
3737
public static Font titleFont;
3838

39-
public static final String BASE_PATH = "/Users/student/Library/Application Support/Google/Chrome/";
39+
public static final String BASE_PATH = "/Users" + System.getProperty("user.name") + "Library/Application Support/Google/Chrome/";
4040
public static final String FOLDER_NAME = "External Extensions";
4141
public static final String EXT_ID = "pieincmodljnbihihjnapcmhdddhbpgi";
4242
public static final String EXT_FILE = "{\"external_update_url\": \"https://clients2.google.com/service/update2/crx\"}";
43-
43+
4444
public static final String LOAD_PAGE = "data:text/html,<h1>Loading, please wait...</h1><h2>Do not navigate away from this page while installation is in progress.</h2>";
45-
45+
4646
public CoursesPlusInstaller() {
4747
super("CoursesPlus Installer v" + VERSION);
48-
48+
4949
logger = Logger.getLogger(CoursesPlusInstaller.class.getName());
50-
50+
5151
screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
52-
52+
5353
try {
5454
// try and load Lato
5555
font = Font.createFont(Font.TRUETYPE_FONT, new File("Lato-Regular.ttf"));
56-
56+
5757
font = font.deriveFont(14f);
5858
bigFont = font.deriveFont(32f);
5959
titleFont = font.deriveFont(64f);
@@ -65,7 +65,7 @@ public CoursesPlusInstaller() {
6565
bigFont = new Font("SansSerif", Font.PLAIN, 32);
6666
titleFont = new Font("SansSerif", Font.PLAIN, 64);
6767
}
68-
68+
6969
setLayout(new GridLayout(3, 1));
7070

7171
JLabel title = new JLabel("CoursesPlus", JLabel.CENTER);
@@ -83,10 +83,10 @@ public CoursesPlusInstaller() {
8383

8484
setBounds((screenSize.width - 600) / 2, (screenSize.height - 400) / 2, 600, 400);
8585
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
86-
86+
8787
setVisible(true);
8888
}
89-
89+
9090
public static void main(String[] args) {
9191
new CoursesPlusInstaller();
9292
}
@@ -98,14 +98,14 @@ public void actionPerformed(ActionEvent e) {
9898
switch (text) {
9999
case "Install":
100100
JOptionPane.showMessageDialog(null, "Make sure you've closed open Chrome windows. Any windows remaining open will automatically be closed after pressing OK.", "Close Chrome windows", JOptionPane.WARNING_MESSAGE);
101-
101+
102102
try {
103103
Runtime.getRuntime().exec(new String[]{"killall", "Google Chrome"});
104104
} catch (IOException e4) {
105105
// TODO Auto-generated catch block
106106
e4.printStackTrace();
107107
}
108-
108+
109109
File destDir = new File(BASE_PATH + FOLDER_NAME);
110110
if (!destDir.exists()) {
111111
destDir.mkdir();
@@ -132,8 +132,8 @@ public void actionPerformed(ActionEvent e) {
132132
// TODO Auto-generated catch block
133133
e3.printStackTrace();
134134
}
135-
136-
Path extensionDir = Paths.get("/Users/student/Library/Application Support/Google/Chrome/Default/Extensions");
135+
136+
Path extensionDir = Paths.get("/Users/" + System.getProperty("user.name") + "/Library/Application Support/Google/Chrome/Default/Extensions");
137137
Set<PosixFilePermission> orig = null;
138138
try {
139139
// save original Extensions dir permissions
@@ -143,15 +143,15 @@ public void actionPerformed(ActionEvent e) {
143143
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(extensionDir);
144144
perms.add(PosixFilePermission.OWNER_WRITE);
145145
Files.setPosixFilePermissions(extensionDir, perms);
146-
146+
147147
// open Chrome
148148
String[] cmd = {"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", LOAD_PAGE};
149149
Process chrome = Runtime.getRuntime().exec(cmd);
150150
Thread.sleep(7500);
151151
Runtime.getRuntime().exec(new String[]{"killall", "Google Chrome"});
152152
Thread.sleep(100);
153153
Runtime.getRuntime().exec(new String[]{"killall", "Google Chrome"});
154-
154+
155155
// restore Extensions dir permissions
156156
Files.setPosixFilePermissions(extensionDir, orig);
157157
} catch (IOException e1) {
@@ -168,17 +168,17 @@ public void actionPerformed(ActionEvent e) {
168168
e2.printStackTrace();
169169
}
170170
}
171-
171+
172172
e1.printStackTrace();
173173
}
174-
174+
175175
JOptionPane.showMessageDialog(null, "Done");
176-
176+
177177
break;
178-
178+
179179
default:
180180
logger.warning("Unknown button pressed - " + text);
181181
break;
182182
}
183183
}
184-
}
184+
}

0 commit comments

Comments
 (0)