mirror of
https://github.com/k1tbyte/Wand-Enhancer.git
synced 2026-09-04 16:23:17 +00:00
Introduce IShellView and IFileDialogs so MainWindowVm no longer holds the concrete window or reaches through MainWindow.Instance, and file pickers are injectable. Run Restore off the UI thread like Patch and gate both buttons on IsBusy. Gate the log commands on a non-empty log. Move runtime log messages into the locale dictionaries and add the 14 new keys to all 12 languages. Track the injected locale dictionary so switching language replaces it instead of appending a new one each time. Remove the unused InfoItem control, ToVisibilityInvertedConverter, mw_title and the popup placeholder title.
135 lines
3.9 KiB
C#
135 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using Microsoft.Win32;
|
|
using WandEnhancer.Models;
|
|
using WandEnhancer.Utils;
|
|
|
|
namespace WandEnhancer.View.Popups
|
|
{
|
|
public partial class PatchVectorsPopup : UserControl
|
|
{
|
|
private const string JavaScriptDialogFilter = "JavaScript files (*.js)|*.js";
|
|
|
|
private readonly Action<PatchConfig> _onApply;
|
|
private readonly ObservableCollection<SelectedScript> _selectedScripts = new ObservableCollection<SelectedScript>();
|
|
|
|
public PatchVectorsPopup(Action<PatchConfig> onApply)
|
|
{
|
|
_onApply = onApply;
|
|
InitializeComponent();
|
|
ScriptList.ItemsSource = _selectedScripts;
|
|
UpdateScriptsEmptyState();
|
|
}
|
|
|
|
private void OnAddScriptClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var dialog = new OpenFileDialog
|
|
{
|
|
Filter = JavaScriptDialogFilter,
|
|
Multiselect = true,
|
|
CheckFileExists = true
|
|
};
|
|
|
|
if (dialog.ShowDialog() != true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var path in dialog.FileNames.Where(WeModInstalls.IsJavaScriptFile))
|
|
{
|
|
AddScript(path);
|
|
}
|
|
|
|
if (_selectedScripts.Count > 0)
|
|
{
|
|
RemoteWebPanelPreviewBox.IsChecked = true;
|
|
}
|
|
|
|
UpdateScriptsEmptyState();
|
|
}
|
|
|
|
private void OnRemoveScriptClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
var script = button?.Tag as SelectedScript;
|
|
if (script == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_selectedScripts.Remove(script);
|
|
UpdateScriptsEmptyState();
|
|
}
|
|
|
|
private void OnPatchButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ActivateProBox.IsChecked != true && DisableUpdateBox.IsChecked != true &&
|
|
DevToolsHotkeyBox.IsChecked != true && RemoteWebPanelPreviewBox.IsChecked != true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var result = new HashSet<EPatchType>();
|
|
if (ActivateProBox.IsChecked == true)
|
|
{
|
|
result.Add(EPatchType.ActivatePro);
|
|
}
|
|
|
|
if (DisableUpdateBox.IsChecked == true)
|
|
{
|
|
result.Add(EPatchType.DisableUpdates);
|
|
}
|
|
|
|
if (DevToolsHotkeyBox.IsChecked == true)
|
|
{
|
|
result.Add(EPatchType.DevToolsOnF12);
|
|
}
|
|
|
|
if (RemoteWebPanelPreviewBox.IsChecked == true)
|
|
{
|
|
result.Add(EPatchType.RemoteWebPanelPreview);
|
|
}
|
|
|
|
_onApply(new PatchConfig
|
|
{
|
|
PatchTypes = result,
|
|
CustomScriptPaths = _selectedScripts.Select(script => script.FullPath).ToList(),
|
|
AutoApplyAfterUpdate = AutoApplyBox.IsChecked == true
|
|
});
|
|
}
|
|
|
|
private void AddScript(string path)
|
|
{
|
|
var fullPath = Path.GetFullPath(path);
|
|
if (_selectedScripts.Any(script => string.Equals(script.FullPath, fullPath, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_selectedScripts.Add(new SelectedScript(fullPath));
|
|
}
|
|
|
|
private void UpdateScriptsEmptyState()
|
|
{
|
|
NoScriptsText.Visibility = _selectedScripts.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
private sealed class SelectedScript
|
|
{
|
|
public SelectedScript(string fullPath)
|
|
{
|
|
FullPath = fullPath;
|
|
FileName = Path.GetFileName(fullPath);
|
|
}
|
|
|
|
public string FullPath { get; }
|
|
|
|
public string FileName { get; }
|
|
}
|
|
}
|
|
} |