Skip to content

Commit 5abe1fd

Browse files
author
Kristian Picon
committed
initial commit
0 parents  commit 5abe1fd

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>MultiLOL</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7

src/ca/mcgill/sus/multilol/Main.java

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package ca.mcgill.sus.multilol;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.InputStreamReader;
8+
import java.nio.file.FileVisitResult;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.SimpleFileVisitor;
12+
import java.nio.file.StandardCopyOption;
13+
import java.nio.file.attribute.BasicFileAttributes;
14+
import java.util.ArrayList;
15+
import java.util.Arrays;
16+
17+
import javax.swing.JOptionPane;
18+
19+
public class Main {
20+
public static void main(String[] args) throws IOException {
21+
String appData = System.getenv("LocalAppData");
22+
File lolDir = new File(appData+"\\LOL");
23+
lolDir.mkdir();
24+
File radsDir = new File(appData+"\\LOL\\RADS");
25+
radsDir.mkdir();
26+
String lolInstallDir = System.getenv("SystemDrive")+"\\Riot Games\\League of Legends";
27+
Path launcherDir = new File(lolInstallDir).toPath();
28+
boolean success = false;
29+
for (int i = 0; i < 3 && success == false; i++) {
30+
try {
31+
copyFiles(launcherDir, lolDir.toPath(), new String[]{"lol.launcher.exe"});
32+
copyFiles(new File(launcherDir+"\\RADS").toPath(), radsDir.toPath(), new String[]{"solutions","system"});
33+
success = true;
34+
} catch (Exception e) {
35+
e.printStackTrace();
36+
Runtime.getRuntime().exec("taskkill /f /im lollauncher.exe", null, new File(System.getenv("SystemDrive")+"\\"));
37+
try {
38+
Thread.sleep(3000);
39+
} catch (InterruptedException e1) {
40+
e1.printStackTrace();
41+
}
42+
}
43+
}
44+
if (!success) {
45+
JOptionPane.showMessageDialog(null,"The launcher is already running but not responding, please terminate it.","League of Legends",JOptionPane.ERROR_MESSAGE);
46+
return;
47+
}
48+
File projectsDir = new File(appData+"\\LOL\\RADS\\projects");
49+
projectsDir.mkdir();
50+
massLink(new File(launcherDir+"\\RADS\\projects").toPath(), projectsDir.toPath(), new String[]{"lol_air_client_config_na","lol_game_client","lol_game_client_en_us","lol_launcher"});
51+
String[] releases = new File(launcherDir+"\\RADS\\projects\\lol_air_client\\releases").list();
52+
Arrays.sort(releases);
53+
File lolAirClientSourceDir = new File(launcherDir+"\\RADS\\projects\\lol_air_client\\releases\\"+releases[0]);
54+
File lolAirClientDir = new File(appData+"\\LOL\\RADS\\projects\\lol_air_client\\releases\\"+releases[0]);
55+
lolAirClientDir.mkdirs();
56+
copyFiles(lolAirClientSourceDir.toPath(), lolAirClientDir.toPath(), new String[]{"releasemanifest","S_OK"});
57+
File deploySourceDir = new File(launcherDir+"\\RADS\\projects\\lol_air_client\\releases\\"+releases[0]+"\\deploy");
58+
File deployDir = new File(appData+"\\LOL\\RADS\\projects\\lol_air_client\\releases\\"+releases[0]+"\\deploy");
59+
deployDir.mkdir();
60+
copyFiles(deploySourceDir.toPath(), deployDir.toPath(), new String[]{"locale.properties","lol.properties","LolClient.exe","LolClient.swf","mimetype"});
61+
massLink(deploySourceDir.toPath(), deployDir.toPath(), new String[]{"Adobe Air","assets","css","lib","logs","META-INF","mod"});
62+
File preferencesSourceDir = new File(System.getenv("AppData")+"\\LOL\\preferences");
63+
Path roamingLolDir = new File(System.getenv("AppData")+"\\LOL").toPath();
64+
if (preferencesSourceDir.exists()) {
65+
try {
66+
copyFiles(roamingLolDir,deployDir.toPath(),new String[]{"preferences"});
67+
copyFiles(roamingLolDir,lolDir.toPath(),new String[]{"Config"});
68+
} catch (Exception e) {
69+
e.printStackTrace();
70+
}
71+
} else {
72+
preferencesSourceDir.mkdirs();
73+
File preferencesDir = new File(appData+"\\LOL\\RADS\\projects\\lol_air_client\\releases\\"+releases[0]+"\\deploy\\preferences");
74+
preferencesDir.mkdir();
75+
}
76+
Runtime.getRuntime().exec(lolDir+"\\lol.launcher.exe", null, lolDir);
77+
try {
78+
Thread.sleep(3000);
79+
} catch (InterruptedException e1) {
80+
e1.printStackTrace();
81+
}
82+
while(isProcessRunning("LoLLauncher.exe")) {
83+
try {
84+
Thread.sleep(5000);
85+
} catch (InterruptedException e1) {
86+
e1.printStackTrace();
87+
}
88+
}
89+
copyFiles(deployDir.toPath(),roamingLolDir,new String[]{"preferences"});
90+
copyFiles(lolDir.toPath(),roamingLolDir,new String[]{"Config"});
91+
}
92+
public static void makeJunctionPoint(Path link, Path target) {
93+
try {
94+
/*Process p =*/ Runtime.getRuntime().exec("cmd /c mklink /j \""+link+"\" \""+target+"\"", null, new File(System.getenv("SystemDrive")+"\\"));
95+
// String err = dumpStream(p.getErrorStream());
96+
// String out = dumpStream(p.getInputStream());
97+
} catch (Exception e) {
98+
}
99+
}
100+
public static String dumpStream(InputStream is) throws IOException {
101+
BufferedReader r = new BufferedReader(new InputStreamReader(is));
102+
StringBuilder sb = new StringBuilder();
103+
String line;
104+
while ((line = r.readLine()) != null) {
105+
sb.append(line);
106+
sb.append("\n");
107+
}
108+
r.close();
109+
return sb.toString().trim();
110+
}
111+
public static void copyFiles(Path sourceDir, Path targetDir, String[] filenames) throws IOException {
112+
for (String filename : filenames) {
113+
final Path sourceFile = new File(sourceDir+"\\"+filename).toPath();
114+
final Path targetFile = new File(targetDir+"\\"+filename).toPath();
115+
if (sourceFile.toFile().isDirectory()) {
116+
Files.walkFileTree(sourceFile, new SimpleFileVisitor<Path>() {
117+
private Path fromPath = sourceFile;
118+
private Path toPath = targetFile;
119+
private StandardCopyOption copyOption = StandardCopyOption.REPLACE_EXISTING;
120+
@Override
121+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
122+
Path targetPath = toPath.resolve(fromPath.relativize(dir));
123+
if(!Files.exists(targetPath)){
124+
Files.createDirectory(targetPath);
125+
}
126+
return FileVisitResult.CONTINUE;
127+
}
128+
129+
@Override
130+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
131+
Files.copy(file, toPath.resolve(fromPath.relativize(file)), copyOption);
132+
return FileVisitResult.CONTINUE;
133+
}
134+
});
135+
} else {
136+
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING);
137+
}
138+
139+
}
140+
}
141+
public static void massLink(Path sourceDir, Path targetDir, String[] dirNames) throws IOException {
142+
for (String dirName : dirNames) {
143+
final Path sourceFile = new File(sourceDir+"\\"+dirName).toPath();
144+
final Path targetFile = new File(targetDir+"\\"+dirName).toPath();
145+
makeJunctionPoint(targetFile, sourceFile);
146+
}
147+
}
148+
public static String[] getRunningProcesses() {
149+
try {
150+
String line;
151+
Process p = Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
152+
BufferedReader input =
153+
new BufferedReader(new InputStreamReader(p.getInputStream()));
154+
String divider = "========================= ======== ================ =========== ============";
155+
boolean write = false;
156+
ArrayList<String> processes = new ArrayList<String>();
157+
while ((line = input.readLine()) != null) {
158+
if (write) {
159+
processes.add(line);
160+
}
161+
if (line.equals(divider)) write = true;
162+
}
163+
input.close();
164+
return processes.toArray(new String[]{});
165+
} catch (Exception err) {
166+
err.printStackTrace();
167+
}
168+
return new String[]{};
169+
}
170+
public static boolean isProcessRunning(String processName) {
171+
String[] processes = getRunningProcesses();
172+
for (String process : processes) {
173+
if (process.toLowerCase().contains(processName.toLowerCase())) return true;
174+
}
175+
return false;
176+
}
177+
}

0 commit comments

Comments
 (0)