15 internal class WinGetDirectoryBuilder : WinGetObjectBuilder<WinGetDirectory?>
17 private string _entryName =
string.Empty;
18 private string _rawContent =
string.Empty;
19 private bool _hasShortenedContent =
false;
20 private DirectoryInfo? _directoryInfo =
null;
25 public WinGetDirectoryBuilder()
34 public void AddEntryName(
string entryName)
36 _entryName = entryName;
46 public void AddRawContent(
string rawContent)
48 _hasShortenedContent = CheckShortenedValue(rawContent);
50 if (_hasShortenedContent)
53#if NETCOREAPP3_1_OR_GREATER
54 _rawContent = rawContent[..^1];
56 _rawContent = rawContent.Remove(rawContent.Length - 1);
61 _rawContent = rawContent;
64 SetDirectoryInfo(_rawContent, _hasShortenedContent);
75 if (_directoryInfo ==
null)
80 return new WinGetDirectory(_entryName, _rawContent, _hasShortenedContent, _directoryInfo);
84 public override void Clear()
86 _entryName =
string.Empty;
87 _rawContent =
string.Empty;
88 _hasShortenedContent =
false;
89 _directoryInfo =
null;
97 private void SetDirectoryInfo(
string rawContent,
bool hasShortenedContent)
101 string path = rawContent;
103#if NETCOREAPP3_1_OR_GREATER
104 if (path.StartsWith(
'%'))
106 path = Environment.ExpandEnvironmentVariables(path);
109 if (path.StartsWith(
"%"))
111 path = Environment.ExpandEnvironmentVariables(path);
115 if (!hasShortenedContent)
117 _directoryInfo =
new DirectoryInfo(path);
121 _directoryInfo =
new DirectoryInfo(PathHelper.TrimLastPathPart(path, PathHelper.PathType.Directory));
125 _directoryInfo =
null;
Represents a winget directory in the info set.