81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace JD.Core
|
|
{
|
|
/// <summary>
|
|
/// The project id is used to find the data corresponding to an executable.
|
|
/// </summary>
|
|
public static class ProjectId
|
|
{
|
|
private static string _value;
|
|
private static string _location;
|
|
|
|
/// <summary>
|
|
/// Full project id. Example: JD2017_Main
|
|
/// </summary>
|
|
public static string Value
|
|
{
|
|
get
|
|
{
|
|
if (_value == null)
|
|
{
|
|
return _value = ReadProjectId();
|
|
}
|
|
return _value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Game name is the first part of the id
|
|
/// </summary>
|
|
public static string GameName => Value.Split('_').First();
|
|
|
|
/// <summary>
|
|
/// Branch name is the second part of the id
|
|
/// </summary>
|
|
public static string BranchName => Value.Substring(GameName.Length + 1);
|
|
|
|
/// <summary>
|
|
/// Location where to look for ProjectId.txt, default is current assembly location
|
|
/// </summary>
|
|
public static string Location
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(_location))
|
|
{
|
|
_location = Path.GetDirectoryName(typeof(ProjectId).Assembly.Location());
|
|
}
|
|
return _location;
|
|
|
|
}
|
|
set
|
|
{
|
|
_location = value;
|
|
_value = ReadProjectId();
|
|
}
|
|
}
|
|
|
|
private static string ReadProjectId()
|
|
{
|
|
var projectIdFile = Path.Combine(Location, "ProjectId.txt");
|
|
|
|
if (!File.Exists(projectIdFile))
|
|
{
|
|
throw new InvalidProgramException($"Cannot find file {projectIdFile} so the initialization of the data path cannot be done.");
|
|
}
|
|
|
|
try
|
|
{
|
|
var projectId = File.ReadAllText(projectIdFile).Trim();
|
|
return projectId;
|
|
}
|
|
catch (IOException)
|
|
{
|
|
throw new InvalidProgramException($"Cannot read file {projectIdFile} so the initialization of the data path cannot be done.");
|
|
}
|
|
}
|
|
}
|
|
}
|