Files
asesidaa_GC-local-server-re…/GC-local-server-rewrite/common/PathHelper.cs
T
2022-04-05 16:19:11 +08:00

45 lines
1.3 KiB
C#

using System.Diagnostics;
using Swan;
namespace GCLocalServerRewrite.common;
public static class PathHelper
{
/// <summary>
/// Gets the local path of html/static files.
/// </summary>
public static string HtmlRootPath => Path.Combine(BasePath, Configs.STATIC_FOLDER);
/// <summary>
/// Root path for database, when debug, it's under source root, when release, it's the exe dir
/// </summary>
public static string DataBaseRootPath => Path.Combine(BasePath, Configs.DB_FOLDER);
public static string LogRootPath => Path.Combine(BasePath, Configs.LOG_FOLDER, Configs.LOG_BASE_NAME);
private static string BasePath
{
get
{
var assemblyPath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
#if DEBUG
Debug.Assert(assemblyPath != null, $"{nameof(assemblyPath)} != null");
var parentFullName = Directory.GetParent(assemblyPath)?.Parent?.Parent?.FullName;
Debug.Assert(parentFullName != null, $"{nameof(parentFullName)} != null");
return parentFullName;
#else
if (assemblyPath != null)
{
return assemblyPath;
}
throw SelfCheck.Failure("Cannot get assembly path!");
#endif
}
}
}