更新/升级调整
This commit is contained in:
parent
d2e960243c
commit
99e0792772
Binary file not shown.
@ -336,6 +336,7 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Util\HostHelper.cs" />
|
||||
<Compile Include="Util\HttpUtil.cs" />
|
||||
<EmbeddedResource Include="Controls\FormContact.resx">
|
||||
<DependentUpon>FormContact.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<SupportUrlHistory />
|
||||
</PropertyGroup>
|
||||
<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>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -13,7 +13,6 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using UtilLib;
|
||||
using Document = Microsoft.Office.Interop.Word.Document;
|
||||
@ -45,11 +44,68 @@ namespace AIProofread
|
||||
|
||||
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()
|
||||
{
|
||||
return Config.APP_VERSION;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showDialog(string 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()
|
||||
{
|
||||
Globals.ThisAddIn.SendMessageToWeb("start", "login");
|
||||
@ -183,15 +258,36 @@ namespace AIProofread
|
||||
}
|
||||
public string getDocumentData()
|
||||
{
|
||||
|
||||
Dictionary<string, object> data = new Dictionary<string, object>();
|
||||
var doc = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -271,12 +367,27 @@ namespace AIProofread
|
||||
|
||||
public void ShowUpgrade(string 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);
|
||||
if (ret == System.Windows.Forms.DialogResult.Yes)
|
||||
{
|
||||
OpenUrlWithOsBrowser(upgradeData.DownloadUrl);
|
||||
}
|
||||
//var upgradeData = JsonConvert.DeserializeObject<UpgradeData>(data);
|
||||
//var needUpgrade = upgradeData.NeedUpgrade(Config.APP_VERSION);
|
||||
//if (upgradeData.Ext == 1)
|
||||
//{
|
||||
// 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)
|
||||
@ -335,6 +446,10 @@ namespace AIProofread
|
||||
}
|
||||
|
||||
|
||||
public void clearAllProofreadMarkById(int documentId)
|
||||
{
|
||||
clearAllProofreadMark(GetDocumentById(documentId));
|
||||
}
|
||||
// 清除所有标记
|
||||
public void clearAllProofreadMark(Document document)
|
||||
{
|
||||
@ -496,7 +611,7 @@ namespace AIProofread
|
||||
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);
|
||||
//
|
||||
@ -566,13 +681,13 @@ namespace AIProofread
|
||||
}
|
||||
}
|
||||
|
||||
public string InitContent(string content,int documentId)
|
||||
public string InitContent(string content, int documentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 根据文档编号 获取当前文档避免数据混乱
|
||||
CurrentDocument = GetDocumentById(documentId);
|
||||
if(CurrentDocument == null)
|
||||
if (CurrentDocument == null)
|
||||
{
|
||||
throw new Exception("没有找到校对文档对象");
|
||||
}
|
||||
@ -594,23 +709,19 @@ namespace AIProofread
|
||||
int index = 0;
|
||||
foreach (var item in correct.Diffs)
|
||||
{
|
||||
if (item.id == 187095)
|
||||
{
|
||||
Console.WriteLine("xx");
|
||||
}
|
||||
int _prev = prevOffset;
|
||||
// 查找对应区域并再该区域添加书签
|
||||
var mark = FindRangeAndCreateBookmark(item, correct,ref prevOffset);
|
||||
var mark = DocumentUtil.FindRangeAndCreateBookmark(item, correct, CurrentDocument, ref prevOffset);
|
||||
// 防止调用方法中没有更新
|
||||
if (_prev >= prevOffset)
|
||||
{
|
||||
prevOffset = correct.SentenceOffset + item.end;
|
||||
prevOffset = correct.SentenceOffset + item.start;
|
||||
}
|
||||
|
||||
if (item.tag != "i") index++;
|
||||
if (mark != null)
|
||||
{
|
||||
marks.Add(item.id, new ProofreadItem(item, mark,documentId));
|
||||
marks.Add(item.id, new ProofreadItem(item, mark, documentId));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -637,8 +748,16 @@ namespace AIProofread
|
||||
}
|
||||
if (item.Value.content.color != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var color = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.Value.content.color));
|
||||
// 给选区添加背景颜色
|
||||
item.Value.mark.Shading.BackgroundPatternColor = (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="prevOffset"></param>
|
||||
/// <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;
|
||||
try
|
||||
@ -793,7 +912,7 @@ namespace AIProofread
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -32,7 +32,7 @@ namespace AIProofread
|
||||
}
|
||||
public static void Log( Exception e)
|
||||
{
|
||||
Log(e.StackTrace);
|
||||
Log(e.Message + "\n" + e.StackTrace);
|
||||
}
|
||||
public static void Log(string tag, Exception e)
|
||||
{
|
||||
|
@ -83,18 +83,32 @@ namespace UtilLib
|
||||
|
||||
}
|
||||
public void UnSelect()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (mark == null) return;
|
||||
mark.Range.Font.Size = originSize; // 还原
|
||||
mark.Shading.ForegroundPatternColor = originColor;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetMarkStyle()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (mark == null) return;
|
||||
//mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
|
||||
mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(content.color));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetMarkStyle()
|
||||
{
|
||||
@ -108,7 +122,10 @@ namespace UtilLib
|
||||
mark.Shading.ForegroundPatternColor = originColor;
|
||||
mark.Range.Shading.BackgroundPatternColor = originColor;// Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Process(int status)
|
||||
|
@ -124,7 +124,8 @@ namespace AIProofread
|
||||
private void BtnUpdate_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
//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)
|
||||
@ -396,12 +397,6 @@ namespace AIProofread
|
||||
{
|
||||
return string.IsNullOrEmpty(range.Text) ? "" : range.Text;
|
||||
}
|
||||
|
||||
//private async Task ProcessCorrectCut()
|
||||
//{
|
||||
|
||||
|
||||
//}
|
||||
private void BtnOpenLog_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
// 打开日志目录
|
||||
@ -410,11 +405,7 @@ namespace AIProofread
|
||||
|
||||
private void button1_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
string applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
string path = "updater.exe";
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(Path.Combine(applicationBase, Path.GetFileName(path)));
|
||||
processStartInfo.WorkingDirectory = applicationBase;
|
||||
Process.Start(processStartInfo);
|
||||
Bridge.StartUpgradeProcess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -303,6 +303,8 @@ namespace AIProofread
|
||||
//Application.DocumentChange +=
|
||||
// 选区发生变化事件
|
||||
this.Application.WindowSelectionChange += Application_WindowSelectionChange;
|
||||
// 检测升级信息
|
||||
Bridge.bridge.InitPluginUpgrade();
|
||||
|
||||
try
|
||||
{
|
||||
|
36
AIProofread/Util/HttpUtil.cs
Normal file
36
AIProofread/Util/HttpUtil.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
//using Microsoft.Office.Interop.Word;
|
||||
using Section = Microsoft.Office.Interop.Word.Section;
|
||||
using WdColor = Microsoft.Office.Interop.Word.WdColor;
|
||||
using System.Drawing;
|
||||
using UtilLib;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using Bookmark = Microsoft.Office.Tools.Word.Bookmark;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Office.Tools.Word;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
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
|
||||
{
|
||||
@ -291,5 +290,124 @@ namespace AIProofread
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -1 +1 @@
|
||||
fe1ae839bfb706b80f0b4718d7a4129a4057bf53be655076474daf866eae1d58
|
||||
4c1c6aa096bd384197619062b3689b9a218de9da2c1b7adc250936855349c9f3
|
||||
|
@ -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.dll.manifest
|
||||
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\Microsoft.Win32.Primitives.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.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.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\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.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.OOXML.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.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\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\Enums.NET.pdb
|
||||
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\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.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.xml
|
||||
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.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\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
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12
updater/AppConfig.cs
Normal file
12
updater/AppConfig.cs
Normal 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; }
|
||||
}
|
||||
}
|
21
updater/Form1.Designer.cs
generated
21
updater/Form1.Designer.cs
generated
@ -33,6 +33,7 @@
|
||||
this.ButtonUpdate = new System.Windows.Forms.Button();
|
||||
this.LabelLocalVersion = new System.Windows.Forms.Label();
|
||||
this.progressBar1 = new System.Windows.Forms.ProgressBar();
|
||||
this.BtnCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// LabelLog
|
||||
@ -55,7 +56,7 @@
|
||||
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.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.Size = new System.Drawing.Size(78, 31);
|
||||
this.ButtonUpdate.TabIndex = 1;
|
||||
@ -79,12 +80,29 @@
|
||||
this.progressBar1.TabIndex = 3;
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.ClientSize = new System.Drawing.Size(438, 286);
|
||||
this.Controls.Add(this.BtnCancel);
|
||||
this.Controls.Add(this.progressBar1);
|
||||
this.Controls.Add(this.LabelLocalVersion);
|
||||
this.Controls.Add(this.ButtonUpdate);
|
||||
@ -106,6 +124,7 @@
|
||||
private System.Windows.Forms.Button ButtonUpdate;
|
||||
private System.Windows.Forms.Label LabelLocalVersion;
|
||||
private System.Windows.Forms.ProgressBar progressBar1;
|
||||
private System.Windows.Forms.Button BtnCancel;
|
||||
}
|
||||
}
|
||||
|
||||
|
108
updater/Form1.cs
108
updater/Form1.cs
@ -15,23 +15,53 @@ namespace updater
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private int localVersionCode = 0;
|
||||
private UpdateModel model;
|
||||
private static string applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
private string versionFilePath = applicationBase + Path.GetFileName("version.json");
|
||||
private string updateDir = applicationBase + "update\\";
|
||||
private string updateInfoUri = "https://file.wx.wm-app.xyz/jdw/latest.json";
|
||||
private UpgradeInfo localVersion;
|
||||
private UpgradeInfo upgradeInfo;
|
||||
private static readonly string ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
private static readonly string LocalVersionFilePath = ApplicationBase + Path.GetFileName("version.json");
|
||||
public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.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 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()
|
||||
{
|
||||
InitAppByConfig();
|
||||
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)
|
||||
{
|
||||
UpdateModel update = JsonConvert.DeserializeObject<UpdateModel>(source);
|
||||
this.localVersionCode = update.VersionCode;
|
||||
LabelLocalVersion.Text = update.Version;
|
||||
UpgradeModel local = JsonConvert.DeserializeObject<UpgradeModel>(source);
|
||||
this.localVersion = local.Info;
|
||||
LabelLocalVersion.Text = localVersion.Version;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,18 +73,18 @@ namespace updater
|
||||
return;
|
||||
}
|
||||
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))
|
||||
{
|
||||
ExtractUpdatePackage();
|
||||
return;
|
||||
}
|
||||
DownLoadFile(model.UpdateFile, updateFileName);
|
||||
DownLoadFile(upgradeInfo.DownloadUrl, updateFileName);
|
||||
}
|
||||
|
||||
public bool CheckHostAppRunning()
|
||||
@ -70,6 +100,7 @@ namespace updater
|
||||
else if (item2.ProcessName.Equals("WINWORD"))
|
||||
{
|
||||
MessageBox.Show("检测到 Word 正在运行中,请关闭后再执行更新操作");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -82,7 +113,9 @@ namespace updater
|
||||
|
||||
public void CheckUpdate()
|
||||
{
|
||||
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(updateInfoUri);
|
||||
try
|
||||
{
|
||||
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version");
|
||||
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
|
||||
// 获取响应内容
|
||||
if (resp.StatusCode == HttpStatusCode.OK)
|
||||
@ -92,26 +125,33 @@ namespace updater
|
||||
updateSource = readStream.ReadToEnd();
|
||||
if (updateSource == null && updateSource.Length == 0)
|
||||
{
|
||||
LabelLog.Text = "获取更新信息失败";
|
||||
LabelLog.Text = "获取更新信息失败,请稍后重试";
|
||||
return;
|
||||
}
|
||||
resp.Close();
|
||||
UpdateModel update = JsonConvert.DeserializeObject<UpdateModel>(updateSource);
|
||||
UpgradeModel update = JsonConvert.DeserializeObject<UpgradeModel>(updateSource);
|
||||
ProcessUpdate(update);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessUpdate(UpdateModel update)
|
||||
catch (Exception)
|
||||
{
|
||||
LabelLog.Text = update.Log;
|
||||
this.model = update;
|
||||
if (update.VersionCode > this.localVersionCode)
|
||||
LabelLog.Text = "获取更新信息失败,请稍后重试";
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessUpdate(UpgradeModel update)
|
||||
{
|
||||
this.upgradeInfo = update.Info;
|
||||
LabelLog.Text = update.Info.Message;
|
||||
|
||||
if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version))
|
||||
{
|
||||
ButtonUpdate.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ButtonUpdate.Visible = false;
|
||||
BtnCancel.Visible = false;
|
||||
LabelLocalVersion.Text = "当前是最新版本";
|
||||
}
|
||||
}
|
||||
@ -158,22 +198,32 @@ namespace updater
|
||||
private void ExtractUpdatePackage()
|
||||
{
|
||||
progressBar1.Value = 100;
|
||||
string zipFilePath = updateDir + Path.GetFileName(model.UpdateFile);
|
||||
// 获取升级包路径
|
||||
string zipFilePath = UpgradeDir + Path.GetFileName(upgradeInfo.DownloadUrl);
|
||||
|
||||
// 可以考虑备份旧文件
|
||||
//string destinationFolder = Path.Combine(applicationBase, "update\\old");
|
||||
//CopyDirectory(applicationBase, destinationFolder);
|
||||
//ZipFile.ExtractToDirectory(zipFilePath, applicationBase);
|
||||
|
||||
using (ZipArchive zip = ZipFile.OpenRead(zipFilePath))
|
||||
{
|
||||
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("更新完成");
|
||||
// 保存日志
|
||||
File.WriteAllText(versionFilePath, updateSource);
|
||||
// 保存最新版本日志
|
||||
File.WriteAllText(LocalVersionFilePath, updateSource);
|
||||
this.Close();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,13 @@
|
||||
以下节点之一替换 requestedExecutionLevel 节点。
|
||||
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
||||
|
||||
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
|
||||
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
|
||||
元素。
|
||||
-->
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
</requestedPrivileges>
|
||||
<applicationRequestMinimum>
|
||||
<defaultAssemblyRequest permissionSetReference="Custom" />
|
||||
|
@ -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
49
updater/UpgradeModel.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@ -71,6 +72,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppConfig.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@ -83,7 +85,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RegistHelper.cs" />
|
||||
<Compile Include="UpdateData.cs" />
|
||||
<Compile Include="UpdateModel.cs" />
|
||||
<Compile Include="UpgradeModel.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
@ -1,21 +1,34 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Security.Principal;
|
||||
|
||||
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 int Id { get; set; }
|
||||
/// <summary>
|
||||
/// APP名称
|
||||
/// </summary>
|
||||
[JsonProperty("app_name")]
|
||||
public string AppName { get; set; }
|
||||
/// <summary>
|
||||
/// 客户端类型 1ios 2安卓 3window插件 4 5
|
||||
/// </summary>
|
||||
[JsonProperty("client_type")]
|
||||
public int ClientType { get; set; }
|
||||
/// <summary>
|
||||
/// 发布类型
|
||||
/// </summary>
|
||||
[JsonProperty("publish_type")]
|
||||
public int PublishType { get; set; }
|
||||
/// <summary>
|
||||
/// 发布的版本号
|
||||
@ -24,19 +37,26 @@ namespace UtilLib
|
||||
/// <summary>
|
||||
/// 升级类型(1强制升级 2强制提示 3弱提示)
|
||||
/// </summary>
|
||||
[JsonProperty("upgrade_type")]
|
||||
public int UpgradeType { get; set; }
|
||||
[JsonProperty("download_url")]
|
||||
public string DownloadUrl { get; set; }
|
||||
/// <summary>
|
||||
/// 发布时间
|
||||
/// </summary>
|
||||
[JsonProperty("publish_time")]
|
||||
public int PublishTime { get; set; }
|
||||
/// <summary>
|
||||
/// 发布的信息
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
[JsonProperty("compatible_version_id")]
|
||||
public int CompatibleVersionId { get; set; }
|
||||
[JsonProperty("is_show_pop")]
|
||||
public int IsShowPop { get; set; }
|
||||
|
||||
public int Ext { get; set; }
|
||||
|
||||
public bool NeedUpgrade(string currentVersion)
|
||||
{
|
||||
var remoteVer = new Version(Version);
|
||||
|
Loading…
x
Reference in New Issue
Block a user