diff --git a/App/Common/DualKeyDictionary.cs b/App/Common/DualKeyDictionary.cs index b4e7a399..9f632d6b 100644 --- a/App/Common/DualKeyDictionary.cs +++ b/App/Common/DualKeyDictionary.cs @@ -4,6 +4,8 @@ namespace PDFPatcher.Common { public class DualKeyDictionary : IDictionary + where K : notnull + where V : notnull { private readonly Dictionary _keyDictionary = new Dictionary(); private readonly Dictionary _reverseDictionary = new Dictionary(); diff --git a/App/Common/FilePath.cs b/App/Common/FilePath.cs index 4b6705b3..407646ba 100644 --- a/App/Common/FilePath.cs +++ b/App/Common/FilePath.cs @@ -1097,7 +1097,7 @@ public bool Equals(FilePath other) { /// 需要与当前实例比较的对象。 /// 在两个文件路径相等时,返回 true。 [DebuggerStepThrough] - public override bool Equals(object obj) { + public override bool Equals(object? obj) { return obj is FilePath && Equals((FilePath)obj); } diff --git a/App/Common/FontUtility.cs b/App/Common/FontUtility.cs index 64d7266f..fb3bce95 100644 --- a/App/Common/FontUtility.cs +++ b/App/Common/FontUtility.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text; using System.Text.RegularExpressions; @@ -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 { @@ -21,6 +22,7 @@ public static FriendlyFontName[] InstalledFonts { } } + [MemberNotNull("_Fonts")] private static void ListInstalledFonts() { var uf = new List(); // 可能包含中文的字体 var of = new List(); // 其他字体 @@ -48,7 +50,7 @@ private static void ListInstalledFonts() { internal struct FriendlyFontName : IComparable { public string OriginalName; - public string DisplayName; + public string? DisplayName; public FriendlyFontName(string originalName, string displayName) { OriginalName = originalName; DisplayName = displayName != originalName ? displayName : null; diff --git a/App/Common/PInvokeHelper.cs b/App/Common/PInvokeHelper.cs index f90dc0b4..b6dd0efb 100644 --- a/App/Common/PInvokeHelper.cs +++ b/App/Common/PInvokeHelper.cs @@ -18,6 +18,8 @@ static class PInvokeHelper return t; } - + internal static T UnwrapPointer(IntPtr p) { + throw new NotImplementedException(); + } } } diff --git a/App/Functions/AboutControl.cs b/App/Functions/AboutControl.cs index 6d042452..00d58138 100644 --- a/App/Functions/AboutControl.cs +++ b/App/Functions/AboutControl.cs @@ -37,7 +37,7 @@ public string AssemblyTitle { return titleAttribute.Title; } } - return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); + return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location); } } diff --git a/App/Functions/DocumentInspectorControl.cs b/App/Functions/DocumentInspectorControl.cs index 9793a26d..927af810 100644 --- a/App/Functions/DocumentInspectorControl.cs +++ b/App/Functions/DocumentInspectorControl.cs @@ -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; @@ -288,8 +287,6 @@ public override void ExecuteCommand(string commandName, params string[] paramete 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); diff --git a/App/Functions/EditorControl.cs b/App/Functions/EditorControl.cs index c733674f..70cc5f29 100644 --- a/App/Functions/EditorControl.cs +++ b/App/Functions/EditorControl.cs @@ -475,7 +475,6 @@ private void _OpenButton_DropDownItemClicked(object sender, ToolStripItemClicked 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); diff --git a/App/Functions/MergerControl.cs b/App/Functions/MergerControl.cs index 54fb6517..7da0db65 100644 --- a/App/Functions/MergerControl.cs +++ b/App/Functions/MergerControl.cs @@ -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; @@ -121,7 +120,7 @@ private void MergerControl_Load(object sender, EventArgs args) { }; } - [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); diff --git a/App/Functions/UpdateForm.cs b/App/Functions/UpdateForm.cs index 218842bd..146e1109 100644 --- a/App/Functions/UpdateForm.cs +++ b/App/Functions/UpdateForm.cs @@ -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(); @@ -30,7 +34,7 @@ public UpdateForm() { 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) { @@ -46,27 +50,23 @@ public UpdateForm() { } 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) { @@ -74,6 +74,7 @@ private void CheckResult(System.Xml.XmlDocument x) { if (r == null || r.Name != Constants.AppEngName) { _InfoBox.SelectionColor = Color.Red; _InfoBox.AppendLine("版本信息文件格式错误,请稍候重试。"); + return; } var v = r.GetAttribute("version"); var d = r.GetAttribute("date"); diff --git a/App/Model/ColorSpaces/CIELab.cs b/App/Model/ColorSpaces/CIELab.cs index a87267e9..64264725 100644 --- a/App/Model/ColorSpaces/CIELab.cs +++ b/App/Model/ColorSpaces/CIELab.cs @@ -73,7 +73,7 @@ public CIELab(double l, double a, double b) { } #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); diff --git a/App/Model/ColorSpaces/CIEXYZ.cs b/App/Model/ColorSpaces/CIEXYZ.cs index 68d35170..300b1aee 100644 --- a/App/Model/ColorSpaces/CIEXYZ.cs +++ b/App/Model/ColorSpaces/CIEXYZ.cs @@ -77,7 +77,7 @@ public CIEXYZ(double x, double y, double z) { } #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); diff --git a/App/Model/ColorSpaces/CMYK.cs b/App/Model/ColorSpaces/CMYK.cs index 1ac56e90..dfba27df 100644 --- a/App/Model/ColorSpaces/CMYK.cs +++ b/App/Model/ColorSpaces/CMYK.cs @@ -86,7 +86,7 @@ public CMYK(double c, double m, double y, double k) { } #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); diff --git a/App/Model/ColorSpaces/HSB.cs b/App/Model/ColorSpaces/HSB.cs index 954d9c39..ec382ca2 100644 --- a/App/Model/ColorSpaces/HSB.cs +++ b/App/Model/ColorSpaces/HSB.cs @@ -80,7 +80,7 @@ public HSB(double h, double s, double b) { } #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); diff --git a/App/Model/ColorSpaces/HSL.cs b/App/Model/ColorSpaces/HSL.cs index 73f3a0a8..91ee4337 100644 --- a/App/Model/ColorSpaces/HSL.cs +++ b/App/Model/ColorSpaces/HSL.cs @@ -81,7 +81,7 @@ public HSL(double h, double s, double l) { } #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); diff --git a/App/Model/ColorSpaces/RGB.cs b/App/Model/ColorSpaces/RGB.cs index c82976a2..bc6aa275 100644 --- a/App/Model/ColorSpaces/RGB.cs +++ b/App/Model/ColorSpaces/RGB.cs @@ -66,7 +66,7 @@ public RGB(int R, int G, int B) { } #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); diff --git a/App/Model/ColorSpaces/YUV.cs b/App/Model/ColorSpaces/YUV.cs index 78cbeb23..8ce81cd9 100644 --- a/App/Model/ColorSpaces/YUV.cs +++ b/App/Model/ColorSpaces/YUV.cs @@ -74,7 +74,7 @@ public YUV(double y, double u, double v) { } #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); diff --git a/App/PDFPatcher.csproj b/App/PDFPatcher.csproj index f146476e..43d6bfc4 100644 --- a/App/PDFPatcher.csproj +++ b/App/PDFPatcher.csproj @@ -1,1054 +1,89 @@  - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {77A9FBD2-FB25-4590-864A-64A01A8724C4} - WinExe - Properties - PDFPatcher - PDFPatcher - v4.0 - 512 - pdf_icon.ico - true - true - wmjordan.snk - PDFPatcher.Program - OnOutputUpdated - - - - - true - ..\bin\Debug\ - TRACE;DEBUG;NET40;SOURCE_INCLUDE - true - full - x86 - prompt - false - latest - - - ..\bin\Release\ - TRACE;NET40;SOURCE_INCLUDE - true - true - pdbonly - x86 - false - prompt - latest - - - Common\app.manifest - - - - Lib\ColorPicker.dll - - - ..\packages\CyotekImageBox.1.3.0\lib\net20\Cyotek.Windows.Forms.ImageBox.dll - - - Lib\FreeImageNET.dll - - - Lib\HtmlRenderer.dll - - - Lib\HtmlRenderer.WinForms.dll - - - Lib\itextAsian.dll - - - Lib\itextsharp.dll - - - ..\packages\ObjectListView.Official.2.9.1\lib\net20\ObjectListView.dll - - - Lib\PowerJson.dll - - - - - - - - Lib\TradeWright.TabControlExtra.dll - - - - - True - True - ChineseCharMap.resx - - - - - - - - - - - - - - - - Form - - - FontCharSubstitutionForm.cs - - - Form - - - AddBookmarkConditionForm.cs - - - - - - - - - - - - - - - - - - - - - - - Form - - - PagePropertyForm.cs - - - - - - - Component - - - - - - - - - Form - - - CustomizeToolbarForm.cs - - - Form - - - Form - - - AutoBookmarkForm.cs - - - Form - - - DocumentInfoForm.cs - - - Form - - - InsertPageLabelForm.cs - - - - - - UserControl - - - - - - - - - - - - - - Component - - - Form - - - InsertBookmarkForm.cs - - - Component - - - - UserControl - - - FrontPageControl.cs - - - Form - - - DocumentFontListForm.cs - - - Form - - - AddPdfObjectForm.cs - - - Form - - - EditAdjustmentForm.cs - - - Form - - - FontFilterForm.cs - - - UserControl - - - FontNameConditionEditor.cs - - - UserControl - - - PageSettingsEditor.cs - - - UserControl - - - FontSubstitutionsEditor.cs - - - UserControl - - - Form - - - ImageViewerForm.cs - - - Form - - - SavePdfForm.cs - - - Form - - - MergerOptionForm.cs - - - UserControl - - - InfoExchangerControl.cs - - - - UserControl - - - RenameControl.cs - - - Component - - - UserControl - - - TextSizeConditionEditor.cs - - - - - - UserControl - - - OcrControl.cs - - - UserControl - - - PageRangeConditionEditor.cs - - - UserControl - - - TextConditionEditor.cs - - - UserControl - - - DocumentInspectorControl.cs - - - UserControl - - - TextPositionConditionEditor.cs - - - Form - - - TextViewerForm.cs - - - UserControl - - - RenderImageControl.cs - - - UserControl - - - MergerControl.cs - - - Form - - - SourcePdfOptionForm.cs - - - Form - - - UpdateForm.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Form - - - ActionEditorForm.cs - - - Component - - - BookmarkEditorView.cs - - - UserControl - - - EditorControl.cs - - - UserControl - - - DocumentInfoEditor.cs - - - Component - - - Component - - - Form - - - NewCoordinateEntryForm.cs - - - UserControl - - - PageLabelEditor.cs - - - Form - - - RenamePreviewForm.cs - - - Component - - - Form - - - SearchBookmarkForm.cs - - - Form - - - ShiftPageNumberEntryForm.cs - - - UserControl - - - ExtractImageControl.cs - - - Form - - - SourceImageOptionForm.cs - - - Form - - - AppOptionForm.cs - - - UserControl - - - ViewerPreferenceEditor.cs - - - UserControl - - - AutoBookmarkControl.cs - - - Form - - - ZoomRateEntryForm.cs - - - Form - - - MainForm.cs - - - - - - - - - - - - - - - - - - - - Code - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - - - - Code - - - - - - - - - - UserControl - - - AboutControl.cs - - - - UserControl - - - BookmarkControl.cs - - - Form - - - PatcherOptionForm.cs - - - - UserControl - - - TargetFileControl.cs - - - UserControl - - - PatcherControl.cs - - - - - - - - - - True - True - Resources.resx - - - - - - - - - Form - - - InfoFileOptionControl.cs - - - - - Form - - - PasswordEntryForm.cs - - - - - - - - - ResXFileCodeGenerator - ChineseCharMap.Designer.cs - - - - FontCharSubstitutionForm.cs - - - AddBookmarkConditionForm.cs - - - AutoBookmarkForm.cs - - - DocumentInfoForm.cs - - - InsertBookmarkForm.cs - - - CustomizeToolbarForm.cs - - - InsertPageLabelForm.cs - - - PagePropertyForm.cs - - - FrontPageControl.cs - Designer - - - AboutControl.cs - Designer - - - ActionEditorForm.cs - - - BookmarkEditorView.cs - - - EditorControl.cs - - - DocumentInfoEditor.cs - - - EditAdjustmentForm.cs - - - InfoFileOptionControl.cs - Designer - - - InfoExchangerControl.cs - - - RenameControl.cs - - - PatcherControl.cs - - - BookmarkControl.cs - Designer - - - PatcherOptionForm.cs - - - FontFilterForm.cs - - - FontNameConditionEditor.cs - - - ImageViewerForm.cs - - - SavePdfForm.cs - - - TextSizeConditionEditor.cs - - - NewCoordinateEntryForm.cs - - - PageLabelEditor.cs - - - RenamePreviewForm.cs - - - SearchBookmarkForm.cs - - - ShiftPageNumberEntryForm.cs - - - TargetFileControl.cs - Designer - - - ExtractImageControl.cs - Designer - - - SourceImageOptionForm.cs - - - AppOptionForm.cs - Designer - - - ViewerPreferenceEditor.cs - - - AutoBookmarkControl.cs - Designer - - - PasswordEntryForm.cs - Designer - - - ZoomRateEntryForm.cs - - - OcrControl.cs - Designer - - - PageRangeConditionEditor.cs - - - TextConditionEditor.cs - - - DocumentInspectorControl.cs - - - MainForm.cs - Designer - - - ResXFileCodeGenerator - Designer - Resources.Designer.cs - - - SourceFileControl.cs - Designer - - - ExtractPageControl.cs - Designer - - - ReportControl.cs - Designer - - - - UserControl - - - SourceFileControl.cs - - - UserControl - - - ExtractPageControl.cs - - - - UserControl - - - ReportControl.cs - - - - - PreserveNewest - - - PreserveNewest - - - - - Designer - - - Designer - - - - - - - - - DocumentFontListForm.cs - - - AddPdfObjectForm.cs - - - PageSettingsEditor.cs - - - FontSubstitutionsEditor.cs - - - MergerOptionForm.cs - - - TextPositionConditionEditor.cs - - - TextViewerForm.cs - - - RenderImageControl.cs - Designer - - - MergerControl.cs - - - SourcePdfOptionForm.cs - - - UpdateForm.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 此项目引用这台计算机上缺少的 NuGet 程序包。使用 NuGet 程序包还原可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - - - - - - - - - - + + + 9.0.30729 + 2.0 + {77A9FBD2-FB25-4590-864A-64A01A8724C4} + WinExe + Properties + PDFPatcher + PDFPatcher + pdf_icon.ico + true + PDFPatcher.Program + net5.0 + x86;x64 + true + False + true + $(DefineConstants);NET40;SOURCE_INCLUDE + Common\app.manifest + enable + ..\bin + + false + + wmjordan.snk + true + + + + + + + + + + + + + Lib\ColorPicker.dll + + + Lib\FreeImageNET.dll + + + Lib\HtmlRenderer.dll + + + Lib\HtmlRenderer.WinForms.dll + + + Lib\itextAsian.dll + + + Lib\itextsharp.dll + + + Lib\PowerJson.dll + + + Lib\TradeWright.TabControlExtra.dll + + + + + PreserveNewest + + + PreserveNewest + + + + + Designer + + + Designer + + + + + + + + + PreserveNewest + + \ No newline at end of file diff --git a/App/Processor/Mupdf/Interop.cs b/App/Processor/Mupdf/Interop.cs index f87c95a3..a3069faa 100644 --- a/App/Processor/Mupdf/Interop.cs +++ b/App/Processor/Mupdf/Interop.cs @@ -23,7 +23,7 @@ internal interface ILinkedList } internal static T MarshalAs(this IntPtr ptr) where T : struct { - return (T)Marshal.PtrToStructure(ptr, typeof(T)); + return (T)Marshal.PtrToStructure(ptr, typeof(T))!; } internal static bool IsValid(this SafeHandle handle) { diff --git a/App/Processor/Mupdf/MuHandle.cs b/App/Processor/Mupdf/MuHandle.cs index 223637ad..8d7bf8a7 100644 --- a/App/Processor/Mupdf/MuHandle.cs +++ b/App/Processor/Mupdf/MuHandle.cs @@ -4,8 +4,6 @@ namespace MuPdfSharp { - [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)] - [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)] abstract class MuHandle : System.Runtime.InteropServices.SafeHandle { protected MuHandle() : base(IntPtr.Zero, true) { } @@ -29,7 +27,6 @@ internal static ContextHandle Create() { return NativeMethods.NewContext(); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] protected override bool ReleaseHandle() { NativeMethods.DropContext(handle); SetHandleAsInvalid(); @@ -65,13 +62,11 @@ sealed class DocumentHandle : MuHandle { readonly ContextHandle _context; readonly bool _releaseContext; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] internal DocumentHandle(ContextHandle context, StreamHandle stream) { handle = NativeMethods.OpenPdfDocumentStream(context, stream); _context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] internal DocumentHandle(ContextHandle context, IntPtr documentHandle) { handle = documentHandle; _context = context; @@ -80,7 +75,6 @@ internal DocumentHandle(ContextHandle context, IntPtr documentHandle) { internal ContextHandle Context => _context; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] protected override bool ReleaseHandle() { NativeMethods.DropDocument(_context, handle); if (_releaseContext) { @@ -94,20 +88,17 @@ sealed class StreamHandle : MuHandle { readonly bool _releaseContext; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] internal StreamHandle(ContextHandle context, IntPtr handle) { this.handle = handle; Context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] internal StreamHandle(ContextHandle context, string filePath) : this(context, NativeMethods.OpenFile(context, filePath)) { } internal ContextHandle Context { get; } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] protected override bool ReleaseHandle() { NativeMethods.DropStream(Context, handle); if (_releaseContext) { @@ -132,23 +123,23 @@ sealed class DeviceHandle : MuHandle context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal DeviceHandle(ContextHandle context, ref Rectangle rectangle) : this(context, NativeMethods.NewBBoxDevice(context, ref rectangle)) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal DeviceHandle(ContextHandle context, PixmapHandle pixmap, Matrix matrix) : this(context, NativeMethods.NewDrawDevice(context, matrix, pixmap)) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal DeviceHandle(ContextHandle context, PixmapHandle pixmap, Matrix matrix, ref BBox box) : this(context, NativeMethods.NewDrawDevice(context, matrix, pixmap, ref box)) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal DeviceHandle(ContextHandle context, DisplayListHandle displayList) : this(context, NativeMethods.NewListDevice(context, displayList)) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal DeviceHandle(ContextHandle context, TextPageHandle page) : this(context, NativeMethods.NewTextDevice(context, page, null)) { } @@ -156,7 +147,7 @@ internal void EndOperations() { NativeMethods.CloseDevice(_context, handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + protected override bool ReleaseHandle() { NativeMethods.DropDevice(_context, handle); if (_releaseContext) { @@ -170,7 +161,7 @@ sealed class PageHandle : MuHandle { readonly DocumentHandle _document; readonly bool _releaseDocument; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + public PageHandle(DocumentHandle document, int pageNumber) { handle = NativeMethods.LoadPage(document.Context, document, pageNumber); _document = document; @@ -179,7 +170,7 @@ public PageHandle(DocumentHandle document, int pageNumber) { internal unsafe IntPtr PageDictionary => ((NativePage*)handle)->PageDictionary; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + protected override bool ReleaseHandle() { NativeMethods.DropPage(_document.Context, handle); if (_releaseDocument) { @@ -228,14 +219,14 @@ sealed class DisplayListHandle : MuHandle { readonly ContextHandle _context; readonly bool _releaseContext; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal DisplayListHandle(ContextHandle context, Rectangle mediaBox) { handle = NativeMethods.NewDisplayList(context, mediaBox); _context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + protected override bool ReleaseHandle() { NativeMethods.DropDisplayList(_context, handle); if (_releaseContext) { @@ -249,27 +240,27 @@ sealed class PixmapHandle : MuHandle { readonly ContextHandle _context; readonly bool _releaseContext; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal PixmapHandle(ContextHandle context, IntPtr pixmap) { handle = pixmap; _context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal PixmapHandle(ContextHandle context, IntPtr colorspace, int width, int height) { handle = NativeMethods.NewPixmap(context, colorspace, width, height, IntPtr.Zero, 0); _context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal PixmapHandle(ContextHandle context, IntPtr colorspace, BBox box) { handle = NativeMethods.NewPixmap(context, colorspace, box, IntPtr.Zero, 0); _context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + protected override bool ReleaseHandle() { NativeMethods.DropPixmap(_context, handle); if (_releaseContext) { @@ -283,14 +274,14 @@ sealed class TextPageHandle : MuHandle { readonly ContextHandle _context; readonly bool _releaseContext; - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + internal TextPageHandle(ContextHandle context, Rectangle mediaBox) { handle = NativeMethods.NewTextPage(context, mediaBox); _context = context; context.DangerousAddRef(ref _releaseContext); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)] + protected override bool ReleaseHandle() { NativeMethods.DropTextPage(_context, handle); if (_releaseContext) { diff --git a/App/Processor/Mupdf/NativeMethods.cs b/App/Processor/Mupdf/NativeMethods.cs index 62e448c8..befd9ed3 100644 --- a/App/Processor/Mupdf/NativeMethods.cs +++ b/App/Processor/Mupdf/NativeMethods.cs @@ -71,7 +71,7 @@ internal static ContextHandle NewContext() { internal static extern IntPtr NewListDevice(ContextHandle ctx, DisplayListHandle list); [DllImport(DLL, CallingConvention = CC.Cdecl, EntryPoint = "fz_new_stext_device")] - internal static extern IntPtr NewTextDevice(ContextHandle ctx, TextPageHandle page, TextOptions options); + internal static extern IntPtr NewTextDevice(ContextHandle ctx, TextPageHandle page, TextOptions? options); [DllImport(DLL, CallingConvention = CC.Cdecl, EntryPoint = "fz_close_device")] internal static extern void CloseDevice(ContextHandle context, IntPtr dev); diff --git a/App/Processor/NullXmlWriter.cs b/App/Processor/NullXmlWriter.cs index d03de06f..9101a286 100644 --- a/App/Processor/NullXmlWriter.cs +++ b/App/Processor/NullXmlWriter.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Text; - +#nullable disable namespace PDFPatcher.Processor { sealed class NullXmlWriter : System.Xml.XmlWriter diff --git a/App/Properties/AssemblyInfo.cs b/App/Properties/AssemblyInfo.cs deleted file mode 100644 index 86fec431..00000000 --- a/App/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过下列属性集 -// 控制。更改这些属性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("PDFPatcher")] -[assembly: AssemblyDescription(PDFPatcher.Constants.AppName)] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("wmjordan@163.com")] -[assembly: AssemblyProduct(PDFPatcher.Constants.AppEngName)] -[assembly: AssemblyCopyright("著作权所有 © WMJordan 2009~2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 则将该类型上的 ComVisible 属性设置为 true。 -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("e8969c5f-a5fe-4dce-a08b-555686483732")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.3744")] diff --git a/App/Properties/PublishProfiles/FxDependent.pubxml b/App/Properties/PublishProfiles/FxDependent.pubxml new file mode 100644 index 00000000..96961249 --- /dev/null +++ b/App/Properties/PublishProfiles/FxDependent.pubxml @@ -0,0 +1,17 @@ + + + + + Release + x86 + ..\bin\publish\fx-dependent-x86 + FileSystem + net5.0-windows + false + win-x86 + False + False + + \ No newline at end of file diff --git a/App/Properties/PublishProfiles/Independent.pubxml b/App/Properties/PublishProfiles/Independent.pubxml new file mode 100644 index 00000000..c3e144c0 --- /dev/null +++ b/App/Properties/PublishProfiles/Independent.pubxml @@ -0,0 +1,17 @@ + + + + + Release + x86 + ..\bin\publish\win-x86\ + FileSystem + net5.0-windows + win-x86 + true + False + False + + \ No newline at end of file diff --git a/App/packages.config b/App/packages.config deleted file mode 100644 index 61e67767..00000000 --- a/App/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/JBig2/DetectHighestPlatformToolset.props b/JBig2/DetectHighestPlatformToolset.props new file mode 100644 index 00000000..339519c4 --- /dev/null +++ b/JBig2/DetectHighestPlatformToolset.props @@ -0,0 +1,7 @@ + + + + v142 + v143 + + diff --git a/JBig2/jbig2.vcxproj b/JBig2/jbig2.vcxproj index 7bafea3d..3a9205f5 100644 --- a/JBig2/jbig2.vcxproj +++ b/JBig2/jbig2.vcxproj @@ -1,205 +1,202 @@ - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 16.0 - Win32Proj - {a8c76a16-25e3-45b6-b974-4f4cb88e5ae2} - jbig2 - 10.0 - - - - DynamicLibrary - true - Unicode - v142 - - - DynamicLibrary - false - true - Unicode - v142 - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(ProjectDir)include;$(IncludePath) - $(SolutionDir)bin\$(Configuration)\ - obj\$(Configuration)\ - - - false - $(ProjectDir)include;$(IncludePath) - $(SolutionDir)bin\$(Configuration)\ - obj\$(Configuration)\ - - - true - $(SolutionDir)bin\$(Platform)\$(Configuration)\ - - - false - $(SolutionDir)bin\$(Platform)\$(Configuration)\ - - - - Level3 - true - WIN32;__STDC_LIMIT_MACROS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - jbig2.def - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) - - - - - Level3 - true - true - true - WIN32;__STDC_LIMIT_MACROS;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - jbig2.def - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + Win32Proj + {a8c76a16-25e3-45b6-b974-4f4cb88e5ae2} + jbig2 + 10.0 + + + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)include;$(IncludePath) + $(SolutionDir)bin\$(Configuration)\ + obj\$(Configuration)\ + + + false + $(ProjectDir)include;$(IncludePath) + $(SolutionDir)bin\$(Configuration)\ + obj\$(Configuration)\ + + + true + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + + + + Level3 + true + WIN32;__STDC_LIMIT_MACROS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + jbig2.def + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;__STDC_LIMIT_MACROS;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + jbig2.def + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + \ No newline at end of file diff --git a/PDFPatcher.sln b/PDFPatcher.sln index 572ae762..e39680ab 100644 --- a/PDFPatcher.sln +++ b/PDFPatcher.sln @@ -1,14 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31829.152 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFPatcher", "App\PDFPatcher.csproj", "{77A9FBD2-FB25-4590-864A-64A01A8724C4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PDFPatcher", "App\PDFPatcher.csproj", "{77A9FBD2-FB25-4590-864A-64A01A8724C4}" ProjectSection(ProjectDependencies) = postProject {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2} = {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jbig2", "jbig2\jbig2.vcxproj", "{A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jbig2", "JBig2\jbig2.vcxproj", "{A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3243E921-0EC3-44D1-96CC-C3E05BF9C89B}" ProjectSection(SolutionItems) = preProject @@ -18,38 +18,24 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|Win32 = Release|Win32 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|Any CPU.ActiveCfg = Debug|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|Win32.ActiveCfg = Debug|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|Win32.Build.0 = Debug|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|x64.ActiveCfg = Debug|x86 + {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|x64.ActiveCfg = Debug|x64 + {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|x64.Build.0 = Debug|x64 {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|x86.ActiveCfg = Debug|x86 {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Debug|x86.Build.0 = Debug|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|Any CPU.ActiveCfg = Release|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|Win32.ActiveCfg = Release|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|Win32.Build.0 = Release|x86 - {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|x64.ActiveCfg = Release|x86 + {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|x64.ActiveCfg = Release|x64 + {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|x64.Build.0 = Release|x64 {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|x86.ActiveCfg = Release|x86 {77A9FBD2-FB25-4590-864A-64A01A8724C4}.Release|x86.Build.0 = Release|x86 - {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|Win32.ActiveCfg = Debug|Win32 - {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|Win32.Build.0 = Debug|Win32 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|x64.ActiveCfg = Debug|x64 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|x64.Build.0 = Debug|x64 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|x86.ActiveCfg = Debug|Win32 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Debug|x86.Build.0 = Debug|Win32 - {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Release|Any CPU.ActiveCfg = Release|Win32 - {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Release|Win32.ActiveCfg = Release|Win32 - {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Release|Win32.Build.0 = Release|Win32 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Release|x64.ActiveCfg = Release|x64 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Release|x64.Build.0 = Release|x64 {A8C76A16-25E3-45B6-B974-4F4CB88E5AE2}.Release|x86.ActiveCfg = Release|Win32