#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_icon=
#AutoIt3Wrapper_outfile=ControlHideFiles.exe
#AutoIt3Wrapper_Res_Description=Aktiviert oder deaktiviert die Ordneroption "Versteckte Dateien anzeigen".
#AutoIt3Wrapper_Res_Fileversion=1.0.0.27
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (C) 2008 by Patric Pendelin
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_Field=Firma|.pcp 2008
#AutoIt3Wrapper_Res_Field=Author|Patric Pendelin
#AutoIt3Wrapper_Res_Field=Author eMail|patricpendelin@gmx.de
#AutoIt3Wrapper_Res_Field=Orginaldateiname|ControlHideFiles.exe
#AutoIt3Wrapper_Res_Field=Produktname|Control Hide Files
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/gd /rel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;
#cs ----------------------------------------------------------------------------
	
	AutoIt Version:	3.2.11.1 (Beta)
	
	Name:		Control Hide Files
	Version:	1.0.0.17 (Alpha)
	Datum:		31.01.2008
	
	Author: Patric Pendelin	eMail: <patricpendelin@gmx.de>
	
	
	Info:
	
	Script Function:	Aktiviert oder deaktiviert die Ordneroption "Versteckte Dateien anzeigen".
	
	
	Fixes:
	
	
	To Do:
	- Refresh für Explorer-Fenster
		-Notlösung RunDll32.exe shell32.dll,Options_RunDLL 0
	
#ce ----------------------------------------------------------------------------
;
#include <Array.au3>
#include <Process.au3>
#include <Misc.au3>
#Include <WinAPI.au3>
;
AutoItSetOption("WinTitleMatchMode", 4)
Opt("MustDeclareVars", 1)
;
;
;===============================================================================
;	Start Program
;===============================================================================
_main()
;
;
;===============================================================================
;	Functions
;===============================================================================
Func _main()
	_changeFileVisible()
	If @error Then Exit
	_listWin()
EndFunc   ;==>_main
;
;===============================================================================
; Function Name:    _listWin
; Description:		Listet alle offenen Fenster auf und selektiert die "WindowS-Explorer" Fenster in ein Array.
;					Der erste Wert im Array ist auch gleichzeitig das "Aktive".
; Parameter(s):
;
;
; Syntax:           _listWin()
; Return Value(s):  On Success - 	Gibt ein Array zurück mit allen existierenden "Windows-Explorer" Fenstern
;									deren Handle und Status
;									$av_ExplorerWinList["Fenstertitel"]["Handle"]["Status"]
;					On Failure -
;
; Author(s):        Patric Pendelin <patricpendelin@gmx.de>
;===============================================================================
Func _listWin()
	Local $ah_WinList = WinList()
	Local $av_ExplorerWinList[$ah_WinList[0][0]][3]
	Local $s_winState
	Local $s_winStatus
	Local $f_Class
	;
	For $i = 0 To $ah_WinList[0][0] Step 1
		If $ah_WinList[$i][0] <> "" And _isVisible($ah_WinList[$i][1]) Then
			$f_Class = _isClass($ah_WinList[$i][0], "ExploreWClass")
			If $f_Class Then
				$av_ExplorerWinList[0][0] += 1
				$av_ExplorerWinList[$i][0] = $ah_WinList[$i][0]
				$av_ExplorerWinList[$i][1] = $ah_WinList[$i][1]
				$s_winState = WinGetState($ah_WinList[$i][1], "")
				;
				If $s_winState = 7 Then
					$s_winStatus = "@SW_RESTORE"
				ElseIf $s_winState = 23 Then
					$s_winStatus = "@SW_MINIMIZE"
				ElseIf $s_winState = 39 Or $s_winState = 35 Then
					$s_winStatus = "@SW_MAXIMIZE"
				Else
					$s_winStatus = ""
				EndIf
				$av_ExplorerWinList[$i][2] = $s_winStatus
			EndIf
		EndIf
	Next
	$ah_WinList = ""; leert das Array
	_Array2DEmptyDel($av_ExplorerWinList, 0); löscht alle lehren Spalten
	;
;~ 	_ArrayDisplay($av_ExplorerWinList, "_listWin")
	;
	Return $av_ExplorerWinList
EndFunc   ;==>_listWin
;
;===============================================================================
; Function Name:    _changeFileVisible
; Description:
;
; Parameter(s):		Prüft, sdie Registry, wie der aktuelle Zustand der Versteckten Dateien ist
;					und ändert den Wert dementsprechend
;
;
; Syntax:           _changeFileVisible()
; Return Value(s):  On Success -	Return 1
;					On Failure - 	Return 0
;
; Author(s):        Patric Pendelin <patricpendelin@gmx.de>
;===============================================================================
Func _changeFileVisible()
	Local $i_State
	;
	$i_State = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden")
	If $i_State = 1 Then
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", "2")
		If Not @error Then Return 1
	ElseIf $i_State = 2 Then
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", "1")
		If Not @error Then Return 1
	EndIf
	If @error Then Return 0
