Skip to content

Commit 13f50bc

Browse files
author
Benjamin Faal
committed
0.0.1
1 parent 878d8b9 commit 13f50bc

File tree

8 files changed

+14962
-0
lines changed

8 files changed

+14962
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
target/
12
# Compiled class file
23
*.class
34

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
11
# ps4-error-codes
22
PS4 Error Codes
3+
4+
Sources:
5+
- https://github.com/xXxTheDarkprogramerxXx/PS4_Error_Code_Viewer
6+
- https://www.psdevwiki.com/ps4/Error_Codes
7+
- https://www.psdevwiki.com/ps4/Talk:Error_Codes
8+
9+
[![Release](https://jitpack.io/v/BenjaminFaal/ps4-error-codes.svg)](https://jitpack.io/#BenjaminFaal/ps4-error-codes)
10+
## Maven
11+
```xml
12+
<repositories>
13+
<repository>
14+
<id>jitpack.io</id>
15+
<url>https://jitpack.io</url>
16+
</repository>
17+
</repositories>
18+
19+
<dependency>
20+
<groupId>com.github.BenjaminFaal</groupId>
21+
<artifactId>ps4-error-codes</artifactId>
22+
<version>0.0.1</version>
23+
</dependency>
24+
```
25+
26+
## Usage
27+
```java
28+
import com.benjaminfaal.ps4errorcodes.PS4ErrorCodes;
29+
30+
public class PS4ErrorCodesTest {
31+
32+
public static void main(String[] args) {
33+
PS4ErrorCodes.findByName("SCE_KERNEL_ERROR_E2BIG");
34+
PS4ErrorCodes.findByCode("CE-30007-0");
35+
PS4ErrorCodes.findByReturnCode("0x80020007");
36+
PS4ErrorCodes.findBySigned(-2147352569);
37+
PS4ErrorCodes.findByUnsigned(2147614727L);
38+
}
39+
40+
}
41+
```

pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.github.BenjaminFaal</groupId>
5+
<artifactId>ps4-error-codes</artifactId>
6+
<version>0.0.1</version>
7+
<name>PS4 Error Codes</name>
8+
<url>https://github.com/BenjaminFaal/ps4-error-codes</url>
9+
10+
<properties>
11+
<maven.compiler.source>8</maven.compiler.source>
12+
<maven.compiler.target>8</maven.compiler.target>
13+
14+
<!--Dependencies versions-->
15+
<lombok.version>1.18.16</lombok.version>
16+
<commons-csv.version>1.8</commons-csv.version>
17+
<junit.version>4.13.1</junit.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.projectlombok</groupId>
23+
<artifactId>lombok</artifactId>
24+
<version>${lombok.version}</version>
25+
<scope>provided</scope>
26+
<optional>true</optional>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.apache.commons</groupId>
31+
<artifactId>commons-csv</artifactId>
32+
<version>${commons-csv.version}</version>
33+
</dependency>
34+
35+
<!--Test-->
36+
<dependency>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
<version>${junit.version}</version>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.benjaminfaal.ps4errorcodes;
2+
3+
import lombok.Data;
4+
import lombok.NonNull;
5+
6+
@Data
7+
public class PS4ErrorCode {
8+
9+
private final String name;
10+
11+
@NonNull
12+
private final String code;
13+
14+
@NonNull
15+
private final String returnCode;
16+
17+
private final String description;
18+
19+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.benjaminfaal.ps4errorcodes;
2+
3+
import lombok.SneakyThrows;
4+
import lombok.experimental.UtilityClass;
5+
import org.apache.commons.csv.CSVFormat;
6+
import org.apache.commons.csv.CSVPrinter;
7+
8+
import java.io.FileWriter;
9+
import java.io.IOException;
10+
import java.io.InputStreamReader;
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
import java.util.stream.Stream;
15+
import java.util.stream.StreamSupport;
16+
17+
@UtilityClass
18+
public class PS4ErrorCodes {
19+
20+
private static final Map<String, PS4ErrorCode> BY_NAME = new HashMap<>();
21+
22+
private static final Map<String, PS4ErrorCode> BY_CODE = new HashMap<>();
23+
24+
private static final Map<String, PS4ErrorCode> BY_RETURNCODE = new HashMap<>();
25+
26+
private static final Map<Integer, PS4ErrorCode> BY_SIGNED = new HashMap<>();
27+
28+
private static final Map<Long, PS4ErrorCode> BY_UNSIGNED = new HashMap<>();
29+
30+
static {
31+
load("input/error_codes.csv");
32+
load("input/psdevwiki_error_codes.csv");
33+
}
34+
35+
public PS4ErrorCode findByCode(String code) {
36+
return BY_CODE.get(code);
37+
}
38+
39+
public PS4ErrorCode findByReturnCode(String returnCode) {
40+
return BY_RETURNCODE.get(returnCode.toUpperCase());
41+
}
42+
43+
public PS4ErrorCode findByName(String name) {
44+
return BY_NAME.get(name);
45+
}
46+
47+
public PS4ErrorCode findBySigned(int signed) {
48+
return BY_SIGNED.get(signed);
49+
}
50+
51+
public PS4ErrorCode findByUnsigned(long unsigned) {
52+
return BY_UNSIGNED.get(unsigned);
53+
}
54+
55+
private void load(String csvResourceName) {
56+
fillMaps(parseCsv(csvResourceName));
57+
}
58+
59+
private void fillMaps(Stream<PS4ErrorCode> ps4ErrorCodes) {
60+
ps4ErrorCodes.forEach(ps4ErrorCode -> {
61+
if (ps4ErrorCode.getName() != null && !ps4ErrorCode.getName().trim().isEmpty()) {
62+
put(BY_NAME, ps4ErrorCode.getName().toUpperCase(), ps4ErrorCode);
63+
}
64+
put(BY_CODE, ps4ErrorCode.getCode().toUpperCase(), ps4ErrorCode);
65+
66+
if (ps4ErrorCode.getReturnCode() != null && !ps4ErrorCode.getReturnCode().trim().isEmpty()) {
67+
String returnCodeUppercase = ps4ErrorCode.getReturnCode().toUpperCase();
68+
put(BY_RETURNCODE, returnCodeUppercase, ps4ErrorCode);
69+
70+
int signed = Long.decode(returnCodeUppercase).intValue();
71+
long unsigned = Integer.toUnsignedLong(signed);
72+
put(BY_SIGNED, signed, ps4ErrorCode);
73+
put(BY_UNSIGNED, unsigned, ps4ErrorCode);
74+
}
75+
});
76+
}
77+
78+
private <K> void put(Map<K, PS4ErrorCode> map, K key, PS4ErrorCode ps4ErrorCode) {
79+
PS4ErrorCode existingErrorCode = map.get(key);
80+
if (existingErrorCode == null || (existingErrorCode.getDescription() == null || existingErrorCode.getDescription().length() == 0)) {
81+
map.put(key, ps4ErrorCode);
82+
}
83+
}
84+
85+
@SneakyThrows
86+
private Stream<PS4ErrorCode> parseCsv(String csvResourceName) {
87+
return StreamSupport.stream(CSVFormat.DEFAULT.parse(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(csvResourceName))).spliterator(), false)
88+
.map(record -> {
89+
String name = record.get(0);
90+
String code = record.get(1);
91+
String returnCode = record.get(2).toUpperCase();
92+
93+
return new PS4ErrorCode(name, code, returnCode, record.size() == 4 ? record.get(3) : null);
94+
});
95+
}
96+
97+
private void printCsv(List<PS4ErrorCode> ps4ErrorCodes, String resourceName) throws IOException {
98+
CSVPrinter csvPrinter = new CSVPrinter(new FileWriter("src/main/resources/" + resourceName + ".csv"), CSVFormat.DEFAULT);
99+
for (PS4ErrorCode ps4ErrorCode : ps4ErrorCodes) {
100+
csvPrinter.printRecord(ps4ErrorCode.getName(), ps4ErrorCode.getCode(), ps4ErrorCode.getReturnCode(), ps4ErrorCode.getDescription());
101+
}
102+
csvPrinter.flush();
103+
csvPrinter.close();
104+
}
105+
106+
}

0 commit comments

Comments
 (0)