pathhelper.cs

来自「C#开发的运行于windows mobile PDA上的游戏」· CS 代码 · 共 65 行

CS
65
字号
////////////////////////////////////////////////
// 
// Project: Lines.NET
// Version: 1.1
// Author:  Vladimir L.
// 
// homepage: http://www.boomsoft.org
// e-mail:   support@boomsoft.org
// 
// Copyright (c) 2003-2004, Boomsoft.org
// 

using System;
using System.IO;
using System.Reflection;

namespace Lines.Utils
{
	/// <summary>
	/// Contains functions that simplify some path operations related to running application.
	/// </summary>
	public class PathHelper
	{
		/// <summary>
		/// Keeps the directory of application that was once detected, so there is no need to 
		/// lookup for it again.
		/// </summary>
		private static string appDirCache = null;

		/// <summary>
		/// This static method helps to detect a location where the application has been 
		/// started from.
		/// </summary>
		/// <returns>The full path to the application.</returns>
		public static string GetAppDir()
		{
			// return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
			if (appDirCache == null)
			{
				appDirCache = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
			}
			return appDirCache;
		}
		
		/// <summary>
		/// Helps to determine a full path to the application related file.
		/// </summary>
		/// 
		/// <param name="filename">The file name or relative path to a file.</param>
		/// <returns>The full path to the file.</returns>
		/// 
		/// <remarks>
		/// <p>Helps to determine a full path of file that is placed in the same with 
		/// application directory from the name of this file or out of the relative 
		/// to application location path.</p>
		/// <p>This method takes the application directory and concatenates it with a provided file 
		/// name to get the full path to this file.</p>
		/// </remarks>
		public static string GetAppFile(string filename)
		{
			return GetAppDir() + "\\" + filename;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?