Update to water shot with addict code
This commit is contained in:
parent
a05493c56c
commit
0c906b701f
8 changed files with 142 additions and 43 deletions
|
|
@ -1,26 +0,0 @@
|
|||
package love.distributedrebirth.warpme.hash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class WaterDrugs {
|
||||
|
||||
private List<WaterFileHash> fileHashes = new ArrayList<>();
|
||||
|
||||
public List<WaterFileHash> getFileHashes() {
|
||||
return fileHashes;
|
||||
}
|
||||
|
||||
public void setFileHashes(List<WaterFileHash> fileHashes) {
|
||||
for (WaterFileHash hash:fileHashes) {
|
||||
addFileHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
public void addFileHash(WaterFileHash fileHash) {
|
||||
this.fileHashes.add(fileHash);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package love.distributedrebirth.warpme.hash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class WaterShot {
|
||||
|
||||
private List<WaterShotHash> shotHashes = new ArrayList<>();
|
||||
|
||||
public List<WaterShotHash> getShotHashes() {
|
||||
return shotHashes;
|
||||
}
|
||||
|
||||
public void setShotHashes(List<WaterShotHash> shotHashes) {
|
||||
for (WaterShotHash hash:shotHashes) {
|
||||
addShotHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
public void addShotHash(WaterShotHash shotHash) {
|
||||
this.shotHashes.add(shotHash);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package love.distributedrebirth.warpme.hash;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.x4o.xml.io.X4OConnectionException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
import love.distributedrebirth.warpme.Warpᵐᵉ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class WaterShotAddict {
|
||||
|
||||
public boolean validateWarpChainLink(File folder) throws FileNotFoundException, X4OConnectionException, SAXException, IOException, NoSuchAlgorithmException {
|
||||
File fileWarpHash = new File(folder, Warpᵐᵉ.WARP_HASH);
|
||||
if (!fileWarpHash.exists()) {
|
||||
return false;
|
||||
}
|
||||
WaterShot waterShot = WaterShotDriver.newInstance().createReader().readFile(fileWarpHash);
|
||||
for (WaterShotHash hash:waterShot.getShotHashes()) {
|
||||
File checkFile = new File(folder, hash.getFile());
|
||||
if (!checkFile.exists()) {
|
||||
return false;
|
||||
}
|
||||
String fileHex = calcHashInHex(checkFile);
|
||||
if (!fileHex.equals(hash.getHex())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateWarpHashes(File folder) throws FileNotFoundException, X4OConnectionException, SAXException, IOException, NoSuchAlgorithmException {
|
||||
File fileWarpHash = new File(folder, Warpᵐᵉ.WARP_HASH);
|
||||
WaterShot waterShot = WaterShotDriver.newInstance().createReader().readFile(fileWarpHash);
|
||||
for (WaterShotHash hash:waterShot.getShotHashes()) {
|
||||
hash.setHex(calcHashInHex(new File(folder, hash.getFile())));
|
||||
}
|
||||
WaterShotDriver.newInstance().createWriter().writeFile(waterShot, fileWarpHash);
|
||||
}
|
||||
|
||||
private String calcHashInHex(File file) throws IOException, NoSuchAlgorithmException {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] bytes = Files.readAllBytes(file.toPath());
|
||||
byte[] encodedhash = digest.digest(bytes);
|
||||
return bytesToHex(encodedhash);
|
||||
}
|
||||
|
||||
private String bytesToHex(byte[] hash) {
|
||||
StringBuilder hexString = new StringBuilder(2 * hash.length);
|
||||
for (int i = 0; i < hash.length; i++) {
|
||||
String hex = Integer.toHexString(0xff & hash[i]);
|
||||
if(hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import org.x4o.xml.X4ODriverManager;
|
|||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class WaterDrugsDriver extends X4ODriver<WaterDrugs> {
|
||||
public class WaterShotDriver extends X4ODriver<WaterShot> {
|
||||
|
||||
static final public String LANGUAGE_NAME = "warp-hash";
|
||||
static final public String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
|
||||
|
|
@ -21,7 +21,7 @@ public class WaterDrugsDriver extends X4ODriver<WaterDrugs> {
|
|||
return LANGUAGE_VERSIONS;
|
||||
}
|
||||
|
||||
static public WaterDrugsDriver newInstance() {
|
||||
return (WaterDrugsDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
||||
static public WaterShotDriver newInstance() {
|
||||
return (WaterShotDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,10 +3,18 @@ package love.distributedrebirth.warpme.hash;
|
|||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class WaterFileHash {
|
||||
public class WaterShotHash {
|
||||
|
||||
private String file;
|
||||
private String hash;
|
||||
private String hex;
|
||||
|
||||
public WaterShotHash() {
|
||||
}
|
||||
|
||||
public WaterShotHash(String file, String hex) {
|
||||
setFile(file);
|
||||
setHex(hex);
|
||||
}
|
||||
|
||||
public String getFile() {
|
||||
return file;
|
||||
|
|
@ -16,11 +24,11 @@ public class WaterFileHash {
|
|||
this.file = file;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return hash;
|
||||
public String getHex() {
|
||||
return hex;
|
||||
}
|
||||
|
||||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
public void setHex(String hex) {
|
||||
this.hex = hex;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue