INI File Helper

Post your working scripts, libraries and tools
User avatar
Delta Pythagorean
Posts: 423
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

INI File Helper

12 Jul 2017, 00:58

I think some newish people to AHK could use this tool to help write their scripts.
So, some of these new people (Or lazy coders, I'm not judging.) might want to use this.
So here it is!
The INI File Helper!

Here's the code. Make sure to keep the whole code for it to work!

Code: Select all

/*
      /=========|
     /          |
    /  HH   HH  |
    |  HH   HH  |
    |  HHHHHHH  |
    |  HH   HH  |
    |  HH   HH  |
    |           |
    |===========|

	AutoHotkey Version:				1.1.26.00
	Language:						English
	Platform:						Win XP, Win 7, Win 8.1, Win 10
	Author:							Delta
	Contact information:			octalblockmc@gmail.com

	|=======================================================|
	|	Hotkeys:											|
	|		None											|
	|=======================================================|
*/

#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
#NoTrayIcon
; #Include <Notify>		; Personal Library, unneeded here.
Process, Priority,, H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode, Input
Menu, Tray, Icon, %A_AHKPath%, 2
; Even though NoTrayIcon is set,
; it still sets the Gui's Icon to be the white file with the capital H

Gui, INI: -MinimizeBox
Gui, INI:Add, Tab3, x0 y0 w470 h330 +0x2, Write|Read

Gui, INI:Tab, Write, 1
Gui, INI:Font,, Segoe UI
Gui, INI:Add, GroupBox, x10 y15 w435 h50, The Text or Variable to Write [Be sure to add the `% signs acordingly!]
Gui, INI:Add, Edit, x20 y35 w415 h20 vOutA, `%Var`%
Gui, INI:Add, GroupBox, x10 y70 w435 h50, The File to Write in
Gui, INI:Add, Edit, x20 y90 w330 h20 vFileA, %A_Desktop%\Config.ini
Gui, INI:Add, Button, x360 y90 w75 h23 vFileSelectA gSelectA, Select File
Gui, INI:Add, GroupBox, x10 y125 w435 h50, The Category to Write in
Gui, INI:Add, Edit, x20 y145 w415 h20 vCatA, Settings
Gui, INI:Add, GroupBox, x10 y180 w435 h50, The Key to Write to
Gui, INI:Add, Edit, x20 y200 w415 h20 vKeyA, KeyA
Gui, INI:Add, Button, x375 y275 w70 h25 gUpdate, Update
Gui, INI:Font,, Consolas
Gui, INI:Add, Edit, x15 y250 w430 h20 vUPWrite ReadOnly

Gui, INI:Tab, Read, 1
Gui, INI:Font,, Segoe UI
Gui, INI:Add, GroupBox, x10 y15 w435 h50, The Text or Variable to Read [There's no need for the `% signs here.]
Gui, INI:Add, Edit, x20 y35 w415 h20 vOutB, Var
Gui, INI:Add, GroupBox, x10 y70 w435 h50, The File to Read From
Gui, INI:Add, Edit, x20 y90 w330 h20 vFileB, %A_Desktop%\Config.ini
Gui, INI:Add, Button, x360 y90 w75 h23 vFileSelectB gSelectB, Select File
Gui, INI:Add, GroupBox, x10 y125 w435 h50, The Category to Read From
Gui, INI:Add, DDL, x20 y145 w415 h200 vCatB, Settings||
Gui, INI:Add, GroupBox, x10 y180 w435 h50, The Key to Read From
Gui, INI:Add, Edit, x20 y200 w415 h20 vKeyB, KeyA
Gui, INI:Add, Button, x375 y275 w70 h25 gUpdate, Update
Gui, INI:Font,, Consolas
Gui, INI:Add, Edit, x15 y250 w430 h20 vUPRead ReadOnly
Gui, INI:Show, w465 h335, INI File Helper
GoSub, Update
Return

Update:
Gui, INI:Submit, NoHide
GuiControl INI:, UPWrite, % "IniWrite, " OutA ", " FileA ", " CatA ", " KeyA
GuiControl INI:, UPRead , % "IniRead, "  OutB ", " FileB ", " CatB ", " KeyB
Return

SelectA:
FileSelectFile, FileA, 8, %A_Desktop%\, Please Create an INI File to Use., Configuration Files (*.ini)
GuiControl, INI:, FileA, % FileA
Return

SelectB:
FileSelectFile, FileB, 8, %A_Desktop%\, Please Create an INI File to Use., Configuration Files (*.ini)
SplitPath, % FileB,,, OutExtension
If (ErrorLevel or (OutExtension != "ini"))
	Return
GuiControl, INI:,FileB, % FileB
IniRead, OutputVarSectionNames, % FileB ; retrieves a linefeed (`n) delimited list of section names
GuiControl, INI:,CatB, % "|" StrReplace(OutputVarSectionNames, "`n", "|") ; fill the drop down list with the section names of the selected ini file
GuiControl, INI:Choose, CatB, 1
Return

Close:
INIGuiClose:
ExitApp
Return
I also added a little AHK Icon for you to enjoy ;)
Last edited by Delta Pythagorean on 13 Jul 2017, 22:15, edited 1 time in total.
User avatar
metacognition
Posts: 87
Joined: 22 Oct 2014, 05:57
Location: Alaska

Re: INI File Helper

12 Jul 2017, 02:12

Nice icon :)
User avatar
metacognition
Posts: 87
Joined: 22 Oct 2014, 05:57
Location: Alaska

