Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#]How to save settings?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Sun Nov 02, 2008 7:35 pm    Post subject: [C#]How to save settings? Reply with quote

How can I save application settings?

I heard about .ini and .xml, i've also heard using the .settings built into .net which i heard creates an .xml for you

I would like to know maybe how i could do a couple of things:

save which of 2 radiobuttons was checked as the form was closing, and how to read WHICH button was last checked, and check it during run-time

how i could save the text of 2 different textboxes during closing, and upon runtime have the same text remain

i've saved text to like a .txt, but i can't seem to figure out how i can like "label" controls and such

i hope i made sense

_________________
Back to top
View user's profile Send private message AIM Address
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Nov 02, 2008 8:11 pm    Post subject: Reply with quote

You can use the registry, ini file, or xml file.
There are examples on all over the internet. I prefer to use the registry.

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sun Nov 02, 2008 8:42 pm    Post subject: Reply with quote

you dont have to use INI Files in particular.
The main concept, is to write your information to a Text File.
Then to load it, read the file line by line and compare strings Wink
Back to top
View user's profile Send private message AIM Address MSN Messenger
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sun Nov 02, 2008 9:00 pm    Post subject: Reply with quote

If there are lots of things to save, I like to use a database file, (mdb) to store them. If it is a few things, make a filestream and save to a .ini or .txt file.
_________________
Back to top
View user's profile Send private message Send e-mail
deleted19776
I post too much
Reputation: 11

Joined: 29 Apr 2007
Posts: 3838

PostPosted: Sun Nov 02, 2008 9:37 pm    Post subject: Reply with quote

I personally would prefer the registry, since even if you delete the files, the settings are still there.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Nov 03, 2008 2:01 am    Post subject: Reply with quote

If you decide to use registry, remember that you can always delete/modify the info you made in the registry using "Start>run>regedit"
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Mon Nov 03, 2008 10:50 am    Post subject: Reply with quote

and how to read WHICH button was last checked

PSEUDO CODE:
Code:
if radiobutton1 = true then save radiobutton1 else if radiobutton = true save radiobutton2


Doesn't have to be more complicated than that.
I recommend you to use XML with C#.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Nov 03, 2008 1:45 pm    Post subject: Reply with quote

It depends on what you want:
If users see an ini file in the folder of your program, they might edit it. If you don't want them to edit it, you might want to use the registry. (It's still possible to edit it off course, but harder for most people)
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Tue Nov 04, 2008 4:48 pm    Post subject: Reply with quote

Spawnfestis wrote:
and how to read WHICH button was last checked

PSEUDO CODE:
Code:
if radiobutton1 = true then save radiobutton1 else if radiobutton = true save radiobutton2


Doesn't have to be more complicated than that.
I recommend you to use XML with C#.


Real code:

Code:

StreamWriter sw = new StreamWriter("settings.xml");

if (rdbOne.Checked)
{
    XMLWrite("SelectedRDB", "rdbOne");
}
else if (rdbTwo.Checked)
{
    XMLWrite("SelectedRDB", "rdbTwo");
}
else
{
    MessageBox.Show("wtf?");
}


...



private void XMLWrite(StreamWriter sw, string Node, string Value)
{
    StringBuilder sb = new StringBuilder();
    sb.Append("<").Append(Node).AppendLine(">").Append("    ").AppendLine(Value).Append("</").Append(Node).Append(">");
    sw.Write(sb.ToString());
}

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Dylanwade
How do I cheat?
Ban
Reputation: 0

Joined: 21 Feb 2009
Posts: 0
Location: Hacking Gaia

PostPosted: Tue Nov 04, 2008 6:33 pm    Post subject: Reply with quote

I save mine into an .ini file, registry is good too.
Back to top
View user's profile Send private message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Wed Nov 05, 2008 5:27 pm    Post subject: Reply with quote

on vista, would editing registry need admin permission?
_________________
Back to top
View user's profile Send private message AIM Address
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Nov 05, 2008 6:18 pm    Post subject: Reply with quote

yoyonerd wrote:
on vista, would editing registry need admin permission?


I think XP would require it too.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Habufe
Expert Cheater
Reputation: 0

Joined: 03 Sep 2007
Posts: 149
Location: http://www.SaviourFagFails.com/

PostPosted: Thu Nov 06, 2008 10:31 am    Post subject: Reply with quote

if you are inexperienced with this, you would probably like the registry method. its very organized, easy to use and user friendly.

and about the administrator question, you only need to be admin if you are writing into protected area (i think this includes all areas other then hkey current user)
Back to top
View user's profile Send private message
ElJEffro
Grandmaster Cheater Supreme
Reputation: 0

Joined: 15 Apr 2007
Posts: 1881
Location: La Tierra

PostPosted: Fri Nov 07, 2008 2:14 am    Post subject: Reply with quote

Code:
List<string> allLines = new List<string>();
                using (StreamReader reader = new StreamReader("whatever.ini"))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                       
                        allLines.Add(line);
                    }
                }

to get numerical data, ill use this example of a .ini

Code:
[data]
number1=42
number2=69

now to convert it to a format you can use
Code:

foreach (string line in allLines)
{
if ( line.StartsWith("number") ) // it is numerical data
{
int data;
if (!Int32.TryParse( line.Split('=')[1], out data)
MessageBox.Show("Invalid integer read from file");
}
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites