mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-01-13 19:02:05 +01:00
82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Test.Loader
|
|
{
|
|
public class TestUtils
|
|
{
|
|
private static string solutionDir;
|
|
private static string executableDir;
|
|
|
|
#region DeploymentItem()
|
|
|
|
/// <summary>
|
|
/// DeploymentItemAttribute doesn't work with the combination of VS2010, ReSharper 7.1.3, Target Framework 3.5
|
|
/// </summary>
|
|
public static string DeploymentItem(string file)
|
|
{
|
|
GetSolutionBaseDir();
|
|
GetExecutableDir();
|
|
|
|
|
|
var src = Path.Combine(solutionDir, file);
|
|
var dest = Path.Combine(executableDir, Path.GetFileName(file));
|
|
if (Directory.Exists(src))
|
|
DeployRecursively(src, dest);
|
|
else
|
|
File.Copy(src, dest, true);
|
|
return dest;
|
|
}
|
|
|
|
private static void DeployRecursively(string src, string dest)
|
|
{
|
|
foreach(var file in Directory.GetFiles(src))
|
|
File.Copy(file, Path.Combine(dest, Path.GetFileName(file)), true);
|
|
foreach(var subdir in Directory.GetDirectories(src))
|
|
DeployRecursively(subdir, Path.Combine(dest, Path.GetFileName(subdir)));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetSolutionBaseDir()
|
|
public static string GetSolutionBaseDir()
|
|
{
|
|
if (solutionDir != null)
|
|
return solutionDir;
|
|
|
|
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
do
|
|
{
|
|
if (File.Exists(dir + "\\ChanSort.sln"))
|
|
return solutionDir = dir;
|
|
dir = Path.GetDirectoryName(dir);
|
|
} while (!string.IsNullOrEmpty(dir));
|
|
|
|
dir = Environment.CurrentDirectory;
|
|
do
|
|
{
|
|
if (File.Exists(dir + "\\ChanSort.sln"))
|
|
return solutionDir = dir;
|
|
dir = Path.GetDirectoryName(dir);
|
|
} while (!string.IsNullOrEmpty(dir));
|
|
|
|
throw new InvalidOperationException("Cannot determine base directory of ChanSort solution");
|
|
}
|
|
#endregion
|
|
|
|
#region GetExecutableDir()
|
|
public static string GetExecutableDir()
|
|
{
|
|
if (executableDir == null)
|
|
executableDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
return executableDir;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|