-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebViewSample.java
More file actions
672 lines (571 loc) · 18.5 KB
/
Copy pathWebViewSample.java
File metadata and controls
672 lines (571 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import java.io.File;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.util.Duration;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.text.Font;
import javafx.scene.effect.Reflection;
import javafx.scene.layout.StackPane;
import javafx.scene.image.Image;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.FileEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.Header;
import org.apache.http.ContentTooLongException;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.net.*;
import java.nio.channels.FileLock;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.security.GeneralSecurityException;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.prefs.Preferences;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import java.lang.reflect.InvocationTargetException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import javafx.embed.swing.SwingFXUtils;
import java.util.prefs.Preferences;
import org.json.*;
import java.nio.charset.Charset;
import java.io.BufferedReader;
@SuppressWarnings("deprecation")
public class WebViewSample extends Application {
private Scene scene;
private static Preferences prefs = Preferences.userNodeForPackage(WebViewSample.class);
private static String uploadName;
private static boolean running = false;
private static Label statuss;
private static int Version = 4;
@Override public void start(Stage stage) {
int offset = 45;
ClassLoader classLoader = getClass().getClassLoader();
// create the scene
stage.setTitle("LP Launcher");
BufferedImage img = null;
try{
img = ImageIO.read(WebViewSample.class.getResourceAsStream("ico.png"));
}catch (IOException e){}
Image card = SwingFXUtils.toFXImage(img, null );
stage.getIcons().add(card);
StackPane pane = new StackPane();
pane.getChildren().add(new Browser());
TextField uidField = new TextField();
uidField.setText(prefs.get("UID", "0"));
uidField.textProperty().addListener((observable, oldValue, newValue) -> {
prefs.put("UID", newValue);
});
uidField.setMaxWidth(150);
uidField.setTranslateY(-125+offset);
uidField.setTranslateX(15);
pane.getChildren().add(uidField);
Button b1 = new Button("Launch");
b1.setTranslateY(-80+offset);
b1.setPrefWidth(185);
Button b2 = new Button("Reupload");
b2.setTranslateY(-30+offset);
b2.setPrefWidth(185);
Button b3 = new Button("Clear WDB");
b3.setTranslateY(20+offset);
b3.setPrefWidth(185);
Button b4 = new Button("Upload saved");
b4.setTranslateY(70+offset);
b4.setPrefWidth(185);
b1.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
Launch(false);
}
});
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
FileDialog dialog = new FileDialog((Frame)null, "Select File to Open");
dialog.setMode(FileDialog.LOAD);
dialog.setVisible(true);
String path = dialog.getFile();
File file = new File("RPLLLogs/"+path);
if (file.exists())
{
String extension = getFileExtension(file);
if (extension.equals("zip"))
{
if (1000000 * 20 >= file.length())
{
uploadName = "RPLLLogs/"+path;
UploadLog("RPLLLogs/"+path);
}
}
}
}
});
b3.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
File index = new File("Cache/WDB");
if (!index.exists())
index = new File("WDB");
if (index.exists()){
String[] entries = index.list();
for(String s: entries){
File dir = new File(index.getPath(),s);
if (dir.isDirectory())
{
String[] entries2 = dir.list();
for(String s2: entries2){
File currentFile = new File(dir.getPath(),s2);
currentFile.delete();
}
}
else
{
dir.delete();
}
}
JOptionPane.showMessageDialog(null, "WDB cleared");
}
else
{
JOptionPane.showMessageDialog(null, "Could not find WDB");
}
}
});
b4.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
//Launch(true);
UploadLog("");
ClearCache();
}
});
pane.getChildren().add(b1);
pane.getChildren().add(b2);
pane.getChildren().add(b3);
pane.getChildren().add(b4);
statuss = new Label();
statuss.setTranslateY(100 + offset);
statuss.setText("Ready");
statuss.setFont(new Font("Arial", 12));
statuss.setTextFill(Color.web("#ffffff"));
pane.getChildren().add(statuss);
scene = new Scene(pane,250,310, Color.web("#666970"));
scene.getStylesheets().add(getClass().getResource("main.css").toExternalForm());
stage.setScene(scene);
stage.setResizable(false);
stage.show();
// Hack code, please ignore
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
CheckVersion();
}
private static boolean compressFile(String path) {
String subName = prefs.get("UID", "0")+"-"+System.currentTimeMillis();
uploadName = "RPLLLogs/"+subName+".zip";
String zipFile = uploadName;
File logs = new File("RPLLLogs");
if (!logs.exists()) logs.mkdir();
// Renaming files
File f1 = new File("Logs/WoWCombatLog.txt");
try{if (!f1.exists()) f1.createNewFile();}catch(IOException e){}
File f2 = new File(subName+".txt");
f1.renameTo(f2);
File f3 = new File(path);
File f4 = new File(subName+".lua");
f3.renameTo(f4);
String[] srcFiles = { subName+".txt", subName+".lua"};
try {
// create byte buffer
byte[] buffer = new byte[1024];
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
for (int i=0; i < srcFiles.length; i++) {
File srcFile = new File(srcFiles[i]);
FileInputStream fis = new FileInputStream(srcFile);
// begin writing a new ZIP entry, positions the stream to the start of the entry data
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
// close the InputStream
fis.close();
}
// close the ZipOutputStream
zos.close();
}
catch (IOException ioe) {
JOptionPane.showMessageDialog(null, "Could not find the addon file!");
return false;
}
if (f2.exists()) f2.delete();
if (f4.exists()) f4.delete();
return true;
}
private static String getFileExtension(File file) {
String name = file.getName();
try {
return name.substring(name.lastIndexOf(".") + 1);
} catch (Exception e) {
return "";
}
}
public static void Launch(boolean nampower)
{
if (running)
{
JOptionPane.showMessageDialog(null, "You can only use one instance at the same time!");
return;
}
ClearCache();
try{
Process p;
if (nampower)
{
File np = new File("nampower.exe");
if (!np.exists())
{
JOptionPane.showMessageDialog(null, "Could not find nampower.exe");
return;
}
p = Runtime.getRuntime().exec("nampower.exe");
}
else
{
p = Runtime.getRuntime().exec("WoW.exe");
}
running = true;
try {
p.waitFor();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
UploadLog("");
running = false;
}
catch (IOException e2)
{
JOptionPane.showMessageDialog(null, "Could not find WoW.exe");
}
}
public static void ClearCache(){
File dir = new File("WTF/Account");
if (dir.exists() && dir.isDirectory())
{
for (File g : dir.listFiles()){
if (g.exists())
{
File svd1 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLVanilla.lua");
if (svd1.exists()) svd1.delete();
File svd2 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLTBC.lua");
if (svd2.exists()) svd2.delete();
File svd3 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLWOTLK.lua");
if (svd3.exists()) svd3.delete();
File svd4 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLCATA.lua");
if (svd4.exists()) svd4.delete();
File svd5 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLMOP.lua");
if (svd5.exists()) svd5.delete();
File svd6 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLWOD.lua");
if (svd6.exists()) svd6.delete();
}
}
}
File cbtLog = new File("Logs/WoWCombatLog.txt");
if (cbtLog.exists()) cbtLog.delete();
}
// Empty argument means to find it itself
public static void UploadLog(String path){
// Finding path
if (path.isEmpty())
{
long time = 0;
File dir = new File("WTF/Account");
if (dir.exists() && dir.isDirectory())
{
for (File g : dir.listFiles()){
if (g.exists())
{
File svd1 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLVanilla.lua");
if (svd1.exists() && time < svd1.lastModified()){
path = svd1.getAbsolutePath();
time = svd1.lastModified();
}
File svd2 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLTBC.lua");
if (svd2.exists() && time < svd2.lastModified()){
path = svd2.getAbsolutePath();
time = svd2.lastModified();
}
File svd3 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLWOTLK.lua");
if (svd3.exists() && time < svd3.lastModified()){
path = svd3.getAbsolutePath();
time = svd3.lastModified();
}
File svd4 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLCATA.lua");
if (svd4.exists() && time < svd4.lastModified()){
path = svd4.getAbsolutePath();
time = svd4.lastModified();
}
File svd5 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLMOP.lua");
if (svd5.exists() && time < svd5.lastModified()){
path = svd5.getAbsolutePath();
time = svd5.lastModified();
}
File svd6 = new File("WTF/Account/"+g.getName()+"/SavedVariables/RPLLWOD.lua");
if (svd6.exists() && time < svd6.lastModified()){
path = svd6.getAbsolutePath();
time = svd6.lastModified();
}
}
}
}
else
{
JOptionPane.showMessageDialog(null, "Could not find WTF/Account");
return;
}
}
if (path.isEmpty())
{
JOptionPane.showMessageDialog(null, "Could not find the addon data.");
return;
}
if (!getFileExtension(new File(path)).equals("zip"))
{
if (!compressFile(path)) return;
}
File logs = new File("RPLLLogs");
if (!logs.exists()) logs.mkdir();
statuss.setText("Uploading...");
Thread thread = new Thread() {
public void run() {
File file2 = new File(uploadName);
String url = "https://legacyplayers.com/Upload.aspx?exp="+getExpansion();
CloseableHttpClient httpClient = HttpClientBuilder.create()
.build();
HttpEntity requestEntity = MultipartEntityBuilder.create()
.addBinaryBody("file", file2)
.build();
HttpPost post = new HttpPost(url);
post.setEntity(requestEntity);
try (CloseableHttpResponse response = httpClient.execute(post)) {
System.out.print(response.getStatusLine());
Header[] headers = post.getAllHeaders();
String content = EntityUtils.toString(requestEntity);
System.out.println(post.toString());
for (Header header : headers) {
System.out.println(header.getName() + ": " + header.getValue());
}
System.out.println();
System.out.println(content);
System.out.println();
System.out.println();
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
EntityUtils.consume(response.getEntity());
}
catch(ContentTooLongException e)
{
// Even if it occours, it uploads just fine
// Odd...
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Some error occoured during the upload. Please try later again!");
return;
}
JOptionPane.showMessageDialog(null, "Upload complete!");
}
};
thread.start();
try
{
thread.join();
}catch(InterruptedException e){}
statuss.setText("Ready");
}
private static int getExpansion(){
File wowexe = new File("WoW.exe");
if (wowexe.exists()){
long len = wowexe.length()/1024;
if (len>7600){
return 1; // TBC
}
if (len>5000){
return 2; // WOTLK
}
}
return 0; // Vanilla
}
private static void CheckVersion(){
try
{
InputStream is = new URL("https://legacyplayers.com/API.aspx?type=1338").openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = null;
String line = null;
StringBuffer stringBuffer = new StringBuffer();
while((line =rd.readLine())!=null){
stringBuffer.append(line);
}
jsonText = stringBuffer.toString();
JSONObject json = new JSONObject(jsonText);
if (json.getInt("Launcher") > Version)
{
JOptionPane.showMessageDialog(null, "The launcher is outdated. Please redownload it!");
}
// Get Addon version
int exp = getExpansion();
File f;
if (exp == 0) f = new File("Interface/AddOns/RPLLVanilla/core.lua");
else if (exp == 1) f = new File("Interface/AddOns/RPLLTBC/core.lua");
else f = new File("Interface/AddOns/RPLLWOTLK/core.lua");
if (f.exists())
{
FileInputStream fs = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fs));
br.readLine();
String str = br.readLine();
int ver = 99999999;
str = str.replaceAll("\\D+", "");
if (str.isEmpty()) {
br.close();
fs.close();
}
else
{
ver = Integer.parseInt(str);
br.close();
fs.close();
if (
(exp == 0 && json.getInt("Vanilla") > ver)
|| (exp == 1 && json.getInt("TBC") > ver)
|| (exp == 2 && json.getInt("WOTLK") > ver)
)
{
JOptionPane.showMessageDialog(null, "The AddOn is outdated. Please redownload it!");
}
}
}
}
finally {
is.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args){
launch(args);
}
}
class Browser extends Region {
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
public Browser() {
//apply the styles
ClassLoader classLoader = getClass().getClassLoader();
getStyleClass().add("browser");
// load the web page
webEngine.load(getClass().getResource("index.html").toExternalForm());
//add the web view to the scene
getChildren().add(browser);
}
private Node createSpacer() {
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
return spacer;
}
@Override protected void layoutChildren() {
double w = getWidth();
double h = getHeight();
layoutInArea(browser,0,0,w,h,0, HPos.CENTER, VPos.CENTER);
}
@Override protected double computePrefWidth(double height) {
return 250;
}
@Override protected double computePrefHeight(double width) {
return 300;
}
}