Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
Replaced List by Set in file deleter to fix an issue

Replaced int by long in mcp/mod/extfile
  • Loading branch information
FlowArg committed Oct 11, 2020
1 parent 2c64908 commit b1d167c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ExternalFile
private final String path;
private final String downloadURL;
private final String sha1;
private final int size;
private final long size;
private final boolean update;

/**
Expand All @@ -24,7 +24,7 @@ public class ExternalFile
* @param size Size of external file.
* @param downloadURL external file URL.
*/
public ExternalFile(String path, String downloadURL, String sha1, int size)
public ExternalFile(String path, String downloadURL, String sha1, long size)
{
this.path = path;
this.downloadURL = downloadURL;
Expand All @@ -41,7 +41,7 @@ public ExternalFile(String path, String downloadURL, String sha1, int size)
* @param downloadURL external file URL.
* @param update false -> not checking if the file is valid. true -> checking if the file is valid.
*/
public ExternalFile(String path, String downloadURL, String sha1, int size, boolean update)
public ExternalFile(String path, String downloadURL, String sha1, long size, boolean update)
{
this.path = path;
this.downloadURL = downloadURL;
Expand Down Expand Up @@ -82,7 +82,7 @@ public static List<ExternalFile> getExternalFilesFromJson(URL jsonUrl)
final String path = obj.get("path").getAsString();
final String sha1 = obj.get("sha1").getAsString();
final String downloadURL = obj.get("downloadURL").getAsString();
final int size = obj.get("size").getAsInt();
final long size = obj.get("size").getAsLong();
if(obj.get("update") != null)
result.add(new ExternalFile(path, downloadURL, sha1, size, obj.get("update").getAsBoolean()));
else result.add(new ExternalFile(path, downloadURL, sha1, size));
Expand Down Expand Up @@ -114,7 +114,7 @@ public String getSha1()
{
return this.sha1;
}
public int getSize()
public long getSize()
{
return this.size;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/fr/flowarg/flowupdater/download/json/MCP.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class MCP
{
private final String clientURL;
private final String clientSha1;
private final int clientSize;
private final int serverSize;
private final long clientSize;
private final long serverSize;
private final String serverURL;
private final String serverSha1;

Expand All @@ -24,7 +24,7 @@ public class MCP
* @param clientSize Size (bytes) of client.jar
* @param serverSize Size (bytes) of server.jar
*/
public MCP(String clientURL, String clientSha1, String serverURL, String serverSha1, int clientSize, int serverSize)
public MCP(String clientURL, String clientSha1, String serverURL, String serverSha1, long clientSize, long serverSize)
{
this.clientURL = clientURL;
this.clientSha1 = clientSha1;
Expand Down Expand Up @@ -56,8 +56,8 @@ public static MCP getMCPFromJson(URL jsonUrl)
object.get("clientSha1").getAsString(),
object.get("serverURL").getAsString(),
object.get("serverSha1").getAsString(),
object.get("clientSize").getAsInt(),
object.get("serverSize").getAsInt());
object.get("clientSize").getAsLong(),
object.get("serverSize").getAsLong());
}

public static MCP getMCPFromJson(String jsonUrl)
Expand Down Expand Up @@ -88,11 +88,11 @@ public String getServerSha1()
{
return this.serverSha1;
}
public int getClientSize()
public long getClientSize()
{
return this.clientSize;
}
public int getServerSize()
public long getServerSize()
{
return this.serverSize;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fr/flowarg/flowupdater/download/json/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Mod
{
private final String name;
private final String sha1;
private final int size;
private final long size;
private final String downloadURL;

/**
Expand All @@ -23,7 +23,7 @@ public class Mod
* @param size Size of mod file.
* @param downloadURL Mod download URL.
*/
public Mod(String name, String sha1, int size, String downloadURL)
public Mod(String name, String sha1, long size, String downloadURL)
{
this.name = name;
this.sha1 = sha1;
Expand Down Expand Up @@ -63,7 +63,7 @@ public static List<Mod> getModsFromJson(URL jsonUrl)
final String name = obj.get("name").getAsString();
final String sha1 = obj.get("sha1").getAsString();
final String downloadURL = obj.get("downloadURL").getAsString();
final int size = obj.get("size").getAsInt();
final long size = obj.get("size").getAsLong();

result.add(new Mod(name, sha1, size, downloadURL));
});
Expand Down Expand Up @@ -91,7 +91,7 @@ public String getSha1()
{
return this.sha1;
}
public int getSize()
public long getSize()
{
return this.size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static fr.flowarg.flowio.FileUtils.*;

Expand Down Expand Up @@ -148,7 +150,7 @@ public void installMods(File modsDir, boolean cursePluginLoaded) throws Exceptio

if(this.useFileDeleter)
{
final List<File> badFiles = new ArrayList<>();
final Set<File> badFiles = new HashSet<>();
final List<File> verifiedFiles = new ArrayList<>();
for(File fileInDir : modsDir.listFiles())
{
Expand All @@ -157,6 +159,7 @@ public void installMods(File modsDir, boolean cursePluginLoaded) throws Exceptio
if(this.mods.isEmpty() && this.allCurseMods.isEmpty())
{
badFiles.add(fileInDir);
break;
}
else
{
Expand All @@ -165,10 +168,9 @@ public void installMods(File modsDir, boolean cursePluginLoaded) throws Exceptio
for(Object obj : this.getAllCurseMods())
{
final CurseMod mod = (CurseMod)obj;
final File file = new File(modsDir, mod.getName().endsWith(".jar") ? mod.getName() : mod.getName() + ".jar");
if(file.getName().equalsIgnoreCase(fileInDir.getName()))
if(mod.getName().equalsIgnoreCase(fileInDir.getName()))
{
if(getMD5ofFile(fileInDir).equals(mod.getMd5()) && getFileSizeBytes(fileInDir) == mod.getLength())
if(getMD5ofFile(fileInDir).equalsIgnoreCase(mod.getMd5()) && getFileSizeBytes(fileInDir) == mod.getLength())
{
badFiles.remove(fileInDir);
verifiedFiles.add(fileInDir);
Expand All @@ -185,10 +187,9 @@ public void installMods(File modsDir, boolean cursePluginLoaded) throws Exceptio

for(Mod mod : this.mods)
{
final File file = new File(modsDir, mod.getName().endsWith(".jar") ? mod.getName() : mod.getName() + ".jar");
if(file.getName().equalsIgnoreCase(fileInDir.getName()))
if(mod.getName().equalsIgnoreCase(fileInDir.getName()))
{
if(getSHA1(fileInDir).equals(mod.getSha1()) && getFileSizeBytes(fileInDir) == mod.getSize())
if(getSHA1(fileInDir).equalsIgnoreCase(mod.getSha1()) && getFileSizeBytes(fileInDir) == mod.getSize())
{
badFiles.remove(fileInDir);
verifiedFiles.add(fileInDir);
Expand All @@ -204,7 +205,7 @@ public void installMods(File modsDir, boolean cursePluginLoaded) throws Exceptio
}
}
}

badFiles.forEach(File::delete);
badFiles.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public JsonObject getMinecraftClient()
final JsonObject result = new JsonObject();
final String sha1 = this.mcp.getClientSha1();
final String url = this.mcp.getClientURL();
final int size =this.mcp.getClientSize();
final long size = this.mcp.getClientSize();
if(Utils.checkString(sha1) && Utils.checkString(url) && size > 0)
{
result.addProperty("sha1", this.mcp.getClientSha1());
Expand All @@ -92,7 +92,7 @@ public JsonObject getMinecraftServer()
final JsonObject result = new JsonObject();
final String sha1 = this.mcp.getServerSha1();
final String url = this.mcp.getServerURL();
final int size = this.mcp.getServerSize();
final long size = this.mcp.getServerSize();
if(Utils.checkString(url) && Utils.checkString(sha1) && size > 0)
{
result.addProperty("sha1", this.mcp.getServerSha1());
Expand Down

0 comments on commit b1d167c

Please sign in to comment.