Browse Source

Bug 1857: Do not prevent WinSCP from starting when jump list cannot be updated

https://winscp.net/tracker/1857
(cherry picked from commit 1f458be396759430fffa8bd7ac80520ccfe5aba2)

Source commit: 549121649a4f1290720b564feaa2ccdb174e6be5
Martin Prikryl 5 years ago
parent
commit
3226c7dc43

+ 1 - 0
source/resource/TextsWin.h

@@ -90,6 +90,7 @@
 #define EXTENSION_LOAD_ERROR    1207
 #define NO_SITE_FOR_COMMAND     1208
 #define DD_TARGET_UNKNOWN       1209
+#define JUMPLIST_ERROR          1210
 
 #define WIN_CONFIRMATION_STRINGS 1300
 #define CONFIRM_OVERWRITE_SESSION 1301

+ 1 - 0
source/resource/TextsWin1.rc

@@ -98,6 +98,7 @@ BEGIN
         EXTENSION_LOAD_ERROR, "Error loading an extension from \"%s\"."
         NO_SITE_FOR_COMMAND, "**No session is opened**\nThe selected command has site-specific options, but no session is opened."
         DD_TARGET_UNKNOWN, "**WinSCP was not able to detect a folder, where the dragged file(s) was dropped.** In the default drag&drop mode, WinSCP allows dropping files only to local drives and mapped network drives.\n\nYou can allow dropping files to other targets in preferences. Press Help button for details."
+        JUMPLIST_ERROR, "Error updating jump list."
 
         WIN_CONFIRMATION_STRINGS, "WIN_CONFIRMATION"
         CONFIRM_OVERWRITE_SESSION, "Site with name '%s' already exists. Overwrite?"

+ 8 - 1
source/windows/Setup.cpp

@@ -1763,7 +1763,14 @@ void __fastcall StopUpdateThread()
 //---------------------------------------------------------------------------
 void __fastcall SetupInitialize()
 {
-  WinConfiguration->UpdateJumpList();
+  try
+  {
+    WinConfiguration->UpdateJumpList();
+  }
+  catch (Exception & E)
+  {
+    ShowExtendedException(&E);
+  }
 }
 //---------------------------------------------------------------------------
 static bool __fastcall AddJumpListCategory(TStrings * Names,

+ 9 - 9
source/windows/WinConfiguration.cpp

@@ -2712,18 +2712,19 @@ void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
 void __fastcall TWinConfiguration::UpdateEntryInJumpList(
   bool Session, const UnicodeString & Name, bool Add)
 {
-  THierarchicalStorage * Storage = CreateConfigStorage();
   try
   {
-    FDontDecryptPasswords++;
+    std::auto_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
+    TAutoNestingCounter DontDecryptPasswordsCounter(FDontDecryptPasswords);
+
     Storage->AccessMode = smReadWrite;
 
     // For initial call from UpdateJumpList, do not create the key if it does ot exist yet.
     // To avoid creating the key if we are being started just for a maintenance task.
     if (Storage->OpenSubKey(ConfigurationSubKey, !Name.IsEmpty()))
     {
-      std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage, L"JumpList"));
-      std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage, L"JumpListWorkspaces"));
+      std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage.get(), L"JumpList"));
+      std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage.get(), L"JumpListWorkspaces"));
 
       if (!Name.IsEmpty())
       {
@@ -2745,14 +2746,13 @@ void __fastcall TWinConfiguration::UpdateEntryInJumpList(
 
       ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
 
-      SaveJumpList(Storage, L"JumpList", ListSessions.get());
-      SaveJumpList(Storage, L"JumpListWorkspaces", ListWorkspaces.get());
+      SaveJumpList(Storage.get(), L"JumpList", ListSessions.get());
+      SaveJumpList(Storage.get(), L"JumpListWorkspaces", ListWorkspaces.get());
     }
   }
-  __finally
+  catch (Exception & E)
   {
-    FDontDecryptPasswords--;
-    delete Storage;
+    throw ExtException(&E, MainInstructions(LoadStr(JUMPLIST_ERROR)));
   }
 }
 //---------------------------------------------------------------------------