/ src / modules / FileLocksmith / FileLocksmithUI / Converters / FileListToDescriptionConverter.cs
FileListToDescriptionConverter.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  using System.IO;
 7  
 8  using Microsoft.UI.Xaml.Data;
 9  
10  namespace PowerToys.FileLocksmithUI.Converters
11  {
12      public sealed partial class FileListToDescriptionConverter : IValueConverter
13      {
14          public object Convert(object value, Type targetType, object parameter, string language)
15          {
16              var paths = (string[])value;
17              if (paths.Length == 0)
18              {
19                  return string.Empty;
20              }
21  
22              string firstPath = paths[0];
23              firstPath = Path.GetFileName(paths[0]);
24              if (string.IsNullOrEmpty(firstPath))
25              {
26                  firstPath = Path.GetDirectoryName(paths[0]);
27              }
28  
29              if (string.IsNullOrEmpty(firstPath))
30              {
31                  firstPath = Path.GetPathRoot(paths[0]);
32              }
33  
34              if (paths.Length == 1)
35              {
36                  return firstPath;
37              }
38              else
39              {
40                  return firstPath + "; +" + (paths.Length - 1);
41              }
42          }
43  
44          public object ConvertBack(object value, Type targetType, object parameter, string language)
45          {
46              return value;
47          }
48      }
49  }