import se.datadosen.util.*;

// Add functionality common to the plug-in mechanism
engine.processBeanShellFile(new File(skinDirectory, "plugins.bsh"));

// Figure out if we can integrate with on-line printing service
engine.processBeanShellFile(new File(programDirectory, "includes/printing.bsh"));
showPrintingWarnings();

// If we are using plug-ins - copy their res and style files to $resPath/Pluginname
// We also processes any init.bsh files included in the plug-ins
if (Plugins != null && Plugins != void) {
	String[] arrPlugins = Plugins.split("#");
	for (int i = 0; i < arrPlugins.length; i++) {
		// Create folder resDirectory/Pluginname
		File plgRes = new File(resDirectory, arrPlugins[i]);
		if (!plgRes.exists()) {
			plgRes.mkdirs();
		}
		// Copy plugin res folder to resDirectory/Pluginname
		File plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/res");
		if (plg.exists()) {
			IO.copyDirectoryContent(plg, plgRes, true);
		}
		// Copy selected style to resDirectory/Pluginname/styles.css
		plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/styles/" + engine.getStyle());
		if (plg.exists())
			IO.copyFile(plg, new File(plgRes, "styles.css"), true);
		// If an corresponding style folder exists - copy it's contents to resDirectory/Pluginname
		plg = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/styles/" + engine.getStyle().substring(0, engine.getStyle().length() - 4));
		if (plg.exists())
			IO.copyDirectoryContent(plg, plgRes, true);
	}
	
	// Iterate over all plug-ins to evaluate any init.bsh found in their folders
	for (int i = 0; i < arrPlugins.length; i++) {
		File plgInit = new File(skinDirectory, "plugins/" + arrPlugins[i] + "/init.bsh");
		if (plgInit.exists())
			engine.processBeanShellFile(plgInit);
	}
}

// Remove any tree.dat file found in the output directory
try {
	File fTree = new File(engine.getOutputDirectory() + "/tree.dat");
	if (fTree.exists())
		fTree.delete();
} catch (Exception ex) {
}
