JD2022-TU1/main/tools/modules/JD.SceneExplorer/ViewModels/ResourcePath.cs

49 lines
1.5 KiB
C#

using System;
using System.Linq;
namespace JD.SceneExplorer.ViewModels
{
public class ResourcePath
{
private readonly string m_filename;
private readonly string m_directory;
private readonly string m_composedRepresentation;
/// <summary>
/// Constructor. Split the path into basename+ext and directory, and build a representation in the form : "basename.ext (directory)"
/// </summary>
/// <param name="path"></param>
public ResourcePath(string _path)
{
m_filename = null;
m_directory = null;
try
{
if (_path != null && _path != "")
{
m_filename = System.IO.Path.GetFileName(_path);
m_directory = System.IO.Path.GetDirectoryName(_path);
}
}
catch
{
}
if (m_filename == null)
m_filename = "";
if (m_directory == null)
m_directory = "";
if (m_directory.Length != 0)
m_composedRepresentation = $"{m_filename} ({m_directory})";
else
m_composedRepresentation = m_filename;
}
//Get information (read only properties)
public string Filename { get { return m_filename; } }
public string Directory { get { return m_directory; } }
public string ComposedRepresentation { get { return m_composedRepresentation; } }
}
}