diff --git a/Configuration/LockManager.cs b/Configuration/LockManager.cs index b1c4314e..af754de0 100644 --- a/Configuration/LockManager.cs +++ b/Configuration/LockManager.cs @@ -163,15 +163,12 @@ public bool CloseLockingProcess(int closeTimeout, int killTimeout){ lockingProcess = null; return true; } - }catch(Exception ex){ - if (ex is InvalidOperationException || ex is Win32Exception){ - if (lockingProcess != null){ - bool hasExited = CheckLockingProcessExited(); - lockingProcess.Dispose(); - return hasExited; - } + }catch(Exception ex) when (ex is InvalidOperationException || ex is Win32Exception){ + if (lockingProcess != null){ + bool hasExited = CheckLockingProcessExited(); + lockingProcess.Dispose(); + return hasExited; } - else throw; } } diff --git a/Core/Controls/FlatProgressBar.cs b/Core/Controls/FlatProgressBar.cs index b5393766..dbb1bd13 100644 --- a/Core/Controls/FlatProgressBar.cs +++ b/Core/Controls/FlatProgressBar.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Windows.Forms; namespace TweetDuck.Core.Controls{ @@ -13,7 +14,7 @@ public FlatProgressBar(){ } public void SetValueInstant(int value){ - ControlExtensions.SetValueInstant(this, value); + ControlExtensions.SetValueInstant(this, Math.Max(Minimum, Math.Min(Maximum, value))); } protected override void OnPaint(PaintEventArgs e){ diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs index 464dd47e..f61f70ad 100644 --- a/Core/Notification/FormNotificationBase.cs +++ b/Core/Notification/FormNotificationBase.cs @@ -69,7 +69,9 @@ protected virtual Point PrimaryLocation{ protected virtual bool CanDragWindow => true; public new Point Location{ - get => base.Location; + get{ + return base.Location; + } set{ Visible = (base.Location = value) != ControlExtensions.InvisibleLocation; diff --git a/Core/Notification/FormNotificationMain.cs b/Core/Notification/FormNotificationMain.cs index 30dc4f52..6e5d8f98 100644 --- a/Core/Notification/FormNotificationMain.cs +++ b/Core/Notification/FormNotificationMain.cs @@ -175,12 +175,14 @@ private void timerDisplayDelay_Tick(object sender, EventArgs e){ } private void timerHideProgress_Tick(object sender, EventArgs e){ - if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen)return; + if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen){ + return; + } timeLeft -= timerProgress.Interval; - int value = BrowserUtils.Scale(1025, (totalTime-timeLeft)/(double)totalTime); - progressBarTimer.SetValueInstant(Math.Min(1000, Math.Max(0, Program.UserConfig.NotificationTimerCountDown ? 1000-value : value))); + int value = BrowserUtils.Scale(progressBarTimer.Maximum+25, (totalTime-timeLeft)/(double)totalTime); + progressBarTimer.SetValueInstant(Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum-value : value); if (timeLeft <= 0){ FinishCurrentNotification(); @@ -196,7 +198,7 @@ public virtual void ShowNotification(TweetNotification notification){ public override void HideNotification(){ base.HideNotification(); - progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? 1000 : 0; + progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum; timerProgress.Stop(); totalTime = 0; @@ -239,7 +241,7 @@ protected override string GetTweetHTML(TweetNotification tweet){ protected override void LoadTweet(TweetNotification tweet){ timerProgress.Stop(); totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue); - progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? 1000 : 0; + progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum; base.LoadTweet(tweet); } diff --git a/Core/Other/Management/VideoPlayer.cs b/Core/Other/Management/VideoPlayer.cs index 50150bb0..ed3682b6 100644 --- a/Core/Other/Management/VideoPlayer.cs +++ b/Core/Other/Management/VideoPlayer.cs @@ -8,8 +8,6 @@ namespace TweetDuck.Core.Other.Management{ sealed class VideoPlayer : IDisposable{ - private readonly string PlayerExe = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"); - public bool Running{ get{ if (currentProcess == null){ @@ -50,7 +48,7 @@ public void Launch(string url, string username){ currentPipe.DataIn += currentPipe_DataIn; if ((currentProcess = Process.Start(new ProcessStartInfo{ - FileName = PlayerExe, + FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"), Arguments = $"{owner.Handle} {Program.UserConfig.VideoPlayerVolume} \"{url}\" \"{currentPipe.GenerateToken()}\"", UseShellExecute = false, RedirectStandardOutput = true diff --git a/Core/Other/Settings/TabSettingsAdvanced.cs b/Core/Other/Settings/TabSettingsAdvanced.cs index 503f3969..cb13f19a 100644 --- a/Core/Other/Settings/TabSettingsAdvanced.cs +++ b/Core/Other/Settings/TabSettingsAdvanced.cs @@ -29,14 +29,10 @@ public TabSettingsAdvanced(Action<string> reinjectBrowserCSS){ numMemoryThreshold.Enabled = checkBrowserGCReload.Checked; numMemoryThreshold.SetValueSafe(SysConfig.BrowserMemoryThreshold); - BrowserCache.CalculateCacheSize(bytes => this.InvokeSafe(() => { - if (bytes == -1L){ - btnClearCache.Text = "Clear Cache (unknown size)"; - } - else{ - btnClearCache.Text = "Clear Cache ("+(int)Math.Ceiling(bytes/(1024.0*1024.0))+" MB)"; - } - })); + BrowserCache.CalculateCacheSize(task => { + string text = task.IsCompleted ? (int)Math.Ceiling(task.Result/(1024.0*1024.0))+" MB" : "(unknown size)"; + this.InvokeSafe(() => btnClearCache.Text = $"Clear Cache ({text})"); + }); } public override void OnReady(){ diff --git a/Core/Utils/BrowserCache.cs b/Core/Utils/BrowserCache.cs index af6cf2af..ab4ee33f 100644 --- a/Core/Utils/BrowserCache.cs +++ b/Core/Utils/BrowserCache.cs @@ -9,14 +9,9 @@ static class BrowserCache{ private static bool ClearOnExit { get; set; } public static readonly string CacheFolder = Path.Combine(Program.StoragePath, "Cache"); + private static IEnumerable<string> CacheFiles => Directory.EnumerateFiles(CacheFolder); - private static IEnumerable<string> CacheFiles{ - get{ - return Directory.EnumerateFiles(CacheFolder); - } - } - - public static void CalculateCacheSize(Action<long> callbackBytes){ + public static void CalculateCacheSize(Action<Task<long>> callbackBytes){ Task<long> task = new Task<long>(() => { return CacheFiles.Select(file => { try{ @@ -27,7 +22,7 @@ public static void CalculateCacheSize(Action<long> callbackBytes){ }).Sum(); }); - task.ContinueWith(originalTask => callbackBytes(originalTask.Exception == null ? originalTask.Result : -1L), TaskContinuationOptions.ExecuteSynchronously); + task.ContinueWith(callbackBytes); task.Start(); }