[Help]Read .ini from a website

08/28/2009 21:23 Basser#1
Source: LOTF v2
Need Help With:
Since the database is being read from a .ini, I was hoping I could make it read the .ini from a website (e.g. localhost/co/servername/config.ini (I know localhost isn't a good example)).


I have no idea how to make this, I know this seems kinda useless, but there is a reason I'm using for something, which I is private for now. I think I will release it after finishing it 100%.

~Bas
08/28/2009 23:35 kinshi88#2
You would have to download the .ini file, then read it, then delete it.
08/28/2009 23:40 Basser#3
Err okay, but how to?
08/29/2009 00:16 kinshi88#4
Code:
using System.Net;
Code:
WebClient Downloader = new WebClient();
Downloader.DownloadFile("localhost/co/servername/config.ini", "config.ini");
Then read the Database and load what you need.

Then Delete:
Code:
File.Delete(Application.StartupPath + @"/config.ini");
Something like that.
08/29/2009 11:43 Basser#5
Quote:
Originally Posted by kinshi88 View Post
Code:
using System.Net;
Code:
WebClient Downloader = new WebClient();
Downloader.DownloadFile("localhost/co/servername/config.ini", "config.ini");
Then read the Database and load what you need.

Then Delete:
Code:
File.Delete(Application.StartupPath + @"/config.ini");
Something like that.
Except for the save location, it worked, however the File.Delete didn't work, but I figured out how to add it.

Thanks a lot, this really helped me out. :)


#request close
08/29/2009 21:35 unknownone#6
Bit of a backwards solution. Ideally you should create an Ini reading class which takes a System.IO.Stream argument rather then using those unmanaged imports. The GetPrivateProfileString etc are really Windows Registry functions, but luckily compatible with COs ini files.

There are already some other managed Ini reading libraries that will take a stream. Quick google search should find one. Using a managed ini reader has plenty of advantages, such as exception handling, where you can actually see what a problem is, rather then obtaining a "0" meaning error, with no explanation.

If you do grab one, you could use a HttpWebRequest and HttpWebResponse to collect the file, use response.GetStream() to get a stream you can pass to the ini reader. This also has the advantage that you can do it asynchronously.
09/02/2009 06:36 kinshi88#7
#Moved
09/02/2009 11:22 Basser#8
Kinshi's solution was fine, I've got it working, it just takes some time to load the ini, but that doesn't matter since I never use it myself, it's a security thing.
09/03/2009 06:19 PeTe Ninja#9
Wait, May i know the reason why you are doing this?
09/03/2009 11:15 Basser#10
As I said before, this is private, and I probably won't release it.
09/03/2009 11:16 Basser#11
#request close
09/04/2009 03:25 kinshi88#12
#Closed