Home » U++ Library support » U++ Core » Configurations [Solved]
Configurations [Solved] [message #55060] |
Wed, 07 October 2020 19:27  |
jimlef
Messages: 90 Registered: September 2020 Location: US
|
Member |
|
|
I'm almost there My last hurdle is to work out the configuration for my program. I've looked around here and found information on configfile etc, but can't seem to get it right.
This part works well enough:
Configs::Configs()
{
configfile = ConfigFile("Invoices.ini");
if (!FileExists(configfile))
{
cfg = "OutputDirectory=/home/james/Desktop/\n";
cfg << "Companyname=Company Name\n";
cfg << "Companyowner=James Lefavour\n";
cfg << "Companyaddress=Home\n";
cfg << "Companycity=My City\n";
cfg << "Companystate=My State\n";
cfg << "Companyzip=MyZip\n";
cfg << "Companyphone=(555) 555 - 1212\n";
cfg << "Companyemail=jim@myemail.com\n";
cfg << "DBFile=/home/james/upp/MyApps/Invoices/sample.db\n";
SaveSettings();
}
VectorMap<String, String> mycfg = LoadIniFile(configfile);
OutputDirectory = mycfg.Get("OutputDirectory", Null);
companyname = mycfg.Get("Companyname", Null);
companyowner = mycfg.Get("Companyowne", Null);
companyaddress = mycfg.Get("Companyaddress", Null);
companycity = mycfg.Get("Companycity", Null);;
companystate = mycfg.Get("Companystate", Null);
companyzip = mycfg.Get("Companyzip", Null);
companyphone = mycfg.Get("Companyphone", Null);
companyemail = mycfg.Get("Companyemail", Null);
DBFile = mycfg.Get("DBFile", Null);
}
Of course, hard-coded things like my home directory need to be changed for the public version Here's my issue though.
Do I have to load the entire config each time I change one item (not a big deal, as it's not large but...) or is there a way to udpate one single value and store that?
If there is a better/simpler configuration method for this, I'd appreciate that info - I've learned a lot but I have a lot to learn It's just simple key/value pairs as you can see.
And I'm sorry if this is in the wrong spot - didn't see something specific to app config issues/questions?
Thank you!
Jim
[Updated on: Thu, 08 October 2020 15:03] Report message to a moderator
|
|
|
Re: Configurations [message #55066 is a reply to message #55060] |
Wed, 07 October 2020 23:10   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
jimlef wrote on Wed, 07 October 2020 19:27I'm almost there My last hurdle is to work out the configuration for my program. I've looked around here and found information on configfile etc, but can't seem to get it right.
This part works well enough:
Configs::Configs()
{
configfile = ConfigFile("Invoices.ini");
if (!FileExists(configfile))
{
cfg = "OutputDirectory=/home/james/Desktop/\n";
cfg << "Companyname=Company Name\n";
cfg << "Companyowner=James Lefavour\n";
cfg << "Companyaddress=Home\n";
cfg << "Companycity=My City\n";
cfg << "Companystate=My State\n";
cfg << "Companyzip=MyZip\n";
cfg << "Companyphone=(555) 555 - 1212\n";
cfg << "Companyemail=jim@myemail.com\n";
cfg << "DBFile=/home/james/upp/MyApps/Invoices/sample.db\n";
SaveSettings();
}
VectorMap<String, String> mycfg = LoadIniFile(configfile);
OutputDirectory = mycfg.Get("OutputDirectory", Null);
companyname = mycfg.Get("Companyname", Null);
companyowner = mycfg.Get("Companyowne", Null);
companyaddress = mycfg.Get("Companyaddress", Null);
companycity = mycfg.Get("Companycity", Null);;
companystate = mycfg.Get("Companystate", Null);
companyzip = mycfg.Get("Companyzip", Null);
companyphone = mycfg.Get("Companyphone", Null);
companyemail = mycfg.Get("Companyemail", Null);
DBFile = mycfg.Get("DBFile", Null);
}
Of course, hard-coded things like my home directory need to be changed for the public version Here's my issue though.
Do I have to load the entire config each time I change one item (not a big deal, as it's not large but...) or is there a way to udpate one single value and store that?
If there is a better/simpler configuration method for this, I'd appreciate that info - I've learned a lot but I have a lot to learn It's just simple key/value pairs as you can see.
And I'm sorry if this is in the wrong spot - didn't see something specific to app config issues/questions?
Thank you!
Jim
Usually you just load config on program start, so why that matters?
Mirek
|
|
|
|
Re: Configurations [message #55068 is a reply to message #55067] |
Thu, 08 October 2020 08:55   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
jimlef wrote on Wed, 07 October 2020 23:46Primarily, when I first run the program I want it to know my details - the db file, company info, and the default directory for saving files such as pdf's (haven't figured out how to implement that last yet). When you run the program, it starts with a default and errors out if say the db file can't be opened.
Also, if details change, would be easier to update info - such as new business location etc.
I an always hand edit my config file, but thought it would be cleaner if things were done programmatically.
Jim
I see. Well, you can do that, but I think the best fit then for you would be storing config in JSON. Check this one:
https://www.ultimatepp.org/reference$Jsonize$en-us.html
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:56:18 CEST 2025
Total time taken to generate the page: 0.01051 seconds
|