#Include <GuiTreeView.au3>
#Include "gh3_songs.au3"

Func _Trucha_Init( $trucha, $gui, $isofile )
	Run($trucha)
	WinWaitActive($gui)
	Send("!S")
	Send("c")
	Send("{ENTER}")
	Send("!i")
	Send("{ENTER}")
	WinWaitActive("[ACTIVE]")
	send($isofile)
	Send("{ENTER}")
	WinWaitActive("Operation completed")
	Send("{ENTER}")
EndFunc

Func _Extract_File( $filename, $path, $hWnd)
      Local $hItem = _GUICtrlTreeView_FindItem( $hWnd, $filename )
      if ($hItem<>0) Then
	 _GUICtrlTreeView_SelectItem( $hWnd, $hItem )
	 _GUICtrlTreeView_ClickItem($hWnd, $hItem, "right", True)
	 Send("e")
	 WinWaitActive("[ACTIVE]")
	 ControlSetText("[ACTIVE]","","Edit1",$path);
	 Send("{ENTER}")
	 WinWaitActive($gui)
      EndIf
EndFunc

Func _Replace_File( $filename, $path, $hWnd)
	 If FileExists($path&$filename) Then
	    Local $hItem = _GUICtrlTreeView_FindItem( $hWnd, $filename )
	    if ($hItem) Then
	       _GUICtrlTreeView_SelectItem( $hWnd, $hItem )
	       _GUICtrlTreeView_ClickItem($hWnd, $hItem, "right", True)
	       Send("r")
	       WinWaitActive("[ACTIVE]")
	       ControlSetText("[ACTIVE]","","Edit1",$path&$filename);
	       Send("{ENTER}")
	       WinWaitActive("[CLASS:#32770]")
	       Send("{ENTER}")
	       WinWaitActive($gui)
	    EndIf
	 EndIf
EndFunc

Func _Sign_Partition( $partition, $hWnd)
      Local $hItem = _GUICtrlTreeView_FindItem( $hWnd, $partition )
      if ($hItem) Then
	 _GUICtrlTreeView_SelectItem( $hWnd, $hItem )
	 _GUICtrlTreeView_ClickItem($hWnd, $hItem, "right", True)
	 Send("t")
	 WinWaitActive("[CLASS:#32770]")
	 Send("{ENTER}")
	 WinWaitActive($gui)
      Else
	 MsgBox(0,"","Error: Cannot find the partition to sign")
      EndIf
EndFunc

Func _Replace3( $file, $path, $hWnd)
   _Replace_File($file&".dat.ngc",$path,$hWnd)
   _Replace_File($file&".pak.ngc",$path,$hWnd)
   _Replace_File($file&".wad.ngc",$path,$hWnd)
EndFunc

Func _Replace_All( $path, $hWnd)
   For $filename In $songs
	_replace3($filename,$path, $hWnd)
   Next
EndFunc


Func _Extract3( $file, $path, $hWnd)
   _extract_File($file&".dat.ngc",$path,$hWnd)
   _extract_File($file&".pak.ngc",$path,$hWnd)
   _extract_File($file&".wad.ngc",$path,$hWnd)
EndFunc

Func _extract_All( $path, $hWnd)
   For $filename In $songs
	_extract3($filename,$path, $hWnd)
   Next
EndFunc