Что нового

Подскажите как лучше удалить блоки из текстового файла ?

mitiya

Новичок
Сообщения
75
Репутация
0
Есть у меня вот такой файл:

https://www.dropbox.com/s/s4x9cof0nwjli3s/persistent.sfs

это сэйв из игры kerbal space program, файл текстовый (конфиг)

Там есть блоки начинающиеся со строки VESSEL , дальше идет { и где-то в конце блока идет } , внутри разумеется тоже есть блоки, внутри блока переменная = значение.
Есть блоки VESSEL в которых переменная type = Debris , их бы надо как-то найти и удалить вместе с подблоками.

Приведу тут один из эти блоков.

VESSEL
{
pid = 42239b90262a4a19a67e6ca4ce939761
name = MitStationLenderModule Debris
type = Debris
sit = ORBITING
landed = False
landedAt =
splashed = False
met = 1306.77388690412
lct = 49991127.7669508
root = 0
lat = -0.31863196967221
lon = 240.018042422462
alt = 233109.565727973
hgt = -1
nrm = 0.6116739,0.6992198,0.3700632
rot = 0.5128423,-0.3204779,0.2699478,-0.7492763
CoM = 4.224205E-05,-1.912823,-5.027419E-05
stg = 3
prst = False
ref = 0
cPch = 0
cHdg = 0
cMod = -1
ORBIT
{
SMA = 832481.726602322
ECC = 0.00424076231980354
INC = 14.961613386552
LPE = 281.754936655557
LAN = 316.067528645999
MNA = 1.37192000078099
EPH = 49991155.2269553
REF = 1
}
PART
{
name = decoupler1-2
uid = 764791971
mid = 2084853708
parent = 0
position = 0,0,0
rotation = 0,0,0,1
mirror = 1,1,1
istg = 2
dstg = 1
sqor = 2
sidx = 1
attm = 0
srfN = None, -1
attN = bottom, 1
attN = None, -1
mass = 0.4
temp = -40.19011
expt = 0.5
state = 0
connected = False
attached = False
flag = Squad/Flags/circles
rTrf = decoupler1-2 (MitStationLenderModule Debris)
EVENTS
{
}
ACTIONS
{
}
MODULE
{
name = ModuleDecouple
isEnabled = True
isDecoupled = True
EVENTS
{
Decouple
{
active = False
guiActive = True
guiIcon = Decouple
guiName = Decouple
category = Decouple
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
DecoupleAction
{
actionGroup = None
}
}
}
MODULE
{
name = FARBasicDragModel
isEnabled = True
EVENTS
{
}
ACTIONS
{
}
}
MODULE
{
name = DecouplerJointReinforcementModule
isEnabled = True
EVENTS
{
}
ACTIONS
{
}
}
MODULE
{
name = ModuleAeroReentry
isEnabled = True
adjustCollider = 0
crashTolerance = 8
damage = 0
dead = False
EVENTS
{
RepairDamage
{
active = True
guiActive = False
guiIcon = No Damage
guiName = No Damage
category = No Damage
guiActiveUnfocused = True
unfocusedRange = 4
externalToEVAOnly = True
}
}
ACTIONS
{
}
}
}
PART
{
name = fuelTank1-2
uid = 1927699924
mid = 2084853708
parent = 0
position = 0,-2.24047088623047,0
rotation = 0,0,0,1
mirror = 1,1,1
istg = 2
dstg = 2
sqor = -1
sidx = -1
attm = 0
srfN = None, -1
attN = top, 0
attN = bottom, 2
mass = 2
temp = -40.19011
expt = 0.5
state = 0
connected = False
attached = True
flag = Squad/Flags/circles
rTrf = fuelTank1-2
EVENTS
{
}
ACTIONS
{
}
MODULE
{
name = FARBasicDragModel
isEnabled = True
EVENTS
{
}
ACTIONS
{
}
}
MODULE
{
name = ModuleAeroReentry
isEnabled = True
adjustCollider = 0
crashTolerance = 8
damage = 0
dead = False
EVENTS
{
RepairDamage
{
active = True
guiActive = False
guiIcon = No Damage
guiName = No Damage
category = No Damage
guiActiveUnfocused = True
unfocusedRange = 4
externalToEVAOnly = True
}
}
ACTIONS
{
}
}
RESOURCE
{
name = LiquidFuel
amount = 0
maxAmount = 1440
flowState = True
isTweakable = True
hideFlow = False
flowMode = Both
}
RESOURCE
{
name = Oxidizer
amount = 0
maxAmount = 1760
flowState = True
isTweakable = True
hideFlow = False
flowMode = Both
}
}
PART
{
name = engineLargeSkipper
uid = 391621165
mid = 2084853708
parent = 1
position = 0,-4.11547088623047,0
rotation = 0,0,0,1
mirror = 1,1,1
istg = 2
dstg = 2
sqor = 2
sidx = 2
attm = 0
srfN = None, -1
attN = top, 1
attN = None, -1
mass = 4
temp = -40.19011
expt = 0.5
state = 0
connected = False
attached = True
flag = Squad/Flags/circles
rTrf = engineLargeSkipper
EVENTS
{
}
ACTIONS
{
}
MODULE
{
name = ModuleJettison
isEnabled = True
EVENTS
{
Jettison
{
active = False
guiActive = True
guiIcon = Jettison
guiName = Jettison
category = Jettison
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
JettisonAction
{
actionGroup = None
}
}
}
MODULE
{
name = ModuleGimbal
isEnabled = True
gimbalLock = False
EVENTS
{
LockGimbal
{
active = True
guiActive = True
guiActiveEditor = True
guiIcon = Lock Gimbal
guiName = Lock Gimbal
category = Lock Gimbal
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
FreeGimbal
{
active = False
guiActive = True
guiActiveEditor = True
guiIcon = Free Gimbal
guiName = Free Gimbal
category = Free Gimbal
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
ToggleAction
{
actionGroup = None
}
}
}
MODULE
{
name = ModuleAnimateHeat
isEnabled = True
EVENTS
{
}
ACTIONS
{
}
}
MODULE
{
name = ModuleAlternator
isEnabled = True
EVENTS
{
}
ACTIONS
{
}
}
MODULE
{
name = ModuleEngines
isEnabled = True
staged = True
flameout = True
EngineIgnited = True
engineShutdown = False
currentThrottle = 1
thrustPercentage = 100
manuallyOverridden = False
thrustPercentage_UIFlight
{
controlEnabled = True
minValue = 0
maxValue = 100
stepIncrement = 0.5
}
EVENTS
{
Activate
{
active = False
guiActive = True
guiIcon = Activate Engine
guiName = Activate Engine
category = Activate Engine
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
Shutdown
{
active = True
guiActive = True
guiIcon = Shutdown Engine
guiName = Shutdown Engine
category = Shutdown Engine
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
OnAction
{
actionGroup = None
}
ShutdownAction
{
actionGroup = None
}
ActivateAction
{
actionGroup = None
}
}
}
MODULE
{
name = FARBasicDragModel
isEnabled = True
EVENTS
{
}
ACTIONS
{
}
}
MODULE
{
name = ModuleAeroReentry
isEnabled = True
adjustCollider = 0
crashTolerance = 8
damage = 0
dead = False
EVENTS
{
RepairDamage
{
active = True
guiActive = False
guiIcon = No Damage
guiName = No Damage
category = No Damage
guiActiveUnfocused = True
unfocusedRange = 4
externalToEVAOnly = True
}
}
ACTIONS
{
}
}
RESOURCE
{
name = ElectricCharge
amount = 0
maxAmount = 0.199999995529652
flowState = True
isTweakable = False
hideFlow = True
flowMode = Both
}
}
PART
{
name = winglet3
uid = 197959781
mid = 2084853708
parent = 1
position = -2.08616256713867E-07,-1.70699119567871,-1.68586015701294
rotation = 0,0.7071069,0,-0.707107
mirror = 1,1,1
istg = 2
dstg = 2
sqor = -1
sidx = -1
attm = 1
sym = 4
sym = 5
srfN = srfAttach, 1
mass = 0.02
temp = -40.19011
expt = 0.1
state = 0
connected = False
attached = True
flag = Squad/Flags/circles
rTrf = winglet3
EVENTS
{
}
ACTIONS
{
}
MODULE
{
name = FARControllableSurface
isEnabled = True
pitchaxis = True
yawaxis = True
rollaxis = True
isFlap = False
isSpoiler = False
flapDeflectionLevel = 2
ma:rofl:eflect = 15
ma:rofl:eflectFlap = 15
pitchaxis_UIEditor
{
controlEnabled = True
}
yawaxis_UIEditor
{
controlEnabled = True
}
rollaxis_UIEditor
{
controlEnabled = True
}
isFlap_UIEditor
{
controlEnabled = True
}
isSpoiler_UIEditor
{
controlEnabled = True
}
ma:rofl:eflect_UIEditor
{
controlEnabled = True
minValue = 0
maxValue = 30
stepIncrement = 0.5
}
ma:rofl:eflectFlap_UIEditor
{
controlEnabled = True
minValue = 0
maxValue = 75
stepIncrement = 0.5
}
EVENTS
{
DeflectMore
{
active = False
guiActive = True
guiIcon = Deflect more
guiName = Deflect more
category = Deflect more
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
DeflectLess
{
active = False
guiActive = True
guiIcon = Deflect less
guiName = Deflect less
category = Deflect less
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
ActivateSpoiler
{
actionGroup = Brakes
}
IncreaseDeflect
{
actionGroup = None
}
DecreaseDeflect
{
actionGroup = None
}
}
}
MODULE
{
name = ModuleAeroReentry
isEnabled = True
adjustCollider = 0
crashTolerance = 8
damage = 0
dead = False
EVENTS
{
RepairDamage
{
active = True
guiActive = False
guiIcon = No Damage
guiName = No Damage
category = No Damage
guiActiveUnfocused = True
unfocusedRange = 4
externalToEVAOnly = True
}
}
ACTIONS
{
}
}
}
PART
{
name = winglet3
uid = 3369597801
mid = 2084853708
parent = 1
position = -1.45999693870544,-1.70699119567871,0.842930793762207
rotation = 0,-0.2588193,0,-0.965926
mirror = 1,1,1
istg = 2
dstg = 2
sqor = -1
sidx = -1
attm = 1
sym = 3
sym = 5
srfN = srfAttach, 1
mass = 0.02
temp = -40.19011
expt = 0.1
state = 0
connected = False
attached = True
flag = Squad/Flags/circles
rTrf = winglet3
EVENTS
{
}
ACTIONS
{
}
MODULE
{
name = FARControllableSurface
isEnabled = True
pitchaxis = True
yawaxis = True
rollaxis = True
isFlap = False
isSpoiler = False
flapDeflectionLevel = 2
ma:rofl:eflect = 15
ma:rofl:eflectFlap = 15
pitchaxis_UIEditor
{
controlEnabled = True
}
yawaxis_UIEditor
{
controlEnabled = True
}
rollaxis_UIEditor
{
controlEnabled = True
}
isFlap_UIEditor
{
controlEnabled = True
}
isSpoiler_UIEditor
{
controlEnabled = True
}
ma:rofl:eflect_UIEditor
{
controlEnabled = True
minValue = 0
maxValue = 30
stepIncrement = 0.5
}
ma:rofl:eflectFlap_UIEditor
{
controlEnabled = True
minValue = 0
maxValue = 75
stepIncrement = 0.5
}
EVENTS
{
DeflectMore
{
active = False
guiActive = True
guiIcon = Deflect more
guiName = Deflect more
category = Deflect more
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
DeflectLess
{
active = False
guiActive = True
guiIcon = Deflect less
guiName = Deflect less
category = Deflect less
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
ActivateSpoiler
{
actionGroup = Brakes
}
IncreaseDeflect
{
actionGroup = None
}
DecreaseDeflect
{
actionGroup = None
}
}
}
MODULE
{
name = ModuleAeroReentry
isEnabled = True
adjustCollider = 0
crashTolerance = 8
damage = 0
dead = False
EVENTS
{
RepairDamage
{
active = True
guiActive = False
guiIcon = No Damage
guiName = No Damage
category = No Damage
guiActiveUnfocused = True
unfocusedRange = 4
externalToEVAOnly = True
}
}
ACTIONS
{
}
}
}
PART
{
name = winglet3
uid = 3005231599
mid = 2084853708
parent = 1
position = 1.45999777317047,-1.70699119567871,0.842929840087891
rotation = 0,-0.9659261,0,-0.258819
mirror = 1,1,1
istg = 2
dstg = 2
sqor = -1
sidx = -1
attm = 1
sym = 3
sym = 4
srfN = srfAttach, 1
mass = 0.02
temp = -40.19011
expt = 0.1
state = 0
connected = False
attached = True
flag = Squad/Flags/circles
rTrf = winglet3
EVENTS
{
}
ACTIONS
{
}
MODULE
{
name = FARControllableSurface
isEnabled = True
pitchaxis = True
yawaxis = True
rollaxis = True
isFlap = False
isSpoiler = False
flapDeflectionLevel = 2
ma:rofl:eflect = 15
ma:rofl:eflectFlap = 15
pitchaxis_UIEditor
{
controlEnabled = True
}
yawaxis_UIEditor
{
controlEnabled = True
}
rollaxis_UIEditor
{
controlEnabled = True
}
isFlap_UIEditor
{
controlEnabled = True
}
isSpoiler_UIEditor
{
controlEnabled = True
}
ma:rofl:eflect_UIEditor
{
controlEnabled = True
minValue = 0
maxValue = 30
stepIncrement = 0.5
}
ma:rofl:eflectFlap_UIEditor
{
controlEnabled = True
minValue = 0
maxValue = 75
stepIncrement = 0.5
}
EVENTS
{
DeflectMore
{
active = False
guiActive = True
guiIcon = Deflect more
guiName = Deflect more
category = Deflect more
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
DeflectLess
{
active = False
guiActive = True
guiIcon = Deflect less
guiName = Deflect less
category = Deflect less
guiActiveUnfocused = False
unfocusedRange = 2
externalToEVAOnly = True
}
}
ACTIONS
{
ActivateSpoiler
{
actionGroup = Brakes
}
IncreaseDeflect
{
actionGroup = None
}
DecreaseDeflect
{
actionGroup = None
}
}
}
MODULE
{
name = ModuleAeroReentry
isEnabled = True
adjustCollider = 0
crashTolerance = 8
damage = 0
dead = False
EVENTS
{
RepairDamage
{
active = True
guiActive = False
guiIcon = No Damage
guiName = No Damage
category = No Damage
guiActiveUnfocused = True
unfocusedRange = 4
externalToEVAOnly = True
}
}
ACTIONS
{
}
}
}
ACTIONGROUPS
{
Stage = True, 49989590.4322907
Gear = True, 0
Light = False, 0
RCS = False, 0
SAS = False, 49989690.3523071
Brakes = False, 0
Abort = False, 0
Custom01 = False, 0
Custom02 = False, 0
Custom03 = False, 0
Custom04 = False, 0
Custom05 = False, 0
Custom06 = False, 0
Custom07 = False, 0
Custom08 = False, 0
Custom09 = False, 0
Custom10 = False, 0
}
}


Честно говоря пока не знаю даже с какой стороны подойти к этой проблеме.
 

C2H5OH

AutoIT Гуру
Сообщения
1,473
Репутация
333
Сформулируйте, пожалуйста, по каким критериям определяется что это лучше чам другое.
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Код:
$file=FileRead(@ScriptDir&'\123')
$str=StringRegExpReplace($file,'(?sm)\t{2}VESSEL\r\n\t{2}\{\r\n[^\r\n]+\r\n[^\r\n]+\r\n\t+type = Debris.*?^\t{2}}','')
FileWrite(@DesktopDir&'\321',$str)
 
Автор
M

mitiya

Новичок
Сообщения
75
Репутация
0
Это гениально.
Регэкспы никак мне не даются((

Не могли бы вы поподробней его описать ?
 

firex

AutoIT Гуру
Сообщения
943
Репутация
208
mitiya
Если завтра не забуду - скину самописную мини-UDF для работы с sfs файлами (сохранена на другом компьютере), там вы сможете удалять/добавлять/изменять/перемещать ключи и секции.


Добавлено:
Сообщение автоматически объединено:

Как оказалось я ее так и не закончил, однако она писалась после изучения Sfs, вот полноценный пример:
70H38.png

Код:
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=ksp.ico
#AutoIt3Wrapper_Outfile=KSP_SfsEditor.exe
#AutoIt3Wrapper_UseUpx=N
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; #HEAD# ========================================================================================================================
; Title .........: KSP_SfsEditor
; Version .......: v.0.0.1
; Language ......: English/Russian
; Author(s) .....: Firex
; ===============================================================================================================================

#Region Initialization

#NoAutoIt3Execute

;GUI's Constains.
#Include <GUIMenu.au3>
#Include <GUIEdit.au3>
#include <GUIListView.au3>
#include <GUITreeView.au3>
#Include <GUIConstantsEx.au3>

;CTRL's Constains.
#Include <Constants.au3>
#include <EditConstants.au3>
#Include <StaticConstants.au3>
#include <ButtonConstants.au3>
#Include <HeaderConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>

;Other Functions
#Include <Array.au3>
#Include <WinAPIEx.au3>

Opt("TrayMenuMode",1)
Opt('WinWaitDelay', 5)
Opt('GUICloseOnEsc',0)

Const $_MAX = 44444 ; -- CONST'S -MAX OBJECTS

; --- ; GUIMain_Var's Rgion
Global $_GuiMain_Menu[13], $_GuiMain_Tree[2], $_GuiMain_TreeItm[$_MAX], $_GuiMain_List[2], $_GuiMain_ListItm[99]
Global $_GuiMain_Button[19], $_GuiMain_Label[3], $_GuiMain_Dummy, $_GuiMain_Input, $_hGui_Main = _GUIMain_Create()

Global $_hGui_Add = _GUIAdd_Create( @SW_HIDE )

Global $_hGui_Orbit = _GUIOrbit_Create( @SW_HIDE )

Global $_GuiRename_Input[3], $_GuiRename_Button[2]
Global $_hGui_Rename = _GUIRename_Create( @SW_HIDE )

Global $_GuiWait_Label[3]
Global $_hGui_Wait = _GUIWait_Create( @SW_HIDE )
; --- ; End

; --- ; MAIN_Var's Rgion
Global $_hMsg, $_aRet, $_vItem = -1, $_sOpened = ''
;
Global $_aActive, $_aItem[2] = [-1,-1] ;[0]Old selected; [1]New selected
Global $_aTmpInfo[3], $_aInfo[3] = [-1,-1,-1] ;[0]Index;

; ==
Global $_aActiveList[1] = [-1], $_aActiveTree[3] = [-1,-1,-1], $_iUpdate = False
; --- ; End

;----
Global $_aSfs_Main[$_MAX][3] = [[0]] ;[0]([0]Index); [1+X]([0]Parent; ;[1]Name; [2]Array of keys)
#EndRegion Initialization

#Region KSP.Body
While 1
	$_hMsg = GUIGetMsg(1)
	Switch $_hMsg[1]
		Case $_hGui_Main
			Switch $_hMsg[0]
				Case $GUI_EVENT_CLOSE
					If _KSP_Sfs_Close(1) Then _
						Exit 1488

				Case $_GuiMain_Dummy ;ListView {ENTER}
					If ControlGetFocus($_hGui_Main) = 'Edit1' Then
						$_aRet = _GUICtrlListView_SaveChanges()
						If Not @Error And IsArray($_aActive) Then
							$_aActive[$_aRet[0] + 1][$_aRet[1]] = $_aRet[2]
							$_aSfs_Main[$_aInfo[0]][2] = $_aActive
						EndIf
					EndIf

				Case $_GuiMain_Menu[12]
					_GUIAbout_Show()

				Case $_GuiMain_Menu[1] ;Открыть Sfs
					_KSP_Sfs_Load()
				Case $_GuiMain_Menu[2] ;Сохранить Sfs
					_KSP_Sfs_Save( $_sOpened )
				Case $_GuiMain_Menu[3] ;Сохранить Sfs
					_KSP_Sfs_SaveAs()
				Case $_GuiMain_Menu[4] ;Закрыть Sfs
					_KSP_Sfs_Close(1)

				Case $_GuiMain_Button[7]
					If $_aInfo[0] > 0 Then
						_GUIState( $_hGui_Orbit )
					EndIf

				Case $_GuiMain_Button[6], $_GuiMain_Button[9]
					If $_aInfo[0] > 0 Then
						MsgBox( 64, '', 'Not avaible in current version :C' )
					EndIf
				Case $_GuiMain_Button[10]
					If $_aInfo[0] > 0 Then
						ClipPut( _Sfs_ExportSection($_aInfo[0]) )
						MsgBox( 64, '', 'Exported section code is now in clipboard!' )
					EndIf

				Case $_GuiMain_Button[12] ;Add new section
					If $_aInfo[0] > 0 Then
						_GUIState( $_hGui_Add )
					EndIf
				Case $_GuiMain_Button[13] ;Rename section
					If $_aInfo[0] > 0 Then
						_GUIState( $_hGui_Rename )
						GUICtrlSetData( $_GuiRename_Input[0], $_aInfo[1] )
						GUICtrlSetData( $_GuiRename_Input[1], $_aInfo[2] )
						GUICtrlSetData( $_GuiRename_Input[2], $_aInfo[0] )
					EndIf
				Case $_GuiMain_Button[14] ;Delete section
					If $_aInfo[0] > 0 And MsgBox( 68, '', 'Oh my God, are you sure?' ) = 6 Then
						_Sfs_RemoveSection( $_aInfo[0] )
					EndIf

				Case $_GuiMain_Button[0] ;Add key
					_Sfs_ArrayAddKey( $_aActive, 'NewKey', 'NewValue' )
					If Not @Error Then
						$_aSfs_Main[$_aInfo[0]][2] = $_aActive ;SAVING
						GUICtrlCreateListViewItem( $_aActive[$_aActive[0][0]][0] & '|' & $_aActive[$_aActive[0][0]][1], $_GuiMain_List[0] )
					EndIf
				Case $_GuiMain_Button[1] ;Del key
					_Sfs_ArrayDelKey( $_aActive, $_aActiveList[0]+1 )
					If Not @Error Then
						$_aSfs_Main[$_aInfo[0]][2] = $_aActive ;SAVING
						_GUICtrlListView_DeleteItem( $_GuiMain_List[1], $_aActiveList[0] )
					EndIf

				Case $_GuiMain_Button[2] ;Del all keys
					_Sfs_ArrayDelKey( $_aActive, 1, 0 )
					If Not @Error And MsgBox( 68, '', 'Oh my God, are you sure?' ) = 6 Then
						$_aSfs_Main[$_aInfo[0]][2] = $_aActive ;SAVING
						GUICtrlSendMsg($_GuiMain_List[0], $LVM_DELETEALLITEMS, 0, 0)
					EndIf
			EndSwitch
		Case $_hGui_Add
			Switch $_hMsg[0]
				Case $GUI_EVENT_CLOSE
					_GUIState( $_hGui_Add, @SW_HIDE )
			EndSwitch
		Case $_hGui_Orbit
			Switch $_hMsg[0]
				Case $GUI_EVENT_CLOSE
					_GUIState( $_hGui_Orbit, @SW_HIDE )
			EndSwitch
		Case $_hGui_Rename
			Switch $_hMsg[0]
				Case $_GuiRename_Button[0]
					For $Idx = 0 To 2 Step 1
						$_aTmpInfo[$Idx] = GUICtrlRead( $_GuiRename_Input[$Idx] )
						$_aRet = StringRegExp( $_aTmpInfo[$Idx], '^([0-9\w]+)$' )
						If Not $_aRet Then
							MsgBox( 64, '', 'Эти параметры очень важны, а ты вводишь поебень. Не делай так.' )
							ContinueLoop 2
						EndIf
					Next
					$_aSfs_Main[$_aInfo[0]][0] = $_aTmpInfo[1]
					$_aSfs_Main[$_aInfo[0]][1] = $_aTmpInfo[0]
					ContinueCase

				Case $GUI_EVENT_CLOSE, $_GuiRename_Button[1], $_GuiRename_Button[0]
					_GUIState( $_hGui_Rename, @SW_HIDE )
			EndSwitch
	EndSwitch
	If $_iUpdate Then
		$_iUpdate = False

		$_aItem[0] = _GUICtrlTreeView_GetSelection( $_GuiMain_Tree[1] )
		If $_aItem[0] <> $_aItem[1] And $_aItem[0] <> -1 Then
			$_aItem[1] = $_aItem[0]

			$_vItem = StringRegExp( _GUICtrlTreeView_GetText( $_GuiMain_Tree[1], $_aItem[0] ), '\[([0-9]+)\]$', 3 )

			GUICtrlSendMsg($_GuiMain_List[0], $LVM_DELETEALLITEMS, 0, 0)
			If IsArray( $_vItem ) And $_vItem[0] Then
				$_aInfo[0] = $_vItem[0] ;Index
				$_aInfo[1] = $_aSfs_Main[$_vItem[0]][1] ;Name
				$_aInfo[2] = $_aSfs_Main[$_vItem[0]][0] ;Parent

				GUICtrlSetData( $_GuiMain_Label[0], $_aInfo[1] )
				GUICtrlSetData( $_GuiMain_Label[1], $_aInfo[2] )
				GUICtrlSetData( $_GuiMain_Label[2], $_vItem[0] & ' (with ?)' )

				$_aActive = $_aSfs_Main[$_vItem[0]][2] ; CURRENT SELECTED
				For $Idx = 1 To $_aActive[0][0] Step 1
					GUICtrlCreateListViewItem( $_aActive[$Idx][0] & '|' & $_aActive[$Idx][1], $_GuiMain_List[0] )
				Next
			EndIf
		EndIf
	EndIf
WEnd
#EndRegion KSP.Body


#Region KSP.LoadStuff
Func _KSP_Sfs_Load()
	If $_sOpened <> '' And MsgBox( 68, 'Save Warning!', 'Save changes in ' & $_sOpened & ' ?' ) = 6 Then
		_KSP_Sfs_Save( $_sOpened ) ;Saving the file
	EndIf
	_KSP_Sfs_Close() ;Close the file

	Local $_sSelect = FileOpenDialog("Select *.sfs", @ScriptDir, "Sfs (*.sfs)", 3, "", $_hGui_Main)
	If @Error Then _
		Return SetError(1, 0, 0) ;Файл не выбран

	Local $_hFile = FileOpen( $_sSelect )
	If @Error Then _
		Return SetError(2, 0, 0) ;Файл не открыт

	Local $_sRead = StringReplace( FileRead( $_hFile ), @TAB, '' )
	; ---
	_GUIState( $_hGui_Wait )
	GUICtrlSetData( $_GuiWait_Label[0], 'Please wait while loading...' )

	_GUICtrlTreeView_BeginUpdate($_GuiMain_Tree[1])
	_KSP_Sfs_Hierarchy_Load( $_sRead )
	_GUICtrlTreeView_EndUpdate($_GuiMain_Tree[1])

	GUICtrlSetState($_GuiMain_TreeItm[1], BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
	_GUIState( $_hGui_Wait, @SW_HIDE )

	GUICtrlSetState( $_GuiMain_Menu[2], $GUI_ENABLE )
	GUICtrlSetState( $_GuiMain_Menu[3], $GUI_ENABLE )
	GUICtrlSetState( $_GuiMain_Menu[4], $GUI_ENABLE )

	$_sOpened = $_sSelect
	ReDim $_aSfs_Main[$_aSfs_Main[0][0]+1][3]

	FileClose( $_hFile )
EndFunc

Func _KSP_Sfs_Save( $_sPath )
	If $_sPath = '' Then _
		Return SetError(1,0,0)

	; ---
	Local $_sCode = _Sfs_ExportSection( 1 )

	Local $_hFile = FileOpen( $_sPath, 2 )
	FileWrite( $_hFile, $_sCode )

	_GUIState( $_hGui_Wait, @SW_HIDE )

	FileClose( $_hFile )
EndFunc

Func _KSP_Sfs_SaveAs()
	Local $_sSelect = FileSaveDialog("Save *.sfs", @ScriptDir, "Sfs (*.sfs)", 18, "", $_hGui_Main)
	If Not @Error Then
		If StringRight( $_sSelect, 4 ) <> '.sfs' Then _
			$_sSelect &= '.sfs'

		_KSP_Sfs_Save( $_sSelect )
	EndIf
EndFunc

Func _KSP_Sfs_Hierarchy_Save( $_sCode, $_iIdx, $_sTabs = '' )
	Local $_aKeys = $_aSfs_Main[$_iIdx][2], $Idx

	$_sCode &= $_sTabs & $_aSfs_Main[$_iIdx][1] & @CRLF & $_sTabs & '{' & @CRLF

	$_sTabs &= @TAB
	For $Idx = 1 To $_aKeys[0][0] Step 1
		$_sCode &= $_sTabs & $_aKeys[$Idx][0] & ' = ' & $_aKeys[$Idx][1] & @CRLF
	Next

	; --Indication
	_WinAPI_SetWindowText( $_GuiWait_Label[2], 'Exported ' & $_iIdx & ' sections!' )

	Local $_aChilds = _ArrayFindAll( $_aSfs_Main, $_iIdx, 1 )
	If $_aChilds <> -1 Then
		For $Idx = 0 To UBound($_aChilds)-1 Step 1
			$_sCode = _KSP_Sfs_Hierarchy_Save( $_sCode, $_aChilds[$Idx], $_sTabs )

			$_aSfs_Main[$_aChilds[$Idx]][0] = ''
			$_aSfs_Main[$_aChilds[$Idx]][1] = ''
			$_aSfs_Main[$_aChilds[$Idx]][2] = ''
		Next
	EndIf
	$_sCode &= StringTrimLeft($_sTabs,1) & '}' & @CRLF

	Return $_sCode
EndFunc

Func _Sfs_ExportSection( $iIndex )
	If $iIndex Then
		_GUIState( $_hGui_Wait )
		GUICtrlSetData( $_GuiWait_Label[0], 'Please wait while exporting...' )

		Local $_sCode = ''
		$_sCode = _KSP_Sfs_Hierarchy_Save( $_sCode, $iIndex )

		_GUIState( $_hGui_Wait, @SW_HIDE )

		Return $_sCode
	Else
		Return SetError(1,0,'')
	EndIf
EndFunc

Func _KSP_Sfs_Close( $_iWarning = 0 )
	If $_iWarning And $_sOpened <> '' Then
		If MsgBox( 65, 'Close Warning!', 'Are you sure? All unsaved data will be lost!' ) <> 1 Then

			Return False
		EndIf
	EndIf

	$_sOpened = ''

	GUICtrlSetData( $_GuiMain_Label[0], '%SECTION_TYPE%' )
	GUICtrlSetData( $_GuiMain_Label[1], '%SECTION_INDEX%' )
	GUICtrlSetData( $_GuiMain_Label[2], '%SECTION_CHILD%' )

	GUICtrlSetState( $_GuiMain_Menu[2], $GUI_DISABLE )
	GUICtrlSetState( $_GuiMain_Menu[3], $GUI_DISABLE )
	GUICtrlSetState( $_GuiMain_Menu[4], $GUI_DISABLE )

	GUICtrlSendMsg($_GuiMain_List[0], $LVM_DELETEALLITEMS, 0, 0)

	_GUICtrlTreeView_BeginUpdate($_GuiMain_Tree[1])
	_GUICtrlTreeView_DeleteAll($_GuiMain_Tree[1])
	_GUICtrlTreeView_EndUpdate($_GuiMain_Tree[1])

	$_aActive = -1
	$_iUpdate = False

	ReDim $_GuiMain_TreeItm[1] ;Lol'd
	ReDim $_GuiMain_TreeItm[$_MAX]

	ReDim $_aSfs_Main[1][3] ;Lol'd x2
	ReDim $_aSfs_Main[$_MAX][3]
	$_aSfs_Main[0][0] = 0

	Return True
EndFunc

Func _KSP_Sfs_Hierarchy_Load( $_sCode, $_iParent = 0, $_sSection = '' )
	Local $_SectionList = _Sfs_ReadSection( $_sCode )
	If @Error Then _
		_Sfs_ProcessFail( 'RegExp.Report[' & $_SectionList & ']: Error code = ' & @Error )

	Local $Idx, $Size, $Keys, $Id, $Color, $Name, $State
	For $Idx = 1 To $_SectionList[0][0] Step 1
		$Size = $_aSfs_Main[0][0] + 1

		If $Size > $_MAX-1 Then _
			_Sfs_ProcessFail( 'MAX SECTIONS = ' & $_MAX & '! Your save is biggest!' & @Error )

		$Keys = _Sfs_ReadKeys( $_SectionList[$Idx][1] )

		$_aSfs_Main[0][0] = $Size
		$_aSfs_Main[$Size][0] = $_iParent
		$_aSfs_Main[$Size][1] = $_SectionList[$Idx][0]
		$_aSfs_Main[$Size][2] = $Keys

		; --Indication
		_WinAPI_SetWindowText( $_GuiWait_Label[2], 'Loaded ' & $Size & ' sections!' )

		If $_iParent Then
			$Id = $_GuiMain_TreeItm[$_iParent]
		Else
			$Id = $_GuiMain_Tree[0]
		EndIf

		$Name = ''
		$State = $GUI_SHOW
		Switch $_SectionList[$Idx][0]
			Case 'ORBIT'
				$Color = 0xbbbbbb

			Case 'GAME'
				$Name &= _Sfs_ArrayGetValue( $Keys, 'title' )
				$Color = 0x0000C0
				$State = $GUI_DEFBUTTON

			Case 'PART'
				$Name =  _Sfs_ArrayGetValue( $Keys, 'name' )
				$Color = 0x99958c
				$State = $GUI_DEFBUTTON

			Case 'RESOURCE'
				$Color = 0x50c878
				$Name = _Sfs_ArrayGetValue( $Keys, 'name' )

			Case 'CREW', 'RECRUIT'
				$Name = _Sfs_ArrayGetValue( $Keys, 'name' )
				$Color = 0x5020ba

			Case 'VESSEL'
				$Name &= _Sfs_ArrayGetValue( $Keys, 'name' )
				$Color = 0x1f43ba
				$State = $GUI_DEFBUTTON

			Case 'APPLICANTS'
				$Color = 0x5020ba
				$State = $GUI_DEFBUTTON

			Case 'PARAMETERS', 'SCENARIO', 'FLIGHTSTATE', 'ROSTER'
				$Color = 0xefaf8c

			Case 'FLIGHT', 'EDITOR', 'TRACKINGSTATION', 'SPACECENTER', 'DIFFICULTY'
				$Color = 0x884535

			Case Else
				$Color = 0x000000
		EndSwitch
		If $Name <> '' Then _
			$Name = ' - ' & $Name

		$_GuiMain_TreeItm[$Size] = GUICtrlCreateTreeViewItem( $_SectionList[$Idx][0] & $Name & ' [' & $Size & ']', $Id )
		GUICtrlSetState(-1, $State)
		GUICtrlSetColor(-1, $Color)
		; ---

		_KSP_Sfs_Hierarchy_Load( $_SectionList[$Idx][1], $Size, $_SectionList[$Idx][0] )
	Next
EndFunc
#EndRegion KSP.LoadStuff


#Region SFS.API
Func _Sfs_ProcessFail( $_iMsg )
	_WinAPI_SetWindowText( $_GuiWait_Label[2], $_iMsg )

	For $Idx = 1 To 100 Step 1
		GUICtrlSetData( $_GuiWait_Label[0], 'Loading terminated! Exiting after ' & (20 - Round( $Idx / 5 )) & ' sec!' )
		Sleep( 200 )
	Next

	Exit 1488
EndFunc

Func _Sfs_RemoveSection( $iSectionIndex )
	If $iSectionIndex Then
		$_aSfs_Main[$iSectionIndex][0] = ''
		$_aSfs_Main[$iSectionIndex][1] = ''
		$_aSfs_Main[$iSectionIndex][2] = ''
		GUICtrlDelete( $_GuiMain_TreeItm[$iSectionIndex] )

		$_iUpdate = True
	EndIf
EndFunc

Func _Sfs_ArrayGetValue( $aKeyArray, $sKeyName )
	Local $Idx

	If IsArray( $aKeyArray ) Then
		For $Idx = 1 To $aKeyArray[0][0] Step 1
			If Not StringCompare( $aKeyArray[$Idx][0], $sKeyName, 2 ) Then
				Return $aKeyArray[$Idx][1]
			EndIf
		Next
	EndIf
	SetError(1, 0, 'Undefined')
EndFunc

Func _Sfs_ArraySetValue( $aKeyArray, $sKeyName, $sKeyValue )
	Local $Idx

	If IsArray( $aKeyArray ) Then
		For $Idx = 1 To $aKeyArray[0][0] Step 1
			If Not StringCompare( $aKeyArray[$Idx][0], $sKeyName, 2 ) Then
				$aKeyArray[$Idx][1] = $sKeyValue
			EndIf
		Next
	EndIf
	SetError(1)
EndFunc

Func _Sfs_ArrayAddKey( ByRef $aKeyArray, $sKeyName, $sKeyValue )
	If IsArray( $aKeyArray ) Then
		Local $iSize = UBound( $aKeyArray )

		ReDim $aKeyArray[$iSize+1][2]
		$aKeyArray[0][0] = $iSize
		$aKeyArray[$iSize][0] = $sKeyName
		$aKeyArray[$iSize][1] = $sKeyValue
	Else
		SetError(1)
	EndIf
EndFunc

Func _Sfs_ArrayDelKey( ByRef $aKeyArray, $sKeyIdx, $iFlag = 1 )
	If IsArray( $aKeyArray ) And $sKeyIdx Then
		If $iFlag Then
			$aKeyArray[0][0] -= 1
			_ArrayDelete( $aKeyArray, $sKeyIdx )
		Else
			ReDim $aKeyArray[1][2]
			$aKeyArray[0][0] = 0
		EndIf
	Else
		SetError(1)
	EndIf
EndFunc

Func _Sfs_ReadSection( $sCode, $iMode = 0 )
	Local $_aCode = __Sfs_CodeToArray( $sCode ), $Idx

	Local $_aRet[1][2] = [[0]], $_iOpen = 0, $_aSection, $_sSection, $_iSize
	For $Idx = 1 To $_aCode[0] Step 1
		If Not $_iOpen Then
			$_aSection = StringRegExp( $_aCode[$Idx], '^([\w]+)$', 3 )
			If IsArray( $_aSection ) Then
				$_iSize = $_aRet[0][0] + 1

				ReDim $_aRet[$_iSize + 1][2]
				$_aRet[0][0] = $_iSize
				$_aRet[$_iSize][0] = $_aSection[0]

				$Idx += 1
				$_iOpen = 1
				$_sSection = ''
			EndIf
		Else
			If $_aCode[$Idx] = '{' Then
				$_iOpen += 1
			ElseIf $_aCode[$Idx] = '}' Then
				$_iOpen -= 1
				If Not $_iOpen Then
					$_aRet[$_aRet[0][0]][1] = StringTrimRight( $_sSection, 1 )
					ContinueLoop
				EndIf
			EndIf

			$_sSection &= $_aCode[$Idx] & @LF
		EndIf
	Next

	If $iMode Then _
		Return $_aRet[1][1]

	Return $_aRet
EndFunc

Func _Sfs_ReadKeys( $sCode )
	Local $_aCode = __Sfs_CodeToArray( $sCode ), $Idx

	Local $_aRet[1][2] = [[0]], $_aKey, $_iSize
	For $Idx = 1 To $_aCode[0] Step 1
		$_aKey = StringRegExp( $_aCode[$Idx], '([\w]+)\040=\040(.*)', 3 )

		If IsArray( $_aKey ) Then
			$_iSize = $_aRet[0][0] + 1
			ReDim $_aRet[$_iSize+1][2]

			$_aRet[0][0] = $_iSize
			$_aRet[$_iSize][0] = $_aKey[0]
			$_aRet[$_iSize][1] = $_aKey[1]
		Else
			Return $_aRet
		EndIf
	Next

	Return $_aRet
EndFunc

; --- Internal
Func __Sfs_CodeToArray( $sCode )
	Local $_aRet = StringSplit( StringStripCR( $sCode ), @LF )

	Return $_aRet
EndFunc
#EndRegion SFS.API


#Region KSP.GUI's
Func _GUIMain_Create()
	Local $_hGui = GUICreate("KSP_SfsEditor - Alpha v0.0.1", 676, 573, -1, -1, 0x94CA0000, 0x00000100)

	; ---
	$_GuiMain_Menu[0] = GUICtrlCreateMenu("&Файл")
	$_GuiMain_Menu[1] = GUICtrlCreateMenuItem("&Открыть", $_GuiMain_Menu[0])
	GUICtrlSetState(-1, $GUI_DEFBUTTON)

	$_GuiMain_Menu[2] = GUICtrlCreateMenuItem("&Сохранить", $_GuiMain_Menu[0])
	$_GuiMain_Menu[3] = GUICtrlCreateMenuItem("&Сохранить как...", $_GuiMain_Menu[0])
	$_GuiMain_Menu[4] = GUICtrlCreateMenuItem("&Закрыть", $_GuiMain_Menu[0])
	GUICtrlCreateMenuItem("", $_GuiMain_Menu[0], 5)

	$_GuiMain_Menu[5] = GUICtrlCreateMenuItem("&Выход", $_GuiMain_Menu[0])
	For $Idx = 2 To 4 Step 1
		GUICtrlSetState( $_GuiMain_Menu[$Idx], $GUI_DISABLE )
	Next

	$_GuiMain_Menu[6] = GUICtrlCreateMenu("Operations")
	$_GuiMain_Menu[7] = GUICtrlCreateMenuItem("Remove all debris", $_GuiMain_Menu[6])
	$_GuiMain_Menu[8] = GUICtrlCreateMenuItem("Refuel all ships", $_GuiMain_Menu[6])
	$_GuiMain_Menu[9] = GUICtrlCreateMenuItem("Populate all modules", $_GuiMain_Menu[6])
	GUICtrlCreateMenuItem("", $_GuiMain_Menu[6], 4)
	$_GuiMain_Menu[10] = GUICtrlCreateMenuItem("Add vessel...", $_GuiMain_Menu[6])

	; ---
	$_GuiMain_Menu[11] = GUICtrlCreateMenu("About")
	$_GuiMain_Menu[12] = GUICtrlCreateMenuItem("KSP_SfsEditor - Alpha v0.0.1", $_GuiMain_Menu[11])

	$_GuiMain_Tree[0] = GUICtrlCreateTreeView(6, 6, 363, 541, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
	$_GuiMain_Tree[1] = GUICtrlGetHandle(-1)

	GUICtrlCreateGroup( 'Editing / Details / Operations', 375, 2, 295, 443 )
	$_GuiMain_List[0] = GUICtrlCreateListView( 'Key name|Key value', 380, 18, 285, 180, BitOr($GUI_SS_DEFAULT_LISTVIEW, $LVS_REPORT) )
	$_GuiMain_List[1] = GUICtrlGetHandle(-1)
	GUICtrlSendMsg($_GuiMain_List[0], $LVM_SETCOLUMNWIDTH, 0, 120)
	GUICtrlSendMsg($_GuiMain_List[0], $LVM_SETCOLUMNWIDTH, 1, 160)

	$_GuiMain_Input = GUICtrlCreateInput( '', 0, 0, 0, 0 )
	GUICtrlSetFont( -1, 9, 400, 0 )
	GUICtrlSetState( -1, $GUI_HIDE )

	$_GuiMain_Dummy = GUICtrlCreateDummy()
	Local $AccelKeys[1][2] = [["{ENTER}", $_GuiMain_Dummy]]
	GUISetAccelerators($AccelKeys)

	$_GuiMain_Button[0] = GUICtrlCreateButton( 'Add key!', 381, 200, 92, 21 )
	GUICtrlSetColor( -1, 0x00ff00 )
	$_GuiMain_Button[1] = GUICtrlCreateButton( 'Del key!', 476, 200, 92, 21 )
	GUICtrlSetColor( -1, 0xff0000 )
	$_GuiMain_Button[2] = GUICtrlCreateButton( 'Remove all!', 571, 200, 92, 21 )
	GUICtrlSetColor( -1, 0xff0000 )

	GUICtrlCreateGroup( 'Automated', 378, 224, 289, 100 )
	$_GuiMain_Button[3] = GUICtrlCreateButton( 'Refuel!', 382, 238, 80, 21 )
	$_GuiMain_Button[4] = GUICtrlCreateButton( 'Populate!', 382, 259, 80, 21 )
	$_GuiMain_Button[5] = GUICtrlCreateButton( 'Magic tank!', 382, 280, 80, 21 )
	$_GuiMain_Button[6] = GUICtrlCreateButton( 'Part edit!', 466, 238, 112, 21 )
	$_GuiMain_Button[7] = GUICtrlCreateButton( 'Orbit edit!', 466, 259, 112, 21 )
	$_GuiMain_Button[8] = GUICtrlCreateButton( '', 466, 280, 112, 21 )
	$_GuiMain_Button[9] = GUICtrlCreateButton( 'Import current!', 582, 238, 81, 21 ) ;RESERVED
	$_GuiMain_Button[10] = GUICtrlCreateButton( 'Export current!', 582, 259, 81, 21 ) ;RESERVED
	$_GuiMain_Button[11] = GUICtrlCreateButton( '', 582, 280, 81, 21 ) ;RESERVED
	GUICtrlCreateLabel( '<<-- Before using this select the valid section!', 384, 304, 281, 18 )
	For $Idx = 3 To 11 Step 1
		GUICtrlSetColor( $_GuiMain_Button[$Idx], 0xcd5700 )
	Next

	GUICtrlCreateGroup( 'Section Info / Control', 378, 330, 289, 109 )
	GUICtrlCreateLabel( 'Section type: ', 384, 345, 105, 20 )
	GUICtrlSetFont( -1, 12, 800 )
	GUICtrlCreateLabel( 'Parent index: ', 384, 367, 105, 20 )
	GUICtrlSetFont( -1, 12, 800 )
	GUICtrlCreateLabel( 'Childs index: ', 384, 389, 105, 20 )
	GUICtrlSetFont( -1, 12, 800 )

	$_GuiMain_Label[0] = GUICtrlCreateLabel( '%SECTION_TYPE%', 489, 347, 130, 20 )
	$_GuiMain_Label[1] = GUICtrlCreateLabel( '%SECTION_INDEX%', 489, 369, 130, 20 )
	$_GuiMain_Label[2] = GUICtrlCreateLabel( '%SECTION_CHILD%', 489, 391, 130, 20 )
	For $Idx = 0 To 2 Step 1
		GUICtrlSetFont( $_GuiMain_Label[$Idx], 10, 900 )
	Next

	$_GuiMain_Button[12] = GUICtrlCreateButton( 'Add section', 383, 410, 91, 22 )
	$_GuiMain_Button[13] = GUICtrlCreateButton( 'Rename section', 477, 410, 91, 22 )
	$_GuiMain_Button[14] = GUICtrlCreateButton( 'Delete section', 571, 410, 91, 22 )
	For $Idx = 12 To 14 Step 1
		GUICtrlSetColor( $_GuiMain_Button[$Idx], 0x6600ff )
	Next


	GUICtrlCreateLabel( 'Warning: Improper editing can damage your save files and crash your game. Remember to make backups before saving!', 377, 517, 296, 35 )
	GUICtrlSetColor( -1, 0xff0000 )
	GUISetState(@SW_SHOW, $_hGui)

	GUIRegisterMsg( 0x4E, "WM_NOTIFY")
	GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

	Return $_hGui
EndFunc

Func _GUIWait_Create( $_hState )
	Local $_aPos = WinGetPos( $_hGui_Main, '' )
	Local $_fPos[2] = [($_aPos[0]+($_aPos[2]/2))-106,($_aPos[1]+($_aPos[3]/2))-29 ]
	Local $_hGui = GUICreate( '', 212, 58, $_fPos[0], $_fPos[1], $WS_POPUP, BitOr($WS_EX_WINDOWEDGE,$WS_EX_DLGMODALFRAME), $_hGui_Main )

	$_GuiWait_Label[0] = GUICtrlCreateLabel( '', 5, 10, 202, 20, $SS_CENTER )
	$_GuiWait_Label[1] = GUICtrlCreateLabel( '', 5, 32, 202, 20, $SS_CENTER )
	$_GuiWait_Label[2] = GUICtrlGetHandle( $_GuiWait_Label[1] )

	GUISetState( $_hState, $_hGui )

	Return $_hGui
EndFunc

Func  _GUIRename_Create( $_hState )
	Local $_aPos = WinGetPos( $_hGui_Main, '' )
	Local $_fPos[2] = [($_aPos[0]+($_aPos[2]/2))-131,($_aPos[1]+($_aPos[3]/2))-54 ]
	Local $_hGui = GUICreate( '', 262, 108, $_fPos[0], $_fPos[1], BitOr( $WS_POPUP, $WS_BORDER ), -1, $_hGui_Main )

	GUICtrlCreateLabel( 'Enter new section type: ', 5, 5, 155, 20 )
	GUICtrlSetFont( -1, 10, 800 )
	GUICtrlCreateLabel( 'Enter new parent index: ', 5, 25, 155, 20 )
	GUICtrlSetFont( -1, 10, 800 )
	GUICtrlCreateLabel( 'Enter new childs index: ', 5, 45, 155, 20 )
	GUICtrlSetFont( -1, 10, 800 )
	GUICtrlCreateLabel( '^-But this is a very serious options, be careful!', 5, 64, 245, 16)
	GUICtrlSetFont( -1, 8, 400 )

	$_GuiRename_Input[0] = GUICtrlCreateInput( '', 160, 5, 90, 20 )
	$_GuiRename_Input[1] = GUICtrlCreateInput( '', 160, 25, 90, 20, $ES_NUMBER )
	$_GuiRename_Input[2] = GUICtrlCreateInput( '', 160, 45, 90, 20, $ES_NUMBER )
	GUICtrlSetState( -1, $GUI_DISABLE )

	$_GuiRename_Button[0] = GUICtrlCreateButton( 'Apply!', 6, 80, 123, 22 )
	GUICtrlSetColor( -1, 0x000000 )

	$_GuiRename_Button[1] = GUICtrlCreateButton( 'Close!', 133, 80, 123, 22 )
	GUICtrlSetColor( -1, 0x000000 )

	GUISetState( $_hState, $_hGui )

	Return $_hGui
EndFunc

Func _GUIOrbit_Create( $_hState )
	Local $_aPos = WinGetPos( $_hGui_Main, '' )
	Local $_fPos[2] = [($_aPos[0]+($_aPos[2]/2))-172,($_aPos[1]+($_aPos[3]/2))-126 ]
	Local $_hGui = GUICreate( '', 344, 252, $_fPos[0], $_fPos[1], BitOr( $WS_POPUP, $WS_BORDER ), -1, $_hGui_Main )


	GUISetState( $_hState, $_hGui )

	Return $_hGui
EndFunc

Func _GUIAdd_Create( $_hState )
	Local $_aPos = WinGetPos( $_hGui_Main, '' )
	Local $_fPos[2] = [($_aPos[0]+($_aPos[2]/2))-231,($_aPos[1]+($_aPos[3]/2))-254 ]
	Local $_hGui = GUICreate( '', 462, 508, $_fPos[0], $_fPos[1], BitOr( $WS_POPUP, $WS_BORDER ), -1, $_hGui_Main )


	GUISetState( $_hState, $_hGui )

	Return $_hGui
EndFunc

Func _GUIState( $_hGui, $_hState = @SW_SHOW )
	If $_hState = @SW_SHOW Then
		GUISetState( @SW_DISABLE, $_hGui_Main )
	Else
		GUISetState( @SW_ENABLE, $_hGui_Main )
	EndIf
	GUISetState( $_hState, $_hGui )
EndFunc

Func _GUIAbout_Show()
	MsgBox( 64, 'KSP_SfsEditor - About', 'Author: Firex' & @LF & _
			'  Build: 2/2' & @LF & '  Version: Alpha v0.0.1' & _
			@LF & @LF & 'Development took an two days :3' )
EndFunc
; ---
Func _GUICtrlListView_EditItem($hWnd, $iIndex, $iSubItem)
	If $iIndex < 0 Then _
		Return SetError( 1, 0, 0 )

	Local $X, $Y, $W, $H, $aPos, $aRect, $Idx, $iSum = 0
	For $Idx = 0 To $iSubItem - 1
		$iSum += _GUICtrlListView_GetColumnWidth($hWnd, $Idx)
	Next

	$aRect = _GUICtrlListView_GetItemRect($hWnd, $iIndex)
	$aPos = ControlGetPos($_hGui_Main, "", $hWnd)

	$X = $iSum + $aPos[0] + $aRect[0]
	$Y = $aPos[1] + $aRect[1]
	$W = _GUICtrlListView_GetColumnWidth($hWnd, $iSubItem)
	$H = $aRect[3] - $aRect[1]

	GUICtrlSetPos($_GuiMain_Input, $X + 1, $Y + 1, $W + 1, $H + 1)
	GUICtrlSetData($_GuiMain_Input, _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem))
	GUICtrlSetState($_GuiMain_List[0], $GUI_DISABLE)

	GUICtrlSetState($_GuiMain_Input, $GUI_SHOW)
	GUICtrlSetState($_GuiMain_Input, $GUI_FOCUS)

	$_aActiveTree[1] = $iIndex
	$_aActiveTree[2] = $iSubItem
EndFunc

Func _GUICtrlListView_SaveChanges()
	Local $sText = GUICtrlRead($_GuiMain_Input)

	If StringInStr( $sText, '|' ) Or $sText = '' Then
		MsgBox( 64, '', 'Invalid value!' )

		Return SetError(1, 0, '')
	Else
		Local $_aRet[3] = [ $_aActiveTree[1], $_aActiveTree[2], $sText ]

		_GUICtrlListView_BeginUpdate($_aActiveTree[0])
		_GUICtrlListView_SetItemText($_aActiveTree[0], $_aActiveTree[1], $sText, $_aActiveTree[2])

		GUICtrlSetState($_GuiMain_Input, $GUI_HIDE)
		GUICtrlSetState($_GuiMain_List[0], $GUI_ENABLE)

		_GUICtrlListView_EndUpdate($_aActiveTree[0])

		Return $_aRet
	EndIf
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
	Local $hWndFrom, $iCode, $tNMHDR, $tInfo, $iItem

	$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
	$iCode = DllStructGetData($tNMHDR, "Code")
	$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
	Switch $hWndFrom
		Case $_GuiMain_List[1]
			Switch $iCode
				Case $NM_CLICK
					$_aActiveList[0] = DllStructGetData($tInfo, "Index")

				Case $NM_DBLCLK
					_GUICtrlListView_EditItem($_GuiMain_List[1], DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
					$_aActiveTree[0] = $_GuiMain_List[1]
			EndSwitch

		Case $_GuiMain_Tree[1]
			Switch $iCode
				Case $NM_CLICK
					$_iUpdate = True
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg
	Local $iIDFrom, $iCode
	$iIDFrom = BitAND($iwParam, 0xFFFF) ; младшее слово
	$iCode = BitShift($iwParam, 16) ; старшее слово
	Switch $iIDFrom
		Case $_GuiMain_Input
			Switch $iCode
				Case $EN_KILLFOCUS
					GUICtrlSetState($_GuiMain_Input, $GUI_HIDE)
					GUICtrlSetState($_GuiMain_List[0], $GUI_ENABLE)
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc
#EndRegion KSP.GUI's


Сразу копируй и можешь запускать.

P.S. Поскольку операция удаления мусора там не написана - вот ее реализация:
Код:
Case $_GuiMain_Menu[7] ;Удалить мусор
	$aVESSEL = _ArrayFindAll( $_aSfs_Main, "VESSEL", 1 )
	For $Idx = 1 To UBound( $aVESSEL) - 1 Step 1
		$sVesselType = _Sfs_ArrayGetValue( $_aSfs_Main[$aVESSEL[$Idx]][2], "type" )
		If Not @Error And $sVesselType = "Debris" Then
			_Sfs_RemoveSection( $aVESSEL[$Idx] )
		EndIf
	Next
 
Автор
M

mitiya

Новичок
Сообщения
75
Репутация
0
Спасибо. Правда еще не разобрался куда вставить удаление мусора. Положил вроде следующим после Case $_GuiMain_Menu[4], но что-то не заметил чтоб что-то удалялось, когда нажимаю в меню.
 

firex

AutoIT Гуру
Сообщения
943
Репутация
208
mitiya [?]
Спасибо. Правда еще не разобрался куда вставить удаление мусора. Положил вроде следующим после Case $_GuiMain_Menu[4], но что-то не заметил чтоб что-то удалялось, когда нажимаю в меню.
Удаление происходит в памяти, т.е. визуально в TreeView пункт не удаляется ( нет времени опять разбирать свою писанину ), но после сохранения изменений обратно в файл они должны удалиться.
 
Верх