增加开机自启功能和自启设置
This commit is contained in:
@@ -29,6 +29,13 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
public string Title => $"SpineViewer - v{App.Version}";
|
||||
|
||||
public string AutoRunWorkspaceConfigPath
|
||||
{
|
||||
get => _autoRunWorkspaceConfigPath;
|
||||
set => SetProperty(ref _autoRunWorkspaceConfigPath, value);
|
||||
}
|
||||
private string _autoRunWorkspaceConfigPath;
|
||||
|
||||
/// <summary>
|
||||
/// SFML 渲染对象
|
||||
/// </summary>
|
||||
|
||||
@@ -26,10 +26,6 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
/// </summary>
|
||||
public static readonly string PreferenceFilePath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), "preference.json");
|
||||
|
||||
private static readonly string SkelFileDescription = "SpineViewer File";
|
||||
private static readonly string SkelIconFilePath = Path.Combine(App.ProcessDirectory, "Resources\\Images\\skel.ico");
|
||||
private static readonly string ShellOpenCommand = $"\"{App.ProcessPath}\" \"%1\"";
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly MainWindowViewModel _vmMain;
|
||||
@@ -111,6 +107,8 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
DebugPoints = DebugPoints,
|
||||
DebugClippings = DebugClippings,
|
||||
|
||||
AutoRun = AutoRun,
|
||||
AutoRunWorkspaceConfigPath = AutoRunWorkspaceConfigPath,
|
||||
WallpaperView = WallpaperView,
|
||||
RenderSelectedOnly = RenderSelectedOnly,
|
||||
AssociateFileSuffix = AssociateFileSuffix,
|
||||
@@ -137,6 +135,8 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
DebugPoints = value.DebugPoints;
|
||||
DebugClippings = value.DebugClippings;
|
||||
|
||||
AutoRun = value.AutoRun;
|
||||
AutoRunWorkspaceConfigPath = value.AutoRunWorkspaceConfigPath;
|
||||
WallpaperView = value.WallpaperView;
|
||||
RenderSelectedOnly = value.RenderSelectedOnly;
|
||||
AssociateFileSuffix = value.AssociateFileSuffix;
|
||||
@@ -248,16 +248,21 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
public bool AutoRun
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
get => ((App)App.Current).AutoRun;
|
||||
set => SetProperty(((App)App.Current).AutoRun, value, v => ((App)App.Current).AutoRun = v);
|
||||
}
|
||||
|
||||
public string AutoRunWorkspaceConfigPath
|
||||
{
|
||||
get => _vmMain.AutoRunWorkspaceConfigPath;
|
||||
set => SetProperty(_vmMain.AutoRunWorkspaceConfigPath, value, v => _vmMain.AutoRunWorkspaceConfigPath = v);
|
||||
}
|
||||
|
||||
public bool WallpaperView
|
||||
{
|
||||
get => _wallpaperView;
|
||||
set => SetProperty(ref _wallpaperView, value);
|
||||
get => _vmMain.SFMLRendererViewModel.WallpaperView;
|
||||
set => SetProperty(_vmMain.SFMLRendererViewModel.WallpaperView, value, v => _vmMain.SFMLRendererViewModel.WallpaperView = v);
|
||||
}
|
||||
private bool _wallpaperView; // UI 变化通过 PropertyChanged 事件交由 View 层处理
|
||||
|
||||
public bool RenderSelectedOnly
|
||||
{
|
||||
@@ -267,67 +272,8 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
public bool AssociateFileSuffix
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查 .skel 的 ProgID
|
||||
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Classes\.skel"))
|
||||
{
|
||||
var progIdValue = key?.GetValue("") as string;
|
||||
if (!string.Equals(progIdValue, App.ProgId, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查 command 指令是否相同
|
||||
using (var key = Registry.CurrentUser.OpenSubKey($@"Software\Classes\{App.ProgId}\shell\open\command"))
|
||||
{
|
||||
var command = key?.GetValue("") as string;
|
||||
if (string.IsNullOrWhiteSpace(command))
|
||||
return false;
|
||||
return command == ShellOpenCommand;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(AssociateFileSuffix, value, v =>
|
||||
{
|
||||
if (v)
|
||||
{
|
||||
// 文件关联
|
||||
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\Classes\.skel"))
|
||||
{
|
||||
key?.SetValue("", App.ProgId);
|
||||
}
|
||||
|
||||
using (var key = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{App.ProgId}"))
|
||||
{
|
||||
key?.SetValue("", SkelFileDescription);
|
||||
using (var iconKey = key?.CreateSubKey("DefaultIcon"))
|
||||
{
|
||||
iconKey?.SetValue("", $"\"{SkelIconFilePath}\"");
|
||||
}
|
||||
using (var shellKey = key?.CreateSubKey(@"shell\open\command"))
|
||||
{
|
||||
shellKey?.SetValue("", ShellOpenCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 删除关联
|
||||
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Classes\.skel", false);
|
||||
Registry.CurrentUser.DeleteSubKeyTree($@"Software\Classes\{App.ProgId}", false);
|
||||
}
|
||||
|
||||
Shell32.NotifyAssociationChanged();
|
||||
});
|
||||
}
|
||||
get => ((App)App.Current).AssociateFileSuffix;
|
||||
set => SetProperty(((App)App.Current).AssociateFileSuffix, value, v => ((App)App.Current).AssociateFileSuffix = v);
|
||||
}
|
||||
|
||||
public AppLanguage AppLanguage
|
||||
|
||||
@@ -240,6 +240,13 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
}
|
||||
private Stretch _backgroundImageMode = Stretch.Uniform;
|
||||
|
||||
public bool WallpaperView
|
||||
{
|
||||
get => _wallpaperView;
|
||||
set => SetProperty(ref _wallpaperView, value);
|
||||
}
|
||||
private bool _wallpaperView;
|
||||
|
||||
public bool RenderSelectedOnly
|
||||
{
|
||||
get => _renderSelectedOnly;
|
||||
@@ -465,10 +472,13 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
}
|
||||
|
||||
using var v = _renderer.GetView();
|
||||
_wallpaperRenderer.SetView(v);
|
||||
|
||||
_renderer.Clear(_backgroundColor);
|
||||
_wallpaperRenderer.Clear(_backgroundColor);
|
||||
|
||||
if (_wallpaperView)
|
||||
{
|
||||
_wallpaperRenderer.SetView(v);
|
||||
_wallpaperRenderer.Clear(_backgroundColor);
|
||||
}
|
||||
|
||||
// 渲染背景
|
||||
lock (_bgLock)
|
||||
@@ -499,7 +509,11 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
bg.Position = view.Center;
|
||||
bg.Rotation = view.Rotation;
|
||||
_renderer.Draw(bg);
|
||||
_wallpaperRenderer.Draw(bg);
|
||||
|
||||
if (_wallpaperView)
|
||||
{
|
||||
_wallpaperRenderer.Draw(bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,12 +553,20 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
sp.EnableDebug = true;
|
||||
_renderer.Draw(sp);
|
||||
sp.EnableDebug = false;
|
||||
_wallpaperRenderer.Draw(sp);
|
||||
|
||||
if (_wallpaperView)
|
||||
{
|
||||
_wallpaperRenderer.Draw(sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_renderer.Display();
|
||||
_wallpaperRenderer.Display();
|
||||
|
||||
if (_wallpaperView)
|
||||
{
|
||||
_wallpaperRenderer.Display();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user