更新/升级调整

This commit is contained in:
LittleBoy 2024-09-04 23:05:14 +08:00
parent d2e960243c
commit 99e0792772
26 changed files with 564 additions and 132 deletions

Binary file not shown.

View File

@ -336,6 +336,7 @@
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Util\HostHelper.cs" /> <Compile Include="Util\HostHelper.cs" />
<Compile Include="Util\HttpUtil.cs" />
<EmbeddedResource Include="Controls\FormContact.resx"> <EmbeddedResource Include="Controls\FormContact.resx">
<DependentUpon>FormContact.cs</DependentUpon> <DependentUpon>FormContact.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View File

@ -7,7 +7,7 @@
<SupportUrlHistory /> <SupportUrlHistory />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Project</StartAction> <StartAction>Program</StartAction>
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.17827\office6\wps.exe</StartProgram> <StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.17827\office6\wps.exe</StartProgram>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -13,7 +13,6 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using UtilLib; using UtilLib;
using Document = Microsoft.Office.Interop.Word.Document; using Document = Microsoft.Office.Interop.Word.Document;
@ -45,11 +44,68 @@ namespace AIProofread
private static object missing = System.Reflection.Missing.Value; private static object missing = System.Reflection.Missing.Value;
private static UpgradeData CurrentUpgrade = null;
public void ShowUpgradeView()
{
var needUpgrade = CurrentUpgrade.NeedUpgrade(Config.APP_VERSION);
if (CurrentUpgrade.Ext == 1)
{
if (!needUpgrade)
{
showDialog("当前版本为最新版本,无需升级");
}
else
{
var ret = MessageBox.Show(CurrentUpgrade.Message, "是否确认更新", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
if (ret == DialogResult.Yes)
{
OpenUrlWithOsBrowser(CurrentUpgrade.DownloadUrl);
}
}
}
else
{
StartUpgradeProcess();
}
}
public bool ShouldUpgradeForced()
{
return CurrentUpgrade != null && CurrentUpgrade.NeedUpgrade(Config.APP_VERSION) && CurrentUpgrade.UpgradeType == 1;
}
public void InitPluginUpgrade()
{
try
{
string source = HttpUtil.GetHttpSource(Config.WEB_PATH + "api/v1/common/download/version");
if (source == null) return;
UpgradeSource data = JsonConvert.DeserializeObject<UpgradeSource>(source);
if (data == null || data.Code != 0) return;
CurrentUpgrade = data.Data;
// 是否需要强制升级
//if (ShouldUpgradeForced())
//{
// // 显示升级框
// ShowUpgradeView();
//}
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
public string GetAppVersion() public string GetAppVersion()
{ {
return Config.APP_VERSION; return Config.APP_VERSION;
} }
public void showDialog(string message) public void showDialog(string message)
{ {
System.Windows.Forms.MessageBox.Show(message); System.Windows.Forms.MessageBox.Show(message);
@ -133,6 +189,25 @@ namespace AIProofread
} }
} }
public static void StartUpgradeProcess()
{
try
{
string applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
string path = "updater.exe";
ProcessStartInfo processStartInfo = new ProcessStartInfo(Path.Combine(applicationBase, Path.GetFileName(path)))
{
WorkingDirectory = applicationBase,
};
Process.Start(processStartInfo);
}
catch (Exception e)
{
Logger.Log(e);
MessageBox.Show("启动升级程序失败,请重试");
}
}
public void StartProofread() public void StartProofread()
{ {
Globals.ThisAddIn.SendMessageToWeb("start", "login"); Globals.ThisAddIn.SendMessageToWeb("start", "login");
@ -183,15 +258,36 @@ namespace AIProofread
} }
public string getDocumentData() public string getDocumentData()
{ {
Dictionary<string, object> data = new Dictionary<string, object>(); Dictionary<string, object> data = new Dictionary<string, object>();
var doc = Globals.ThisAddIn.Application.ActiveDocument; var doc = Globals.ThisAddIn.Application.ActiveDocument;
data.Add("name", doc.Name);
data.Add("fullName", doc.FullName);
//data.Add("documentId", GeIdBytDocument(doc));
data.Add("wordsCount", doc.Words.Count);
data.Add("charactersCount", doc.Characters.Count);
data.Add("content", Tools.GetAllText(doc));
if (!doc.Saved)
{
data.Add("code", 1);
data.Add("message", "请保存文档后再进行校对");
}
else if (ShouldUpgradeForced())
{
data.Add("code", 2);
data.Add("message", "请升级插件后再进行校对");
}
else if (doc.ProtectionType != WdProtectionType.wdNoProtection)
{
data.Add("code", 3);
data.Add("message", "文档受保护,无法编辑");
}
else
{
data.Add("code", 0);
data.Add("message", "success");
data.Add("name", doc.Name);
data.Add("fullName", doc.FullName);
//data.Add("documentId", GeIdBytDocument(doc));
data.Add("wordsCount", doc.Words.Count);
data.Add("charactersCount", doc.Characters.Count);
data.Add("content", Tools.GetAllText(doc));
}
return Tools.GetJSONString(data); return Tools.GetJSONString(data);
} }
@ -271,12 +367,27 @@ namespace AIProofread
public void ShowUpgrade(string data) public void ShowUpgrade(string data)
{ {
var upgradeData = JsonConvert.DeserializeObject<UpgradeData>(data); //var upgradeData = JsonConvert.DeserializeObject<UpgradeData>(data);
var ret = System.Windows.Forms.MessageBox.Show(upgradeData.Message, "更新提示", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question); //var needUpgrade = upgradeData.NeedUpgrade(Config.APP_VERSION);
if (ret == System.Windows.Forms.DialogResult.Yes) //if (upgradeData.Ext == 1)
{ //{
OpenUrlWithOsBrowser(upgradeData.DownloadUrl); // if (!needUpgrade)
} // {
// showDialog("当前版本为最新版本,无需升级");
// }
// else
// {
// var ret = MessageBox.Show(upgradeData.Message, "是否确认更新", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
// if (ret == DialogResult.Yes)
// {
// OpenUrlWithOsBrowser(upgradeData.DownloadUrl);
// }
// }
//}
//else
//{
// StartUpgradeProcess();
//}
} }
public void noticeOtherWeb(string json, string targetWebName) public void noticeOtherWeb(string json, string targetWebName)
@ -335,6 +446,10 @@ namespace AIProofread
} }
public void clearAllProofreadMarkById(int documentId)
{
clearAllProofreadMark(GetDocumentById(documentId));
}
// 清除所有标记 // 清除所有标记
public void clearAllProofreadMark(Document document) public void clearAllProofreadMark(Document document)
{ {
@ -496,7 +611,7 @@ namespace AIProofread
rng.Select(); rng.Select();
} }
public void SelectMarkById(int proofreadId,int documentId) public void SelectMarkById(int proofreadId, int documentId)
{ {
var doc = documentId < 1 ? Globals.ThisAddIn.Application.ActiveDocument : GetDocumentById(documentId); var doc = documentId < 1 ? Globals.ThisAddIn.Application.ActiveDocument : GetDocumentById(documentId);
// //
@ -566,13 +681,13 @@ namespace AIProofread
} }
} }
public string InitContent(string content,int documentId) public string InitContent(string content, int documentId)
{ {
try try
{ {
// 根据文档编号 获取当前文档避免数据混乱 // 根据文档编号 获取当前文档避免数据混乱
CurrentDocument = GetDocumentById(documentId); CurrentDocument = GetDocumentById(documentId);
if(CurrentDocument == null) if (CurrentDocument == null)
{ {
throw new Exception("没有找到校对文档对象"); throw new Exception("没有找到校对文档对象");
} }
@ -594,23 +709,19 @@ namespace AIProofread
int index = 0; int index = 0;
foreach (var item in correct.Diffs) foreach (var item in correct.Diffs)
{ {
if (item.id == 187095)
{
Console.WriteLine("xx");
}
int _prev = prevOffset; int _prev = prevOffset;
// 查找对应区域并再该区域添加书签 // 查找对应区域并再该区域添加书签
var mark = FindRangeAndCreateBookmark(item, correct,ref prevOffset); var mark = DocumentUtil.FindRangeAndCreateBookmark(item, correct, CurrentDocument, ref prevOffset);
// 防止调用方法中没有更新 // 防止调用方法中没有更新
if (_prev >= prevOffset) if (_prev >= prevOffset)
{ {
prevOffset = correct.SentenceOffset + item.end; prevOffset = correct.SentenceOffset + item.start;
} }
if (item.tag != "i") index++; if (item.tag != "i") index++;
if (mark != null) if (mark != null)
{ {
marks.Add(item.id, new ProofreadItem(item, mark,documentId)); marks.Add(item.id, new ProofreadItem(item, mark, documentId));
} }
else else
{ {
@ -637,8 +748,16 @@ namespace AIProofread
} }
if (item.Value.content.color != null) if (item.Value.content.color != null)
{ {
// 给选区添加背景颜色 try
item.Value.mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.Value.content.color)); {
var color = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.Value.content.color));
// 给选区添加背景颜色
item.Value.mark.Shading.BackgroundPatternColor = color;
}
catch (Exception)
{
//item.Value.mark.Shading.BackgroundPatternColor = WdColor.wdColorLightOrange;
}
} }
} }
} }
@ -693,7 +812,7 @@ namespace AIProofread
/// <param name="sentense">校对</param> /// <param name="sentense">校对</param>
/// <param name="prevOffset"></param> /// <param name="prevOffset"></param>
/// <returns></returns> /// <returns></returns>
public Microsoft.Office.Tools.Word.Bookmark FindRangeAndCreateBookmark(CorrectedContent correct, DocumentCorrectItem sentense,ref int prevOffset) public Microsoft.Office.Tools.Word.Bookmark FindRangeAndCreateBookmark1(CorrectedContent correct, DocumentCorrectItem sentense, ref int prevOffset)
{ {
Microsoft.Office.Tools.Word.Bookmark bookmark = null; Microsoft.Office.Tools.Word.Bookmark bookmark = null;
try try
@ -793,7 +912,7 @@ namespace AIProofread
if (correct.tag != "i" && findRange.Text != correct.origin) if (correct.tag != "i" && findRange.Text != correct.origin)
{ {
// 查找 // 查找
findRange = DocumentUtil.FindRange(correct,sentense,ref prevOffset,CurrentDocument, paragraphRange); findRange = DocumentUtil.FindRange(correct, sentense, ref prevOffset, CurrentDocument, paragraphRange);
} }
// 能够找到对应的区域 则再对应区域添加书签 // 能够找到对应的区域 则再对应区域添加书签
@ -853,6 +972,7 @@ namespace AIProofread
return bookmark; return bookmark;
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@ -32,7 +32,7 @@ namespace AIProofread
} }
public static void Log( Exception e) public static void Log( Exception e)
{ {
Log(e.StackTrace); Log(e.Message + "\n" + e.StackTrace);
} }
public static void Log(string tag, Exception e) public static void Log(string tag, Exception e)
{ {

View File

@ -84,16 +84,30 @@ namespace UtilLib
} }
public void UnSelect() public void UnSelect()
{ {
if (mark == null) return; try
mark.Range.Font.Size = originSize; // 还原 {
mark.Shading.ForegroundPatternColor = originColor; if (mark == null) return;
mark.Range.Font.Size = originSize; // 还原
mark.Shading.ForegroundPatternColor = originColor;
}
catch (Exception e)
{
Logger.Log(e);
}
} }
private void SetMarkStyle() private void SetMarkStyle()
{ {
if (mark == null) return; try
{
if (mark == null) return;
//mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick; //mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(content.color)); mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(content.color));
}
catch (Exception e)
{
Logger.Log(e);
}
} }
public void ResetMarkStyle() public void ResetMarkStyle()
@ -108,7 +122,10 @@ namespace UtilLib
mark.Shading.ForegroundPatternColor = originColor; mark.Shading.ForegroundPatternColor = originColor;
mark.Range.Shading.BackgroundPatternColor = originColor;// Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic; mark.Range.Shading.BackgroundPatternColor = originColor;// Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
} }
catch (Exception) { } catch (Exception e)
{
Logger.Log(e);
}
} }
public void Process(int status) public void Process(int status)

