68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace HanvonF710XAttendanceService
|
|
{
|
|
internal static class ApplicationPaths
|
|
{
|
|
public static string BaseDirectory { get; private set; } = AppDomain.CurrentDomain.BaseDirectory ?? "";
|
|
|
|
public static string InternalLogs => Path.Combine(BaseDirectory, "InternalLogs");
|
|
public static string Logs => Path.Combine(BaseDirectory, "Logs");
|
|
public static string TemplateRawLogs => Path.Combine(BaseDirectory, "TemplateRawLogs");
|
|
|
|
public static void Initialize()
|
|
{
|
|
BaseDirectory = AppDomain.CurrentDomain.BaseDirectory ?? "";
|
|
try
|
|
{
|
|
Environment.CurrentDirectory = BaseDirectory;
|
|
}
|
|
catch
|
|
{
|
|
// Best effort; paths below are always rooted to BaseDirectory.
|
|
}
|
|
|
|
EnsureDirectory(InternalLogs);
|
|
EnsureDirectory(Logs);
|
|
EnsureDirectory(TemplateRawLogs);
|
|
EnsureDirectory(Path.Combine(Logs, "Attendance"));
|
|
EnsureDirectory(Path.Combine(Logs, "Machine User service"));
|
|
EnsureDirectory(Path.Combine(Logs, "SaveFaceTemplate logs"));
|
|
EnsureDirectory(Path.Combine(Logs, "FaceTransferLog"));
|
|
}
|
|
|
|
public static string Resolve(string relativeOrAbsolutePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(relativeOrAbsolutePath))
|
|
{
|
|
return BaseDirectory;
|
|
}
|
|
|
|
string trimmed = relativeOrAbsolutePath.Trim();
|
|
return Path.IsPathRooted(trimmed)
|
|
? trimmed
|
|
: Path.Combine(BaseDirectory, trimmed);
|
|
}
|
|
|
|
public static string DatedFile(string directory, string filePrefix)
|
|
{
|
|
string datePart = DateTime.Now.Date.ToShortDateString().Replace('/', '_');
|
|
return Path.Combine(directory, filePrefix + "_" + datePart + ".txt");
|
|
}
|
|
|
|
private static void EnsureDirectory(string path)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
}
|
|
}
|
|
}
|