154 lines
3.7 KiB
C#
154 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace HashCalculator.GUI
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
DataContext = new ViewModel();
|
|
}
|
|
}
|
|
|
|
internal sealed class ViewModel : INotifyPropertyChanged
|
|
{
|
|
#region INotifyPropertyChanged
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
private void SetField<X>(ref X field, X value, [CallerMemberName] string? propertyName = null)
|
|
{
|
|
if (propertyName == null)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
|
|
if (EqualityComparer<X>.Default.Equals(field, value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
field = value;
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
#endregion
|
|
|
|
public IReadOnlyList<Person> Items
|
|
{
|
|
get { return PersonModule.All; }
|
|
}
|
|
|
|
Person selectedItem;
|
|
public Person SelectedItem
|
|
{
|
|
get { return selectedItem; }
|
|
set { SetField(ref selectedItem, value); }
|
|
}
|
|
|
|
long? selectedValue;
|
|
public long? SelectedValue
|
|
{
|
|
get { return selectedValue; }
|
|
set { SetField(ref selectedValue, value); }
|
|
}
|
|
}
|
|
|
|
internal enum InputEntryType
|
|
{
|
|
Text,
|
|
SupportedFilePath,
|
|
BinaryFilePath,
|
|
Path,
|
|
}
|
|
|
|
internal sealed class InputEntry
|
|
{
|
|
public InputEntryType Type { get; }
|
|
public string Value { get; }
|
|
|
|
public InputEntry(InputEntryType type, string value)
|
|
{
|
|
Type = type;
|
|
Value = value;
|
|
}
|
|
|
|
public static List<InputEntry> CreateSuggestion(string value)
|
|
{
|
|
var list = new List<InputEntry>();
|
|
try
|
|
{
|
|
var path = new FileInfo(value);
|
|
path.Directory.GetFiles()
|
|
}
|
|
catch { }
|
|
|
|
}
|
|
|
|
public static bool IsSupportedFile(string value)
|
|
{
|
|
|
|
}
|
|
|
|
public static IEnumerable<InputEntry> ProvideFileSystemSuggestions(string path)
|
|
{
|
|
var empty = Enumerable.Empty<InputEntry>();
|
|
var list = empty;
|
|
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
{
|
|
return list;
|
|
}
|
|
|
|
var directories = empty;
|
|
try
|
|
{
|
|
var directoryInfo = new DirectoryInfo(path);
|
|
if (directoryInfo.Exists)
|
|
{
|
|
directories = directoryInfo.GetDirectories()
|
|
.Select(info => new InputEntry(InputEntryType.Path, info.FullName));
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
var files = empty;
|
|
try
|
|
{
|
|
var fileInfo = new FileInfo(path);
|
|
if (fileInfo.Exists)
|
|
{
|
|
files = files.Concat()
|
|
}
|
|
if (fileInfo.Directory.Exists)
|
|
{
|
|
|
|
}
|
|
|
|
//fileInfo.Directory.get
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
}
|