Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71fbd6ee80 |
+1
-1
@@ -1 +1 @@
|
||||
1.0.16
|
||||
1.0.17
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("JiraTimeBot")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("JiraTimeBot")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.16")]
|
||||
[assembly: AssemblyFileVersion("1.0.16")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.16")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("JiraTimeBot")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("JiraTimeBot")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.17")]
|
||||
[assembly: AssemblyFileVersion("1.0.17")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.17")]
|
||||
|
||||
Generated
+1
-1
@@ -114,7 +114,7 @@
|
||||
//
|
||||
// tmrUpdate
|
||||
//
|
||||
this.tmrUpdate.Interval = 1000;
|
||||
this.tmrUpdate.Interval = 10000;
|
||||
this.tmrUpdate.Tick += new System.EventHandler(this.tmrUpdate_Tick);
|
||||
//
|
||||
// frmMain
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
@@ -189,23 +190,86 @@ namespace JiraTimeBotForm.UI
|
||||
|
||||
private void tmrUpdate_Tick(object sender, EventArgs e)
|
||||
{
|
||||
tmrUpdate.Interval = 8 * 60 * 60 * 1000;
|
||||
|
||||
var checker = new UpdateChecker();
|
||||
var release = checker.GetRelease();
|
||||
if (release == null)
|
||||
try
|
||||
{
|
||||
return;
|
||||
tmrUpdate.Interval = 8 * 60 * 60 * 1000;
|
||||
|
||||
var checker = new UpdateChecker();
|
||||
var release = checker.GetRelease();
|
||||
if (release == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var gitVersionStr = checker.GetLatestVersion(release);
|
||||
var gitVersion = new Version(gitVersionStr);
|
||||
var appVersion = new Version(Application.ProductVersion);
|
||||
|
||||
if (gitVersion > appVersion)
|
||||
{
|
||||
var downloadUrl = checker.GetDownloadUrl(release);
|
||||
_log.Info($"Доступна новая версия: {gitVersion} {downloadUrl}");
|
||||
|
||||
var success = checker.DownloadFile(downloadUrl);
|
||||
if (!success)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var result = InstallUpdate(gitVersion);
|
||||
if (result)
|
||||
{
|
||||
//если обновились - отключаем до рестарта
|
||||
tmrUpdate.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var gitVersionStr = checker.GetLatestVersion(release);
|
||||
var gitVersion = new Version(gitVersionStr);
|
||||
var appVersion = new Version(Application.ProductVersion);
|
||||
|
||||
if (gitVersion > appVersion)
|
||||
catch (Exception ex)
|
||||
{
|
||||
var downloadUrl = checker.GetDownloadUrl(release);
|
||||
_log.Info($"Доступна новая версия: {gitVersion} {downloadUrl}");
|
||||
//в процессе обновления ни при каком раскладе мы не должны уложить бота.
|
||||
_log.Error($"Фатальная ошибка в процессе обновления: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private bool InstallUpdate(Version gitVersion)
|
||||
{
|
||||
try
|
||||
{
|
||||
_log.Info($"Устанавливаю обновление до версии {gitVersion}.");
|
||||
//Rename he executing file
|
||||
System.IO.FileInfo appFile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
var bkpDir = Path.Combine(appFile.DirectoryName, "bkp");
|
||||
if (!Directory.Exists(bkpDir))
|
||||
{
|
||||
Directory.CreateDirectory(bkpDir);
|
||||
}
|
||||
|
||||
using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(appFile.DirectoryName, "update.zip")))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
var zipEntryPath = Path.Combine(appFile.DirectoryName, entry.FullName);
|
||||
if (File.Exists(zipEntryPath))
|
||||
{
|
||||
System.IO.FileInfo zipEntryFile = new System.IO.FileInfo(zipEntryPath);
|
||||
if (File.Exists(bkpDir + "\\" + zipEntryFile.Name))
|
||||
{
|
||||
File.Delete(bkpDir + "\\" + zipEntryFile.Name);
|
||||
}
|
||||
System.IO.File.Move(zipEntryFile.FullName, bkpDir + "\\" + zipEntryFile.Name);
|
||||
}
|
||||
|
||||
entry.ExtractToFile(zipEntryPath);
|
||||
}
|
||||
}
|
||||
|
||||
_log.Info("Обновление установлено. Перезапустите программу для применения изменений.");
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_log.Error($"Что-то пошло не так при обновлении.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,22 @@ namespace JiraTimeBotForm.Update
|
||||
return release;
|
||||
}
|
||||
|
||||
public void DownloadFile(string url)
|
||||
public bool DownloadFile(string url)
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
try
|
||||
{
|
||||
client.Headers.Add("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0");
|
||||
client.DownloadFile(url, "update.zip");
|
||||
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
client.Headers.Add("User-Agent",
|
||||
"Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0");
|
||||
client.DownloadFile(url, "update.zip");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user