View File

@ -124,7 +124,8 @@ namespace AIProofread
private void BtnUpdate_Click(object sender, RibbonControlEventArgs e) private void BtnUpdate_Click(object sender, RibbonControlEventArgs e)
{ {
//System.Windows.Forms.MessageBox.Show("当前插件是最新版本"); //System.Windows.Forms.MessageBox.Show("当前插件是最新版本");
Globals.ThisAddIn.SendMessageToWeb("upgrade", Config.APP_VERSION); //Globals.ThisAddIn.SendMessageToWeb("upgrade", Config.APP_VERSION);
Bridge.bridge.ShowUpgradeView();
} }
private void BtnProofreadAll_Click(object sender, RibbonControlEventArgs e) private void BtnProofreadAll_Click(object sender, RibbonControlEventArgs e)
@ -396,12 +397,6 @@ namespace AIProofread
{ {
return string.IsNullOrEmpty(range.Text) ? "" : range.Text; return string.IsNullOrEmpty(range.Text) ? "" : range.Text;
} }
//private async Task ProcessCorrectCut()
//{
//}
private void BtnOpenLog_Click(object sender, RibbonControlEventArgs e) private void BtnOpenLog_Click(object sender, RibbonControlEventArgs e)
{ {
// 打开日志目录 // 打开日志目录
@ -410,11 +405,7 @@ namespace AIProofread
private void button1_Click(object sender, RibbonControlEventArgs e) private void button1_Click(object sender, RibbonControlEventArgs e)
{ {
string applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; Bridge.StartUpgradeProcess();
string path = "updater.exe";
ProcessStartInfo processStartInfo = new ProcessStartInfo(Path.Combine(applicationBase, Path.GetFileName(path)));
processStartInfo.WorkingDirectory = applicationBase;
Process.Start(processStartInfo);
} }
} }
} }

