Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-06

GetAppConfigFileUTf8

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Suppose I'm using
FConfigFileName:=GetAppConfigFileUTF8(false);
to get a config file for my application.

The help for GetAppConfigFile says you can't rely on the file/directory being there so I assumed it would be the same for the UTF8 version.

On Windows Vista, no problems. A user with XP says the directory C:\Documents and Settings\<username>\Local Settings\Application Data\<application name>
didn't exist.
Once he created the <application name> directory, it worked.

I changed the code to this:
  // Make sure the directory exists. Let's hope
  // GetappConfigDirUTF8 and the file version give the same directory.
  ForceDirectoriesUTF8(GetAppConfigDirUTF8(false));
  FConfigFileName:=GetAppConfigFileUTF8(false);

... is this how it is supposed to work?

Wouldn't it be easier to have another function that just gives a guaranteed to exist filename?

Reply by email

Mattias Gaertner
to Reinier Olislagers
Show quoted text 20 lines
Suppose I'm using FConfigFileName:=GetAppConfigFileUTF8(false); to get a config file for my application. The help for GetAppConfigFile says you can't rely on the file/directory being there so I assumed it would be the same for the UTF8 version. On Windows Vista, no problems. A user with XP says the directory C:\Documents and Settings\<username>\Local Settings\Application Data\<application name> didn't exist. Once he created the <application name> directory, it worked. I changed the code to this: // Make sure the directory exists. Let's hope // GetappConfigDirUTF8 and the file version give the same directory. ForceDirectoriesUTF8(GetAppConfigDirUTF8(false)); FConfigFileName:=GetAppConfigFileUTF8(false); ... is this how it is supposed to work?

Yes.

Wouldn't it be easier to have another function that just gives a guaranteed to exist filename?

Do you mean a function that automatically creates the file and if it fails raises an exception?

Mattias

Reply by email

Reinier Olislagers
to Mattias Gaertner
Mattias Gaertner wrote 27 lines
On Mon, 25 Jun 2012 18:14:54 +0200 Reinier Olislagers wrote: > Suppose I'm using > FConfigFileName:=GetAppConfigFileUTF8(false); > to get a config file for my application. > <snip> > A user with XP says the directory > C:\Documents and Settings\<username>\Local Settings\Application > Data\<application name> > didn't exist. > > I changed the code to this: > // Make sure the directory exists. Let's hope > // GetappConfigDirUTF8 and the file version give the same directory. > ForceDirectoriesUTF8(GetAppConfigDirUTF8(false)); > FConfigFileName:=GetAppConfigFileUTF8(false); > > ... is this how it is supposed to work? Yes. > Wouldn't it be easier to have another function that just gives a > guaranteed to exist filename? Do you mean a function that automatically creates the file and if it fails raises an exception?

I think that would indeed be a good solution...

Reply by email

Mattias Gaertner
to Reinier Olislagers
Show quoted text 30 lines
On 26-6-2012 10:06, Mattias Gaertner wrote: > On Mon, 25 Jun 2012 18:14:54 +0200 > Reinier Olislagers wrote: > >> Suppose I'm using >> FConfigFileName:=GetAppConfigFileUTF8(false); >> to get a config file for my application. >> <snip> >> A user with XP says the directory >> C:\Documents and Settings\<username>\Local Settings\Application >> Data\<application name> >> didn't exist. >> >> I changed the code to this: >> // Make sure the directory exists. Let's hope >> // GetappConfigDirUTF8 and the file version give the same directory. >> ForceDirectoriesUTF8(GetAppConfigDirUTF8(false)); >> FConfigFileName:=GetAppConfigFileUTF8(false); >> >> ... is this how it is supposed to work? > > Yes. > >> Wouldn't it be easier to have another function that just gives a >> guaranteed to exist filename? > > Do you mean a function that automatically creates the file and if > it fails raises an exception? I think that would indeed be a good solution...

I added a parameter.

Mattias

Reply by email

Reinier Olislagers
to Mattias Gaertner
Mattias Gaertner wrote 7 lines
On Tue, 26 Jun 2012 10:11:56 +0200 Reinier Olislagers wrote: > On 26-6-2012 10:06, Mattias Gaertner wrote: >> On Mon, 25 Jun 2012 18:14:54 +0200 >> Reinier Olislagers wrote: >>> Suppose I'm using >>> FConfigFileName:=GetAppConfigFileUTF8(false);

<snip>

Show quoted text 13 lines
>>> >>> I changed the code to this: >>> // Make sure the directory exists. Let's hope >>> // GetappConfigDirUTF8 and the file version give the same directory. >>> ForceDirectoriesUTF8(GetAppConfigDirUTF8(false)); >>> FConfigFileName:=GetAppConfigFileUTF8(false); >>> Wouldn't it be easier to have another function that just gives a >>> guaranteed to exist filename? >> >> Do you mean a function that automatically creates the file and if >> it fails raises an exception? I added a parameter.

Thanks, Mattias... I'll test it once trunk builds again ;)

Reply by email