سؤال

I got a settings.ini file, which I want to be included in the game when installed. It should be in a folder called Settings and it should be in the same directory as the rest of the game (Like the executable and the default content folder).

I thought I would just add an extra empty content project to my game solution and add the settings.ini file to it.

Guess What! It doesn't work.

It gives me the following error:

Error 6 Cannot autodetect which importer to use for "Settings.ini". There are no importers which handle this file type. Specify the importer that handles this file type in your project. PATH_TO_GAME\Settings\Settings.ini

I googled a bit, but it looks like I need to write my own content pipeline.

Is there a better/more easy way to do this? I don't want to waste my time on writing this very difficult part.

PS. If I install the game and add the settings.ini to the settings directory, I am able to write into and read from the settings.ini file. But now I have to add the settings.ini file manually, which I don't want. I want it to be supplied with the game when you install it.

هل كانت مفيدة؟

المحلول

In your game project solution (not content project!), add a Settings folder, and the Settings.ini file. You might use Add -> Existing Item... for the file if you already have it.

Add a settings file

Under Properties for the file, set Build Action to Content and Copy to Output Directory to Copy if newer.

enter image description here

Your settings file will now be deployed with your application.

نصائح أخرى

Take all the contents of your .ini file and put them into your game's code:

string path = @"path\to\your.ini";
if (!File.Exists(path))
    using (var sw = File.CreateText(path))
    {
    sw.WriteLine(@"This is the .ini file text.");
    sw.WriteLine(@"It can contain all sorts of characters, like !@#$%^&*()_+|");
    sw.WriteLine(@"But you need to use double quotes "" so you don't get errors");
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top