; VisualINI 2.1 - by Titan EnvGet, temp, appdata FileCopy, %temp%\WindowSizing.ini, %A_Temp%\WindowSizing.ini, 1 #NoEnv #NoTrayIcon #SingleInstance ignore SetControlDelay, -1 AutoTrim, Off title = VisualINI EnvGet, settings, AppData settings = %settings%\%title%.ini IniRead, file, %settings%, Main, File, %A_Space% Menu, Tray, Icon, shell32.dll, 70 Gui, +Resize Gui, Font, , Tahoma Gui, Add, Tab, vTab x0 y0 w0 h0, Start|Edit Gui, Tab, Start Gui, Add, Text, Section xm ym+5, Open an existing file or create a new one to begin... Gui, Add, Text, Section xm ys+40, File: Gui, Add, Edit, vFileE ys-2 w395 r1 0x400 gFileE, %file% Gui, Add, Button, vFileB ys h20 gFileBrowse, &... Gui, Add, Button, vFileN Section xm ys+50 w50 gFileNew, &New Gui, Add, Text, ys+5, Create a new file at the specified location Gui, Add, Button, vFileO Section xm w50 gFileOpen, &Open Gui, Add, Text, ys+5, Edit the existing file Gui, Tab, Edit Gui, Add, Text, Section xm ym+5, Sections: Gui, Add, ListBox, vSec w100 h175 HScroll gSubParse Gui, Add, Text, ys, Values: Gui, Add, ListView, vLV w350 h175 AltSubmit gLV, Key|Value Gui, Add, Button, vSecP Section xm w20 h20 gSecP, + Gui, Add, Button, vSecM Section xs+22 ys w20 h20 gSecM, - Gui, Add, Button, vSecRe xs+22 ys h20 gSecRe, &Rename Gui, Add, Text, vValEL Section xm+110 ys+5, Value: Gui, Add, Edit, vValE ys-2 w255 h18 gValE Gui, Add, Button, vValP Section ys-2 w20 h20 gValP, + Gui, Add, Button, vValM xs+23 ys w20 h20 gValM, - Gui, Add, Button, vFileC x425 ym h20 w45 gFileClose, C&lose Gui, Tab Gui, Add, StatusBar SB("Start", 177) ctrl = FileE,FileB,Sec,LV,SecP,SecM,SecRe,ValEL,ValE,ValP,ValM,FileC Loop, Parse, ctrl, `, GuiControlGet, %A_LoopField%_, Pos, %A_LoopField% GuiControl, Focus, Static1 Gui, Show, , %title% Gui, +LastFound WinID := WinExist() GroupAdd, WinID, ahk_id %WinID% FileE: temp := Get("FileE") SplitPath, temp, , dir If FileExist(temp) GuiControl, +Default, FileO Else If FileExist(dir) GuiControl, +Default, FileN Else GuiControl, +Default, FileB IniWrite, %temp%, %settings%, Main, File Return GuiDropFiles: If (A_GuiControl = "FileE") { Loop, Parse, A_GuiControlEvent, `n If (A_Index = 1) { Set("FileE", A_LoopField) Break } } Return SubParse: SubParse(file) Return FileBrowse: file := Get("FileE") SplitPath, file, name, dir If FileExist(dir) If FileExist(file) temp = %file% Else temp = %dir% Else temp = %A_MyDocuments% Gui, +OwnDialogs FileSelectFile, filex, S2, %temp%, %title% - Select file..., Configuration Settings (*.ini`; *.inf`; *.txt) If !filex Return SplitPath, filex, , , ext If !ext file = %filex%.ini Else file = %filex% GuiControl, Focus, FileE Set("FileE", file) Goto, FileE Return FileNew: file := Get("FileE") If FileExist(file) { Gui, +OwnDialogs MsgBox, 36, Overwrite file?, Do you wish to overwrite the file? IfMsgBox, No Return } FileDelete, %file% FileOpen: file := Get("FileE") FileSet: FileAppend, , %file% If ErrorLevel { Gui, +OwnDialogs MsgBox, 16, Invalid file/path, Please specify a valid file. Return } IniWrite, %file%, %settings%, Main, File Parse(file) SB_SetParts(125) SB_SetText(file, 2) SplitPath, file, name Gui, Show, , %name% - %title% Set("Tab", "|Start|Edit||") Return FileClose: Set("Tab", "|Start||Edit") SB_SetParts() SB("Closed file", 132) Return SecP: SecSet("Add", file) Return SecM: SecSet("Delete", file) Return SecRe: SecSet("Rename", file) Return LV: If A_GuiEvent = I Return Set("ValE") If LV_GetCount("Selected") > 1 or !LV_GetCount("Selected") GuiControl, Disable, ValE Else { GuiControl, Enable, ValE If !LV_GetNext(0) Return LV_GetText(temp, LV_GetNext(0), 2) Set("ValE", temp) } Return ValE: GuiControlGet, f, FocusV If (f != "ValE") Return ValSet("Update", file) GuiControlGet, temp, Enabled, ValE If LV_GetCount("Selected") = 1 and !temp GuiControl, Enable, ValE Else If LV_GetCount("Selected") < 1 or LV_GetCount("Selected") > 1 and temp { GuiControl, Disable, ValE Set("ValE") } Return ValP: ValSet("Add", file) Return ValM: ValSet("Delete", file) Return GuiSize: If !GS { Gui, +LastFound WinGetPos, , , gW, gH OnMessage(0x24, "WM_GETMINMAXINFO") GS := true } Anchor("FileE", "", "", FileE_W) Anchor("FileB", FileB_X) Anchor("Sec", "", "", "", Sec_H) Anchor("LV", "", "", LV_W, LV_H) Anchor("SecP", "", SecP_Y, "", "", true) Anchor("SecM", "", SecM_Y, "", "", true) Anchor("SecRe", "", SecRE_Y, "", "", true) Anchor("ValEL", "", ValEL_Y, "", "", true) Anchor("ValE", "", ValE_Y, ValE_W) Anchor("ValP", ValP_X, ValP_Y, "", "", true) Anchor("ValM", ValM_X, ValM_Y, "", "", true) Anchor("FileC", FileC_X, "", "", "", true) Loop, 2 LV_ModifyCol(A_Index, "AutoHdr") Return SecSet(act, file) { Critical If (act = "Add") { Gui, +OwnDialogs InputBox, new, New section, Enter the name of the new section:, , , 125 If new { skey = _TODELETE[%A_Now%] IniWrite, %A_Now%, %file%, %new%, %skey% IniDelete, %file%, %new%, %skey% Parse(file) SB("Section added", 67) } Else SB("Cancelled new key", 110) } Else If (act = "Delete") { IniDelete, %file%, % Get("Sec") Parse(file) SB("Section deleted", 132) } Else If (act = "Rename") { Gui, +OwnDialogs InputBox, new, Rename section, Rename section to:, , , 125, , , , , % Get("Sec") If new { FileRead, c, %file% r := InStr(c, "`r") StringReplace, c, c, `r, , All s := Get("Sec") StringReplace, c, c, `n[%s%]`n, `n[%new%]`n If r StringReplace, c, c, `n, `r`n, All FileDelete, %file% FileAppend, %c%, %file% Parse(file) SB("Section renamed", 75) } } } ValSet(act, file) { Critical If (act = "Update") { LV_GetText(key, LV_GetNext(0), 1) IniRead, value, %file%, % Get("Sec"), %key%, %A_Space% If Get("ValE") != value { IniWrite, % Get("ValE"), %file%, % Get("Sec"), %key% LV_Modify(LV_GetNext(0), "", key, Get("ValE")) ; causes value to go to the beginning SB("Value updated", 58) } } Else If (act = "Add") { GuiControl, -Redraw, LV Gui, +OwnDialogs InputBox, new, New key, Enter the name of the new key:, , , 125 If new { Loop, % LV_GetCount() { LV_Modify(A_Index, "-Select") LV_GetText(key, A_Index, 1) If (key = new) { found := true LV_Modify(A_Index, "Select") LV_GetText(value, A_Index, 2) Set("ValE", value) } } If !found { LV_Add("Select Focus", new) IniWrite, %A_Space%, %file%, % Get("Sec"), %new% Set("ValE") } GuiControl, Focus, ValE SB("Added key", 67) } Else SB("Cancelled new key", 110) GuiControl, +Redraw, LV } Else If (act = "Delete") { GuiControl, -Redraw, LV Loop, % LV_GetCount("Selected") { LV_GetText(key, LV_GetNext(0), 1) LV_GetText(value, LV_GetNext(0), 2) LV_Delete(LV_GetNext(0)) sig = _TODELETE[%A_NOW%] IniWrite, %sig%, %file%, % Get("Sec"), %key% FileRead, c, %file% StringReplace, c, c, `r`n%key%=%sig% StringReplace, c, c, `n%key%=%sig% FileDelete, %file% FileAppend, %c%, %file% } GuiControl, +Redraw, LV SB("Deleted key", 132) } } Parse(file) { Critical If !FileExist(file) Return, true SB("Parsing file...", 166) FileAppend, , %file% FileRead, c, *t %file% Loop, Parse, c, `n If InStr(A_LoopField, "]") { StringLeft, f, A_LoopField, 1 If f != [ Continue StringMid, item, A_LoopField, 2, StrLen(A_LoopField) - 2 If item items = %items%|%item% } Set("ValE") Set("Sec", items) SubParse(file) SB("Loaded file", 35) Return, items } SubParse(file) { Critical SB("Parsing content...", 166) LV_Delete() s := Get("Sec") If (s = "") { GuiControl, Choose, Sec, 1 s := Get("Sec") } FileRead, c, *t %file% c = `n%c%`n[] StringTrimLeft, c, c, InStr(c, "`n[" . s . "]`n") - 1 + StrLen("`n[" . s . "]`n") StringLeft, c, c, InStr(c, "`n[") - 1 GuiControl, -Redraw, LV Loop, Parse, c, `n { StringLeft, f, A_LoopField, 1 If !InStr(A_LoopField, "=") or f = ";" or f = "[" or A_LoopField = "" Continue StringLeft, key, A_LoopField, InStr(A_LoopField, "=") - 1 StringTrimLeft, value, A_LoopField, InStr(A_LoopField, "=") If !(key = "" and value = "") LV_Add("", key, value) } LV_Modify(1, "Select") Loop, 2 LV_ModifyCol(A_Index, "AutoHdr") Set("ValE") LV_GetText(val, LV_GetNext(0), 2) If LV_GetCount() { Set("ValE", val) GuiControl, Enable, ValE } Else GuiControl, Disable, ValE GuiControl, +Redraw, LV SB("Content updated", 134) } Set(ctrl, text = "") { GuiControl, , %ctrl%, %text% } Get(ctrl, text = false) { If text GuiControlGet, v, , %ctrl%, Text Else GuiControlGet, v, , %ctrl% Return, v } SB(text, icon = 0) { SB_SetText(text) If icon SB_SetIcon("shell32.dll", icon) } Anchor(Control, x = "", y = "", w = "", h = "", Draw = 0) { ; by Titan global GuiW, GuiH IfEqual, GuiW, , SetEnv, GuiW, %A_GuiWidth% IfEqual, GuiH, , SetEnv, GuiH, %A_GuiHeight% pos = xywh Loop, Parse, pos If (%A_LoopField% != "") { If A_LoopField in x,w v := %A_LoopField% + (A_GuiWidth - GuiW) Else v := %A_LoopField% + (A_GuiHeight - GuiH) move := move . A_LoopField . v } IfNotEqual, Draw, 0, SetEnv, MDraw, Draw GuiControl, Move%MDraw%, %Control%, %move% Return, ErrorLevel } WM_GETMINMAXINFO(wParam, lParam) { global gW,gH If (not A_Gui) Return InsertIntegerAtAddress(gW, lParam, 24, 4) InsertIntegerAtAddress(gH, lParam, 28, 4) Return 0 } InsertIntegerAtAddress(pInteger, pAddress, pOffset = 0, pSize = 4) { mask := 0xFF Loop %pSize% { DllCall("RtlFillMemory", UInt, pAddress + pOffset + A_Index - 1, UInt, 1, UChar, (pInteger & mask) >> 8 * (A_Index - 1)) mask := mask << 8 } } GuiClose: ExitApp Return #IfWinActive ahk_group WinID ~*-:: ~*NumpadSub:: ~*Del:: ~*+=:: ~*NumpadAdd:: If A_ThisHotkey in ~*+=,~*NumpadAdd act = P Else act = M GuiControlGet, f, FocusV If f = LV Goto, Val%act% Else If f = Sec Goto, Sec%act% Return #IfWinActive