Help with IniRead & IniWrite to replace matched text Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Quisquose
Posts: 74
Joined: 24 Jun 2016, 04:16

Help with IniRead & IniWrite to replace matched text

04 Feb 2020, 08:38

I'm having difficulty using the IniRead and IniWrite commands to write to an ini file, and I would appreciate some help.

I would like to check a specified .ini file C:\Users\ABC\AppData\Roaming\XnViewMP\xnview.ini for a section called [Browser] and look within only that section for a line that starts with state=@ByteArray.

If the line that is found matches the text shown below, then do nothing. But if the text does not match, then replace the exisitng line with the text shown below, and then save the .ini file:

Code: Select all

state=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\0\0\0\x2\x34\0\0\x1\xfd\xfc\x2\0\0\0\x2\xfb\0\0\0\xe\0\x66\0i\0l\0t\0\x65\0r\0\x44\0\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\0\x42\0\0\x1\xfd\0\0\0\x7f\0\xff\xff\xfe\xfa\0\0\0\0\x2\0\0\0\x3\xfb\0\0\0\xe\0\x66\0o\0l\0\x64\0\x65\0r\0\x44\x1\0\0\0\0\xff\xff\xff\xff\0\0\0V\0\xff\xff\xfe\xfb\0\0\0\x12\0\x66\0\x61\0v\0o\0r\0i\0t\0\x65\0\x44\x1\0\0\0\0\xff\xff\xff\xff\xff\xff\xff\xff\0\xff\xff\xff\xfb\0\0\0\x12\0\x63\0\x61\0t\0\x65\0g\0o\0r\0y\0\x44\x1\0\0\0\0\xff\xff\xff\xff\xff\xff\xff\xff\0\xff\xff\xff\0\0\0\x3\0\0\x6\xc1\0\0\x1-\xfc\x1\0\0\0\x3\xfb\0\0\0\n\0p\0r\0\x65\0v\0\x44\x1\0\0\0\0\0\0\x2\x37\0\0\0\x87\0\xff\xff\xff\xfb\0\0\0\x16\0P\0r\0\x65\0v\0i\0\x65\0w\0\x44\0o\0\x63\0k\x1\0\0\x2<\0\0\x2\x35\0\0\0W\0\xff\xff\xff\xfc\0\0\x4v\0\0\x2K\0\0\x1:\0\xff\xff\xff\xfa\0\0\0\x1\x2\0\0\0\x2\xfb\0\0\0\b\0\x63\0\x61\0t\0\x44\0\0\0\0\0\xff\xff\xff\xff\0\0\0u\0\xff\xff\xfe\xfb\0\0\0\n\0s\0\x65\0t\0s\0\x44\x1\0\0\x1\x38\0\0\x1\t\0\0\0s\0\xff\xff\xfe\0\0\x4\x88\0\0\x1\xfd\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x2\0\0\0\x12\0T\0o\0o\0l\0\x42\0\x61\0r\0 \0\x31\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x12\0T\0o\0o\0l\0\x42\0\x61\0r\0 \0\x32\x1\0\0\x2\xdb\xff\xff\xff\xff\0\0\0\0\0\0\0\0)
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Help with IniRead & IniWrite to replace matched text  Topic is solved

04 Feb 2020, 12:43

Code: Select all

byteArray := "@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\0\0\0\x2\x34\0\0\x1\xfd\xfc\x2\0\0\0\x2\xfb\0\0\0\xe\0\x66\0i\0l\0t\0\x65\0r\0\x44\0\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\0\x42\0\0\x1\xfd\0\0\0\x7f\0\xff\xff\xfe\xfa\0\0\0\0\x2\0\0\0\x3\xfb\0\0\0\xe\0\x66\0o\0l\0\x64\0\x65\0r\0\x44\x1\0\0\0\0\xff\xff\xff\xff\0\0\0V\0\xff\xff\xfe\xfb\0\0\0\x12\0\x66\0\x61\0v\0o\0r\0i\0t\0\x65\0\x44\x1\0\0\0\0\xff\xff\xff\xff\xff\xff\xff\xff\0\xff\xff\xff\xfb\0\0\0\x12\0\x63\0\x61\0t\0\x65\0g\0o\0r\0y\0\x44\x1\0\0\0\0\xff\xff\xff\xff\xff\xff\xff\xff\0\xff\xff\xff\0\0\0\x3\0\0\x6\xc1\0\0\x1-\xfc\x1\0\0\0\x3\xfb\0\0\0\n\0p\0r\0\x65\0v\0\x44\x1\0\0\0\0\0\0\x2\x37\0\0\0\x87\0\xff\xff\xff\xfb\0\0\0\x16\0P\0r\0\x65\0v\0i\0\x65\0w\0\x44\0o\0\x63\0k\x1\0\0\x2<\0\0\x2\x35\0\0\0W\0\xff\xff\xff\xfc\0\0\x4v\0\0\x2K\0\0\x1:\0\xff\xff\xff\xfa\0\0\0\x1\x2\0\0\0\x2\xfb\0\0\0\b\0\x63\0\x61\0t\0\x44\0\0\0\0\0\xff\xff\xff\xff\0\0\0u\0\xff\xff\xfe\xfb\0\0\0\n\0s\0\x65\0t\0s\0\x44\x1\0\0\x1\x38\0\0\x1\t\0\0\0s\0\xff\xff\xfe\0\0\x4\x88\0\0\x1\xfd\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x2\0\0\0\x12\0T\0o\0o\0l\0\x42\0\x61\0r\0 \0\x31\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x12\0T\0o\0o\0l\0\x42\0\x61\0r\0 \0\x32\x1\0\0\x2\xdb\xff\xff\xff\xff\0\0\0\0\0\0\0\0)"

iniFileName := "C:\Users\ABC\AppData\Roaming\XnViewMP\xnview.ini"

IniRead, iniVar, % iniFileName, Browser, state
if (iniVar != byteArray)
    IniWrite, % byteArray, % iniFileName, Browser, state
HTH
Quisquose
Posts: 74
Joined: 24 Jun 2016, 04:16

Re: Help with IniRead & IniWrite to replace matched text

08 Feb 2020, 14:40

Thank you very much, Xtra.

The code that you provided works well, and it very clearly sets out how the command should be structured. I understand it much better now that I can see exactly which bit goes where.

However, despite this code working perfectly in a test file, I was still having problems getting it to work in practice. I therefore had to spend some time trying to figure out what the problem was.

It turns out that the ini file was being written to correctly, it's just that whenever the program was closed, it would write its current settings to the ini file (thereby over-writing the changes that my script had previously made). That's why when I relaunched the program it seemed as if the ini file had not been written to (because my changes were not retained).

I am aware of the command WinWaitClose and so I thought I'd use that to write to the ini file after the XnView program has closed. But, I want this action attached to a hotkey that toggles a page element on an off, and If I put a WinWaitClose command in that section of code, it prevents my hotkey from working more than once in the current session (for obvious reasons).

Question: Does anyone know how I can trigger WinWaitClose (just once) on the press of a hotkey (e.g. # key) so that the ini file will be written to after the program has closed, while still being able to use that same hotkey to trigger my other script command (which toggles a screen element on and off with each subsequent key press) without its toggle ability being interfered with by the inclusion of a WinWaitClose command?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, justcop, Rohwedder and 169 guests