[Implemented] WritePreference() should be without spaces

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

[Implemented] WritePreference() should be without spaces

Post by eJan »

I have problems when I have tried to modify Maxthon 'config.ini' where Version should be writen without spaces like in all other .ini files.

Code: Select all

[Settings]
Language=English
language_file=
Version=1.5.9
But PB write only like. When program read its .ini file it fails. Actualy not a bug.

Code: Select all

[Settings]
Language = English
language_file = 
Version = 1.5.9
My replacement to modify config.ini without spaces:

Code: Select all

  OpenFile(0, path + "\Config\config.ini")
  While Eof(0) = 0
    loc = Loc(0)
    fnd_string.s = ReadString(0)
    If Left(fnd_string, 8) = "Version="
      FileSeek(0, loc)
      WriteStringN(0, "Version=" + short_ver)
      Break
    EndIf
  Wend
  CloseFile(0)
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

I'd also appreciate it, if this works without spaces... IMHO this was requested several times before...
PB 4.30

Code: Select all

onErrorGoto(?Fred)
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post by horst »

AND51 wrote:I'd also appreciate it, if this works without spaces... IMHO this was requested several times before...
... and it should make an empty line after each section.. it's a widespread custom.
Horst.
maw

Post by maw »

This can be easily done with WinAPI! See my post in this thread: http://www.purebasic.fr/english/viewtopic.php?t=27023

Basically to write a value all you need is this:

Code: Select all

WritePrivateProfileString_(@"Section", @"Key", @"Value", @"ini-file.ini")
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

horst wrote:
AND51 wrote:I'd also appreciate it, if this works without spaces... IMHO this was requested several times before...
... and it should make an empty line after each section.. it's a widespread custom.
Actually, your're right. But removing the spaces is more important at the moment!


> This can be easily done with WinAPI
Haha, but this is not Linux compatible; IMHO the PB Team tries to only implement new features that are useful for all platforms.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

AND51 wrote:> This can be easily done with WinAPI
Haha, but this is not Linux compatible; IMHO the PB Team tries to only implement new features that are useful for all platforms.
INI != Prefs
INI only on windows available and easy to use with API

pref a linux compatible without problems, what is the problem. Write INI with
the right function, not with the preference-lib

With spaces looks better than without
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
maw

Post by maw »

AND51 wrote:Haha, but this is not Linux compatible; IMHO the PB Team tries to only implement new features that are useful for all platforms.
Not sure what you found so funny, perhaps your sence of humour is a bit warped? :roll:

I was replying to the author of this thread. His question was about modifying an ini-file for Maxthon, which is a Windows program. And it could be solved with a one line of code. What's the problem?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

> With spaces looks better than without
It does not have anything to do with its looking, but with compatibility with non-PB programs.

@ maw:
Sorry, then I misunderstood you. I thought you were responding to the whole thread (me inclusive).
PB 4.30

Code: Select all

onErrorGoto(?Fred)
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

maw wrote:This can be easily done with WinAPI! See my post in this thread: http://www.purebasic.fr/english/viewtopic.php?t=27023

Basically to write a value all you need is this:

Code: Select all

WritePrivateProfileString_(@"Section", @"Key", @"Value", @"ini-file.ini")
Thanks to all!
I didn't know for API function: http://msdn2.microsoft.com/en-us/library/ms725501.aspx
Going to use API until PB Win problem has been corrected?.
maw

Post by maw »

eJan wrote:Going to use API until PB Win problem has been corrected?.
It's not a problem/bug that needs correcting. It's doing exactly what it's supposed to do. Though some will argue with Fred whether it is the right way to do it. Me being one of them :lol: But I think there are far more important things to implement so I simply get around these little things any way I can.
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post by horst »

Has anyone tested the performance of WritePrivateProfileString_() on USB flash drives? It may take several seconds to write a small INI file (just tested with a 128 Mb FAT32 flash drive).

After users complained that one of my programs took 10 seconds to close on a flash drive, I abandoned the M$ functions.
Horst.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: WritePreference() should be without spaces ' = ' <> '=

Post by Michael Vogel »

Spaces are still here, I know :wink:

But I didn't know, that also an empty line will be done when doing this...

Code: Select all

OpenPreferences("Reader.ini")

	PreferenceGroup("Reader")
	For i=0 To 5
		WritePreferenceInteger(StringField("Case.Match.Time.Path.Show.Hide",i+1,"."),i)
	Next i

	ClosePreferences()

moogle
Enthusiast
Enthusiast
Posts: 372
Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK

Re: WritePreference() should be without spaces ' = ' <> '=

Post by moogle »

I asked too but no changes :)

http://www.purebasic.fr/english/viewtop ... =3&t=31617


anyway since I just saw this thread I posted some code that you might be able to use here

http://www.purebasic.fr/english/viewtop ... 12&t=45532
Image
Post Reply