refactor:迁移设置
This commit is contained in:
@@ -1,76 +1,11 @@
|
||||
using IWshRuntimeLibrary;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
using File = System.IO.File;
|
||||
using Ink_Canvas.Windows.SettingsViews.Helpers;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建开机自启动快捷方式。
|
||||
/// </summary>
|
||||
/// <param name="exeName">可执行文件名,用于命名快捷方式。</param>
|
||||
/// <returns>创建成功返回true,失败返回false。</returns>
|
||||
/// <remarks>
|
||||
/// 操作包括:
|
||||
/// 1. 创建Windows Shell对象
|
||||
/// 2. 在启动文件夹中创建快捷方式
|
||||
/// 3. 设置快捷方式的目标路径为当前可执行文件路径
|
||||
/// 4. 设置工作目录为当前目录
|
||||
/// 5. 设置窗口样式为普通窗口
|
||||
/// 6. 设置快捷方式描述
|
||||
/// 7. 保存快捷方式
|
||||
/// 8. 捕获可能的异常,确保方法不会因异常而崩溃
|
||||
/// </remarks>
|
||||
public static bool StartAutomaticallyCreate(string exeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var shell = new WshShell();
|
||||
var shortcut = (IWshShortcut)shell.CreateShortcut(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + exeName + ".lnk");
|
||||
//设置快捷方式的目标所在的位置(源程序完整路径)
|
||||
shortcut.TargetPath = Application.ExecutablePath;
|
||||
//应用程序的工作目录
|
||||
//当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
|
||||
shortcut.WorkingDirectory = Environment.CurrentDirectory;
|
||||
//目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化)
|
||||
shortcut.WindowStyle = 1;
|
||||
//快捷方式的描述
|
||||
shortcut.Description = exeName + "_Ink";
|
||||
//设置快捷键(如果有必要的话.)
|
||||
//shortcut.Hotkey = "CTRL+ALT+D";
|
||||
shortcut.Save();
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { }
|
||||
public static bool StartAutomaticallyCreate(string exeName) => AutoStartHelper.StartAutomaticallyCreate(exeName);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除开机自启动快捷方式。
|
||||
/// </summary>
|
||||
/// <param name="exeName">可执行文件名,用于定位要删除的快捷方式。</param>
|
||||
/// <returns>删除成功返回true,失败返回false。</returns>
|
||||
/// <remarks>
|
||||
/// 操作包括:
|
||||
/// 1. 在启动文件夹中删除指定名称的快捷方式
|
||||
/// 2. 捕获可能的异常,确保方法不会因异常而崩溃
|
||||
/// </remarks>
|
||||
public static bool StartAutomaticallyDel(string exeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + exeName +
|
||||
".lnk");
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
return false;
|
||||
}
|
||||
public static bool StartAutomaticallyDel(string exeName) => AutoStartHelper.StartAutomaticallyDel(exeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Ink_Canvas.Controls;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Windows.SettingsViews.Helpers;
|
||||
using iNKORE.UI.WPF.Modern;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@@ -416,9 +417,9 @@ namespace Ink_Canvas
|
||||
{
|
||||
BorderSettings.Visibility = Visibility.Collapsed;
|
||||
isOpeningOrHidingSettingsPane = false;
|
||||
if (isTemporarilyDisablingNoFocusMode)
|
||||
if (WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode)
|
||||
{
|
||||
isTemporarilyDisablingNoFocusMode = false;
|
||||
WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode = false;
|
||||
ApplyNoFocusMode();
|
||||
}
|
||||
};
|
||||
@@ -3080,9 +3081,9 @@ namespace Ink_Canvas
|
||||
// 如果当前在设置面板中,需要先恢复无焦点模式状态
|
||||
if (BorderSettings.Visibility == Visibility.Visible)
|
||||
{
|
||||
if (isTemporarilyDisablingNoFocusMode)
|
||||
if (WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode)
|
||||
{
|
||||
isTemporarilyDisablingNoFocusMode = false;
|
||||
WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode = false;
|
||||
ApplyNoFocusMode();
|
||||
}
|
||||
SaveSettingsToFile();
|
||||
@@ -3102,9 +3103,9 @@ namespace Ink_Canvas
|
||||
{
|
||||
if (BorderSettings.Visibility == Visibility.Visible)
|
||||
{
|
||||
if (isTemporarilyDisablingNoFocusMode)
|
||||
if (WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode)
|
||||
{
|
||||
isTemporarilyDisablingNoFocusMode = false;
|
||||
WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode = false;
|
||||
ApplyNoFocusMode();
|
||||
}
|
||||
SaveSettingsToFile();
|
||||
@@ -3178,7 +3179,7 @@ namespace Ink_Canvas
|
||||
wasNoFocusModeBeforeSettings = Settings.Advanced.IsNoFocusMode;
|
||||
if (wasNoFocusModeBeforeSettings)
|
||||
{
|
||||
isTemporarilyDisablingNoFocusMode = true;
|
||||
WindowSettingsHelper.IsTemporarilyDisablingNoFocusMode = true;
|
||||
ApplyNoFocusMode();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using H.NotifyIcon;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Windows.SettingsViews.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using OSVersionExtension;
|
||||
using System;
|
||||
@@ -5113,22 +5114,7 @@ namespace Ink_Canvas
|
||||
/// <remarks>
|
||||
/// 在写入前会确保目标目录/文件具有写入权限(使用 ProcessProtectionManager)。任何写入失败或异常都会被吞掉,调用方不会收到异常抛出。
|
||||
/// </remarks>
|
||||
public static void SaveSettingsToFile()
|
||||
{
|
||||
var text = JsonConvert.SerializeObject(Settings, Formatting.Indented);
|
||||
try
|
||||
{
|
||||
string configsDir = Path.Combine(App.RootPath, "Configs");
|
||||
if (!Directory.Exists(configsDir))
|
||||
{
|
||||
ProcessProtectionManager.WithWriteAccess(configsDir, () => Directory.CreateDirectory(configsDir));
|
||||
}
|
||||
|
||||
var path = App.RootPath + settingsFileName;
|
||||
ProcessProtectionManager.WithWriteAccess(path, () => File.WriteAllText(path, text));
|
||||
}
|
||||
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
|
||||
}
|
||||
public static void SaveSettingsToFile() => SettingsManager.SaveSettingsToFile();
|
||||
|
||||
private void SCManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user