Rawox Posted March 14, 2011 Posted March 14, 2011 (edited) Hi there, I'm working on a script that has the ability to save and load from .cgf files (ContextGen File, came up with the extension myself ) And they look like this: Unreal Tournament 2004 +1 Play Unreal Tournament 2004 =1 +1 Servers +2 WOH +3 lol =3 +2 FFM +2 IT's NL +1 Demo Recording +2 Start VirtualDub =2 The first line is the title of the current project In this file the lines that start with = are seperators and + are lines with text. The numbers indicitate that the items are subitems from the previous number which is one lower. So it will have to come out something like this: Play Unreal Tournament 2004 [Seperator] ---- Servers -------- WOH ------------ lol ------------ [Seperator] -------- FFM -------- IT's NL ---- Demo Recording -------- Start VirtualDub The problem is that I can't get the items under the right parent. I tried some methods but I can't get it to work. This is what I want: _readCFG ( $LatestCFG ) Func _readCFG ( $CFGPath ) Global $hItem[_FileCountLines ( $CFGPath )+1] = [""], $CurrentTree = 1 $hFile = FileOpen ( $CFGPath, 0 ) GUICtrlSetData ( $CFGName, FileReadLine ( $hFile, 1 ) ) For $i = 2 To _FileCountLines ( $CFGPath ) Step 1 $fRead = FileReadLine ( $hFile, $i ) If StringLeft ( $fRead, 1 ) == "+" Then $sText = StringTrimLeft ( $fRead, 3 ) ElseIf StringLeft ( $fRead, 1 ) == "=" Then $sText = "[Seperator]" EndIf If StringMid ( $fRead, 2, 1 ) == 1 Then $hParent = $hTree Else ; ....? EndIf $hItem[$i] = GUICtrlCreateTreeViewItem ( $sText, $hParent ) Next EndFunc The full code so far and the Unreal Tournament 2004.cgf are included in the attachments. Anyone can come up with a algorithm that correctly imports the .cgf file into the treeview in the main GUI? Thanks in advance, RawoxContextGen.rar Edited March 14, 2011 by Rawox
Rawox Posted March 14, 2011 Author Posted March 14, 2011 (edited) Well, nevermind I got it already expandcollapse popupFunc _readCFG ( $CFGPath ) Global $hItem[_FileCountLines ( $CFGPath )+1] = [""] Local $CurLvl = 0, $hParent, $CurrentTree, $cLine $hFile = FileOpen ( $CFGPath, 0 ) GUICtrlSetData ( $CFGName, FileReadLine ( $hFile, 1 ) ) For $i = 2 To _FileCountLines ( $CFGPath ) Step 1 $fRead = FileReadLine ( $hFile, $i ) If StringLeft ( $fRead, 1 ) == "+" Then $sText = StringTrimLeft ( $fRead, 3 ) ElseIf StringLeft ( $fRead, 1 ) == "=" Then $sText = "[Seperator]" EndIf If StringMid ( $fRead, 2, 1 ) == 0 Then $hParent = $hTree $CurLvl = 0 ElseIf StringMid ( $fRead, 2, 1 ) > 0 Then If StringMid ( $fRead, 2, 1 ) < $CurLvl Then $CurrentTree = StringSplit ( _GUICtrlTreeView_GetTree ( $hTree, $hItem[$i-1] ), "|" ) $j = 1 While 1 $cLine = FileReadLine ( $hFile, $j ) If $cLine = ( "+" & StringMid ( $fRead, 2, 1) - 1 & " " & $CurrentTree[StringMid ( $fRead, 2, 1)] ) Then ExitLoop If @Error = -1 Then ExitLoop $j += 1 WEnd $hParent = $hItem[$j] ElseIf StringMid ( $fRead, 2, 1 ) > $CurLvl Then $hParent = $hItem[$i-1] EndIf EndIf $hItem[$i] = GUICtrlCreateTreeViewItem ( $sText, $hParent ) $CurLvl = _GUICtrlTreeView_Level ( $hTree, $hItem[$i] ) Next GUICtrlSetState ( $hTree, $GUI_FOCUS ) FileClose ( $hFile ) EndFunc Edited March 15, 2011 by Rawox
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now