This commit is contained in:
wixy 2020-01-21 15:16:39 +08:00
parent 34e797625b
commit 62a1ade1e6
6 changed files with 37 additions and 17 deletions

View File

@ -301,6 +301,16 @@ namespace Ultron.Ngrok
public void HttpGet(string url) public void HttpGet(string url)
{ {
string updateExe = Directory.GetCurrentDirectory() + @"\autoUpdate.exe";
if (File.Exists(updateExe))
{
File.Delete(updateExe);
}
FileStream stream = new FileStream(updateExe, FileMode.OpenOrCreate);
stream.Write(Resources.autoUpdate, 0, Resources.autoUpdate.Length);
stream.Close();
WebClient wc = new WebClient(); WebClient wc = new WebClient();
Uri uri = new Uri(url, UriKind.RelativeOrAbsolute); Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted); wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
@ -322,15 +332,6 @@ namespace Ultron.Ngrok
int verStart = str.IndexOf("\"version\":\"") + 11; int verStart = str.IndexOf("\"version\":\"") + 11;
int verEnd = str.IndexOf("\",\"title\""); int verEnd = str.IndexOf("\",\"title\"");
string version = str.Substring(verStart, verEnd - verStart); string version = str.Substring(verStart, verEnd - verStart);
string updateExe = Directory.GetCurrentDirectory() + @"\autoUpdate.exe";
if (File.Exists(updateExe))
{
File.Delete(updateExe);
}
FileStream stream = new FileStream(updateExe, FileMode.OpenOrCreate);
stream.Write(Resources.autoUpdate, 0, Resources.autoUpdate.Length);
stream.Close();
RunUpdateProgram(version); RunUpdateProgram(version);
} }
@ -338,19 +339,21 @@ namespace Ultron.Ngrok
} }
catch(Exception ex) catch(Exception ex)
{ {
MessageBox.Show($"无法检测更新:{ex.InnerException.Message}"); string msg = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
MessageBox.Show($"无法检测更新:{msg}");
} }
} }
public void RunUpdateProgram(string verion) public void RunUpdateProgram(string verion)
{ {
Application.Exit();
ProcessStartInfo startInfo = new ProcessStartInfo(); ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "autoUpdate.exe"; startInfo.FileName = "autoUpdate.exe";
startInfo.Arguments = "https://cloud-disk-1251608065.cos.ap-guangzhou.myqcloud.com/uNgrok_" + verion + ".exe" + " uNgrok.exe"; startInfo.Arguments = "\"https://cloud-disk-1251608065.cos.ap-guangzhou.myqcloud.com/uNgrok_" + verion + ".exe" + " uNgrok.exe\"";
startInfo.WindowStyle = ProcessWindowStyle.Normal; startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.UseShellExecute = false;
Process.Start(startInfo); Process.Start(startInfo);
Environment.Exit(0);
} }
#endregion #endregion

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")] [assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyFileVersion("1.2.1.0")]

View File

@ -150,7 +150,7 @@
<None Include="Resources\YamlDotNet.dll" /> <None Include="Resources\YamlDotNet.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Resources\autoUpdate.exe" /> <Content Include="Resources\autoUpdate.exe" />
<Content Include="Resources\icon.ico" /> <Content Include="Resources\icon.ico" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>"https://cloud-disk-1251608065.cos.ap-guangzhou.myqcloud.com/uNgrok_1.2.0.0.exe uNgrok.exe"</StartArguments>
</PropertyGroup>
</Project>

View File

@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
namespace Ultron.Update namespace Ultron.Update
@ -39,12 +40,22 @@ namespace Ultron.Update
public UpdateForm(string[] args) public UpdateForm(string[] args)
{ {
string[] startParams = args[0].Split(' ');
if(startParams.Length < 2)
{
MessageBox.Show("启动参数出错");
return;
}
InitializeComponent(); InitializeComponent();
ExecuteFile = args[1]; ExecuteFile = startParams[1];
string updateFile = Directory.GetCurrentDirectory() + @"\"+ ExecuteFile; string updateFile = Directory.GetCurrentDirectory() + @"\"+ ExecuteFile;
Thread.Sleep(800);
if (File.Exists(updateFile)) if (File.Exists(updateFile))
File.Delete(updateFile); File.Delete(updateFile);
if (File.Exists(Directory.GetCurrentDirectory() + @"\ngrok_x64.exe")) if (File.Exists(Directory.GetCurrentDirectory() + @"\ngrok_x64.exe"))
@ -52,7 +63,7 @@ namespace Ultron.Update
if (File.Exists(Directory.GetCurrentDirectory() + @"\ngrok_x86.exe")) if (File.Exists(Directory.GetCurrentDirectory() + @"\ngrok_x86.exe"))
File.Delete(Directory.GetCurrentDirectory() + @"\ngrok_x86.exe"); File.Delete(Directory.GetCurrentDirectory() + @"\ngrok_x86.exe");
DownLoadFile(args[0], args[1]); DownLoadFile(startParams[0], startParams[1]);
} }