Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Configurations [Solved]
Configurations [Solved] [message #55060] Wed, 07 October 2020 19:27 Go to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
I'm almost there Smile 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 Smile 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 Smile 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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jimlef wrote on Wed, 07 October 2020 19:27
I'm almost there Smile 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 Smile 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 Smile 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 #55067 is a reply to message #55060] Wed, 07 October 2020 23:46 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Primarily, 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
Re: Configurations [message #55068 is a reply to message #55067] Thu, 08 October 2020 08:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jimlef wrote on Wed, 07 October 2020 23:46
Primarily, 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
Re: Configurations [message #55072 is a reply to message #55060] Thu, 08 October 2020 14:57 Go to previous message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Mirek, Again, Thank you! That is Perfect for what I'm looking for.
Previous Topic: Big issue with Visual Studio 2019 (some versions)
Next Topic: How to construct a struct to get data from this XML?
Goto Forum:
  


Current Time: Fri Apr 19 19:40:32 CEST 2024

Total time taken to generate the page: 1.05039 seconds