@ -40,13 +40,20 @@ public class FileHandler {
this . TargetImageFile = new File ( sourceFolder . getAbsolutePath ( ) + fs + "Target" ) ;
this . TargetImageFile = new File ( sourceFolder . getAbsolutePath ( ) + fs + "Target" ) ;
this . OutputFolder = new File ( sourceFolder . getAbsolutePath ( ) + fs + "Output" ) ;
this . OutputFolder = new File ( sourceFolder . getAbsolutePath ( ) + fs + "Output" ) ;
this . indexFile = new File ( this . InputImagesFolder . getAbsolutePath ( ) + "Index.txt" ) ;
this . indexFile = new File ( this . InputImagesFolder . getAbsolutePath ( ) + "Index.txt" ) ;
Log . initLog ( this . sourceFolder . getAbsolutePath ( ) ) ;
if ( ! this . sourceFolder . exists ( ) ) {
this . sourceFolder . mkdirs ( ) ;
}
Log . initLog ( this . sourceFolder . getAbsolutePath ( ) , this ) ;
if ( fs = = "\\" ) {
if ( fs = = "\\" ) {
Log . log ( LogLevel . Debug , "Assumed Windows like Folder declaration. Therefore using " + fs + " as a separator." ) ;
Log . log ( LogLevel . Debug , "Assumed Windows like Folder declaration. Therefore using " + fs + " as a separator." ) ;
} else {
} else {
Log . log ( LogLevel . Debug , "Detected Linux or OSX." ) ;
Log . log ( LogLevel . Debug , "Detected Linux or OSX." ) ;
}
}
this . validateFolderStructure ( ) ;
if ( ! this . validateFolderStructure ( ) ) {
Log . log ( LogLevel . Error , "Could not validate folder structure! Things are missing!" ) ;
Log . spawnReadMe ( this ) ;
System . exit ( 1 ) ;
}
}
}
public boolean validateFolderStructure ( ) {
public boolean validateFolderStructure ( ) {
@ -56,6 +63,11 @@ public class FileHandler {
Log . log ( LogLevel . Debug , "Detected Input folder at " + this . InputImagesFolder . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Debug , "Detected Input folder at " + this . InputImagesFolder . getAbsolutePath ( ) ) ;
if ( this . OutputFolder . isDirectory ( ) ) {
if ( this . OutputFolder . isDirectory ( ) ) {
Log . log ( LogLevel . Debug , "Detected Output folder at " + this . OutputFolder . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Debug , "Detected Output folder at " + this . OutputFolder . getAbsolutePath ( ) ) ;
} else {
Log . log ( LogLevel . Info , "No Output folder found." ) ;
Log . log ( LogLevel . Info , "Creating one at " + this . OutputFolder . getAbsolutePath ( ) ) ;
this . OutputFolder . mkdirs ( ) ;
}
if ( this . TargetImageFile . isFile ( ) ) {
if ( this . TargetImageFile . isFile ( ) ) {
Log . log ( LogLevel . Debug , "Detected Target Image at " + this . TargetImageFile . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Debug , "Detected Target Image at " + this . TargetImageFile . getAbsolutePath ( ) ) ;
if ( ! this . indexFile . isDirectory ( ) ) {
if ( ! this . indexFile . isDirectory ( ) ) {
@ -64,16 +76,11 @@ public class FileHandler {
}
}
else {
else {
Log . log ( LogLevel . Error , "Following folder collides with the index file name: " + this . indexFile . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Error , "Following folder collides with the index file name: " + this . indexFile . getAbsolutePath ( ) ) ;
System . exit ( 1 ) ;
return false ;
}
}
} else {
} else {
Log . log ( LogLevel . Critical , "No Target Image found! Exiting..." ) ;
Log . log ( LogLevel . Critical , "No Target Image found! Exiting..." ) ;
System . exit ( 1 ) ;
return false ;
}
} else {
Log . log ( LogLevel . Info , "No Output folder found." ) ;
Log . log ( LogLevel . Info , "Creating one at " + this . OutputFolder . getAbsolutePath ( ) ) ;
this . OutputFolder . mkdirs ( ) ;
}
}
} else {
} else {
Log . log ( LogLevel . Critical , "No Input folder found." ) ;
Log . log ( LogLevel . Critical , "No Input folder found." ) ;
@ -81,7 +88,7 @@ public class FileHandler {
this . InputImagesFolder . mkdirs ( ) ;
this . InputImagesFolder . mkdirs ( ) ;
}
}
} else {
} else {
Log . log ( LogLevel . Critical , "No source folder found .") ;
Log . log ( LogLevel . Critical , "No source folder found (redundant check) .") ;
Log . log ( LogLevel . Critical , "Creating one at " + this . sourceFolder . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Critical , "Creating one at " + this . sourceFolder . getAbsolutePath ( ) ) ;
this . sourceFolder . mkdirs ( ) ;
this . sourceFolder . mkdirs ( ) ;
}
}
@ -123,6 +130,7 @@ public class FileHandler {
public void saveImage ( BufferedImage img , File file ) {
public void saveImage ( BufferedImage img , File file ) {
Log . log ( LogLevel . Info , "Saving image as file " + file . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Info , "Saving image as file " + file . getAbsolutePath ( ) ) ;
Log . log ( LogLevel . Info , "This could take a moment ..." ) ;
try {
try {
ImageIO . write ( img , "png" , file ) ;
ImageIO . write ( img , "png" , file ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {