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 » Community » Newbie corner » Initial settings for U++ application
Initial settings for U++ application [message #27282] Sat, 10 July 2010 23:59 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
How can the settings of a U++ app be be saved/implemented the next time the app is run?

I think it uses an .ini file in C/C++. In Java an .xml config file can be used.

It is an app ported from Java and works great in U++.

There may be ~20 options for settings ranging from meters or feet to the default directory for files.
Re: Initial settings for U++ application [message #27285 is a reply to message #27282] Sun, 11 July 2010 01:05 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

There is many options. All you have named and even more, though I would not recommend some of them (I really don't like apps which store their settings in windows registry Smile ) Anyway, you can choose whatever format you like. One more option is to use Serialize() methods to create binary configuration file.

One useful function you might want to know about (if you don't) is ConfigFile(). That will help you to determine the correct location.

For complex solution you can have a look at theide. Search for RegisterWorkspaceConfig, SerializeWorkspaceConfigs and sWorkspaceCfg.

In my opinion, for simple apps, with low and fixed number of options, the best solution is simple text file. Something like ini, or even simpler.

When you choose the format, we can help you in greater detail Wink

Best regards,
Honza
Re: Initial settings for U++ application [message #27288 is a reply to message #27285] Sun, 11 July 2010 02:22 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Honza

dolik.rce wrote on Sun, 11 July 2010 01:05

(I really don't like apps which store their settings in windows registry Smile

Serialize() methods

ConfigFile()

In my opinion, for simple apps, with low and fixed number of options, the best solution is simple text file. Something like ini, or even simpler.



I definitely do not want to tinker with the registry!

A simple text file would seem to be the easiest.

Here is a few that I have:
Set units m, km, ft, mi or nmi - - un = 0 to 4
Set deg, dm or dms - - dms = 0 to 2
Set precision - - dp = 3, 4, 5, 6 or 8
Set goto direct/flyto - - gt = 0, 1
Set draw - - dr = 0, 1
fn <<= Nvl(r_d, recent_dir);

There are several others that just have int variables as above.

So all the config file needs is:

un = 2
dms = 1
dp = 4
gt = 0
dr = 1
...
...
recent_dir = c:\wwdata

So just a text file that would be read and set the variables.
On exit write the variable values to the text file.

Neil

[Updated on: Sun, 11 July 2010 02:31]

Report message to a moderator

Re: Initial settings for U++ application [message #27293 is a reply to message #27288] Sun, 11 July 2010 10:40 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Neil,

Some time ago I write a simple class for similar purpose. I actually used it even for other things, like passing large number of parameters to a function.

It saves key-value pairs as strings. So you have to make all the conversions yourself, but if you have low number of options to save it should not be a problem.

The interface is simple, you will probably need only few functions:
config cfg(filename); //constructor which loads a file
cfg.Load(filename); //load a file into existing config object
cfg.Get(key,default); //get the value from underlaying file
cfg(key,default); //same as Get(), shortcut
cfg.Set(key,value); //store value to config object
cfg.Save(); //write the stored values to the file

It has even some more capabilities, like saving arrays and tables (2D arrays), but based on your description you won't need that. The resulting file is human readable and supports comments (#).

I never had time to really polish it, so it might not follow the U++ coding style. Also, there might be some bugs, since I just quickly stripped out some of my app specific stuff. But don't be afraid, even though this disclaimer, it should do the job Wink

Small example of usage is enclosed with the class.

Bye,
Honza
  • Attachment: config.zip
    (Size: 6.96KB, Downloaded 202 times)
Re: Initial settings for U++ application [message #27311 is a reply to message #27282] Mon, 12 July 2010 03:35 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Honza, I will try your example.

Something like this should work.

Neil
Re: Initial settings for U++ application [message #27526 is a reply to message #27282] Thu, 22 July 2010 07:58 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I tried for a few hours to get the sample to run with no luck.
Linking errors, probably a simple fix for someone that knows what they are doing.

I ended up creating a text config file that is read when the app starts.
Each line sets a variable.
Clicking the red x at the top of the window exits the app without changing the config file.
Clicking "File" -> "Save Exit" saves any changes to the config file.

Works OK.

I did run into one glitch.
I use atof for other parts of the app that works fine.
atoi for the integers gave errors.
Had to compare characters.
		while(!in.IsEof()){
			String Ln = in.GetLine();
			if (i==0) {
			    if (Ln=="0") Setm();
			    if (Ln=="1") Setkm();
			    if (Ln=="2") Setft();
			    if (Ln=="3") Setmi();
			    if (Ln=="4") Setnmi();
			}
			if (i==1) {
                            ....

[Updated on: Thu, 22 July 2010 08:16]

Report message to a moderator

Re: Initial settings for U++ application [message #27527 is a reply to message #27526] Thu, 22 July 2010 08:27 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello nlneilson and Honza

To store the settings of an U++ application I love Xmlize functions (sample here http://www.ultimatepp.org/reference$Xmlize$en-us.html).

It is xml so it is text based. However it can be easily mixed with other functions to be encrypted.


Best regards
IƱaki
Re: Initial settings for U++ application [message #27548 is a reply to message #27527] Thu, 22 July 2010 22:53 Go to previous messageGo to next message
andrei_natanael is currently offline  andrei_natanael
Messages: 262
Registered: January 2009
Experienced Member
If it's not necessary to use a text file(editable by user) why not use Serialize() with LoadFromFile/StoreToFile?
Re: Initial settings for U++ application [message #27740 is a reply to message #27282] Sat, 31 July 2010 16:49 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
The text file does not need to be editable by the user.
I need to look at the code to understand what each line represents, I do not have it commented. It was something I was able to figure out and get to work.

"Serialize() with LoadFromFile/StoreToFile" may work also, I will look at an example that uses it.
Previous Topic: smoother drawing
Next Topic: is U++ the right tool for this?
Goto Forum:
  


Current Time: Fri Apr 26 02:29:25 CEST 2024

Total time taken to generate the page: 0.02615 seconds