Permalink
Browse files

Added getSuffix method

This method will prevent errors being thrown if the file has no suffix
when running the method scanAndDeleteOldFiles.  This is especially
apparent on Linux.
  • Loading branch information...
1 parent 85974ea commit 0fe08aabd8b1c322fb2a34e36b9aafb12eee064d @Sammidysam committed Apr 20, 2013
Showing with 5 additions and 2 deletions.
  1. +5 −2 src/gamepatcher/Downloader.java
@@ -47,8 +47,8 @@ public void constructor(String fileName, String dateName, String fileSite, Strin
datePath = System.getProperty("user.dir") + File.separatorChar + dateName;
this.fileSite = fileSite;
this.dateSite = dateSite;
- scanAndDeleteOldFiles("tempDate", datePath.substring(datePath.lastIndexOf('.'), datePath.length()));
- scanAndDeleteOldFiles("tempFile", filePath.substring(filePath.lastIndexOf('.'), filePath.length()));
+ scanAndDeleteOldFiles("tempDate", getSuffix(datePath));
+ scanAndDeleteOldFiles("tempFile", getSuffix(filePath));
}
public boolean isUpdateNecessary(){
if(new File(filePath).exists() && new File(datePath).exists()){
@@ -129,6 +129,9 @@ private Calendar fileToCalendar(String path){
calendar.set(values[0], values[1] - 1, values[2], values[3], values[4], values[5]);
return calendar;
}
+ private String getSuffix(String fileName){
+ return fileName.contains(".") ? fileName.substring(fileName.lastIndexOf('.'), fileName.length()) : "";
+ }
private void scanAndDeleteOldFiles(String name, String suffix){
// if the download is aborted, a temporary file will be left behind. this method deletes all temporary files left behind in the past
DirectoryStream<Path> ds = null;

0 comments on commit 0fe08aa

Please sign in to comment.