Skip to content

Commit 7e4abb1

Browse files
author
hongjb
committed
1、对于更新的介绍,改成通过rtf的文件路径获取,见local.xml文件
2、修复对于手工点击更新按钮时候,不会弹出更新界面问题(增加了启动时候的运行参数) 3、修复若干BUG
1 parent b805e8b commit 7e4abb1

9 files changed

+135
-54
lines changed

MAutoUpdate.Test/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static class Program
1414
[STAThread]
1515
static void Main()
1616
{
17-
String path = AppDomain.CurrentDomain.BaseDirectory + "MAutoUpdate.exe";
17+
string path = AppDomain.CurrentDomain.BaseDirectory + "MAutoUpdate.exe";
1818
//同时启动自动更新程序
1919
if (File.Exists(path))
2020
{

MAutoUpdate/Local.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<LocalUpdate>
22
<LocalVersion>1.0.0.0</LocalVersion>
3+
<LocalIgnoreVersion>1.1.0.0</LocalIgnoreVersion>
34
<LastUdpate>2016/9/28 9:25:24</LastUdpate>
4-
<ServerUpdateUrl>http://localhost/TestWeb/Server.xml</ServerUpdateUrl>
5+
<ServerUpdateUrl>http://localhost/huidu/server.xml</ServerUpdateUrl>
56
</LocalUpdate>

MAutoUpdate/LocalInfo.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ namespace MAutoUpdate
99
{
1010
public class LocalInfo
1111
{
12-
public String LocalVersion { get; set; }
13-
public String LastUdpate { get; set; }
14-
public String ServerUpdateUrl { get; set; }
12+
public string LocalVersion { get; set; }
13+
public string LastUdpate { get; set; }
14+
public string ServerUpdateUrl { get; set; }
15+
public string LocalIgnoreVersion { get; set; }
1516

16-
private String url = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Local.xml");
17+
private string url = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Local.xml");
1718

18-
public void SaveReg(String subKey)
19+
20+
public LocalInfo(string localAddress)
21+
{
22+
url = Path.Combine(localAddress, "Local.xml");
23+
}
24+
25+
public void SaveReg(string subKey)
1926
{
2027
RegistryKey Key;
2128
Key = Registry.CurrentUser;
@@ -27,7 +34,7 @@ public void SaveReg(String subKey)
2734
Key.SetValue(item.Name.ToString(), this.GetType().GetProperty(item.Name.ToString()).GetValue(this, null).ToString());
2835
}
2936
}
30-
public void LoadReg(String subKey)
37+
public void LoadReg(string subKey)
3138
{
3239
//获取本地配置文件
3340
RegistryKey Key;
@@ -51,7 +58,7 @@ public void LoadXml()
5158
RemoteInfo remote = new RemoteInfo();
5259
foreach (XmlNode pItem in item.ChildNodes)
5360
{
54-
this.GetType().GetProperty(pItem.Name).SetValue(this, pItem.InnerText, null);
61+
GetType().GetProperty(pItem.Name).SetValue(this, pItem.InnerText, null);
5562
}
5663
}
5764
}

MAutoUpdate/MAutoUpdate.csproj

+16-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@
6969
<Reference Include="System.Xml" />
7070
</ItemGroup>
7171
<ItemGroup>
72+
<Compile Include="MainForm1.cs">
73+
<SubType>Form</SubType>
74+
</Compile>
75+
<Compile Include="MainForm1.Designer.cs">
76+
<DependentUpon>MainForm1.cs</DependentUpon>
77+
</Compile>
78+
<Compile Include="MRichTextBox.cs">
79+
<SubType>Component</SubType>
80+
</Compile>
81+
<Compile Include="MRichTextBox.Designer.cs">
82+
<DependentUpon>MRichTextBox.cs</DependentUpon>
83+
</Compile>
7284
<Compile Include="UpdateWork.cs" />
7385
<Compile Include="LocalInfo.cs" />
7486
<Compile Include="LogTool.cs" />
@@ -140,6 +152,9 @@
140152
<Compile Include="Zip DLL\ZlibCodec.cs" />
141153
<Compile Include="Zip DLL\ZlibConstants.cs" />
142154
<Compile Include="Zip DLL\ZlibStream.cs" />
155+
<EmbeddedResource Include="MainForm1.resx">
156+
<DependentUpon>MainForm1.cs</DependentUpon>
157+
</EmbeddedResource>
143158
<EmbeddedResource Include="MainForm.resx">
144159
<DependentUpon>MainForm.cs</DependentUpon>
145160
</EmbeddedResource>
@@ -168,7 +183,7 @@
168183
<Content Include="Zip DLL\msbuild.flymake.xml" />
169184
<None Include="config.update" />
170185
<Content Include="Local.xml">
171-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
186+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
172187
</Content>
173188
<Content Include="Server.xml" />
174189
</ItemGroup>

MAutoUpdate/MainForm.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Drawing;
88
using System.IO;
9+
using System.IO.Compression;
910
using System.Net;
1011
using System.Runtime.InteropServices;
1112
using System.Text;
@@ -22,10 +23,19 @@ public MainForm(UpdateWork _updateWork)
2223
{
2324
InitializeComponent();
2425
updateWork = _updateWork;
25-
foreach (var item in _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc.Split('$'))
26+
var res = _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc;
27+
28+
var temp = WebRequest.Create(res);
29+
var stream = temp.GetResponse().GetResponseStream();
30+
using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default))
2631
{
27-
this.lblContent.Text = this.lblContent.Text + item + Environment.NewLine;
32+
string text = reader.ReadToEnd();
33+
this.lblContent.Text = text;
2834
}
35+
//foreach (var item in _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc.Split('$'))
36+
//{
37+
// this.lblContent.Text = this.lblContent.Text + item + Environment.NewLine;
38+
//}
2939
}
3040
#region 让窗体变成可移动
3141
[DllImport("user32.dll")]
@@ -85,7 +95,6 @@ private void btnIgnore_Click(object sender, EventArgs e)
8595
{
8696
updateWork.IgnoreThisVersion();
8797
Application.Exit();
88-
8998
}
9099
}
91100
}

