mediautilities.cs

来自「Beginning C# Game Programming 的源代码」· CS 代码 · 共 41 行

CS
41
字号
using System;
using System.IO;
using System.Configuration;


	/// <summary>
	/// Summary description for MediaUtilities.
	/// </summary>
public class MediaUtilities
{
	//		private static string defaultPath = @"..\..\media\";
	private static string mediaPath = ConfigurationSettings.AppSettings.Get("MediaPath");
		
	public MediaUtilities()	
	{
	}

	public static string FindFile(string filename) 
	{
		return FindFile(mediaPath, filename);
	}

	public static string FindFile(string path, string filename) 
	{
		// First try to load the file in the full path
		string fullName = AppendDirectorySeparator(path) + filename;
		if (File.Exists(fullName))
			return fullName;
		else
			throw new FileNotFoundException("Could not find this file.", filename);
	}

	private static string AppendDirectorySeparator(string pathname) 
	{
		if (!pathname.EndsWith(@"\"))
			return pathname + @"\";
		else
			return pathname;
	}
}

⌨️ 快捷键说明

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