How to get the full root directory of a ContentManager in XNA 4.0

徘徊边缘 提交于 2020-01-14 04:50:31

问题


I was wondering if anyone here knows how to find the complete path (from the drive letter onwards) of a ContentManager instance. using this I could create a string with the right number of "..\" to append to the file path when I want to load a file from anywhere else on the computer (eg. from a registry key).

So basically I'm asking if there is a way.


回答1:


You may just want to use System.GetFolderPath with one of these locations, most likely Program Files. From there, you can navigate to your application's installation directory. You could also use .Load("\MyFolder\blah") which will load from the default disk (e.g. C:\MyFolder\blah.xnb or whatever).

If you want the path of your .exe file...

using System.IO;
using System.Windows.Forms;

//blah blah
string GetAppDir()
{
    return Path.GetDirectoryName(Application.ExecutablePath);
}


来源:https://stackoverflow.com/questions/8696639/how-to-get-the-full-root-directory-of-a-contentmanager-in-xna-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!