// -------------------------------------------
// 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.*;

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"), props);

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);
	}	
}

/* Check the version */
import javax.swing.*;
String currentVersion = generator.substring(generator.indexOf(' ')+1); if (currentVersion.compareTo("4.4") < 0) {
	JOptionPane.showMessageDialog(window,
	"This skin actually requires JAlbum 4.4. Please upgrade the latest version at www.datadosen.se/jalbum.", 
	"Version warning", 
	JOptionPane.WARNING_MESSAGE);
}

/* 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);
}
