indexing
	description: "Liste der Battle.net Spiele"
	author: "Daniel Jacobi"
	date: "$Date: 2003/10/09 14:16:25 $"
	revision: "$Revision: 1.6 $"

class
	CHECK_GAMES

inherit
	WEL_LIST_VIEW
		redefine
			make, 
			on_lvn_itemchanged,
			on_left_button_double_click
		end

	APPLICATION_IDS
		export
			{NONE} all
		end		

	WEL_ID_CONSTANTS
		export
			{NONE} all
		end

	WEL_COLOR_CONSTANTS
		export
			{NONE} all
		end 

create
	make
feature {NONE} -- Initialization

	make(a_parent: WEL_WINDOW; a_x, a_y, a_width, a_height, an_id: INTEGER) is
			-- Initialize `Current'.
		local
			spalte					: WEL_LIST_VIEW_COLUMN
			game_img				: WEL_IMAGE_LIST
			bild					: WEL_BITMAP
			farbe, background_color	: WEL_COLOR_REF
		do
 			{WEL_LIST_VIEW} Precursor (a_parent, a_x, a_y, a_width, a_height, an_id)

			-- Style
			set_style(Ws_visible + Ws_child + Ws_group + Ws_tabstop + Ws_border + Ws_clipchildren	
						+ Lvs_showselalways+ Lvs_singlesel + Lvs_report)
			set_extended_view_style (Lvs_ex_fullrowselect)

			-- Spalte
			create spalte.make_with_attributes(Lvcf_text, 50, Lvcfmt_center, "Game")
			append_column(spalte)

			-- Game_image_list
			create game_img.make (32, 32, 24, true)

			create farbe.make_rgb(192, 192, 192)
			create background_color.make_system(Color_window)
			game_img.set_background_color(background_color)

			create bild.make_by_id (Idb_starcraft)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_broodwar)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_diablo)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_diablo2)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_lod)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_w2bne)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_war3)
			game_img.add_color_masked_bitmap(bild, farbe)
			create bild.make_by_id (Idb_war3xp)
			game_img.add_color_masked_bitmap(bild, farbe)

			set_image_list(game_img)
			set_small_image_list(game_img)

			fenster ?= a_parent
			scan_for_games
		end

feature {NONE} -- Messages

	on_lvn_itemchanged (info: WEL_NM_LIST_VIEW) is
			-- An item has changed.
		local
			sitem: WEL_LIST_VIEW_ITEM
		do
			if flag_set (info.unewstate, Lvis_selected) and not flag_set (info.uoldstate, Lvis_selected) then
				sitem := get_item (info.iitem, info.isubitem)
				
				if equal(sitem.text, "Starcraft") or equal(sitem.text, "Broodwar") then
					game_id := Idb_starcraft
				elseif equal(sitem.text, "Diablo") then
					game_id := Idb_diablo
				elseif equal(sitem.text, "Diablo 2") or equal(sitem.text, "Lord of Destruction") then
					game_id := Idb_diablo2
				elseif equal(sitem.text, "Warcraft 2") then
					game_id := Idb_w2bne
				elseif equal(sitem.text, "Warcraft 3") or equal(sitem.text, "Frozen Throne") then
					game_id := Idb_war3
				end

				if fenster.closeable then
					fenster.get_bnet_server(game_id)
				end
			end
		end

	on_left_button_double_click (keys, x_pos, y_pos: INTEGER) is
			-- Handle right Mousbutton Events
		local
			msgbox: WEL_MSG_BOX
			reg_key 	: WEL_REGISTRY
			reg_value	: WEL_REGISTRY_KEY_VALUE
			e_env: EXECUTION_ENVIRONMENT
		do
			create msgbox.make
			create e_env
			create reg_key
			
			-- Entsprechendes Spiel starten
			inspect 
				game_id
			when Idb_starcraft then
				reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Starcraft", "Program")
			when Idb_diablo then
				reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Diablo", "Program")
			when Idb_diablo2 then
				reg_value := reg_key.open_key_value ("HKEY_CURRENT_USER\SOFTWARE\Blizzard Entertainment\Diablo II", "Program")
			when Idb_w2bne then
				reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Warcraft II BNE", "Program")
			when Idb_war3 then
				reg_value := reg_key.open_key_value ("HKEY_CURRENT_USER\SOFTWARE\Blizzard Entertainment\Warcraft III", "Program")				
			else
				msgbox.error_message_box (fenster, "No Game selected. Nothing started!", "Exec state")		
			end
			
			if reg_value /= Void and fenster.closeable then
				e_env.launch(reg_value.string_value)
			end
		end

feature {NONE} -- Implementation

	game_id: INTEGER

	fenster: MAIN_WINDOW

	scan_for_games is
		local
			litem		: WEL_LIST_VIEW_ITEM
			i			: INTEGER
			reg_key 	: WEL_REGISTRY
			reg_value	: WEL_REGISTRY_KEY_VALUE
			f			: RAW_FILE
			do_it		: BOOLEAN
		do
			from
				i := 0
				do_it := False
				create reg_key
			invariant 
				8 - i >= 0
			until
				i > 7
			loop
				-- Prüfen
				inspect
					i
				when 0 then
					reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Starcraft", "InstallPath")
				when 1 then
					reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Starcraft", "InstallPath")
				when 2 then
					reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Diablo", "Intro")
				when 3 then
					reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Diablo II", "InstallPath")
				when 4 then
					reg_value := reg_key.open_key_value ("HKEY_CURRENT_USER\SOFTWARE\Blizzard Entertainment\Diablo II", "InstallPath")
				when 5 then
					reg_value := reg_key.open_key_value ("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\Warcraft II BNE", "InstallPath")
				when 6 then
					reg_value := reg_key.open_key_value ("HKEY_CURRENT_USER\SOFTWARE\Blizzard Entertainment\Warcraft III", "InstallPath")
				when 7 then
					reg_value := reg_key.open_key_value ("HKEY_CURRENT_USER\SOFTWARE\Blizzard Entertainment\Warcraft III", "InstallPath")
				end
				
				if reg_value /= Void  then		
				
					-- Check Starcraft/Broodwar
					if i = 0 or i = 1  then
						create f.make(reg_value.string_value + "\BrooDat.mpq")	
						do_it := (i = 0 and not f.exists) or (i = 1 and f.exists)
					end

					-- Check War2bne / Diablo
					if i = 2 or i = 5  then
						do_it := true
					end

					-- Check Diablo 2
					if i = 3 or i = 4  then
						create f.make(reg_value.string_value + "\d2exp.mpq")	
						do_it := (i = 3 and not f.exists) or (i = 4 and f.exists)
					end
					
					-- Check Warcraft 3
					if i = 6 or i = 7  then
						create f.make(reg_value.string_value + "\war3x.mpq")	
						do_it := (i = 6 and not f.exists) or (i = 7 and f.exists)
					end
				
					if do_it then
						-- Bildeintragen
						create litem.make
						inspect
							i
						when 0 then
							litem.set_text ("Starcraft")
						when 1 then
							litem.set_text ("Broodwar")
						when 2 then
							litem.set_text ("Diablo")
						when 3 then
							litem.set_text ("Diablo 2")
						when 4 then
							litem.set_text ("Lord of Destruction")
						when 5 then
							litem.set_text ("Warcraft 2")
						when 6 then
							litem.set_text ("Warcraft 3")
						when 7 then
							litem.set_text ("Frozen Throne")
						end
						litem.set_image(i)
						litem.set_iitem (count)
						insert_item(litem)
						
						do_it := False
					end
				end
				i := i + 1
			end
			
			-- Kein Programm gefunden !
			if count <= 0 then
				create litem.make
				litem.set_text ("No Game Found!")
				litem.set_iitem (0)
				insert_item(litem)
			else
				Current.set_item_state(0, Lvis_selected)
			end
		end
		
end -- class CHECK_GAMES
