Procházet zdrojové kódy

Lots of try catches

flabbet před 4 měsíci
rodič
revize
432e627c06

+ 6 - 2
src/PixiEditor/Models/DocumentModels/Autosave/AutosaverSaveUserFileJob.cs

@@ -46,8 +46,12 @@ internal class AutosaverSaveUserFileJob(DocumentViewModel document) : IAutosaver
 
                 File.Copy(document.AutosaveViewModel.LastAutosavedPath, path, true);
 
-                document.MarkAsSaved();
-                document.AutosaveViewModel.AddAutosaveHistoryEntry(AutosaveHistoryType.Periodic, AutosaveHistoryResult.SavedUserFile);
+                Dispatcher.UIThread.Invoke(() =>
+                {
+                    document.MarkAsSaved();
+                    document.AutosaveViewModel.AddAutosaveHistoryEntry(AutosaveHistoryType.Periodic,
+                        AutosaveHistoryResult.SavedUserFile);
+                });
                 return UserFileAutosaveResult.Success;
             }
             catch (Exception e) when (e is UnauthorizedAccessException or DirectoryNotFoundException)

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/ColorsViewModel.cs

@@ -426,7 +426,7 @@ internal class ColorsViewModel : SubViewModel<ViewModelMain>, IColorsHandler
     [Commands_Command.Internal("PixiEditor.CloseContextMenu")]
     public void CloseContextMenu(XAML_ContextMenu menu)
     {
-        menu.Close();
+        menu?.Close();
     }
 
     public void SetupPaletteProviders(IServiceProvider services)

+ 15 - 5
src/PixiEditor/ViewModels/SubViewModels/UpdateViewModel.cs

@@ -294,12 +294,22 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
             Dispatcher.UIThread.InvokeAsync(async () => await CheckForUpdate());
             return;
         }
-        
-        if (Path.Exists(updaterPath))
+
+        try
+        {
+            if (Path.Exists(updaterPath))
+            {
+                File.Copy(updaterPath, Path.Join(UpdateDownloader.DownloadLocation, $"PixiEditor.UpdateInstaller"),
+                    true);
+                updaterPath = Path.Join(UpdateDownloader.DownloadLocation, $"PixiEditor.UpdateInstaller");
+                File.WriteAllText(Path.Join(UpdateDownloader.DownloadLocation, "update-location.txt"),
+                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty);
+            }
+        }
+        catch (IOException)
         {
-            File.Copy(updaterPath, Path.Join(UpdateDownloader.DownloadLocation, $"PixiEditor.UpdateInstaller"), true);
-            updaterPath = Path.Join(UpdateDownloader.DownloadLocation, $"PixiEditor.UpdateInstaller");
-            File.WriteAllText(Path.Join(UpdateDownloader.DownloadLocation, "update-location.txt"), Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty);
+            NoticeDialog.Show("COULD_NOT_UPDATE_WITHOUT_ADMIN", "INSUFFICIENT_PERMISSIONS");
+            return;
         }
 
         if (updateFileExists && File.Exists(updaterPath))

+ 9 - 2
src/PixiEditor/Views/Visuals/PixiFilePreviewImage.cs

@@ -76,8 +76,15 @@ internal class PixiFilePreviewImage : TextureControl
 
         Dispatcher.UIThread.Post(() =>
         {
-            var surface = LoadTexture(imageBytes);
-            SetImage(surface);
+            try
+            {
+                var surface = LoadTexture(imageBytes);
+                SetImage(surface);
+            }
+            catch (Exception e)
+            {
+                SetCorrupt();
+            }
         });
     }