Editing A Malformed INI File

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Editing A Malformed INI File

Post by CyberCitizen » Tue Oct 30, 2012 6:21 am

Hey Guys,

Not sure if anyone else uses SABNZBD, however I am having an issue reading the main configuration file.

I am wanting to read the file & check a field to see if it matches what I have as a VAR.

The issue is the INI file may be malformed and not being detected by MS correctly.

Code: Select all

[[free.hitnews.com]]
username = USERNAME
enable = 1
name = free.hitnews.com
fillserver = 1
connections = 30
ssl = 1
host = free.hitnews.com
timeout = 120
password = PASSWORD
optional = 0
port = 563
retention = 850
Above is the INI file notice the double [[ brackets as well as the space before and after the =.

I have tried a few things but my MS returns a blank field. Please help.
FIREFIGHTER

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Oct 30, 2012 9:37 am

It's not a valid INI file format so the built in INI file functions won't work with it. I guess you could use ReadFile and then RegEx instead.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Oct 30, 2012 11:42 pm

What makes it invalid. I suspect that was the case, I don't understand why I can't call the additional characters.

eg

Code: Select all

ReadIniFile>FilePATH,[free.hitnews.com],username ,Result
Shouldn't that work?
FIREFIGHTER

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Oct 31, 2012 9:31 am

ReadIniFile calls this Windows API function:

GetPrivateProfileString

http://msdn.microsoft.com/en-us/library ... s.85).aspx

So I can't look at the source and tell you technically why it fails to find the section name/entry in your INI file example. But we can probably guess: it just doesn't match the format/pattern that GetPrivateProfileString looks for.

Sorry if this answer isn't good enough. Someone at Microsoft might have a better explanation. But it's academic really. It just doesn't work in this case, so use an alternative.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Thu Nov 15, 2012 3:57 am

I have had a look at RegEx, although I am stumped at how I can look for the text inbetween the 2x tags and replace it as that text will change.

What I am after is a way of monitoring what is inbetween those logon tags and if it changes the script I have pulls the latest logon info from the site & updates it.
FIREFIGHTER

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Nov 15, 2012 1:46 pm

Which part do you want to read out and modify?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri Nov 16, 2012 1:29 am

Marcus Tettmar wrote:Which part do you want to read out and modify?
Hi Marcus,

The text fields in capitals (USERNAME & PASSWORD).

I have a script that already monitors a site for changes, however I need to have it check against those fields and if its different write the new username to that ini file.
FIREFIGHTER

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

hello

Post by PepsiHog » Sat Nov 17, 2012 4:29 pm

@CyberCitizen

The great thing about ini files is that the program will only pay attention to the information it is looking for. So we can take advantage of this and add our own Sections to the ini file.

What we want is to copy the Sections we want information from and then re-write the Section(s) with the format we need. This macro just reads the entire ini for all Sections. Replaces [[ with [ and ]] with ]. Then it adds the newly formed sections to the ini. You can now retreive your data.

To make it easier, you could write the new Sections into your own ini. Once you have the info needed, just delete the new ini file.

BTW - The spacing between the equal sign(=) does not matter.

Code: Select all

let>FPath=%Desktop_Dir%

ExportData>TEST.INI_DATA,%FPath%\Test.ini

GoSub>AddValid

mdl>The password is : %strValue%

srt>AddValid
ReadFile>%FPath%\test.ini,File
StringReplace>File,[[,[,File
StringReplace>File,]],],File
// add some empty lines for spacing between lines in file.
let>File=%crlf%%crlf%%crlf%%crlf%%File%
// add your valid entries to ini.
writeln>%FPath%\test.ini,wtf,%File%
// read new entry
ReadIniFile>%FPath%\test.ini,free.hitnews.com,password,strValue
END>AddValid


/*
TEST.INI_DATA:
5B5B667265652E6869746E6577732E636F6D5D5D0D0A70617373776F7264203D206E65775F70617373776F72640D0A0D0A0D0A0D0A5B5B4F746865722E696E76616C6964735D5D0D0A7768617465766572203D206F746865725F64617461
*/
Hope this is useful.
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Nov 20, 2012 6:26 am

Thanks PepsiHog,

That is exactly what I need. That allows me to make the changes & replace the file if it changes. Thank you so much, can't believe I didn't think of the good old string replace.
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts