using System;
using System.IO;
using DTT.Utils.Workflow;
namespace DTT.PublishingTools.Utils
{
///
/// Provides utility methods for asset paths related to the DTT package.
///
public static class DTTPathUtility
{
///
/// Returns whether the given asset path is inside a DTT directory.
///
/// The asset path to check.
/// Whether the given asset path is inside a DTT directory.
public static bool InDTTDirectory(string assetPath)
{
if (assetPath == null)
throw new ArgumentNullException(nameof(assetPath));
string rootDirectory = PathUtility.GetPathElementAt(assetPath, 0);
if (rootDirectory == "Assets")
{
return PathUtility.ContainsDirectory(assetPath, "DTT");
}
if (rootDirectory == "Packages")
{
string subDirectory = PathUtility.GetPathElementAt(assetPath, 1);
return subDirectory.Contains("dtt.") || subDirectory.Contains("nl.dtt.");
}
return false;
}
///
/// Returns whether the given asset path is corresponding with a dtt asset.json file.
///
/// The asset path to check.
/// Whether the given asset path is corresponding with a dtt asset.json file.
public static bool IsAssetJson(string assetPath) => Path.HasExtension(assetPath)
&& InDTTDirectory(assetPath) && Path.GetFileName(assetPath) == "asset.json";
}
}