Preference files...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Preference files...

Post by Joakim Christiansen »

The original INI file:
// Some INI files uses comments like this

And even just like this!

[Group1]
Number = 10

[Group2]
Number = 20

; And pure basic use comments like this in INI files
; But it please don't make it mess up the whole file like it does now!
The same file after I changed the value of Number in Group1:
// Some INI files uses comments like this =
And even just like this! =
[Group1]
Number = 99
[Group2]
Number = 20
; And pure basic use comments like this in INI files
; But it please don't make it mess up the whole file like it does now!
Does it really have to trash the whole INI file? :lol:
Please just fix this... <-- that was the feature request
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

The same file after I changed the value of Number in Group1:
o_O
Please just fix this... <-- that was the feature request
:)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

It's not fun making a INI editor for a game when the INI file looks like it was raped after I changed a value in it! :lol:
I know it's a stupid request, but I think it should be easy to fix.
maw

Post by maw »

If it's a windows program I suggest you use the WinAPI to modify INI-files that is created by other programs to avoid this kind of problems. I use them myself in a couple of programs that needs to modify the INI-file for UT2004, which does NOT like being modified by PB :D

This is a link to all available functions: http://msdn.microsoft.com/library/defau ... ctions.asp

Code: Select all

BOOL WritePrivateProfileString(
  LPCTSTR lpAppName,
  LPCTSTR lpKeyName,
  LPCTSTR lpString,
  LPCTSTR lpFileName
);
It's very easy to use. Just one single line of code:

Code: Select all

WritePrivateProfileString_(@"Section", @"Key", @"Value", @"ini-file.ini")
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

You saved the day maw, thank you! :D
Post Reply