2023-12-27 15:34:06 +00:00
|
|
|
|
using HKW.HKWUtils.Observable;
|
2023-12-30 14:54:49 +00:00
|
|
|
|
using LinePutScript;
|
2023-12-27 15:34:06 +00:00
|
|
|
|
using System;
|
2023-12-18 14:53:56 +00:00
|
|
|
|
using System.Collections.Generic;
|
2023-12-30 14:54:49 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
2023-12-18 14:53:56 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-12-30 14:54:49 +00:00
|
|
|
|
using VPet.Solution.Models;
|
2023-12-18 14:53:56 +00:00
|
|
|
|
using VPet_Simulator.Windows.Interface;
|
|
|
|
|
|
|
|
|
|
namespace VPet.Solution.ViewModels;
|
|
|
|
|
|
|
|
|
|
public class MainWindowVM : ObservableClass<MainWindowVM>
|
|
|
|
|
{
|
2023-12-30 14:54:49 +00:00
|
|
|
|
public static MainWindowVM Current { get; private set; }
|
2023-12-18 14:53:56 +00:00
|
|
|
|
|
2023-12-30 14:54:49 +00:00
|
|
|
|
private SettingModel _currentSettings;
|
|
|
|
|
public SettingModel CurrentSetting
|
2023-12-18 14:53:56 +00:00
|
|
|
|
{
|
2023-12-30 14:54:49 +00:00
|
|
|
|
get => _currentSettings;
|
|
|
|
|
set => SetProperty(ref _currentSettings, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly ObservableCollection<SettingModel> _settings = new();
|
|
|
|
|
|
|
|
|
|
private IEnumerable<SettingModel> _showSettings;
|
|
|
|
|
public IEnumerable<SettingModel> ShowSettings
|
|
|
|
|
{
|
|
|
|
|
get => _showSettings;
|
|
|
|
|
set => SetProperty(ref _showSettings, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _searchSetting;
|
|
|
|
|
public string SearchSetting
|
|
|
|
|
{
|
|
|
|
|
get => _searchSetting;
|
|
|
|
|
set => SetProperty(ref _searchSetting, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MainWindowVM()
|
|
|
|
|
{
|
|
|
|
|
Current = this;
|
|
|
|
|
ShowSettings = _settings;
|
|
|
|
|
|
|
|
|
|
foreach (var s in LoadSettings())
|
|
|
|
|
_settings.Add(s);
|
|
|
|
|
|
|
|
|
|
PropertyChanged += MainWindowVM_PropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindowVM_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == nameof(SearchSetting))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(SearchSetting))
|
|
|
|
|
ShowSettings = _settings;
|
|
|
|
|
else
|
|
|
|
|
ShowSettings = _settings.Where(
|
|
|
|
|
s => s.Name.Contains(SearchSetting, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<SettingModel> LoadSettings()
|
|
|
|
|
{
|
|
|
|
|
foreach (
|
|
|
|
|
var file in Directory
|
|
|
|
|
.EnumerateFiles(Environment.CurrentDirectory)
|
|
|
|
|
.Where(
|
|
|
|
|
(s) =>
|
|
|
|
|
{
|
|
|
|
|
if (s.EndsWith(".lps") is false)
|
|
|
|
|
return false;
|
|
|
|
|
return Path.GetFileName(s).StartsWith("Setting");
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
2023-12-18 14:53:56 +00:00
|
|
|
|
{
|
2023-12-30 14:54:49 +00:00
|
|
|
|
var setting = new Setting(File.ReadAllText(file));
|
|
|
|
|
yield return new SettingModel(setting)
|
|
|
|
|
{
|
|
|
|
|
Name = Path.GetFileNameWithoutExtension(file),
|
|
|
|
|
FilePath = file
|
|
|
|
|
};
|
2023-12-18 14:53:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|