// -------------------------------------------
// Copy the contents of the folder named after the style, in the style folder 
// in the root image directory to the "res" folder in the root output directory. 

import se.datadosen.util.*;
setAccessibility(true);

Utils utils = new Utils(engine);
engine.setUsing(utils);

if (guestBook == void) guestBook = false;

if (resPath == void) resPath = "res";
resPathOrig = resPath;
if (resSubPath != void) resPath = resPath + "/" + resSubPath;

File resDirectory = new File(rootOutputDirectory, resPath);
if (!resDirectory.exists()) resDirectory.mkdir();

//  Delete existing files in /res if previous version of ExhibitPlus (prior to 1.3) was used
void deleteAll(File dir) {
   File[] content = dir.listFiles();
    for (File f : content) {
        if (f.isDirectory()) deleteAll(f);
        f.delete();
    }
}
File sourceFile = new File(resDirectory, "glowback-base.gif");
if (sourceFile.exists()) {
	deleteAll(resDirectory);
}

Properties props = new Properties();
props.put("album", album);
String styleFile = engine.getStyle();
style = styleFile.substring(0, style.lastIndexOf('.'));
engine.processTemplateFile(new File(skinDirectory + "/styles/", styleFile), new File(rootOutputDirectory + File.separator + resPath + File.separator, "styles.css"));

if (iconSet == void) iconSet = "default";

buttonSet = (iconSet.equalsIgnoreCase("default") ? album.get("BUTTON_SET") : iconSet);

File sourceFile = new File(skinDirectory + "/styles/", styleFile);
if (sourceFile.exists()) {
     	File outputFile = new File(resDirectory, styleFile);
     	IO.copyFile(sourceFile, outputFile, true);
}

File imageDirResDirectory = new File(skinDirectory, "/button-sets/" + buttonSet );
if (imageDirResDirectory.exists()) {
     	File outputDirResDirectory = new File(rootOutputDirectory + File.separator + resPath + File.separator + buttonSet );
     	IO.copyDirectoryContent(imageDirResDirectory, outputDirResDirectory, true);
}

if (resSubPath != void) {
	File imageDirResDirectory = new File(skinDirectory, "/" + resPathOrig );
	if (imageDirResDirectory.exists()) {
     		File outputDirResDirectory = new File(rootOutputDirectory + File.separator + resPath );
     		IO.copyDirectoryContent(imageDirResDirectory, outputDirResDirectory, true);
	}	
}

if (guestBook) {
	File skinGuestBookDirectory = new File(skinDirectory, "/guestbook" );
	File guestBookDirectory = new File(rootOutputDirectory, "/guestbook" );
     	IO.copyDirectoryContent(skinGuestBookDirectory, guestBookDirectory, true);
}

/* In case the user has unchecked the directory first box, we must set it again */
engine.setDirectoriesFirst(true); //requires JAlbum 4.0

if (watermark != void && watermark.length() > 0) {
	WatermarkFilter f = new WatermarkFilter();
	f.setText(watermark);
	f.setSize(watermarkSize);
	f.setAlign("right");
	f.setValign("bottom");
	f.setStrengthPercent(40);
	f.setStyle("plain");
// Uncomment the following line and enter your own font for the watermark
	f.setFace("Bank Gothic Medium BT");
	engine.addFilter(f, 3);
}

// engine.processBeanShellFile(new File(programDirectory, "tools/Reset file date to camera date.bsh"));
// engine.processBeanShellFile(new File(programDirectory, "tools/Reset folder date to last file date.bsh")); 