View File

@ -303,6 +303,8 @@ namespace AIProofread
//Application.DocumentChange += //Application.DocumentChange +=
// 选区发生变化事件 // 选区发生变化事件
this.Application.WindowSelectionChange += Application_WindowSelectionChange; this.Application.WindowSelectionChange += Application_WindowSelectionChange;
// 检测升级信息
Bridge.bridge.InitPluginUpgrade();
try try
{ {

View File

@ -0,0 +1,36 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using updater;
namespace AIProofread.Util
{
public class HttpUtil
{
public static string GetHttpSource(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse())
{
// 获取响应内容
if (resp.StatusCode == HttpStatusCode.OK)
{
using (Stream receiveStream = resp.GetResponseStream())
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
return readStream.ReadToEnd();
}
}
}
}
return null;
}
}
}

View File

@ -1,15 +1,14 @@
//using Microsoft.Office.Interop.Word; //using Microsoft.Office.Interop.Word;
using Section = Microsoft.Office.Interop.Word.Section;
using WdColor = Microsoft.Office.Interop.Word.WdColor;
using System.Drawing; using System.Drawing;
using UtilLib; using UtilLib;
using Microsoft.Office.Interop.Word;
using Bookmark = Microsoft.Office.Tools.Word.Bookmark;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Office.Tools.Word;
using System; using System;
using System.Xml.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Tools.Word;
using Bookmark = Microsoft.Office.Tools.Word.Bookmark;
using Section = Microsoft.Office.Interop.Word.Section;
using WdColor = Microsoft.Office.Interop.Word.WdColor;
namespace AIProofread namespace AIProofread
{ {
@ -291,5 +290,124 @@ namespace AIProofread
return null; return null;
} }
public static Bookmark FindRangeAndCreateBookmark(CorrectedContent correct, DocumentCorrectItem sentense, Microsoft.Office.Interop.Word.Document document, ref int prevOffset)
{
Bookmark bookmark = null;
try
{
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
var markName = Config.BuildBookmarkName(correct.id);
// 判断是否已经存在
if (controls.Contains(markName))
{
try
{
controls.Remove(markName);
}
catch (Exception) { }
}
// 判断段落是否存在
if (sentense.ParagraphNumber > document.Paragraphs.Count) return null;
var paragraph = document.Paragraphs[sentense.ParagraphNumber];
var findRange = FindRangeByCorrect(sentense, correct, paragraph, document, prevOffset);
if (findRange != null)
{
// 更新查找的结束位置
//prevOffset = findRange.End - paragraphStart;
bookmark = controls.AddBookmark(findRange, markName);
bookmark.Tag = "ai_proofread";
}
}
catch (Exception ex)
{
Logger.Log("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n");
}
return bookmark;
}
private static Range FindRangeByCorrect(DocumentCorrectItem c, CorrectedContent item, Paragraph paragraph, Microsoft.Office.Interop.Word.Document document, int prevOffset)
{
var paraRange = paragraph.Range;
var paraText = paraRange.Text;
var paraStart = paraRange.Start;
// 定位句子的其实位置
var offset = paraStart + c.SentenceOffset;
//var cutLength = Math.Min(c.InsertLen, paraText.Length - offset);
var sentence = paraText.Substring(c.SentenceOffset, c.InsertLength);
if (sentence == c.Insert)
{ // 比对原始内容与校对原文是否一致
var range = document.Range(offset + item.start, offset + item.end);
//
if (range.Text == item.origin) return range;
}
var originText = c.Insert;
// 如果是新增 则查找定位
if (item.tag == "i")
{
// 找前缀
var prefix1 = item.start > 2 ? (
item.start > INSERT_FIND_OFFSET
? originText.Substring(item.start - INSERT_FIND_OFFSET, INSERT_FIND_OFFSET)
: originText.Substring(0, item.start)
) : null;
// 找后缀
var suffix1 = prefix1 == null ? (
item.end + INSERT_FIND_OFFSET < originText.Length
? originText.Substring(item.start, INSERT_FIND_OFFSET)
: originText.Substring(item.start, originText.Length - item.start)
) : null;
// 偏移量
var start1 = prefix1 != null || suffix1 != null
? paraText.IndexOf(prefix1 ?? suffix1, prevOffset)
: -1;
if (start1 != -1)
{
var findOffset = paraStart + start1 + (prefix1 != null ? prefix1.Length : 0);
return document.Range(findOffset, findOffset);
}
}
// 执行查找
int wordStart = item.start;
int wordEnd = item.end;
// 找前缀
var prefix = wordStart > 2 ? (
wordStart > INSERT_FIND_OFFSET
? originText.Substring(wordStart - INSERT_FIND_OFFSET, INSERT_FIND_OFFSET)
: originText.Substring(0, wordStart)
) : null;
// 找后缀
var suffix = prefix == null ? (
wordEnd + INSERT_FIND_OFFSET < originText.Length
? originText.Substring(wordStart, INSERT_FIND_OFFSET)
: originText.Substring(wordStart, originText.Length - wordStart)
) : null;
var start = prefix != null || suffix != null
? paraText.IndexOf(prefix ?? suffix, prevOffset) // item.start +
: -1;
if (start != -1)
{
var findOffset = paraRange.Start + start + (prefix != null ? prefix.Length : 0);
var range = document.Range(findOffset, findOffset + wordEnd - wordStart);
if (range.Text == item.origin) { return range; }
}
// 直接定位查找
start = paraText.IndexOf(item.origin, prevOffset);
if (start == -1) return null;
// 定位整体开始位置
start = paraStart + start;
return document.Range(start, start + item.origin.Length);
}
} }
} }

View File

@ -1 +1 @@
fe1ae839bfb706b80f0b4718d7a4129a4057bf53be655076474daf866eae1d58 4c1c6aa096bd384197619062b3689b9a218de9da2c1b7adc250936855349c9f3

View File

@ -29,34 +29,6 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.pdb C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.dll.manifest C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.dll.manifest
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.vsto C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.vsto
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Office.Tools.Common.v4.0.Utilities.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Core.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.WinForms.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Wpf.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Newtonsoft.Json.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\util-lib.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\util-lib.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Core.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.WinForms.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Wpf.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.AssemblyReference.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormContact.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormLoading.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormLogin.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormMain.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormSetting.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.ProofreadMainControl.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Properties.Resources.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Ribbon1.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.GenerateResource.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CoreCompileInputs.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofr.8811D769.Up2Date
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\updater.exe
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.Compression.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\updater.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\updater.exe.config
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Runtime.InteropServices.RuntimeInformation.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Runtime.InteropServices.RuntimeInformation.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Win32.Primitives.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Win32.Primitives.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\netstandard.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\netstandard.dll
@ -85,6 +57,7 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Dynam
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Globalization.Calendars.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Globalization.Calendars.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Globalization.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Globalization.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Globalization.Extensions.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Globalization.Extensions.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.Compression.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.Compression.ZipFile.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.Compression.ZipFile.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.FileSystem.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.IO.FileSystem.dll
@ -158,6 +131,11 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\ExtendedNume
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\ICSharpCode.SharpZipLib.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\ICSharpCode.SharpZipLib.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\MathNet.Numerics.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\MathNet.Numerics.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.IO.RecyclableMemoryStream.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.IO.RecyclableMemoryStream.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Office.Tools.Common.v4.0.Utilities.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Core.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.WinForms.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Wpf.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Newtonsoft.Json.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.Core.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.Core.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.OOXML.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.OOXML.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.OpenXml4Net.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.OpenXml4Net.dll
@ -176,6 +154,11 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Secur
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Security.Principal.Windows.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Security.Principal.Windows.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Text.Encoding.CodePages.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Text.Encoding.CodePages.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Threading.Tasks.Extensions.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Threading.Tasks.Extensions.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\updater.exe
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\util-lib.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\updater.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\updater.exe.config
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\util-lib.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\BouncyCastle.Cryptography.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\BouncyCastle.Cryptography.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Enums.NET.pdb C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Enums.NET.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Enums.NET.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Enums.NET.xml
@ -184,6 +167,9 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\ICSharpCode.
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\ICSharpCode.SharpZipLib.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\ICSharpCode.SharpZipLib.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\MathNet.Numerics.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\MathNet.Numerics.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.IO.RecyclableMemoryStream.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.IO.RecyclableMemoryStream.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Core.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.WinForms.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\Microsoft.Web.WebView2.Wpf.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.Core.pdb C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.Core.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.Core.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.Core.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.OOXML.pdb C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\NPOI.OOXML.pdb
@ -206,3 +192,17 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Secur
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Security.Principal.Windows.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Security.Principal.Windows.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Text.Encoding.CodePages.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Text.Encoding.CodePages.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Threading.Tasks.Extensions.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.Threading.Tasks.Extensions.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.AssemblyReference.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormContact.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormLoading.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormLogin.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormMain.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormSetting.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.ProofreadMainControl.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Properties.Resources.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Ribbon1.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.GenerateResource.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CoreCompileInputs.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofr.8811D769.Up2Date
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.pdb

