Viewing application/x-csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace Net.XpFramework.Runner
{
class Paths
{
public static string DirName(string filename)
{
return filename.Substring(0, filename.LastIndexOf(Path.DirectorySeparatorChar) + 1);
}
public static IEnumerable<string> Locate(IEnumerable<string> bases, string file, bool expect)
{
foreach (string path in bases)
{
string qualified = path + Path.DirectorySeparatorChar + file;
if (File.Exists(qualified))
{
yield return qualified;
}
}
if (expect)
{
throw new FileNotFoundException("Cannot find " + file + " in [" + String.Join(", ", bases.ToArray()) + "]");
}
}
public static IEnumerable<string> Translate(string root, string[] paths)
{
var HOME = Environment.GetEnvironmentVariable("HOME") ?? Environment.GetFolderPath(Environment.SpecialFolder.Personal);
foreach (string path in paths)
{
if (path.StartsWith("~"))
{
yield return HOME + path.Substring(1);
}
else if (path.Substring(1).StartsWith(":\\") || path.StartsWith("\\\\"))
{
// Fully qualified path
yield return path;
}
else
{
// Relative path, prepend root
yield return root + Path.DirectorySeparatorChar + path;
}
}
}
/// <summary>
/// Return binary file of currently executing process
/// </summary>
/// <returns></returns>
public static string Binary()
{
// Codebase is a URI. file:///F:/cygwin/home/Timm Friebe/bin/xp.exe
var uri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
if (uri.IsFile)
{
return Uri.UnescapeDataString(uri.AbsolutePath.Replace('/', Path.DirectorySeparatorChar));
}
else
{
throw new IOException("Don't know how to handle " + uri.AbsoluteUri);
}
}
}
}
'
|
Download
You can download the file
«Paths.cs»
by using
this link.
|