Recent

Author Topic: Best method of storing info for application  (Read 6931 times)

criss6100

  • New Member
  • *
  • Posts: 24
Best method of storing info for application
« on: March 04, 2015, 05:56:29 pm »
I have a application that connects to a database, and has a couple of other user editable content, so storing said info I the application directly is not an option, so I tought of asking how do you guys store this info, like database connections, application options and things like that, I tought of creating a .ini or .cfg file and encript the content, is this a good method?
Any suggestions are welcomed :)

Thank you

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Best method of storing info for application
« Reply #1 on: March 04, 2015, 06:42:06 pm »
I always use an ini file, usually in the folder where the main program sits. This works in both Windows and Linux with the same code, and is not affected if the registry has problems.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Best method of storing info for application
« Reply #2 on: March 05, 2015, 12:22:17 am »
I always use an ini file, usually in the folder where the main program sits. This works in both Windows and Linux with the same code, and is not affected if the registry has problems.

use the default settings folder that both linux and windows provide. You will have problems installing in program files in vista+
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: Best method of storing info for application
« Reply #3 on: March 05, 2015, 01:14:37 pm »
I always use an ini file, usually in the folder where the main program sits. This works in both Windows and Linux with the same code, and is not affected if the registry has problems.

use the default settings folder that both linux and windows provide. You will have problems installing in program files in vista+

I agree with this.  If you have an administrator install your app and let users have access to using it, the INI file would end up in a directory they won't have write access to if you place your INI with the main program.  So you should place it in the user's directory associated with configurations.  I use the function GetAppConfigDir to find that directory and it has worked fine on both Linux and Windows.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: Best method of storing info for application
« Reply #4 on: March 05, 2015, 01:26:14 pm »
I usually use a variant of the XMLConfig unit (both FPC and Lazarus have one iirc). It is more hierarchical than INI.

I write to the local directory, since I never create installers for my software in the first place (so it will never be in an UACed location). 

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Best method of storing info for application
« Reply #5 on: March 06, 2015, 04:52:48 am »
If it is not credentials or important info then normal ini/xml/cfg will do the job. But otherwise like database connection info must be encrypted. Its up-to you.
Holiday season is online now. :-)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Best method of storing info for application
« Reply #6 on: March 06, 2015, 10:11:34 am »
The comments correcting me are quite correct. (I mentally jump back to Windows 95/98 too often.) This wiki entry is very useful: http://wiki.lazarus.freepascal.org/Deploying_Your_Application

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Best method of storing info for application
« Reply #7 on: March 06, 2015, 08:05:12 pm »
If you have a little bit to store a ini file works great, just don't store it in the same directory as the exe as others have said.
If you have a bit more to store SQLite works pretty good.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

criss6100

  • New Member
  • *
  • Posts: 24
Re: Best method of storing info for application
« Reply #8 on: March 07, 2015, 09:56:21 am »
Thank you all for helping me with this :)

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Best method of storing info for application
« Reply #9 on: March 07, 2015, 05:20:06 pm »
For working with INI files, you can use my library:
https://github.com/t-edson/ConfigFrame
It make easy to read, save an edit properties from disk.

Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: Best method of storing info for application
« Reply #10 on: March 07, 2015, 09:21:17 pm »
If it is not credentials or important info then normal ini/xml/cfg will do the job. But otherwise like database connection info must be encrypted. Its up-to you.

I encrypt such information to a single stream with dcpcrypt, base64 encode it and also put it in the XML.

Basile B.

  • Guest
Re: Best method of storing info for application
« Reply #11 on: March 07, 2015, 10:16:19 pm »
I always use TComponent streaming for the settings.
  • you can simply design you setting file by declaring some published properties: what is published is what is written
  • you can save and load with a TMemoryStream, single method call
  • the property setters are automatically called when the settings are reloaded
  • Some default values can be defined to avoid some values to be written
  • a stored function can be used to filter what will be saved or not according to the context
  • this is a core feature of the standard library so no need for 3rd part packages
  • you can declare encrypted things, plain data streams, arbitrary size array by overriding DefineProperties() and then addBinaryProperty() to the TFiler
In short: quite flexible.
« Last Edit: March 08, 2015, 08:26:19 pm by Basile B. »

bylaardt

  • Sr. Member
  • ****
  • Posts: 309
Re: Best method of storing info for application
« Reply #12 on: March 08, 2015, 12:24:04 am »
I save the encrypted data in a XML file with check flags to validate integrity and  compress the file and put him in [/home/username/].myspecialfolder/systemname
or [c:\userdir]\myspecialfolder\systemname on win

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Best method of storing info for application
« Reply #13 on: March 08, 2015, 05:30:54 am »
I save the encrypted data in a XML file
1 problem.
I save the encrypted data in a XML file with check flags to validate integrity and  compress the file
2 problems

1) never use xml. its a bullshit format even plain text files are better to edit but ini makes things clear.
2) first compress then encrypt. Because of the randomness of the encryption algorithms today you will get far better compression rates if you compress the data first and then encrypt.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

richard_rtech

  • New Member
  • *
  • Posts: 35
Re: Best method of storing info for application
« Reply #14 on: March 08, 2015, 07:13:08 pm »
1) never use xml. its a bullshit format even plain text files are better to edit but ini makes things clear.
+1. After you've lost days to making Cisco phones work properly you'll apreciate this even more.
A correctly built .ini can be made easy enough to read.

And yes, encrypt passwords, especially if lazy database admins may be encountered that use 'grant all on *' when making users.



 

TinyPortal © 2005-2018