|
-
August 19th, 2009, 05:06 PM
#1
Using binary files as database?
Ok, let's rephrase that cause after reading what I typed it didn't really made sense...
I want to save character info (yes, it's for a game)
With ini files the file has a structure like this:
Code:
[Username]
Password= something
Security=Stuff
email=mail
Character profession= prof
level=char level
hit points= hp
skills= skills char has
items= char's items
etc.
Which makes it easy to load/save and serves as a easy editable database.
But I want to use binary files instead of ini files (cause I read that binary files were faster with loading)
But I just can't seem to correctly save or read the files...
Original post:
So I'm trying to code something that saves/reads accounts in binary files but since this is the first time ever that I tried to do something with binary files, I'm kinda stuck.
_____
So let's say that I want to save/read:
Example.dat (where Example is the username)
Password
e-mail
security Q/A
How would I do that?
Last edited by Creqaw; August 20th, 2009 at 10:08 AM.
-
August 19th, 2009, 07:03 PM
#2
Re: Using binary files as database?
Could you please clarify....
Where will you be storing the information. In an SQL database or a File System?
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
August 19th, 2009, 07:06 PM
#3
Re: Using binary files as database?
There is an embedded sql-like database that I've seen but cannot remember what it's called.
-
August 20th, 2009, 04:42 AM
#4
Re: Using binary files as database?
After writing/reading the data to the files try to use some encryption technique so that no can hack the data even if they open it , it should be in binary format - non - readable.
-
August 20th, 2009, 07:23 AM
#5
Re: Using binary files as database?
 Originally Posted by rliq
Could you please clarify....
Where will you be storing the information. In an SQL database or a File System?
I'm doing this so that I don't need a SQL database.
-
August 20th, 2009, 08:32 AM
#6
Re: Using binary files as database?
So what you're saying is that you don't need or want a database? If so, why are you asking how to use a binary file as a database?
Maybe you should describe what you want rather than how you think it should be done. Do you want to know how you can read/write data from a file?
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
-
August 20th, 2009, 10:04 AM
#7
Re: Using binary files as database?
Ok, let's rephrase that cause after reading what I typed it didn't really made sense...
I want to save character info (yes, it's for a game)
With ini files the file has a structure like
Code:
[Username]
Password= something
Security=Stuff
email=mail
Character profession= prof
level=char level
hit points= hp
skills= skills char has
items= char's items
etc.
Which makes it easy to load/save.
But I want to use binary files instead of ini files (cause I read that binary files were faster with loading)
But I just can't seem to correctly save or read the files...
-
August 20th, 2009, 10:23 AM
#8
Re: Using binary files as database?
But I want to use binary files instead of ini files (cause I read that binary files were faster with loading)
For your case, I think you should just stick to just writing things to a text file in the exact format you described above. Performance is not going to be an issue. I'd be very surprised if you could even find the load/save routines in the output of a profiler.
The only reason why the above format would not be ideal would be because the user can easily hand-edit it and change their stats. One way to prevent that would be to append the SHA1 sum (or something similar) of the data to the end of the file. Then, when you read the data into memory, you can verify it has not been altered.
There are other ways, but that's probably one of the easiest ones to do and it's moderately difficult to bypass.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
-
August 20th, 2009, 08:39 PM
#9
Re: Using binary files as database?
Put the data in a DataSet inside your app. Then you can use Read/WriteXML() to save the data to a file system. You could also pipe that XML through an encryption routine when saving and decryption routine when loading and also change the file extension to be .DAT instead of .XML.
For example...
Code:
public static void SaveDataSet(String fileName, String password, DataSet ds)
{
using (MemoryStream ms = new MemoryStream())
{
ds.WriteXml(ms);
// your encryption object - you need to do this bit
RijndaelEnhanced rje = new RijndaelEnhanced(password);
File.WriteAllBytes(fileName, rje.EncryptToBytes(ms.ToArray()));
ms.Close();
}
}
public static void LoadDataSet(String fileName, String password, DataSet ds)
{
// your decryption object - you need to do this bit
RijndaelEnhanced rje = new RijndaelEnhanced(password);
using (MemoryStream ms = new MemoryStream(rje.DecryptToBytes(File.ReadAllBytes(fileName))))
{
ds.ReadXml(ms);
ms.Close();
}
}
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
August 20th, 2009, 11:42 PM
#10
Re: Using binary files as database?
 Originally Posted by Mutant_Fruit
I'd be very surprised if you could even find the load/save routines in the output of a profiler.
I could not understand this. Can you please throw some more light on this - what is profiler here ?
 Originally Posted by Mutant_Fruit
One way to prevent that would be to append the SHA1 sum (or something similar) of the data to the end of the file.
Can you explain more abt SHA1 ? whats the full form of it ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|