12
updater/AppConfig.cs Normal file
View File

@ -0,0 +1,12 @@
namespace updater
{
public class AppConfig
{
public string AppUrl { get; set; }
public bool AppRunInDebug { get; set; }
/// <summary>
/// dev | test | product
/// </summary>
public string Environment { get; set; }
}
}

View File

@ -33,6 +33,7 @@
this.ButtonUpdate = new System.Windows.Forms.Button(); this.ButtonUpdate = new System.Windows.Forms.Button();
this.LabelLocalVersion = new System.Windows.Forms.Label(); this.LabelLocalVersion = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.BtnCancel = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// LabelLog // LabelLog
@ -55,7 +56,7 @@
this.ButtonUpdate.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); this.ButtonUpdate.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215)))));
this.ButtonUpdate.FlatStyle = System.Windows.Forms.FlatStyle.System; this.ButtonUpdate.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonUpdate.ForeColor = System.Drawing.Color.White; this.ButtonUpdate.ForeColor = System.Drawing.Color.White;
this.ButtonUpdate.Location = new System.Drawing.Point(183, 198); this.ButtonUpdate.Location = new System.Drawing.Point(228, 198);
this.ButtonUpdate.Name = "ButtonUpdate"; this.ButtonUpdate.Name = "ButtonUpdate";
this.ButtonUpdate.Size = new System.Drawing.Size(78, 31); this.ButtonUpdate.Size = new System.Drawing.Size(78, 31);
this.ButtonUpdate.TabIndex = 1; this.ButtonUpdate.TabIndex = 1;
@ -79,12 +80,29 @@
this.progressBar1.TabIndex = 3; this.progressBar1.TabIndex = 3;
this.progressBar1.Visible = false; this.progressBar1.Visible = false;
// //
// BtnCancel
//
this.BtnCancel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215)))));
this.BtnCancel.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215)))));
this.BtnCancel.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Blue;
this.BtnCancel.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215)))));
this.BtnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.BtnCancel.ForeColor = System.Drawing.Color.White;
this.BtnCancel.Location = new System.Drawing.Point(144, 198);
this.BtnCancel.Name = "BtnCancel";
this.BtnCancel.Size = new System.Drawing.Size(78, 31);
this.BtnCancel.TabIndex = 4;
this.BtnCancel.Text = "取消更新";
this.BtnCancel.UseVisualStyleBackColor = false;
this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(438, 286); this.ClientSize = new System.Drawing.Size(438, 286);
this.Controls.Add(this.BtnCancel);
this.Controls.Add(this.progressBar1); this.Controls.Add(this.progressBar1);
this.Controls.Add(this.LabelLocalVersion); this.Controls.Add(this.LabelLocalVersion);
this.Controls.Add(this.ButtonUpdate); this.Controls.Add(this.ButtonUpdate);
@ -106,6 +124,7 @@
private System.Windows.Forms.Button ButtonUpdate; private System.Windows.Forms.Button ButtonUpdate;
private System.Windows.Forms.Label LabelLocalVersion; private System.Windows.Forms.Label LabelLocalVersion;
private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Button BtnCancel;
} }
} }

View File

@ -15,23 +15,53 @@ namespace updater
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
private int localVersionCode = 0; private UpgradeInfo localVersion;
private UpdateModel model; private UpgradeInfo upgradeInfo;
private static string applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; private static readonly string ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
private string versionFilePath = applicationBase + Path.GetFileName("version.json"); private static readonly string LocalVersionFilePath = ApplicationBase + Path.GetFileName("version.json");
private string updateDir = applicationBase + "update\\"; public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json";
private string updateInfoUri = "https://file.wx.wm-app.xyz/jdw/latest.json";
private static readonly string UpgradeDir = ApplicationBase + "update\\";
#if DEBUG
private static string UpgradeInfoURI = "http://gm-plugin.zverse.group/";
#else
private static string UpgradeInfoURI = "https://gm-plugin.gachafun.com/";
#endif
private string updateSource; private string updateSource;
private void InitAppByConfig()
{
try
{
if (File.Exists(CONFIG_FILE))
{
string content = File.ReadAllText(CONFIG_FILE);
if (content == null || content.Length == 0) return;
AppConfig config = JsonConvert.DeserializeObject<AppConfig>(content);
// 插件网址
if (!string.IsNullOrEmpty(config.AppUrl))
{
UpgradeInfoURI = config.AppUrl;
}
}
}
catch (Exception) { }
}
public Form1() public Form1()
{ {
InitAppByConfig();
InitializeComponent(); InitializeComponent();
string source = File.Exists(versionFilePath) ? File.ReadAllText(versionFilePath) : null;
// 读取本地版本信息
string source = File.Exists(LocalVersionFilePath) ? File.ReadAllText(LocalVersionFilePath) : null;
if (source != null && source.Length > 0) if (source != null && source.Length > 0)
{ {
UpdateModel update = JsonConvert.DeserializeObject<UpdateModel>(source); UpgradeModel local = JsonConvert.DeserializeObject<UpgradeModel>(source);
this.localVersionCode = update.VersionCode; this.localVersion = local.Info;
LabelLocalVersion.Text = update.Version; LabelLocalVersion.Text = localVersion.Version;
} }
} }
@ -43,18 +73,18 @@ namespace updater
return; return;
} }
progressBar1.Visible = true; progressBar1.Visible = true;
if (!Directory.Exists(updateDir)) if (!Directory.Exists(UpgradeDir))
{ {
Directory.CreateDirectory(updateDir); Directory.CreateDirectory(UpgradeDir);
} }
string updateFileName = updateDir + Path.GetFileName(model.UpdateFile); string updateFileName = UpgradeDir + Path.GetFileName(upgradeInfo.DownloadUrl);
// 判断是否已经存在升级包 // 判断是否已经存在升级包
if (File.Exists(updateFileName)) if (File.Exists(updateFileName))
{ {
ExtractUpdatePackage(); ExtractUpdatePackage();
return; return;
} }
DownLoadFile(model.UpdateFile, updateFileName); DownLoadFile(upgradeInfo.DownloadUrl, updateFileName);
} }
public bool CheckHostAppRunning() public bool CheckHostAppRunning()
@ -70,6 +100,7 @@ namespace updater
else if (item2.ProcessName.Equals("WINWORD")) else if (item2.ProcessName.Equals("WINWORD"))
{ {
MessageBox.Show("检测到 Word 正在运行中,请关闭后再执行更新操作"); MessageBox.Show("检测到 Word 正在运行中,请关闭后再执行更新操作");
return true;
} }
} }
return false; return false;
@ -82,36 +113,45 @@ namespace updater
public void CheckUpdate() public void CheckUpdate()
{ {
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(updateInfoUri); try
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
// 获取响应内容
if (resp.StatusCode == HttpStatusCode.OK)
{ {
Stream receiveStream = resp.GetResponseStream(); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version");
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
updateSource = readStream.ReadToEnd(); // 获取响应内容
if (updateSource == null && updateSource.Length == 0) if (resp.StatusCode == HttpStatusCode.OK)
{ {
LabelLog.Text = "获取更新信息失败"; Stream receiveStream = resp.GetResponseStream();
return; StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
updateSource = readStream.ReadToEnd();
if (updateSource == null && updateSource.Length == 0)
{
LabelLog.Text = "获取更新信息失败,请稍后重试";
return;
}
resp.Close();
UpgradeModel update = JsonConvert.DeserializeObject<UpgradeModel>(updateSource);
ProcessUpdate(update);
} }
resp.Close(); }
UpdateModel update = JsonConvert.DeserializeObject<UpdateModel>(updateSource); catch (Exception)
ProcessUpdate(update); {
LabelLog.Text = "获取更新信息失败,请稍后重试";
} }
} }
private void ProcessUpdate(UpdateModel update) private void ProcessUpdate(UpgradeModel update)
{ {
LabelLog.Text = update.Log; this.upgradeInfo = update.Info;
this.model = update; LabelLog.Text = update.Info.Message;
if (update.VersionCode > this.localVersionCode)
if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version))
{ {
ButtonUpdate.Enabled = true; ButtonUpdate.Enabled = true;
} }
else else
{ {
ButtonUpdate.Visible = false; ButtonUpdate.Visible = false;
BtnCancel.Visible = false;
LabelLocalVersion.Text = "当前是最新版本"; LabelLocalVersion.Text = "当前是最新版本";
} }
} }
@ -158,22 +198,32 @@ namespace updater
private void ExtractUpdatePackage() private void ExtractUpdatePackage()
{ {
progressBar1.Value = 100; progressBar1.Value = 100;
string zipFilePath = updateDir + Path.GetFileName(model.UpdateFile); // 获取升级包路径
string zipFilePath = UpgradeDir + Path.GetFileName(upgradeInfo.DownloadUrl);
// 可以考虑备份旧文件 // 可以考虑备份旧文件
//string destinationFolder = Path.Combine(applicationBase, "update\\old"); //string destinationFolder = Path.Combine(applicationBase, "update\\old");
//CopyDirectory(applicationBase, destinationFolder); //CopyDirectory(applicationBase, destinationFolder);
//ZipFile.ExtractToDirectory(zipFilePath, applicationBase); //ZipFile.ExtractToDirectory(zipFilePath, applicationBase);
using (ZipArchive zip = ZipFile.OpenRead(zipFilePath)) using (ZipArchive zip = ZipFile.OpenRead(zipFilePath))
{ {
foreach (ZipArchiveEntry entry in zip.Entries) foreach (ZipArchiveEntry entry in zip.Entries)
{ {
// 采用覆盖模式进行解压 // 采用覆盖模式进行解压
entry.ExtractToFile(Path.Combine(applicationBase, entry.FullName), true); try
{
entry.ExtractToFile(Path.Combine(ApplicationBase, entry.FullName), true);
}
catch (Exception)
{
}
} }
} }
MessageBox.Show("更新完成"); MessageBox.Show("更新完成");
// 保存日志 // 保存最新版本日志
File.WriteAllText(versionFilePath, updateSource); File.WriteAllText(LocalVersionFilePath, updateSource);
this.Close(); this.Close();
} }
public static void CopyDirectory(string sourceFolder, string destinationFolder) public static void CopyDirectory(string sourceFolder, string destinationFolder)
@ -200,5 +250,11 @@ namespace updater
} }
} }
} }
private void BtnCancel_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
} }
} }