EndFunc   ;==>_changeFileVisible
;
;===============================================================================
; Function Name:    _isClass
; Description:
;
; Parameter(s):		Prüft, ob es sich um die jeweilige Klasse handelt.
;
;
; Syntax:           _isClass($s_WindowTitel, $s_Class)
; Return Value(s):  On Success - 	Return 1
;					On Failure - 	Return 0
;
; Author(s):        Patric Pendelin <patricpendelin@gmx.de>
;===============================================================================
Func _isClass($s_WindowTitel, $s_Class)
	Local $s_ClassName
	Local $h_Handle
	;
	$s_ClassName = "classname=" & $s_Class
	$h_Handle = WinGetHandle($s_ClassName, $s_WindowTitel)
	If @error Then
		SetError(1)
		Return 0
	Else
		Return 1
	EndIf
EndFunc   ;==>_isClass
;
;===============================================================================
; Function Name:    _isVisible
; Description:
;
; Parameter(s):
;
;
; Syntax:           _isVisible($h_Handle)
; Return Value(s):  On Success - 	Return 1
;					On Failure - 	Return 0
;
; Author(s):        AutoIt3 Help
;===============================================================================
Func _isVisible($h_Handle)
	If BitAND(WinGetState($h_Handle), 2) Then
		Return 1
	Else
		Return 0
	EndIf
EndFunc   ;==>_isVisible
;
;
;----------------------------------------------------------------------------------------------------------------------
; UDFs
;----------------------------------------------------------------------------------------------------------------------
;
;----------------------------------------------------------------------------------------------------------------------
;	Function		_Array2DEmptyDel(ByRef $avArray [, $Col=0])
;
;	Description		Delete empty Array elements
;					Delete all emty Rows or all empty Columns
;					Works also with 1D-Array (only Rows)
;
;	Parameter		$avArray	Given Array
;		optional	$Col		set 1 to delete empty Columns; default is 0 to delete empty Rows
;
;	Return			Succes		-1	ByRef the given Array without empty Elements, resized
;					Failure		0 	and set @error = 1
;
;	Author			BugFix  (bugfix@autoit.de)
;----------------------------------------------------------------------------------------------------------------------
Func _Array2DEmptyDel(ByRef $avArray, $Col = 0)
	If (Not IsArray($avArray)) Then
		SetError(1)
		Return 0
	EndIf
	Local $UBound2nd = UBound($avArray, 2)
	If @error = 2 Then
		Local $arTMP[1]
		For $i = 0 To UBound($avArray) - 1
			If StringLen($avArray[$i] > 0) Then
				If StringLen($arTMP[UBound($arTMP) - 1]) = 0 Then
					$arTMP[UBound($arTMP) - 1] = $avArray[$i]
				Else
					ReDim $arTMP[UBound($arTMP) + 1]
					$arTMP[UBound($arTMP) - 1] = $avArray[$i]
				EndIf
			EndIf
		Next
	Else
		If $Col = 0 Then
			Local $arTMP[1][$UBound2nd], $val, $len
			For $i = 0 To UBound($avArray) - 1
				$val = ''
				For $k = 0 To $UBound2nd - 1
					$val &= $avArray[$i][$k]
				Next
				If StringLen($val) > 0 Then
					$len = 0
					For $k = 0 To UBound($arTMP, 2) - 1
						$len &= StringLen($arTMP[UBound($arTMP) - 1][$k])
					Next
					If $len = 0 Then
						For $k = 0 To $UBound2nd - 1
							$arTMP[UBound($arTMP) - 1][$k] = $avArray[$i][$k]
						Next
					Else
						ReDim $arTMP[UBound($arTMP) + 1][$UBound2nd]
						For $k = 0 To $UBound2nd - 1
							$arTMP[UBound($arTMP) - 1][$k] = $avArray[$i][$k]
						Next
					EndIf
				EndIf
			Next
		Else
			Local $arTMP[UBound($avArray)][1], $val, $len
			For $k = 0 To $UBound2nd - 1
				$val = ''
				Local $notEmpty = 0
				For $i = 0 To UBound($avArray) - 1
					$val &= $avArray[$i][$k]
					If StringLen($val) > 0 Then
						$notEmpty = 1
						ExitLoop
					EndIf
				Next
				If $notEmpty = 1 Then
					$len = 0
					For $i = 0 To UBound($arTMP) - 1
						$len &= StringLen($arTMP[$i][UBound($arTMP, 2) - 1])
					Next
					If $len = 0 Then
						For $i = 0 To UBound($avArray) - 1
							$arTMP[$i][0] = $avArray[$i][$k]
						Next
					Else
						ReDim $arTMP[UBound($avArray)][UBound($arTMP, 2) + 1]
						For $i = 0 To UBound($avArray) - 1
							$arTMP[$i][UBound($arTMP, 2) - 1] = $avArray[$i][$k]
						Next
					EndIf
				EndIf
			Next
		EndIf
	EndIf
	$avArray = $arTMP
	Return -1
EndFunc   ;==>_Array2DEmptyDel