Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Core改造 #26

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions App/Common/DualKeyDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace PDFPatcher.Common
{
public class DualKeyDictionary<K, V> : IDictionary<K, V>
where K : notnull
where V : notnull
{
private readonly Dictionary<K, V> _keyDictionary = new Dictionary<K, V>();
private readonly Dictionary<V, K> _reverseDictionary = new Dictionary<V, K>();
Expand Down
2 changes: 1 addition & 1 deletion App/Common/FilePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ namespace PDFPatcher.Common
/// <param name="obj">需要与当前实例比较的对象。</param>
/// <returns>在两个文件路径相等时,返回 true。</returns>
[DebuggerStepThrough]
public override bool Equals(object obj) {
public override bool Equals(object? obj) {
return obj is FilePath && Equals((FilePath)obj);
}

Expand Down
6 changes: 4 additions & 2 deletions App/Common/FontUtility.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.RegularExpressions;

Expand All @@ -10,7 +11,7 @@ static class FontUtility
static readonly Regex _italic = new Regex(" (?:Italic|Oblique)$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
static readonly Regex _bold = new Regex(" Bold$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
static readonly Regex _boldItalic = new Regex(" Bold (?:Italic|Oblique)$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
static FriendlyFontName[] _Fonts;
static FriendlyFontName[]? _Fonts;

public static FriendlyFontName[] InstalledFonts {
get {
Expand All @@ -21,6 +22,7 @@ static class FontUtility
}
}

[MemberNotNull("_Fonts")]
private static void ListInstalledFonts() {
var uf = new List<FriendlyFontName>(); // 可能包含中文的字体
var of = new List<FriendlyFontName>(); // 其他字体
Expand Down Expand Up @@ -48,7 +50,7 @@ static class FontUtility
internal struct FriendlyFontName : IComparable<FriendlyFontName>
{
public string OriginalName;
public string DisplayName;
public string? DisplayName;
public FriendlyFontName(string originalName, string displayName) {
OriginalName = originalName;
DisplayName = displayName != originalName ? displayName : null;
Expand Down
4 changes: 3 additions & 1 deletion App/Common/PInvokeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ static class PInvokeHelper
return t;
}


internal static T UnwrapPointer<T>(IntPtr p) {
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion App/Functions/AboutControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sealed partial class AboutControl : Functions.HtmlPageControl
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location);
}
}

Expand Down
3 changes: 0 additions & 3 deletions App/Functions/DocumentInspectorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Xml;
using BrightIdeasSoftware;
Expand Down Expand Up @@ -288,8 +287,6 @@ public sealed partial class DocumentInspectorControl : FunctionControl, IDocumen
break;
}
}

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (_ObjectDetailBox.IsCellEditing) {
return base.ProcessCmdKey(ref msg, keyData);
Expand Down
1 change: 0 additions & 1 deletion App/Functions/EditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ public sealed partial class EditorControl : FunctionControl, IDocumentEditor, Ed
ExecuteCommand(Commands.OpenFile, e.ClickedItem.ToolTipText);
}

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (_BookmarkBox.IsCellEditing || _BookmarkBox.IsLabelEditing || _CurrentPageBox.Focused) {
return base.ProcessCmdKey(ref msg, keyData);
Expand Down
3 changes: 1 addition & 2 deletions App/Functions/MergerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Windows.Forms;
using BrightIdeasSoftware;
Expand Down Expand Up @@ -121,7 +120,7 @@ public partial class MergerControl : FunctionControl
};
}

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (_ItemList.IsCellEditing || _ItemList.Focused == false) {
return base.ProcessCmdKey(ref msg, keyData);
Expand Down
39 changes: 20 additions & 19 deletions App/Functions/UpdateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using PDFPatcher.Common;

namespace PDFPatcher.Functions
{
public partial class UpdateForm : Form
{
System.Net.WebClient _UpdateChecker;
HttpClient _UpdateChecker;

public UpdateForm() {
InitializeComponent();
Expand All @@ -30,7 +34,7 @@ public partial class UpdateForm : Form
CommonCommands.VisitHomePage();
};
_DownloadButton.Click += (s, args) => {
System.Diagnostics.Process.Start(_DownloadButton.Tag.ToString());
System.Diagnostics.Process.Start(_DownloadButton.Tag.ToString()!);
};
_CheckUpdateIntervalBox.SelectedIndexChanged += (s, args) => {
switch (_CheckUpdateIntervalBox.SelectedIndex) {
Expand All @@ -46,34 +50,31 @@ public partial class UpdateForm : Form
}

private void CheckNewVersion() {
_UpdateChecker = new System.Net.WebClient();
_InfoBox.AppendLine("正在检查新版本,请稍候……");
_UpdateChecker.DownloadDataCompleted += (s, args) => {
_InfoBox.Clear();
if (args.Error != null) {
_InfoBox.AppendText("检查新版本失败:" + args.Error.Message);
goto Exit;
}

Task.Run(async () => {
using HttpClient client = new();
try {
var x = new System.Xml.XmlDocument();
x.Load(new System.IO.MemoryStream(args.Result));
CheckResult(x);
Stream s = await client.GetStreamAsync(Constants.AppUpdateFile);
XmlDocument xdoc = new();
xdoc.Load(s);
CheckResult(xdoc);
}
catch (Exception) {
Common.FormHelper.ErrorBox("版本信息文件格式错误,请稍候重试。");
catch (HttpRequestException e) {
_InfoBox.AppendText("检查新版本失败:" + e.Message);
}
Exit:
_UpdateChecker.Dispose();
_UpdateChecker = null;
};
_UpdateChecker.DownloadDataAsync(new Uri(Constants.AppUpdateFile));
catch (XmlException e) {
FormHelper.ErrorBox("版本信息文件格式错误,请稍候重试。");
}
});
}

private void CheckResult(System.Xml.XmlDocument x) {
var r = x.DocumentElement;
if (r == null || r.Name != Constants.AppEngName) {
_InfoBox.SelectionColor = Color.Red;
_InfoBox.AppendLine("版本信息文件格式错误,请稍候重试。");
return;
}
var v = r.GetAttribute("version");
var d = r.GetAttribute("date");
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/CIELab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public struct CIELab
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (CIELab)obj);
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/CIEXYZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public struct CIEXYZ
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (CIEXYZ)obj);
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/CMYK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public struct CMYK
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (CMYK)obj);
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/HSB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public struct HSB
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (HSB)obj);
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/HSL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public struct HSL
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (HSL)obj);
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/RGB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct RGB
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (RGB)obj);
Expand Down
2 changes: 1 addition & 1 deletion App/Model/ColorSpaces/YUV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct YUV
}

#region Methods
public override bool Equals(Object obj) {
public override bool Equals(Object? obj) {
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (YUV)obj);
Expand Down