Re: INI File Helper

12 Jul 2017, 02:16

Dang, this will come in handy!
User avatar
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: INI File Helper

12 Jul 2017, 10:27

neat! Thanks for sharing
A_AhkUser
Posts: 884
Joined: 06 Mar 2017, 16:18
Location: France

Re: INI File Helper

12 Jul 2017, 20:19

One suggestion among others possible:

You could make the catB edit control to be a dropdownlist:

Code: Select all

Gui, INI:Add, DropDownList, x20 y145 w415 vCatB,
since you can retrieve a linefeed (`n) delimited list of section names, once an ini file is choosen:

Code: Select all

SelectB:
FileSelectFile, FileB, 8, %A_Desktop%\, Please Create an INI File to Use., Configuration Files (*.ini)
SplitPath, % FileB,,, OutExtension
if (ErrorLevel or (OutExtension <> "ini"))
return
GuiControl, INI:, FileB, % FileB
IniRead, OutputVarSectionNames, % FileB ; retrieves a linefeed (`n) delimited list of section names
GuiControl, INI:, CatB, % "|" . StrReplace(OutputVarSectionNames, "`n", "|") ; fill the drop down list with the section names of the selected ini file
GuiControl, INI:Choose, CatB, 1
Return
User avatar
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: INI File Helper

12 Jul 2017, 21:23

The original was able to handle drag-n-drop onto the script's file icon - I like that better than using the file-browser dialogue.
User avatar
Delta Pythagorean
Posts: 423
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

Re: INI File Helper

13 Jul 2017, 22:14

A_AhkUser wrote: One suggestion among others possible:
Alright, I just added it to the original code for download.
Thanks for the suggestion!
A_AhkUser
Posts: 884
Joined: 06 Mar 2017, 16:18
Location: France

Re: INI File Helper

14 Jul 2017, 09:30

I just noticed running your updated script that, however, this way, it doesn't update the UPRead edit control. Actually, this can be solved by, for example, associating the dropdownlist with the update label as well:

Code: Select all

Gui, INI:Add, DDL, x20 y145 w415 h200 vCatB gUpdate, Settings||
and by making the param3 parameter of the GuiControl, Choose sub-command actually trigger the g-label associated, using the pipe character:

Code: Select all

SelectB:
; ...
GuiControl, INI:Choose, CatB, |1
Return
joefiesta
Posts: 197
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: INI File Helper

17 Feb 2018, 10:44

what does this code do? Would you expect me to read the source code for Windows to learn how Windows works?

After having written code for over 40 years, I've learned the value of documenting what I write--even when it is only for myself.
Especially when that 40 year old code still works perfectly fine!
User avatar
Delta Pythagorean
Posts: 423
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

Re: INI File Helper

23 Feb 2018, 00:27

joefiesta wrote:what does this code do? Would you expect me to read the source code for Windows to learn how Windows works?

After having written code for over 40 years, I've learned the value of documenting what I write--even when it is only for myself.
Especially when that 40 year old code still works perfectly fine!
I strongly dislike to use comments in my code unless it is to "remove" something from my code, or for a temporary "balance" in my code.
If I ever do add comments to my code, most likely it's for some complicated class/function that needs a bit of explaining to do.

If anything, with 40+ years of coding experience, you should know to read into the code itself and see what commands does what and why the programmer chose the parameters that they did.

This code was meant for the newer people that just simply need a bit of help with some daily commands to use. I personally don't need it as for I use JSON (I prefer not to use XML as for the large file sizes) to do my saving and reading when it comes to user set variables/"save for later" variables.

TL;DR:
I really don't understand what all the fuss is all about, I'm simply allowing users to use my code for which I have made. If they want to look into the source code, they may want to see how it works, but AHK already allows to see what commands are being executed, line by line, using this command: ListLines.
User avatar
gregster
Posts: 1494
Joined: 30 Sep 2013, 06:48

Re: INI File Helper

23 Feb 2018, 00:43

I think Joe's point might rather be that your original post doesn't state what your script actually does. A "helper" can be a lot of things. At least, this is what I thought when I first read this thread. Is it a library, a class, functions, a GUI of some kind, can I read and/or write ini files? What are the features?

I still don't know what your script does, partly because I don't feel a personal need for a "helper". But I might be wrong - a INI library would be useful, even if there are already others.
I would probably be able to understand the script by reading the source code - but then again, a beginner might not be. Therefore, I would welcome a little description of the actual goal of this script and what it does - because it could make this forum better.

edited
kunkel321
Posts: 166
Joined: 30 Nov 2015, 21:19
Facebook: https://www.facebook.com/kunkel321
Google: kunkel321

Re: INI File Helper

24 Feb 2018, 19:00

Cool thanks! I will likely use this!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: robodesign and 45 guests