Bläddra i källkod

Save all files on close when autosaving is enabled

CPKreuz 1 år sedan
förälder
incheckning
e049fab476

+ 18 - 4
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -128,10 +128,24 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         
         foreach (string file in files)
         {
-            string guidString = Path.GetFileNameWithoutExtension(file)["autosave-".Length..];
-            var document = OpenFromPath(file, false);
-            
-            document.AutosaveViewModel.SetTempFileGuiAndLastSavedPath(Guid.Parse(guidString), file);
+            try
+            {
+                if (file.StartsWith(Paths.PathToUnsavedFilesFolder))
+                {
+                    string guidString = Path.GetFileNameWithoutExtension(file)["autosave-".Length..];
+                    var document = OpenFromPath(file, false);
+
+                    document.AutosaveViewModel.SetTempFileGuiAndLastSavedPath(Guid.Parse(guidString), file);
+                }
+                else
+                {
+                    OpenFromPath(file);
+                }
+            }
+            catch (Exception e)
+            {
+                CrashHelper.SendExceptionInfoToWebhook(e);
+            }
         }
         
         preferences.UpdateLocalPreference(PreferencesConstants.UnsavedNextSessionFiles, Array.Empty<string>());

+ 7 - 3
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -203,7 +203,7 @@ internal class ViewModelMain : ViewModelBase
             throw new ArgumentException();
         }
 
-        AutosaveUnsavedForNextSession();
+        AutosaveAllForNextSession();
         ((CancelEventArgs)property).Cancel = !DisposeAllDocumentsWithSaveConfirmation();
     }
 
@@ -249,7 +249,7 @@ internal class ViewModelMain : ViewModelBase
         return true;
     }
 
-    private void AutosaveUnsavedForNextSession()
+    private void AutosaveAllForNextSession()
     {
         if (!AutosaveDocumentViewModel.AutosavingEnabled)
         {
@@ -257,13 +257,17 @@ internal class ViewModelMain : ViewModelBase
         }
         
         var list = new List<string>();
-        foreach (var document in DocumentManagerSubViewModel.Documents.Where(x => x.FullFilePath == null))
+        foreach (var document in DocumentManagerSubViewModel.Documents)
         {
             document.AutosaveViewModel.TryAutosave();
             if (document.AutosaveViewModel.LastSavedPath != null)
             {
                 list.Add(document.AutosaveViewModel.LastSavedPath);
             }
+            else if (document.FullFilePath != null)
+            {
+                list.Add(document.FullFilePath);
+            }
         }
         
         Preferences.UpdateLocalPreference(PreferencesConstants.UnsavedNextSessionFiles, list);