View File

@ -9,14 +9,13 @@
以下节点之一替换 requestedExecutionLevel 节点。 以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。 指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此 如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。 元素。
--> -->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges> </requestedPrivileges>
<applicationRequestMinimum> <applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" /> <defaultAssemblyRequest permissionSetReference="Custom" />

View File

@ -1,10 +0,0 @@
namespace updater
{
public class UpdateModel
{
public int VersionCode { get; set; }
public string Version { get; set; }
public string Log { get; set; }
public string UpdateFile { get; set; }
}
}

49
updater/UpgradeModel.cs Normal file
View File

@ -0,0 +1,49 @@
using Newtonsoft.Json;
using System;
using System.Security.Permissions;
namespace updater
{
public class UpgradeInfo
{
public int Id { get; set; }
public int PublishType { get; set; }
public string Version { get; set; }
[JsonProperty("download_url")]
public string DownloadUrl { get; set; }
public string Message { get; set; }
/// <summary>
/// 1强制升级
/// 2强制提示
/// 3弱提示
/// </summary>
[JsonProperty("upgrade_type")]
public int UpgradeType { get; set; }
/// <summary>
/// 是否显示弹框 1:显示2:不显示
/// </summary>
[JsonProperty("is_show_pop")]
public int ShowPop { get; set; }
//public int VersionCode { get; set; }
//public string Log { get; set; }
//public string UpdateFile { get; set; }
public bool NeedUpgrade(string currentVersion)
{
var remoteVer = new Version(Version);
var currentVer = new Version(currentVersion);
return remoteVer > currentVer;
}
}
public class UpgradeModel
{
[JsonProperty("msg")]
public string Message { get; set; }
public int Code { get; set; }
[JsonProperty("data")]
public UpgradeInfo Info { get; set; }
}
}

