Skip to content

Commit b741bae

Browse files
Merge pull request #153 from johnnycz/issue-152-quaddicted-json-api-support-pr
Update QuakeInjector to work with the new Quaddicted backend API
2 parents 65fe592 + f94b719 commit b741bae

18 files changed

+2374
-424
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ build
1010

1111

1212
database.xml
13+
database.xml*.tmp
14+
database.json
15+
database.json*.tmp
1316
installedMaps.xml
1417
config.properties
1518
jre/
@@ -21,4 +24,4 @@ jre/
2124
.settings/
2225

2326
*.iml
24-
.idea/
27+
.idea/

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ repositories {
1414

1515
dependencies {
1616
implementation 'edu.stanford.ejalbert:BrowserLauncher2:1.3'
17+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
18+
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
1719
}
1820

1921
application {
@@ -102,4 +104,5 @@ task winDist(type: Zip) {
102104
}
103105
test {
104106
useJUnitPlatform()
107+
maxParallelForks = 1
105108
}

src/main/java/de/haukerehfeld/quakeinjector/Configuration.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class Configuration {
3636
private static final String CONFIGHEADER = "Quake Injector " + BuildCommit.getBuildCommit() + " config file";
37-
public class EnginePath extends FileValue {
37+
public static class EnginePath extends FileValue {
3838
private EnginePath() { super("enginePath", null); }
3939

4040
public File getUnzipDir(Package map) {
@@ -48,18 +48,18 @@ public File getUnzipDir(Package map) {
4848
}
4949
public final EnginePath EnginePath = new EnginePath();
5050

51-
public class EngineExecutable extends FileValue {
51+
public static class EngineExecutable extends FileValue {
5252
private EngineExecutable() { super("engineExecutable", new File("")); }
5353
}
5454
public final EngineExecutable EngineExecutable = new EngineExecutable();
5555

56-
public class WorkingDirAtExecutable extends BooleanValue {
56+
public static class WorkingDirAtExecutable extends BooleanValue {
5757
private WorkingDirAtExecutable() { super("workingDirAtExecutable", false); }
5858
}
5959
public final WorkingDirAtExecutable WorkingDirAtExecutable = new WorkingDirAtExecutable();
6060

61-
public class LocalDatabaseFile extends FileValue {
62-
private LocalDatabaseFile() { super("localDatabaseFile", new File("database.xml")); }
61+
public static class LocalDatabaseFile extends FileValue {
62+
private LocalDatabaseFile() { super("localDatabaseFile", new File("database.json")); }
6363
}
6464
public final LocalDatabaseFile LocalDatabaseFile = new LocalDatabaseFile();
6565

@@ -93,36 +93,38 @@ public void set(File v) {
9393
}
9494
public final DownloadPath DownloadPath = new DownloadPath();
9595

96-
public class EngineCommandLine extends StringValue {
96+
public static class EngineCommandLine extends StringValue {
9797
private EngineCommandLine() { super("engineCommandline", ""); }
9898
}
9999
public final EngineCommandLine EngineCommandLine = new EngineCommandLine();
100100

101-
public class RepositoryDatabasePath extends StringValue {
101+
public static class RepositoryDatabasePath extends StringValue {
102102
private RepositoryDatabasePath() { super("repositoryDatabase",
103-
"https://www.quaddicted.com/reviews/quaddicted_database.xml"); }
103+
"https://api.quaddicted.com/jsons"); }
104+
//"https://www.quaddicted.com/reviews/quaddicted_database.xml"); }
104105
}
105106
public final RepositoryDatabasePath RepositoryDatabasePath = new RepositoryDatabasePath();
106107

107-
public class ScreenshotRepositoryPath extends StringValue {
108+
public static class ScreenshotRepositoryPath extends StringValue {
108109
private ScreenshotRepositoryPath() { super("screenshotRepositoryPath",
109-
"https://www.quaddicted.com/reviews/screenshots/"); }
110+
// https://www.quaddicted.com/files/quaddicted-images/by-sha256/a2/a25043c2b6c1c73b24e4a00c63d95a8a9e08943d8b8e39d7c4571ae3a1899d99/colony3.jpg
111+
"https://www.quaddicted.com/files/quaddicted-images/by-sha256/"); }
110112
}
111113
public final ScreenshotRepositoryPath ScreenshotRepositoryPath = new ScreenshotRepositoryPath();
112114

113-
public class ZipContentsDatabaseUrl extends StringValue {
115+
public static class ZipContentsDatabaseUrl extends StringValue {
114116
private ZipContentsDatabaseUrl() { super("ZipContentsDatabaseUrl",
115117
"http://haukerehfeld.de/projects/quakeinjector/temp/zipContents.xml"); }
116118
}
117119
public final ZipContentsDatabaseUrl ZipContentsDatabaseUrl = new ZipContentsDatabaseUrl();
118120

119121

120-
public class RogueInstalled extends BooleanValue {
122+
public static class RogueInstalled extends BooleanValue {
121123
private RogueInstalled() { super("rogueInstalled", false); }
122124
}
123125
public final RogueInstalled RogueInstalled = new RogueInstalled();
124126

125-
public class OfflineMode extends BooleanValue {
127+
public static class OfflineMode extends BooleanValue {
126128
private ChangeListenerList listeners = new ChangeListenerList();
127129

128130
private OfflineMode() { super("offlineMode", false); }
@@ -139,22 +141,22 @@ public void set(Boolean b) {
139141
}
140142
public final OfflineMode OfflineMode = new OfflineMode();
141143

142-
public class HipnoticInstalled extends BooleanValue {
144+
public static class HipnoticInstalled extends BooleanValue {
143145
private HipnoticInstalled() { super("hipnoticInstalled", false); }
144146
}
145147
public final HipnoticInstalled HipnoticInstalled = new HipnoticInstalled();
146148

147-
public class MainWindowPositionX extends IntegerValue {
149+
public static class MainWindowPositionX extends IntegerValue {
148150
private MainWindowPositionX() { super("mainWindowPositionX", null); }
149151
}
150152
public final MainWindowPositionX MainWindowPositionX = new MainWindowPositionX();
151153

152-
public class MainWindowPositionY extends IntegerValue {
154+
public static class MainWindowPositionY extends IntegerValue {
153155
private MainWindowPositionY() { super("mainWindowPositionY", null); }
154156
}
155157
public final MainWindowPositionY MainWindowPositionY = new MainWindowPositionY();
156158

157-
public class MainWindowWidth extends IntegerValue {
159+
public static class MainWindowWidth extends IntegerValue {
158160
private MainWindowWidth() { super("mainWindowWidth", null); }
159161
}
160162
public final MainWindowWidth MainWindowWidth = new MainWindowWidth();
@@ -164,20 +166,25 @@ public class MainWindowHeight extends IntegerValue {
164166
}
165167
public final MainWindowHeight MainWindowHeight = new MainWindowHeight();
166168

167-
public class RepositoryBasePath extends StringValue {
169+
public static class RepositoryBasePath extends StringValue {
168170
private final static String onlineRepositoryExtension = ".zip";
169171

170-
private RepositoryBasePath() { super("repositoryBase", "https://www.quaddicted.com/filebase/"); }
172+
private RepositoryBasePath() { super("repositoryBase", "https://www.quaddicted.com/files/by-sha256/"); }
171173

172174
/**
173175
* Get a complete Url to a map archive file in the repo
174176
*/
175-
public String getRepositoryUrl(String mapid) {
176-
return get() + mapid + onlineRepositoryExtension;
177+
public String getRepositoryUrl(String filename, String sha256) {
178+
return get() + sha256.substring(0, 2) + "/" + sha256 + "/" + filename;
177179
}
178180
}
179181
public final RepositoryBasePath RepositoryBasePath = new RepositoryBasePath();
180182

183+
public static class MapWebpageBaseUrl extends StringValue {
184+
private MapWebpageBaseUrl() { super("mapWebpageBaseUrl", "https://www.quaddicted.com/db/v1/maps/"); }
185+
}
186+
public final MapWebpageBaseUrl mapWebpageBaseUrl = new MapWebpageBaseUrl();
187+
181188
public final Map<String,Value<?>> All = new HashMap<String,Value<?>>();
182189

183190
private File configFile;
@@ -349,7 +356,7 @@ public interface Value<T> {
349356
public boolean existsOrDefault();
350357
}
351358

352-
public abstract class AbstractValue<T> implements Value<T> {
359+
public abstract static class AbstractValue<T> implements Value<T> {
353360
private String key;
354361
private T defaultValue;
355362
private T value;
@@ -398,7 +405,7 @@ public String toString() {
398405
}
399406
}
400407

401-
public abstract class StringValue extends AbstractValue<String> {
408+
public abstract static class StringValue extends AbstractValue<String> {
402409
protected StringValue(String key, String defaultValue) { super(key, defaultValue); }
403410

404411
public String stringToValue(String v) {
@@ -410,7 +417,7 @@ public String toString() {
410417
}
411418
}
412419

413-
public abstract class FileValue extends AbstractValue<File> {
420+
public abstract static class FileValue extends AbstractValue<File> {
414421
protected FileValue(String key, File defaultValue) { super(key, defaultValue); }
415422

416423
public File stringToValue(String v) {
@@ -419,15 +426,15 @@ public File stringToValue(String v) {
419426
}
420427

421428

422-
public abstract class BooleanValue extends AbstractValue<Boolean> {
429+
public abstract static class BooleanValue extends AbstractValue<Boolean> {
423430
protected BooleanValue(String key, boolean defaultValue) { super(key, defaultValue); }
424431

425432
public Boolean stringToValue(String v) {
426433
return Boolean.valueOf(v);
427434
}
428435
}
429436

430-
public abstract class IntegerValue extends AbstractValue<Integer> {
437+
public abstract static class IntegerValue extends AbstractValue<Integer> {
431438
protected IntegerValue(String key, Integer defaultValue) { super(key, defaultValue); }
432439

433440
public Integer stringToValue(String v) {

src/main/java/de/haukerehfeld/quakeinjector/Installer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public void install(final Package selectedMap,
118118
public void cancel(Package installerMap) {
119119
Worker w;
120120
synchronized (queue) { w = queue.get(installerMap); }
121-
w.cancel();
121+
if (w != null) {
122+
w.cancel();
123+
}
122124
}
123125

124126

src/main/java/de/haukerehfeld/quakeinjector/Package.java

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ public class Package extends SortableRequirement implements Requirement {
3535
*/
3636
private ChangeListenerList listeners = new ChangeListenerList();
3737

38+
private String sha256;
39+
40+
private String filename;
41+
42+
private List<String> downloadUrls;
43+
3844
private String author;
3945

4046
private String title;
4147

42-
private Rating rating;
43-
4448
private float normalizedUsersRating;
4549

4650
private String description;
@@ -64,37 +68,29 @@ public class Package extends SortableRequirement implements Requirement {
6468
private PackageFileList supposedFileList;
6569

6670
public Package(String id,
67-
String author,
68-
String title,
69-
int size,
70-
Date date,
71-
boolean isInstalled,
72-
Rating rating,
73-
float normalizedUsersRating,
74-
String description) {
75-
this(id, author, title, size, date, isInstalled, rating, normalizedUsersRating, description, null, null, null, null);
76-
}
77-
78-
public Package(String id,
71+
String sha256,
72+
String filename,
73+
List<String> downloadUrls,
7974
String author,
8075
String title,
8176
int size,
8277
Date date,
8378
boolean isInstalled,
84-
Rating rating,
8579
float normalizedUsersRating,
8680
String description,
8781
String relativeBaseDir,
8882
String commandline,
8983
List<String> startmaps,
9084
List<Requirement> requirements) {
9185
super(id);
86+
this.sha256 = sha256;
87+
this.filename = filename;
88+
this.downloadUrls = downloadUrls;
9289
this.author = author;
9390
this.title = title;
9491
this.size = size;
9592
this.date = date;
9693
super.setInstalled(isInstalled);
97-
this.rating = rating;
9894
this.normalizedUsersRating = normalizedUsersRating;
9995
this.description = description;
10096
this.relativeBaseDir = relativeBaseDir;
@@ -113,7 +109,19 @@ public void addChangeListener(ChangeListener l) {
113109
public void removeChangeListener(ChangeListener l) {
114110
listeners.removeChangeListener(l);
115111
}
116-
112+
113+
public String getSha256() {
114+
return sha256;
115+
}
116+
117+
public String getFilename() {
118+
return filename;
119+
}
120+
121+
public List<String> getDownloadUrls() {
122+
return downloadUrls;
123+
}
124+
117125
public String getAuthor() {
118126
return author;
119127
}
@@ -127,11 +135,6 @@ public Date getDate() {
127135
return date;
128136
}
129137

130-
/**
131-
* get rating
132-
*/
133-
public Rating getRating() { return rating; }
134-
135138
public float getNormalizedUsersRating() { return normalizedUsersRating; }
136139

137140

@@ -225,22 +228,6 @@ public String toString() {
225228
*/
226229
public void setSupposedFileList(PackageFileList supposedFileList) { this.supposedFileList = supposedFileList; }
227230

228-
public static enum Rating {
229-
Unrated(0),
230-
Crap(1),
231-
Poor(2),
232-
Average(3),
233-
Nice(4),
234-
Excellent(5);
235-
236-
private int rating;
237-
Rating(int rating) {
238-
this.rating = rating;
239-
}
240231

241-
public int getRating() {
242-
return rating;
243-
}
244-
}
245232
}
246233

0 commit comments

Comments
 (0)