Update to water shot with addict code
This commit is contained in:
parent
a05493c56c
commit
0c906b701f
|
@ -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ʸᴰ;
|
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||||
|
|
||||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
@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_NAME = "warp-hash";
|
||||||
static final public String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
|
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;
|
return LANGUAGE_VERSIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public WaterDrugsDriver newInstance() {
|
static public WaterShotDriver newInstance() {
|
||||||
return (WaterDrugsDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
return (WaterShotDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,10 +3,18 @@ package love.distributedrebirth.warpme.hash;
|
||||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||||
|
|
||||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||||
public class WaterFileHash {
|
public class WaterShotHash {
|
||||||
|
|
||||||
private String file;
|
private String file;
|
||||||
private String hash;
|
private String hex;
|
||||||
|
|
||||||
|
public WaterShotHash() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public WaterShotHash(String file, String hex) {
|
||||||
|
setFile(file);
|
||||||
|
setHex(hex);
|
||||||
|
}
|
||||||
|
|
||||||
public String getFile() {
|
public String getFile() {
|
||||||
return file;
|
return file;
|
||||||
|
@ -16,11 +24,11 @@ public class WaterFileHash {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHash() {
|
public String getHex() {
|
||||||
return hash;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHash(String hash) {
|
public void setHex(String hex) {
|
||||||
this.hash = hash;
|
this.hex = hex;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,10 +7,10 @@
|
||||||
providerHost="warp-hash.x4o.distributedrebirth.love" providerName="WarpHashᵐᵉ"
|
providerHost="warp-hash.x4o.distributedrebirth.love" providerName="WarpHashᵐᵉ"
|
||||||
id="warp-hash-module">
|
id="warp-hash-module">
|
||||||
|
|
||||||
<eld:classBindingHandler id="WaterDrugs-WaterFileHash"
|
<eld:classBindingHandler id="WaterShot-WaterShotHash"
|
||||||
parentClass="love.distributedrebirth.warpme.hash.WaterDrugs"
|
parentClass="love.distributedrebirth.warpme.hash.WaterShot"
|
||||||
childClass="love.distributedrebirth.warpme.hash.WaterFileHash"
|
childClass="love.distributedrebirth.warpme.hash.WaterShotHash"
|
||||||
addMethod="addFileHash" getMethod="getFileHashes" />
|
addMethod="addShotHash" getMethod="getShotHashes" />
|
||||||
|
|
||||||
<eld:namespace
|
<eld:namespace
|
||||||
uri="http://wrap-core.x4o.distributedrebirth.love/xml/ns/warp-hash-root"
|
uri="http://wrap-core.x4o.distributedrebirth.love/xml/ns/warp-hash-root"
|
||||||
|
@ -18,8 +18,8 @@
|
||||||
schemaResource="warp-hash-root-1.0.xsd" schemaPrefix="root"
|
schemaResource="warp-hash-root-1.0.xsd" schemaPrefix="root"
|
||||||
description="Root namespace to have nice namespaceing."
|
description="Root namespace to have nice namespaceing."
|
||||||
name="WarpHash Root Namespace" languageRoot="true" id="root">
|
name="WarpHash Root Namespace" languageRoot="true" id="root">
|
||||||
<eld:element tag="drugs"
|
<eld:element tag="shot"
|
||||||
objectClass="love.distributedrebirth.warpme.hash.WaterDrugs"/>
|
objectClass="love.distributedrebirth.warpme.hash.WaterShot"/>
|
||||||
</eld:namespace>
|
</eld:namespace>
|
||||||
|
|
||||||
<eld:namespace
|
<eld:namespace
|
||||||
|
@ -29,6 +29,6 @@
|
||||||
description="Language namespace to store warp hash"
|
description="Language namespace to store warp hash"
|
||||||
name="WarpHash Language Namespace" id="soft">
|
name="WarpHash Language Namespace" id="soft">
|
||||||
<eld:element tag="hash"
|
<eld:element tag="hash"
|
||||||
objectClass="love.distributedrebirth.warpme.hash.WaterFileHash" />
|
objectClass="love.distributedrebirth.warpme.hash.WaterShotHash" />
|
||||||
</eld:namespace>
|
</eld:namespace>
|
||||||
</root:module>
|
</root:module>
|
|
@ -5,6 +5,6 @@
|
||||||
xsi:schemaLocation="http://language.x4o.org/xml/ns/drivers http://language.x4o.org/xml/ns/drivers-1.0.xsd"
|
xsi:schemaLocation="http://language.x4o.org/xml/ns/drivers http://language.x4o.org/xml/ns/drivers-1.0.xsd"
|
||||||
>
|
>
|
||||||
<driver language="warp-core" className="love.distributedrebirth.warpme.core.WaterBucketDriver"/>
|
<driver language="warp-core" className="love.distributedrebirth.warpme.core.WaterBucketDriver"/>
|
||||||
<driver language="warp-hash" className="love.distributedrebirth.warpme.hash.WaterDrugsDriver"/>
|
<driver language="warp-hash" className="love.distributedrebirth.warpme.hash.WaterShotDriver"/>
|
||||||
<driver language="warp-sea" className="love.distributedrebirth.warpme.sea.WaterOceanDriver"/>
|
<driver language="warp-sea" className="love.distributedrebirth.warpme.sea.WaterOceanDriver"/>
|
||||||
</drivers>
|
</drivers>
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package love.distributedrebirth.warpme.hash;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.x4o.xml.io.X4OConnectionException;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||||
|
|
||||||
|
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||||
|
public class WaterShotDriverTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWaterShot() throws X4OConnectionException, SAXException, IOException {
|
||||||
|
|
||||||
|
WaterShot drugs = new WaterShot();
|
||||||
|
drugs.addShotHash(new WaterShotHash("test.txt", "234SDFSDF234234SDFSDF234"));
|
||||||
|
drugs.addShotHash(new WaterShotHash("test2.txt", "ASDFYYF234234SDFSDFASDFS"));
|
||||||
|
|
||||||
|
Assertions.assertNotNull(drugs);
|
||||||
|
//WaterShotDriver.newInstance().createWriter().writeFile(drugs, new File("build/output.xml"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue