Skip to content

Commit

Permalink
v0.2 upload
Browse files Browse the repository at this point in the history
- buffered loading for faster speed
- added serial number option if present
- really unorganized code
  • Loading branch information
SleepyLark authored May 1, 2020
1 parent 196d183 commit cad58b4
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 111 deletions.
12 changes: 8 additions & 4 deletions src/dat/controller/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@ public void loadFile()
}

public void saveFile(boolean includeNum, boolean includeSize, boolean convertBytes, boolean includeRegion, boolean removeRegionTag, boolean includeCRC, boolean includeMD5,
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum)
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum, boolean includeSerial, boolean removeMissingSerial)
{
reader.export(includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5, includeSHA1, mergeHash, removeLanguage, removeNum);
reader.export(includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5, includeSHA1, mergeHash, removeLanguage, removeNum, includeSerial, removeMissingSerial);
}

public String getPreview(boolean includeNum, boolean includeSize, boolean convertBytes, boolean includeRegion, boolean removeRegionTag, boolean includeCRC, boolean includeMD5,
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum)
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum, boolean includeSerial, boolean removeMissingSerial)
{
return reader.makePreview(includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5, includeSHA1, mergeHash, removeLanguage, removeNum);
return reader.makePreview(includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5, includeSHA1, mergeHash, removeLanguage, removeNum, includeSerial, removeMissingSerial);
}

public boolean hasReleaseNumber()
{
return reader.hasReleaseNumber();
}
public boolean hasSerial()
{
return reader.hasSerial();
}

public void errorHandler(Exception problem)
{
Expand Down
5 changes: 3 additions & 2 deletions src/dat/controller/AppRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ public class AppRunner

public static void main(String args[])
{
javax.swing.SwingUtilities.invokeLater(new Runnable() {
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
AppController app = new AppController();
app.start();
}
});

}
}
32 changes: 19 additions & 13 deletions src/dat/model/DatFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,68 @@ public class DatFile
private String version;
private boolean hasSerial;
private boolean hasReleaseNumber;

private int entrySize;

public DatFile(AppController app)
{
game = new ArrayList<String>();
title = "UNKNOWN";
version = "0";
entrySize = -1;
hasSerial = false;
hasReleaseNumber = false;
}
//=====[GET/SET]=====

// =====[GET/SET]=====
public ArrayList<String> getGames()
{
return game;
}

public String getTitle()
{
return title;
}

public String getVersion()
{
return version;
}

public boolean hasSerial()
{
return hasSerial;
}

public boolean isNumbered()
{
return hasReleaseNumber;
}


public int getEntrySize()
{
return game.size();
}

public void setGames(ArrayList<String> games)
{
this.game = games;
hasReleaseNumber = game.get(0).contains("0001 - ");
hasSerial = game.get(0).contains("serial=");
}

public void setTitle(String title)
{
this.title = title;
}

public void setVersion(String version)
{
this.version = version;
}

public void setHasSerial(boolean state)
{
hasSerial = state;
}



}
119 changes: 80 additions & 39 deletions src/dat/model/DatViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,54 @@ public void loadFile()
{
largeFile = false;
loadedFile = io.loadString();
if (loadedFile != null)
if (loadedFile != null && !loadedFile.isEmpty())
{
if (!(findTag("!DOCTYPE", true) || findTag("datafile", true)))
app.errorHandler("This is not a .dat file");

currentDat.setTitle(getTag("name", false));
currentDat.setVersion(getTag("version", false));
currentDat.setGames(this.getTags("game", false, loadedFile));

if(currentDat.getGames().size() >= 1000)
currentDat.setHasSerial(loadedFile.contains("serial="));
if (getTag("url", false).contains("no-intro"))
{
String[] option = {"Yes", "No"};
int choice = JOptionPane.showOptionDialog(null,"There are "+ currentDat.getGames().size() + " entries listed.\n Preview is still possible, however it will be slower.\n Would you like to reduce the limit to 500?","Warning",JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
if(choice == 0)
currentDat.setGames(this.getTags("game", false, loadedFile));

if (currentDat.getGames().size() >= 2000)
{
largeFile = true;
String[] option = { "Yes", "No" };
int choice = JOptionPane.showOptionDialog(null,
"There are " + currentDat.getGames().size()
+ " entries listed.\n Preview is still possible, however it will be slower.\n Would you like to reduce the limit to 500?",
"Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
if (choice == 0)
{
largeFile = true;
}
}
}
else if (getTag("url", false).contains("redump"))
{
app.errorHandler("Redump.org is not supported yet.");
}
else
{
String[] option = { "Yes", "No" };
int choice = JOptionPane.showOptionDialog(null,"Couldn't recongize file as No-Intro/Redump,\n are you sure you want to continue?","Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
if (choice==0)
{
currentDat.setGames(this.getTags("game", false, loadedFile));

if (currentDat.getGames().size() >= 2000)
{
choice = JOptionPane.showOptionDialog(null,
"There are " + currentDat.getGames().size()
+ " entries listed.\n Preview is still possible, however it will be slower.\n Would you like to reduce the limit to 500?",
"Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
if (choice == 0)
{
largeFile = true;
}
}
}
}
}
Expand All @@ -58,6 +90,11 @@ public boolean hasReleaseNumber()
return currentDat.isNumbered();
}

public boolean hasSerial()
{
return currentDat.hasSerial();
}

public boolean findTag(String tag, boolean noEndTag)
{
return !(getTag(tag, noEndTag, true, loadedFile) == null);
Expand Down Expand Up @@ -174,15 +211,15 @@ private String findQuoteParameter(String block, String keyword)
}

public void export(boolean includeNum, boolean includeSize, boolean convertBytes, boolean includeRegion, boolean removeRegionTag, boolean includeCRC, boolean includeMD5,
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum)
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum, boolean includeSerial, boolean removeMissingSerial)
{
largeFile = false;
io.saveString(
makePreview(includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5, includeSHA1, mergeHash, removeLanguage, removeNum));
io.saveString(makePreview(includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5, includeSHA1, mergeHash, removeLanguage, removeNum,
includeSerial, removeMissingSerial));
}

private String convertGameToRow(String entry, boolean includeNum, boolean includeSize, boolean convertBytes, boolean includeRegion, boolean removeRegionTag, boolean includeCRC,
boolean includeMD5, boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum)
boolean includeMD5, boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum, boolean includeSerial, boolean removeMissingSerial)
{
String rowData = "";

Expand Down Expand Up @@ -219,6 +256,19 @@ private String convertGameToRow(String entry, boolean includeNum, boolean includ
if (includeRegion)
rowData += "\"" + region + "\",";

if (includeSerial)
{
String serialID = findQuoteParameter(this.getTag("rom", false, true, entry), "serial=").trim();
if (serialID.isEmpty())
serialID = "UNKNOWN";
if (removeMissingSerial && (serialID.toLowerCase().contains("missing") || serialID.toLowerCase().contains("none") || serialID.toLowerCase().contains("unknown")))
{
serialID = "";
}

rowData += serialID+",";
}

if (includeSize)
{
String size = findQuoteParameter(this.getTag("rom", false, true, entry), "size=");
Expand Down Expand Up @@ -261,34 +311,30 @@ else if (includeMD5)
}
else
{

if (includeCRC)
hash += "\""+crc + "\",";
hash += "\"" + crc + "\",";
if (includeMD5)
hash += "\""+md5 + "\",";
hash += "\"" + md5 + "\",";
if (includeSHA1)
hash += "\""+sha1 + "\",";
hash += "\"" + sha1 + "\",";
}

rowData += hash;

String serialID = findQuoteParameter(this.getTag("rom", false, true, entry), "serial=").trim();
if (serialID.isEmpty())
serialID = "UNKNOWN";
rowData += hash;

return rowData;
}

public String makePreview(boolean includeNum, boolean includeSize, boolean convertBytes, boolean includeRegion, boolean removeRegionTag, boolean includeCRC, boolean includeMD5,
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum)
boolean includeSHA1, boolean mergeHash, boolean removeLanguage, boolean removeNum, boolean includeSerial, boolean removeMissingSerial)
{
String preview = "";
int limit = currentDat.getGames().size();
if(largeFile)
if (largeFile)
limit = 500;
for (int index = 0; index < limit; index++)
preview += convertGameToRow(currentDat.getGames().get(index), includeNum, includeSize, convertBytes, includeRegion, removeRegionTag, includeCRC, includeMD5,
includeSHA1, mergeHash, removeLanguage, removeNum) + "\n";
includeSHA1, mergeHash, removeLanguage, removeNum, includeSerial, removeMissingSerial) + "\n";
return preview;
}

Expand Down Expand Up @@ -471,33 +517,28 @@ public String getSize(long filesize)
{
if (filesize >= 1048576)
{

size = toMegaBytes(filesize) + "MB";
if (filesize >= 1073741824)
{
size = io.toGigaBytes(filesize) + " GB";
}
else
{
size = io.toMegaBytes(filesize) + " MB";
}
}
else
{
size = toKiloBytes(filesize) + "KB";
size = io.toKiloBytes(filesize) + " KB";
}
}
else
{
size = filesize + "bytes";
size = filesize + " bytes";
}

return size;
}

public long toKiloBytes(long fileBytes)
{
return fileBytes / 1024;
}

public long toMegaBytes(long fileBytes)
{

return toKiloBytes(fileBytes) / 1024;
}

public void setLoadedFile(String text)
{
loadedFile = text;
Expand Down
28 changes: 18 additions & 10 deletions src/dat/model/LucarIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* I/O handler reused from other projects
*
* @author Skylark
*
*/
Expand Down Expand Up @@ -97,29 +98,36 @@ public String loadString()
}
loader.close();

while (reader.hasNextLine())
int lastNumber = 0;
int bufferedBlocks = 100;
for (int cycles = 0; cycles <= maxLineSize / bufferedBlocks; cycles++)
{
counter++;
data += reader.nextLine() + "\n";
int lastNumber = 0;
int current = (int) (Math.round(((double) counter) / (maxLineSize) * 100));
if (current != lastNumber)
String buffered = "";
int limit = 0;
while (reader.hasNextLine() && limit <= bufferedBlocks)
{
// app.print((current + "%"));
lastNumber = current;
counter++;
limit++;
buffered += reader.nextLine() + "\n";
int current = (int) ((((double) (counter)) / (maxLineSize)) * 100);
if (current != lastNumber)
{
app.print((current + "%"));
lastNumber = current;
}
}
data += buffered;
}

reader.close();
JOptionPane.showMessageDialog(null, "File loaded successfully");
// JOptionPane.showMessageDialog(null, "File loaded successfully");
app.print("Done!");
}
}
catch (Exception e)
{
app.errorHandler(e);
}

return data;
}

Expand Down
Loading

0 comments on commit cad58b4

Please sign in to comment.