【问题标题】:C# XNA published game can't run and getting the installation locationC# XNA 发布的游戏无法运行并获取安装位置
【发布时间】:2012-04-23 09:07:35
【问题描述】:

我一直在尝试为我的游戏创建第一个错误日志,但遇到了一些问题。首先,我尝试使用以下方法创建一个文本文件:

errorLog = new StreamWriter("c:\\ErrorLog.txt", true);

但是我只能在安装游戏后通过 Setup.exe 运行游戏,因为它是我可以分配管理员权限的唯一可执行文件,游戏快捷方式没有该选项。每当我尝试从其他地方运行游戏时,我都会收到“程序已停止响应”。

我的第二个问题是在我想要的位置创建文本文件,我想在安装游戏的位置创建它,即“c:\Program Files (x86)\MyGame”。我尝试了几种不同的方法:

Environment.GetCommandLineArgs()[0];
Path.GetDirectoryName(baseDir);
Assembly.GetExecutingAssembly().Location;

但它们都在我的本地 AppData 中返回了一条巨大的路径。我不知道这是否会有所不同,但这是单击一次应用程序。

提前感谢您的任何帮助。

【问题讨论】:

    标签: c# xna admin publish installation-path


    【解决方案1】:

    这是因为 ClickOnce 应用程序安装在安装它们的用户的配置文件下。

    您可以使用ApplicationDeployment.CurrentDeployment.DataDirectory,这可能是您正在寻找的,甚至更好:

    private string GetDataDirectory()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
            return ApplicationDeployment.CurrentDeployment.DataDirectory;
        else
            return Application.StartupPath;
    }
    

    【讨论】:

      【解决方案2】:

      Directory.GetCurrentDirectory() 呢?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-10
        • 2010-12-24
        • 2011-02-06
        • 1970-01-01
        相关资源
        最近更新 更多