-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will future-proof it better.
- Loading branch information
Showing
2 changed files
with
38 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
steam-config-reader/src/main/java/com/selesse/steam/appcache/AppCacheFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.selesse.steam.appcache; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum AppCacheFormat { | ||
TWENTY_SEVEN("27"), | ||
TWENTY_EIGHT("28"), | ||
TWENTY_NINE("29"), | ||
; | ||
|
||
private final String number; | ||
|
||
AppCacheFormat(String number) { | ||
this.number = number; | ||
} | ||
|
||
public static AppCacheFormat fromFirstFourBytes(String bytes) { | ||
if (!bytes.endsWith("44 56 7")) { | ||
throw new IllegalStateException("First four bytes didn't end in '44 56 7'"); | ||
} | ||
String magicNumber = bytes.split(" ")[0]; | ||
return fromString(magicNumber); | ||
} | ||
|
||
private static AppCacheFormat fromString(String value) { | ||
return Arrays.stream(values()) | ||
.filter(x -> x.number.equals(value)) | ||
.findFirst() | ||
.orElseThrow(); | ||
} | ||
|
||
public boolean isAtLeast(AppCacheFormat appCacheFormat) { | ||
return this.ordinal() >= appCacheFormat.ordinal(); | ||
} | ||
} |