JD2022-TU1/main/tools/framework/JD.TeaBoxAddinSystem/Bootstrap/ApplicationConfiguration.cs

154 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using JD.Kernel.StaticHelpers;
using JD.TeaBoxAddinSystem.Addins;
namespace JD.TeaBoxAddinSystem.Bootstrap
{
/// <summary>
/// Application Configuration.
/// </summary>
[Serializable]
public class ApplicationConfiguration
{
#region Constants
private const string UbisoftDirectory = "Ubisoft";
#endregion
#region Variables
private readonly string m_applicationName;
private readonly List<string> m_commandLineHandlerPaths = new List<string>();
private string m_dataDirectory;
private string m_applicationRootPath;
private string m_bootstrapAddinPath;
private string m_configApplicationName;
#endregion
#region Constructor
/// <summary>
/// Constructor.
/// </summary>
/// <param name="applicationName"></param>
public ApplicationConfiguration(string applicationName)
{
Throw.IfEmpty(applicationName, "applicationName");
m_applicationName = applicationName;
CommandLineHandlerPaths.Add(ApplicationStartup.CoreBootstrapPath); // This path is always present
}
#endregion
#region Properties
/// <summary>
/// Addin Paths in which there can be command line handlers (used for help command for example).
/// </summary>
public IList<string> CommandLineHandlerPaths
{
get
{
return m_commandLineHandlerPaths;
}
}
/// <summary>
/// The sub directory used to store application properties. If null, it will take the application name.
/// </summary>
/// <remarks>
/// ONLY USED IF <see cref="ConfigDirectory"/> IS NOT SET EXPLICITELY.
/// Set to null or string.Empty to revert to the default value.
/// </remarks>
public string ConfigApplicationName
{
get
{
return string.IsNullOrEmpty(m_configApplicationName) ? m_applicationName : m_configApplicationName;
}
set
{
m_configApplicationName = value;
}
}
/// <summary>
/// The directory used to store user-specific preferences.
/// </summary>
/// <remarks>
/// By default, this is ApplicationData/ApplicationName in the MyDocuments folder of the current user.
/// Set to null or string.Empty to revert to that default.
///
/// If you set this, <see cref="ConfigApplicationName"/> won't be used.
/// </remarks>
public string ConfigDirectory
{
get
{
var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var currentAppDataFolder = Path.Combine(appDataFolder, UbisoftDirectory, ConfigApplicationName);
return currentAppDataFolder;
}
}
/// <summary>
/// The directory used to store global resources.
/// </summary>
/// <remarks>
/// By default, this is ApplicationRootPath/Data.
/// Set to null or string.Empty to revert to that default.
/// </remarks>
public string DataDirectory
{
get
{
return string.IsNullOrEmpty(m_dataDirectory) ? FileUtility.Combine(Runtime.ApplicationRootPath, "Data") : m_dataDirectory;
}
set
{
m_dataDirectory = value;
}
}
/// <summary>
/// Root path of the application.
/// </summary>
public string ApplicationRootPath
{
get
{
return m_applicationRootPath;
}
set
{
m_applicationRootPath = value;
}
}
/// <summary>
/// Bootstrap path in the <see cref="AddinManager.ExtensionTree"/>.
/// </summary>
public string BootstrapAddinPath
{
get
{
return m_bootstrapAddinPath;
}
set
{
m_bootstrapAddinPath = value;
}
}
#endregion
}
}