diff --git a/.semver.txt b/.semver.txt index 818b8de..224d004 100644 --- a/.semver.txt +++ b/.semver.txt @@ -1 +1 @@ -1.0.81 +1.0.82 diff --git a/src/JiraTimeBot/Properties/AssemblyInfo.cs b/src/JiraTimeBot/Properties/AssemblyInfo.cs index 9f90817..1914cff 100644 --- a/src/JiraTimeBot/Properties/AssemblyInfo.cs +++ b/src/JiraTimeBot/Properties/AssemblyInfo.cs @@ -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 © 2020")] -[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.81")] -[assembly: AssemblyFileVersion("1.0.81")] -[assembly: AssemblyInformationalVersion("1.0.81")] +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 © 2020")] +[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.82")] +[assembly: AssemblyFileVersion("1.0.82")] +[assembly: AssemblyInformationalVersion("1.0.82")] diff --git a/src/JiraTimeBot/UI/frmMain.Designer.cs b/src/JiraTimeBot/UI/frmMain.Designer.cs index fa76cd0..60646de 100644 --- a/src/JiraTimeBot/UI/frmMain.Designer.cs +++ b/src/JiraTimeBot/UI/frmMain.Designer.cs @@ -81,6 +81,7 @@ this.tlpControls.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tlpControls.Size = new System.Drawing.Size(759, 416); this.tlpControls.TabIndex = 19; + this.tlpControls.Paint += new System.Windows.Forms.PaintEventHandler(this.tlpControls_Paint); // // txtLog // diff --git a/src/JiraTimeBot/UI/frmMain.cs b/src/JiraTimeBot/UI/frmMain.cs index ba6e3bc..b5fec35 100644 --- a/src/JiraTimeBot/UI/frmMain.cs +++ b/src/JiraTimeBot/UI/frmMain.cs @@ -38,6 +38,7 @@ namespace JiraTimeBot.UI this.WindowState = FormWindowState.Normal; _trayIcon.Hide(); } + base.WndProc(ref message); } @@ -65,14 +66,16 @@ namespace JiraTimeBot.UI _log = _container.Resolve(); _tasksProcessors = _container.Resolve(); - _controls = new Control[] { txtDummyMode, btnStart, btnMeeting, btnSettings, dteForDay, btnDoForDate }; + _controls = new Control[] {txtDummyMode, btnStart, btnMeeting, btnSettings, dteForDay, btnDoForDate}; _settingsWindowShow = () => { var frmSettings = new frmSettings(_container.Resolve()); frmSettings.ShowDialog(this); }; - _settingsErrorReporter = msg => MessageBox.Show(msg, "Загрузка настроек", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ; + _settingsErrorReporter = msg => + MessageBox.Show(msg, "Загрузка настроек", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + ; } private void frmMain_FormClosing(object sender, FormClosingEventArgs e) @@ -121,7 +124,8 @@ namespace JiraTimeBot.UI private void PrintStartMessage() { _settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter); - _log.Info($"Загружен бот для {_settings.JiraUserName}, Режим: {_settings.WorkType.ToString()}, работаем в {_settings.RepositoryPath}"); + _log.Info( + $"Загружен бот для {_settings.JiraUserName}, Режим: {_settings.WorkType.ToString()}, работаем в {_settings.RepositoryPath}"); } private async void btnStart_Click(object sender, EventArgs e) @@ -130,7 +134,8 @@ namespace JiraTimeBot.UI using (_tokenSource = GetTokenSource()) { - await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, _tokenSource.Token); + await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, + _tokenSource.Token); } LockUnlock(true); @@ -176,7 +181,8 @@ namespace JiraTimeBot.UI using (var tokenSource = GetTokenSource()) { - await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, tokenSource.Token); + await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, + tokenSource.Token); } LockUnlock(true); @@ -189,7 +195,8 @@ namespace JiraTimeBot.UI using (_tokenSource = GetTokenSource()) { - await _job.DoTheJob(settings, _tasksProcessors.MeetingProcessor, txtDummyMode.Checked, _tokenSource.Token); + await _job.DoTheJob(settings, _tasksProcessors.MeetingProcessor, txtDummyMode.Checked, + _tokenSource.Token); } LockUnlock(true); @@ -244,11 +251,15 @@ namespace JiraTimeBot.UI using (_tokenSource = GetTokenSource()) { - await _job.SetTaskTimesForDate(dteForDay.Value, dteForDay.Value, settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, _tokenSource.Token); + await _job.SetTaskTimesForDate(dteForDay.Value, dteForDay.Value, settings, + _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, _tokenSource.Token); } LockUnlock(true); + } + private void tlpControls_Paint(object sender, PaintEventArgs e) + { } } -} +} \ No newline at end of file diff --git a/src/JiraTimeBot/Update/Updater.cs b/src/JiraTimeBot/Update/Updater.cs index c799973..23e8e0f 100644 --- a/src/JiraTimeBot/Update/Updater.cs +++ b/src/JiraTimeBot/Update/Updater.cs @@ -5,6 +5,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Net; +using System.Threading.Tasks; using System.Windows.Forms; namespace JiraTimeBot.Update @@ -12,6 +13,7 @@ namespace JiraTimeBot.Update public class Updater : IUpdater { private readonly ILog _log; + private double _downloadPercent = 0; public Updater(ILog log) { @@ -90,45 +92,34 @@ namespace JiraTimeBot.Update try { _log.Info($"Устанавливаю обновление до версии {gitVersion}."); - //Rename he executing file - System.IO.FileInfo appFile = - new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); + + var appFile = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); var bkpDir = Path.Combine(appFile.DirectoryName, "bkp"); - if (!Directory.Exists(bkpDir)) + + if (Directory.Exists(bkpDir)) + Directory.Delete(bkpDir, true); + _log.Info($"Создаю директорию {bkpDir}."); + Directory.CreateDirectory(bkpDir); + + //забэкапим все папки + foreach (var dir in Directory.GetDirectories(appFile.DirectoryName).Where(f=>!f.EndsWith("bkp"))) { - _log.Info($"Создаю директорию {bkpDir}."); - Directory.CreateDirectory(bkpDir); + var dirName = new DirectoryInfo(dir); + var bkpDirPath = Path.Combine(bkpDir, dirName.Name); + if (Directory.Exists(bkpDirPath)) + Directory.Delete(bkpDirPath, true); + Directory.Move(dir, bkpDirPath); + } + //и файлы + foreach (var file in Directory.GetFiles(appFile.DirectoryName).Where(f=>!f.EndsWith("update.zip"))) + { + File.Move(file, Path.Combine(bkpDir, new FileInfo(file).Name)); } + //распакуем архив using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(appFile.DirectoryName, updateFile))) { - foreach (ZipArchiveEntry entry in archive.Entries) - { - var zipEntryPath = Path.Combine(appFile.DirectoryName, entry.FullName); - if (entry.FullName.EndsWith("/")) - { - var bkpEntryPath = Path.Combine(bkpDir, entry.FullName); - bkpEntryPath = bkpEntryPath.TrimEnd('/'); - if (!Directory.Exists(bkpEntryPath)) - { - Directory.CreateDirectory(bkpEntryPath); - } - } - else - { - 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); - } - } + archive.ExtractToDirectory(appFile.DirectoryName); } _log.Info("Обновление установлено. Перезапустите программу для применения изменений."); @@ -164,7 +155,11 @@ namespace JiraTimeBot.Update { client.Headers.Add("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"); - client.DownloadFile(url, to); + client.DownloadProgressChanged += ClientOnDownloadProgressChanged; + client.DownloadFileAsync(new Uri(url), to); + + while (client.IsBusy) { Application.DoEvents(); } + return true; } } @@ -174,6 +169,16 @@ namespace JiraTimeBot.Update } } + private void ClientOnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) + { + var percent = Math.Truncate(e.BytesReceived / (double)e.TotalBytesToReceive * 100); + if (Math.Abs(_downloadPercent - percent) >= 10) + { + _log.Info($"Downloaded: {percent}%"); + _downloadPercent = percent; + } + } + private string Get(string uri) { try