Page 1 of 1

PureINI Editor 1.0 Released

Posted: Thu Dec 02, 2004 10:15 pm
by localmotion34
i added "select all" functions so that you can 1) select all text in the output and 2) can create or alter INI files without ever having to overwrite them. you can open an INI file, edit it, output the text to the editor gadget, copy, and then paste it wherever you like. you can of course read and write INI files too. IM NOT RESPONSIBLE IF YOU OVERWRITE A SYSTEM OR OTHER INI, say for instance, an INI with your software registration # in it. let me know if you find any bugs.

this release DOES NOT include the option to encode or decode INI sections, keys and values. i am writing a function for my own RPG game to encode, and when that is done i will alter the routine so that the public PureINI cant decrypt my game INI, but will still give a different encryption ability to PureINI editor. if you guys want the source, let me know and ill post it. thanks to everyone who has answered my thousands of questions.

Regards

http://ripway.com/members/getfile.asp?f ... itor%2Eexe

Posted: Thu Dec 02, 2004 10:32 pm
by localmotion34
try this link on the purestorage too

http://www.penguinbyte.com/apps/pbwebst ... Editor.exe

Posted: Fri Dec 03, 2004 1:54 pm
by thefool
quite nice little editor.

Things i woul have done [i dont say that everyone likes this..]:

-Put the functions in a toolbar
-Make the "currently editing" be in a statusbar
-Turn on winxp skin [if you dont use the toolbar]

:D

Posted: Fri Dec 03, 2004 3:10 pm
by RJP Computing
I love this idea and have used your previous source and added some stuff to it. I am adding a toolbar and a status bar and making the 'Quick Output' hidden till you want it. I am really getting a kick out of the ini routines you created. I am just making the GUI to my likeing. (Not that yours is bad. You just sparked my interest in this type of a program.) I use .ini files all the time. Thanks for getting me fired up about this type of program.

I would love the source to the update.

PS. is it ok that I use your source and update the GUI? Just want to ask.

Posted: Fri Dec 03, 2004 3:35 pm
by localmotion34
RJ:

yes you can modify the source, just give me some props somewhere.

NOTE RJ: when opening LARGE INI files, and you have deleted some sections thereby shortening the ini length, the program will write from line 0 of the file until all INI sections are done,
!!!!!!!!!!!!!!!
and then will writestringn() until the end of the file to get rid of unneeded or no longer correct headings. it keeps the file about the same size. THIS ONLY applies toi HUGE ini files.

Code: Select all



Global currentfile$,theysaved
;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- MenuBar Constants
;
Enumeration
  #MenuBar_0
EndEnumeration

Enumeration
  #MENU_1
  #MENU_4
  #MENU_5
  #MENU_7
  #MENU_8
  #menu_9
  #menu_10
EndEnumeration

;- Gadget Constants
;

#Tree_0=200
#Button_0=201
#Button_1=202
#String_1=203
#String_2=204
#Text_1=205
#Text_3=206
#Text_2=207
#Button_2=208
#Text_4=209


