From 7a976edc82575f5aeb72f5f1c893f800ba2ead99 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Thu, 23 Aug 2018 20:08:34 +0200
Subject: [PATCH] Ignore cached files for updates and viewed images if their
 contents are empty

---
 Core/Utils/TwitterUtils.cs | 4 ++--
 Core/Utils/WindowsUtils.cs | 8 ++++++++
 Updates/UpdateInfo.cs      | 2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/Core/Utils/TwitterUtils.cs b/Core/Utils/TwitterUtils.cs
index bab34052..77708024 100644
--- a/Core/Utils/TwitterUtils.cs
+++ b/Core/Utils/TwitterUtils.cs
@@ -83,8 +83,8 @@ void ViewImageInternal(string path){
             }
 
             string file = Path.Combine(BrowserCache.CacheFolder, GetImageFileName(url) ?? Path.GetRandomFileName());
-
-            if (File.Exists(file)){
+            
+            if (WindowsUtils.FileExistsAndNotEmpty(file)){
                 ViewImageInternal(file);
             }
             else{
diff --git a/Core/Utils/WindowsUtils.cs b/Core/Utils/WindowsUtils.cs
index 80dd9213..5d20578b 100644
--- a/Core/Utils/WindowsUtils.cs
+++ b/Core/Utils/WindowsUtils.cs
@@ -66,6 +66,14 @@ public static bool CheckFolderWritePermission(string path){
             }
         }
 
+        public static bool FileExistsAndNotEmpty(string path){
+            try{
+                return new FileInfo(path).Length > 0;
+            }catch{
+                return false;
+            }
+        }
+
         public static bool OpenAssociatedProgram(string file, string arguments = "", bool runElevated = false){
             try{
                 using(Process.Start(new ProcessStartInfo{
diff --git a/Updates/UpdateInfo.cs b/Updates/UpdateInfo.cs
index b98d7638..b9a02e20 100644
--- a/Updates/UpdateInfo.cs
+++ b/Updates/UpdateInfo.cs
@@ -26,7 +26,7 @@ public UpdateInfo(string versionTag, string releaseNotes, string downloadUrl, st
         }
 
         public void BeginSilentDownload(){
-            if (File.Exists(InstallerPath)){
+            if (WindowsUtils.FileExistsAndNotEmpty(InstallerPath)){
                 DownloadStatus = UpdateDownloadStatus.Done;
                 return;
             }