MAutoUpdate/Program.cs

+20-12
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ static class Program
1515
static Process pCurrent = Process.GetCurrentProcess();
1616
static Mutex m = new Mutex(true, pCurrent.MainModule.FileName.Replace(":", "").Replace(@"\", "") + "MAutoUpdate", out f);//互斥,
1717

18-
/// <summary>
19-
/// 程序主入口
20-
/// </summary>
21-
/// <param name="args">[0]程序名称,[1]静默更新 0:否 1:是</param>
18+
/// <summary>
19+
/// 程序主入口
20+
/// </summary>
21+
/// <param name="args">[0]程序名称,[1]静默更新 0:否 1:是 [3] 0:程序启动检测 1:手动点击检查更新按钮(在于忽略更新的情况下,手动检测时候还是要弹出来的) </param>
2222
[STAThread]
2323
static void Main(string[] args)
2424
{
2525
if (f)
2626
{
2727
try
2828
{
29-
if (String.IsNullOrEmpty(args[0]) == false)
29+
string programName = args[0];
30+
string silentUpdate = args[1];
31+
string isClickUpdate = "0";
32+
string localAddress = AppDomain.CurrentDomain.BaseDirectory;
33+
if (args.Length == 3)
3034
{
31-
UpdateWork updateWork = new UpdateWork(args[0]);
35+
isClickUpdate = args[2];
36+
}
37+
if (string.IsNullOrEmpty(programName) == false)
38+
{
39+
UpdateWork updateWork = new UpdateWork(programName, localAddress, isClickUpdate);
3240
if (updateWork.UpdateVerList.Count > 0)
3341
{
3442
/* 当前用户是管理员的时候,直接启动应用程序
@@ -42,20 +50,20 @@ static void Main(string[] args)
4250
//判断当前登录用户是否为管理员
4351
if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
4452
{
45-
if (args[1] == "1")
53+
if (silentUpdate == "1")
4654
{
4755
updateWork.Do();
4856
}
4957
else
5058
{
5159
Application.EnableVisualStyles();
5260
Application.SetCompatibleTextRenderingDefault(false);
53-
Application.Run(new MainForm(updateWork));
61+
Application.Run(new MainForm1(updateWork));
5462
}
5563
}
5664
else
5765
{
58-
String result = Environment.GetEnvironmentVariable("systemdrive");
66+
string result = Environment.GetEnvironmentVariable("systemdrive");
5967
if (AppDomain.CurrentDomain.BaseDirectory.Contains(result))
6068
{
6169
//创建启动对象
@@ -66,22 +74,22 @@ static void Main(string[] args)
6674
//设置启动动作,确保以管理员身份运行
6775
Verb = "runas",
6876

69-
Arguments = " " + args[0] + " " + args[1]
77+
Arguments = " " + programName + " " + silentUpdate
7078
};
7179
//如果不是管理员,则启动UAC
7280
System.Diagnostics.Process.Start(startInfo);
7381
}
7482
else
7583
{
76-
if (args[1] == "1")
84+
if (silentUpdate == "1")
7785
{
7886
updateWork.Do();
7987
}
8088
else
8189
{
8290
Application.EnableVisualStyles();
8391
Application.SetCompatibleTextRenderingDefault(false);
84-
Application.Run(new MainForm(updateWork));
92+
Application.Run(new MainForm1(updateWork));
8593
}
8694
}
8795
}

MAutoUpdate/Properties/Resources.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MAutoUpdate/Properties/Settings.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)