;- Fonts
;
Global FontID1
FontID1 = LoadFont(1, "Txt", 10, #PB_Font_Underline)
Global FontID2
FontID2 = LoadFont(2, "Times New Roman", 10)
Global FontID3
FontID3 = LoadFont(3, "Arial", 10)
Global FontID4
FontID4 = LoadFont(4, "Arial", 10, #PB_Font_Underline)
;- Structures and Lists
Structure info
  key.l
  section.l
  value.s
EndStructure

Dim inilist.s(2000)
NewList elements.info()

;- Procedures
Procedure.l writeINI(section.s,key.s,value.s,inifile.s)
  result=WritePrivateProfileString_(section,key,value,inifile)
  ProcedureReturn result
EndProcedure

Procedure Callback(Window.l, message.l, wParam.l, lParam.l) 
  result = #PB_ProcessPureBasicEvents 
  If message = #WM_NOTIFY 
    *lp.NMHDR = lParam 
    Select *lp\code 
      Case #TVN_BEGINLABELEDIT 
        
      Case #TVN_ENDLABELEDIT 
        *pvdi.NMTVDISPINFO = lParam 
        If *pvdi\item\pszText <> #Null 
          Text.s = PeekS(*pvdi\item\pszText) 
          
          If Text = "" 
            result = #False 
          Else 
            result = #True 
          EndIf 
          
        EndIf 
    EndSelect 
  EndIf 
  ProcedureReturn result 
  
EndProcedure 

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 395, 142, 570, 456,  #PB_Window_SystemMenu |  #PB_Window_TitleBar|#PB_Window_WindowCentered , "PureINI Editor - By Localmotion34")
    If CreateMenu(#MenuBar_0, WindowID())
      MenuTitle("File")
      MenuItem(#MENU_1, "New")
      MenuItem(#MENU_4, "Open")
      MenuBar()
      MenuItem(#MENU_5, "Save")
      MenuItem(#MENU_7, "Save As...")
      MenuBar()
      MenuItem(#MENU_8, "Exit")
      MenuTitle("Edit")
      MenuItem(#menu_10 ,"Select All")
      MenuItem(#menu_9,"Copy")
    EndIf
    
    If CreateGadgetList(WindowID())
      TreeGadget(#Tree_0, 1, 10, 130, 420,#PB_Tree_AlwaysShowSelection)
      ButtonGadget(#Button_0, 140, 10, 120, 20, "New Section")
      ButtonGadget(#Button_1, 140, 30, 120, 20, "New Key")
      EditorGadget(#String_1, 140, 140, 420, 290)
      StringGadget(#String_2, 140, 80, 120, 20, ""):DisableGadget(#String_2,1)
      TextGadget(#Text_1, 140, 60, 120, 20, "Value", #PB_Text_Center)
      SetGadgetFont(#Text_1, FontID4)
      TextGadget(#Text_3, 310, 10, 120, 20, "Currently Editing Section:")
      TextGadget(#Text_2, 310, 30, 120, 20, "", #PB_Text_Border|#PB_Text_Center)
      ButtonGadget(#Button_2, 300, 60, 140, 40, "Test Output")
      TextGadget(#Text_4, 180, 120, 320, 20, "Quick Output", #PB_Text_Center)
      SetWindowLong_(GadgetID(#Tree_0),#GWL_STYLE,GetWindowLong_(GadgetID(#Tree_0),#GWL_STYLE) | #TVS_EDITLABELS) 
    EndIf
  EndIf
  SetWindowCallback(@Callback())
EndProcedure

Procedure updateINI()
  SetGadgetText(#String_1,"")
  selectedItem=0
  Repeat
    currentitem=GadgetItemID(#Tree_0,selectedItem)
    If currentitem=#Null
      Break
    EndIf 
    message1=SendMessage_(GadgetID(#Tree_0),#TVM_GETNEXTITEM ,#TVGN_CHILD,currentitem)
    If message1 =#Null
      inilist(selectedItem)=GetGadgetItemText(#Tree_0,selectedItem,0)
      AddGadgetItem(#String_1,-1, "["+inilist(selectedItem)+"]")
      AddGadgetItem(#String_1,-1,"")
      selectedItem=selectedItem+1
    ElseIf message1 <> #Null
      inilist(selectedItem)=GetGadgetItemText(#Tree_0,selectedItem,0)
      AddGadgetItem(#String_1,-1, "["+inilist(selectedItem)+"]")
      nodeitems=CountTreeGadgetNodeItems(#Tree_0, selectedItem)
      For a=selectedItem+1 To selectedItem+nodeitems
        inilist(a)=GetGadgetItemText(#Tree_0,a,0)
        SelectElement(elements(),a)
        AddGadgetItem(#String_1,-1,inilist(a)+"=" +elements()\value)
      Next 
      AddGadgetItem(#String_1,-1,"")
      selectedItem=selectedItem+nodeitems+1
    EndIf 
  Until currentitem=0
EndProcedure 

Procedure openINI(file$)
  If file$=""
  Else 
    currentfile$=file$
    ClearList(elements())
    ClearGadgetItemList(#Tree_0)
    SetGadgetText(#String_1,"")
    SetGadgetText(#String_2,"")
    OpenFile(99, file$) 
    Repeat
      currenttext$=ReadString()
      If currenttext$=""
      Else 
        If Asc(currenttext$)=91
          Length=Len(currenttext$)
          Result$ = Left(currenttext$, Length-1)
          Length=Len(Result$)
          Result1$ = Right(Result$, Length-1)
          thisitem=AddGadgetItem(#Tree_0,-1,Result1$)
          AddElement(elements())
        ElseIf Asc(currenttext$)<>59
          result2$=StringField(currenttext$,1,"=")
          result3$=StringField(currenttext$,2,"=")
          OpenTreeGadgetNode(#Tree_0)
          AddGadgetItem(#Tree_0,-1,result2$)
          AddElement(elements())
          elements()\value=result3$
          CloseTreeGadgetNode(#Tree_0)
        EndIf 
      EndIf 
    Until Eof(99)
    CloseFile(99)
    theysaved=1
  EndIf 
EndProcedure

Procedure saveINI()
  savedfile$=SaveFileRequester("Please Choose A File To Save","","INI Files|*.INI",0)
  files$=GetExtensionPart(savedfile$)
  If files$="ini"
    savefile$=savedfile$
  Else
    savefile$=savedfile$ + ".ini"
  EndIf
  If savedfile$=""
  Else 
    OpenFile(100,savefile$)
    selectedItem=0
    Repeat
      currentitem=GadgetItemID(#Tree_0,selectedItem)
      If currentitem=#Null
        Break
      EndIf 
      message1=SendMessage_(GadgetID(#Tree_0),#TVM_GETNEXTITEM ,#TVGN_CHILD,currentitem)
      If message1 =#Null
        inilist(selectedItem)=GetGadgetItemText(#Tree_0,selectedItem,0)
        WriteStringN("["+inilist(selectedItem)+"]")
        selectedItem=selectedItem+1
      ElseIf message1 <> #Null
        inilist(selectedItem)=GetGadgetItemText(#Tree_0,selectedItem,0)
        WriteStringN("["+inilist(selectedItem)+"]")
        nodeitems=CountTreeGadgetNodeItems(#Tree_0, selectedItem)
        For a=selectedItem+1 To selectedItem+nodeitems
          inilist(a)=GetGadgetItemText(#Tree_0,a,0)
          SelectElement(elements(),a)
          WriteStringN(inilist(a)+"=" +elements()\value)
        Next 
        selectedItem=selectedItem+nodeitems+1
      EndIf 
    Until currentitem=#Null
    Repeat
      WriteStringN("")
    Until Eof(100)
    CloseFile(100)
    theysaved=1
    currentfile$=savefile$
  EndIf 
EndProcedure 

Procedure justsaveINI()
  If OpenFile(100,currentfile$)
  selectedItem=0
  Repeat
    currentitem=GadgetItemID(#Tree_0,selectedItem)
    If currentitem=#Null
      Break
    EndIf 
    message1=SendMessage_(GadgetID(#Tree_0),#TVM_GETNEXTITEM ,#TVGN_CHILD,currentitem)
    If message1 =#Null
      inilist(selectedItem)=GetGadgetItemText(#Tree_0,selectedItem,0)
      WriteStringN("["+inilist(selectedItem)+"]")
      selectedItem=selectedItem+1
    ElseIf message1 <> #Null
      inilist(selectedItem)=GetGadgetItemText(#Tree_0,selectedItem,0)
      WriteStringN("["+inilist(selectedItem)+"]")
      nodeitems=CountTreeGadgetNodeItems(#Tree_0, selectedItem)
      For a=selectedItem+1 To selectedItem+nodeitems
        inilist(a)=GetGadgetItemText(#Tree_0,a,0)
        SelectElement(elements(),a)
        WriteStringN(inilist(a)+"=" +elements()\Value)
      Next 
      selectedItem=selectedItem+nodeitems+1
    EndIf 
  Until currentitem=#Null
  Repeat
    WriteStringN("")
  Until Eof(100)
  CloseFile(100)
EndIf 
EndProcedure

theysaved=0
CreatePopupMenu(100)
MenuItem(100,"Remove Item")
MenuItem(101,"Expand All")
MenuItem(102,"Collapse All")

;- Program
Open_Window_0()
Repeat
  Event = WaitWindowEvent()
  Select Event 
    Case  #PB_EventMenu
      MenuID = EventMenuID()
      Select MenuID
        Case #MENU_1
          proceed=MessageRequester("Info","Are You Sure You Want To Proceed? All Unsaved Information Will Be Lost",#PB_MessageRequester_YesNo)
          If proceed=6
            ClearList(elements())
            SetGadgetText(#String_1,"")
            ClearGadgetItemList(#Tree_0)
            theysaved=0
          EndIf 
        Case #MENU_4
          openedfile$=OpenFileRequester("Please Specify An INI File To Open","","INI File|*.ini",0) 
          openINI(openedfile$)
        Case #MENU_5
          If theysaved=0
            saveINI()
          ElseIf theysaved=1
            justsaveINI()
          EndIf 
        Case #MENU_8
          End 
        Case 100
          selectedentry=GetGadgetState(#Tree_0)
          currentitem=GadgetItemID(#Tree_0,selectedentry)
          message1=SendMessage_(GadgetID(#Tree_0),#TVM_GETNEXTITEM ,#TVGN_CHILD,currentitem)
          If message1 =#Null
            SelectElement(elements(),selectedentry)
            DeleteElement(elements())
            RemoveGadgetItem(#Tree_0,selectedentry)
          ElseIf message1 <> #Null
            nodenumber=CountTreeGadgetNodeItems(#Tree_0,selectedentry)
            RemoveGadgetItem(#Tree_0,selectedentry)
            For a=selectedentry To selectedentry+nodenumber
              SelectElement(elements(),selectedentry)
              DeleteElement(elements())
            Next 
          EndIf 
        Case 101
          For b=0 To CountGadgetItems(#Tree_0)-1
            SetGadgetItemState(#Tree_0, b, #PB_Tree_Expanded )
          Next 
        Case 102
          For b=0 To CountGadgetItems(#Tree_0)-1
            SetGadgetItemState(#Tree_0, b, #PB_Tree_Collapsed)
          Next 
        Case #MENU_7
          saveINI()
        Case #menu_9
          *Buffer = AllocateMemory(64000) 
          SendMessage_(GadgetID(#String_1), #EM_GETSELTEXT, 0, *Buffer) 
          TextCapture$ = PeekS(*Buffer) 
          SetClipboardText(TextCapture$)
          FreeMemory(*Buffer) 
        Case #menu_10
          SendMessage_(GadgetID(#String_1),#em_setsel,0,-1)
      EndSelect 
    Case  #PB_EventGadget
      GadgetID = EventGadgetID()
      Select GadgetID 
        Case #Tree_0
          If EventType()=#PB_EventType_LeftDoubleClick
            selectedItem=GetGadgetState(#Tree_0)
            currentitem=GadgetItemID(#Tree_0,selectedItem) 
            SendMessage_(GadgetID(#Tree_0),#TVM_EDITLABEL,0,currentitem)
          ElseIf EventType()=#PB_EventType_RightClick
            DisplayPopupMenu(100,WindowID())
          EndIf 
            selectedItem=GetGadgetState(#Tree_0)
            currentitem=GadgetItemID(#Tree_0,selectedItem)
            If SendMessage_(GadgetID(#Tree_0),#TVM_GETNEXTITEM ,#TVGN_PARENT,currentitem)<>#Null
              DisableGadget(#String_2,0)
              SelectElement(elements(),selectedItem)
              SetGadgetText(#String_2,elements()\value)
            Else
              DisableGadget(#String_2,1)
              SetGadgetText(#String_2,"")
              SetGadgetText(#Text_2,GetGadgetItemText(#Tree_0,GetGadgetState(#Tree_0),0))
            EndIf 
        
        Case #Button_0
          LastElement(elements())
          AddElement(elements())
          current=ListIndex(elements())
          AddGadgetItem(#Tree_0,-1,"New Section"+ " " + Str(current))
          elements()\section=1
          elements()\key=0
          elements()\value=""
        Case #Button_1
          selectedItem=GetGadgetState(#Tree_0)
          If selectedItem=-1
          Else 
            currentitem=GadgetItemID(#Tree_0,selectedItem)
            If SendMessage_(GadgetID(#Tree_0),#TVM_GETNEXTITEM ,#TVGN_PARENT,currentitem)=#Null 
              currentselection=GetGadgetState(#Tree_0)
              currentitem=OpenTreeGadgetNode(#Tree_0,currentselection)
              itemtoadd=CountTreeGadgetNodeItems(#Tree_0, currentselection)
              AddGadgetItem(#Tree_0,currentselection+itemtoadd+1,"New Key")
              CloseTreeGadgetNode(#Tree_0,currentselection)
              SelectElement(elements(),GetGadgetState(#Tree_0)+itemtoadd)
              AddElement(elements())
              elements()\section=0
              elements()\key=1
              elements()\value=""
            EndIf 
          EndIf 
          
        Case #Button_2
          updateINI()
        Case #String_2
          If EventType()=#PB_EventType_Change 
            If CountGadgetItems(#Tree_0)=0
            Else 
              SelectElement(elements(),GetGadgetState(#Tree_0))
              elements()\value=GetGadgetText(#String_2)
            EndIf 
          ElseIf EventType()=#PB_EventType_LostFocus
            Debug "Hi"
          EndIf 
      EndSelect 
      
  EndSelect 
  
Until Event = #PB_EventCloseWindow
  
End

Posted: Fri Dec 03, 2004 5:43 pm
by TerryHough
Hi localmotion

I believe this could be a very userful tool.

May I suggest that you ask for the name of the New Section or New Key
before creating them. I don't see a way to edit them after creation.
Maybe I just missed it.

Terry

Posted: Fri Dec 03, 2004 6:14 pm
by localmotion34
double click the section or key in the treeview. treeview is EDITABLE

Posted: Fri Dec 03, 2004 6:25 pm
by TerryHough
localmotion34 wrote:double click the section or key in the treeview. treeview is EDITABLE
So it is... so easy when I see the way! Thanks, Terry

Posted: Fri Dec 03, 2004 8:33 pm
by RJP Computing
localmotion34 wrote:RJP:
yes you can modify the source, just give me some props somewhere.
You got it. Of coarse. Thanks for sharing. :D

Posted: Fri Dec 03, 2004 10:48 pm
by localmotion34
PureINI 1.1 update

Added a toolbar with the same functions as the menus.

source is now on the purestorage site too. download both if you want

PureINI 1.1
http://www.penguinbyte.com/apps/pbwebst ... or_1.1.exe

Source
http://www.penguinbyte.com/apps/pbwebst ... _Editor.pb