2012-12-12 41 views
1

我得到了一個settings.ini文件,我想在安裝時將其包含在遊戲中。 它應該在一個名爲Settings的文件夾中,並且應該與遊戲的其餘部分位於同一個目錄中(如可執行文件和默認內容文件夾)。XNA - 如何在安裝時默認添加settings.ini到遊戲中?

我想我只是將一個額外的空白內容項目添加到我的遊戲解決方案,並將settings.ini文件添加到它。

猜猜什麼!它不起作用。

它給了我下面的錯誤:

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

我GOOGLE了一下,但它看起來像我需要寫我自己的內容渠道。

有沒有更好/更簡單的方法來做到這一點?我不想浪費時間寫這個非常困難的部分。

PS。如果我安裝遊戲並將settings.ini添加到設置目錄,我可以寫入settings.ini文件並從中讀取它。但是現在我必須手動添加settings.ini文件,這是我不想要的。我希望它在安裝時與遊戲一起提供。

+1

如果在其文件夾中未檢測到該文件,則可以讓您的遊戲創建該文件。這篇文章應該幫助http://stackoverflow.com/questions/9907682/create-a-txt-file-if-its-not-exist-and-if-it-exist-write-a-line-with-c-鋒利的 – user1306322

+0

嗯,是的。這也是我應該考慮的事情。謝謝! – DijkeMark

回答

1

在你的遊戲項目解決方案(!不滿足項目),加Settings文件夾和Settings.ini文件。如果您已經擁有該文件,您可以使用Add -> Existing Item...

Add a settings file

Properties的文件,設置Build ActionContentCopy to Output DirectoryCopy if newer

enter image description here

你的設置文件現在將你的應用部署。

+0

完全按照我的意願工作。謝謝! – DijkeMark

0

把你的.ini文件中的所有內容,並把它們放到你的遊戲代碼:

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 [email protected]#$%^&*()_+|"); 
    sw.WriteLine(@"But you need to use double quotes "" so you don't get errors"); 
    }