View File

@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@ -71,6 +72,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AppConfig.cs" />
<Compile Include="Form1.cs"> <Compile Include="Form1.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -83,7 +85,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegistHelper.cs" /> <Compile Include="RegistHelper.cs" />
<Compile Include="UpdateData.cs" /> <Compile Include="UpdateData.cs" />
<Compile Include="UpdateModel.cs" /> <Compile Include="UpgradeModel.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View File

@ -1,21 +1,34 @@
using System; using Newtonsoft.Json;
using System;
using System.Security.Principal;
namespace UtilLib namespace UtilLib
{ {
public class UpgradeSource
{
public int Code { get; set; }
[JsonProperty("msg")]
public string Message { get; set; }
public UpgradeData Data { get; set; }
}
public class UpgradeData public class UpgradeData
{ {
public int Id { get; set; } public int Id { get; set; }
/// <summary> /// <summary>
/// APP名称 /// APP名称
/// </summary> /// </summary>
[JsonProperty("app_name")]
public string AppName { get; set; } public string AppName { get; set; }
/// <summary> /// <summary>
/// 客户端类型 1ios 2安卓 3window插件 4 5 /// 客户端类型 1ios 2安卓 3window插件 4 5
/// </summary> /// </summary>
[JsonProperty("client_type")]
public int ClientType { get; set; } public int ClientType { get; set; }
/// <summary> /// <summary>
/// 发布类型 /// 发布类型
/// </summary> /// </summary>
[JsonProperty("publish_type")]
public int PublishType { get; set; } public int PublishType { get; set; }
/// <summary> /// <summary>
/// 发布的版本号 /// 发布的版本号
@ -24,19 +37,26 @@ namespace UtilLib
/// <summary> /// <summary>
/// 升级类型1强制升级 2强制提示 3弱提示 /// 升级类型1强制升级 2强制提示 3弱提示
/// </summary> /// </summary>
[JsonProperty("upgrade_type")]
public int UpgradeType { get; set; } public int UpgradeType { get; set; }
[JsonProperty("download_url")]
public string DownloadUrl { get; set; } public string DownloadUrl { get; set; }
/// <summary> /// <summary>
/// 发布时间 /// 发布时间
/// </summary> /// </summary>
[JsonProperty("publish_time")]
public int PublishTime { get; set; } public int PublishTime { get; set; }
/// <summary> /// <summary>
/// 发布的信息 /// 发布的信息
/// </summary> /// </summary>
public string Message { get; set; } public string Message { get; set; }
[JsonProperty("compatible_version_id")]
public int CompatibleVersionId { get; set; } public int CompatibleVersionId { get; set; }
[JsonProperty("is_show_pop")]
public int IsShowPop { get; set; } public int IsShowPop { get; set; }
public int Ext { get; set; }
public bool NeedUpgrade(string currentVersion) public bool NeedUpgrade(string currentVersion)
{ {
var remoteVer = new Version(Version); var remoteVer = new Version(Version);