indexing
	cluster:	"demangler"
	namespace: "candidate"
	description: "This is the root class of the demangle cluster."
	original_author: "Justin Finnerty"
	original_date: "July 2005"
	current_date: "$Date: 2005/10/31 07:17:08 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.4 $"
   -- $Log: demangle.ge,v $
   -- Revision 2.4  2005/10/31 07:17:08  finnerty
   -- Added check that target directory actually exists.
   --
   -- Revision 2.3  2005/10/30 03:40:59  finnerty
   -- Split REPORT_VIEW into REPORT_CONTROL and REPORT_VIEW. Made changes to other classes as necessary
   --
   -- Revision 2.2  2005/09/27 06:31:00  finnerty
   -- Updated to use GOBO and work with SE and VE
   --
   -- Revision 2.1  2005/09/02 07:23:24  finnerty
   -- Renamed demangle.e to demangle.ge for gepp
   --
   -- Revision 2.0  2005/08/26 23:18:23  finnerty
   -- == alpha version ==
   --
   -- Revision 1.4  2005/08/24 12:45:54  finnerty
   -- Removed SYNC_REPORT config options. Added test that deletes the
   -- trash directory if it was not actually used.
   --
   -- Revision 1.3  2005/08/21 11:57:16  finnerty
   -- Alpha 1 version
   --
   -- Revision 1.2  2005/07/31 02:13:56  finnerty
   -- Changes for fs_parser now being generic made. Added new code to introduce the fs_investigator class.
   --
   -- Revision 1.1.1.1  2005/07/28 05:28:34  finnerty
   -- Imported eiffel sources
   --

class DEMANGLE
	-- This class manages the virtualisation and manipulation of
	-- directories.

#ifdef SE
insert
#else
inherit
#endif
   CONFIGURATION_STATUS
	KL_SHARED_STANDARD_FILES
	KL_SHARED_FILE_SYSTEM

creation {ANY}
	main

feature {ANY}
	-- Queries
	app_name: STRING is "desync"
			-- The name of this application

	has_directory: BOOLEAN is
			-- Are we currently working on a directory?
		do
			Result := sync_dir /= Void
		end

	sync_dir: SYNCHRONISED_DIRECTORY
			-- The current directory being worked on

	report_factory: REPORT_FACTORY
			-- Factory for reports
	
feature {ANY}
	-- Procedures
	add_configuration is
			-- Add config options to config manager
		local
			l_conf_option: CONFIGURATION_OPTION
		do
			-- Create a FSO_PROPERTIES object and report attributes 
			config_manager.set_application_name (app_name)
			config_manager.set_help ("Prune synchronised directories")
			config_manager.set_help_short ("Prune synchronised directories" )
			config_manager.add_std_help
			config_manager.add_std_conf
			
			!!l_conf_option.make("peer"
										, "Treat directory as a peer or working directory"
										, "Directory is a peer")
			l_conf_option.set_tab_label ("Directory")
			config_manager.force (l_conf_option, l_conf_option.name)
			!!l_conf_option.make("store"
										, "Treat directory as a store or back-up directory"
										, "Directory is a store")
			l_conf_option.set_tab_label ("Directory")
			config_manager.force (l_conf_option, l_conf_option.name)
		end

	add_reports is
			-- Add reports to `sync_dir' based on the configuration
		require
			has_directory
		do
		end

	create_directory is
			-- Set `sync_dir' based on the configuration
		do
			if config_manager.item ("peer").is_set then
				if file_system.directory_exists (config_manager.item ("peer").value) then
					std.output.put_string ("Found directory [" + config_manager.item ("peer").value + "].%N")
					!LOCAL_DIRECTORY!sync_dir.make (config_manager.item ("peer").value, True)
				else
					std.output.put_string ("Unable to find directory [" + config_manager.item ("peer").value + "].%N")
				end
			elseif config_manager.item ("store").is_set then
				if file_system.directory_exists (config_manager.item ("store").value) then
					std.output.put_string ("Found directory [" + config_manager.item ("store").value + "].%N")
					!LOCAL_DIRECTORY!sync_dir.make (config_manager.item ("store").value, False)
				else
					std.output.put_string ("Unable to find directory [" + config_manager.item ("store").value + "].%N")
				end
			else
				std.output.put_string ("Programming logic error, no directory given on command line.%N")
				-- No sync dir!
			end
		end

	action is
			-- Do action
		do
			add_configuration
			config_manager.process
			if config_manager.status = Continue then
				std.output.put_string ("Reading directory.")
				std.output.put_new_line
				create_directory
				if has_directory then
					std.output.put_string ("Read directory, doing reports")
					std.output.put_new_line
					report_factory.add_reports_to (sync_dir)
					sync_dir.do_reports
				else
					std.output.put_string ("Nothing to do? (use -h/-? or -help for help)")
					std.output.put_new_line
				end
			elseif config_manager.status = Bad_option then
				-- error
				std.output.put_string ("** Bad option given on command line. **")
				std.output.put_new_line
				config_manager.help_short (std.output)
			end
		end
	
feature {NONE}
	-- Private features and attributes
	main is
			-- Method to create stand-alone program with DEMANGLE as root 
			-- object

			-- Create a DEMANGLE object and use it to virtualise 
			-- directories specified on the command line or the "/etc" 
			-- directory. This implementation will change as the class 
			-- is developed.
		do
			!!report_factory.make
			action
		end
invariant
	-- Assertions about what is always true

end -- class DEMANGLE
