@@ -13,12 +13,17 @@ namespace Wox.Core.Configuration
1313{
1414 public class Portable : IPortable
1515 {
16- private UpdateManager portabilityUpdater ;
16+ /// <summary>
17+ /// As at Squirrel.Windows version 1.5.2, UpdateManager needs to be disposed after finish
18+ /// </summary>
19+ /// <returns></returns>
20+ private UpdateManager NewUpdateManager ( )
21+ {
22+ return new UpdateManager ( string . Empty , Constant . Wox , Constant . RootDirectory ) ;
23+ }
1724
1825 public void DisablePortableMode ( )
1926 {
20- portabilityUpdater = new UpdateManager ( string . Empty , Constant . Wox , Constant . RootDirectory ) ;
21-
2227 try
2328 {
2429 MoveUserDataFolder ( DataLocation . PortableDataPath , DataLocation . RoamingDataPath ) ;
@@ -34,13 +39,10 @@ public void DisablePortableMode()
3439 MessageBox . Show ( "Wox needs to restart to finish disabling portable mode, " +
3540 "after the restart your portable data profile will be deleted and roaming data profile kept" ) ;
3641
37- portabilityUpdater . Dispose ( ) ;
38-
3942 UpdateManager . RestartApp ( ) ;
4043 }
4144 catch ( Exception e )
4245 {
43- portabilityUpdater . Dispose ( ) ;
4446#if ! DEBUG
4547 Log . Exception ( "Portable" , "Error occured while disabling portable mode" , e ) ;
4648#endif
@@ -50,8 +52,6 @@ public void DisablePortableMode()
5052
5153 public void EnablePortableMode ( )
5254 {
53- portabilityUpdater = new UpdateManager ( string . Empty , Constant . Wox , Constant . RootDirectory ) ;
54-
5555 try
5656 {
5757 MoveUserDataFolder ( DataLocation . RoamingDataPath , DataLocation . PortableDataPath ) ;
@@ -67,13 +67,10 @@ public void EnablePortableMode()
6767 MessageBox . Show ( "Wox needs to restart to finish enabling portable mode, " +
6868 "after the restart your roaming data profile will be deleted and portable data profile kept" ) ;
6969
70- portabilityUpdater . Dispose ( ) ;
71-
7270 UpdateManager . RestartApp ( ) ;
7371 }
7472 catch ( Exception e )
7573 {
76- portabilityUpdater . Dispose ( ) ;
7774#if ! DEBUG
7875 Log . Exception ( "Portable" , "Error occured while enabling portable mode" , e ) ;
7976#endif
@@ -83,15 +80,21 @@ public void EnablePortableMode()
8380
8481 public void RemoveShortcuts ( )
8582 {
86- var exeName = Constant . Wox + ".exe" ;
87- portabilityUpdater . RemoveShortcutsForExecutable ( exeName , ShortcutLocation . StartMenu ) ;
88- portabilityUpdater . RemoveShortcutsForExecutable ( exeName , ShortcutLocation . Desktop ) ;
89- portabilityUpdater . RemoveShortcutsForExecutable ( exeName , ShortcutLocation . Startup ) ;
83+ using ( var portabilityUpdater = NewUpdateManager ( ) )
84+ {
85+ var exeName = Constant . Wox + ".exe" ;
86+ portabilityUpdater . RemoveShortcutsForExecutable ( exeName , ShortcutLocation . StartMenu ) ;
87+ portabilityUpdater . RemoveShortcutsForExecutable ( exeName , ShortcutLocation . Desktop ) ;
88+ portabilityUpdater . RemoveShortcutsForExecutable ( exeName , ShortcutLocation . Startup ) ;
89+ }
9090 }
9191
9292 public void RemoveUninstallerEntry ( )
9393 {
94- portabilityUpdater . RemoveUninstallerRegistryEntry ( ) ;
94+ using ( var portabilityUpdater = NewUpdateManager ( ) )
95+ {
96+ portabilityUpdater . RemoveUninstallerRegistryEntry ( ) ;
97+ }
9598 }
9699
97100 public void MoveUserDataFolder ( string fromLocation , string toLocation )
@@ -107,10 +110,13 @@ public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
107110
108111 public void CreateShortcuts ( )
109112 {
110- var exeName = Constant . Wox + ".exe" ;
111- portabilityUpdater . CreateShortcutsForExecutable ( exeName , ShortcutLocation . StartMenu , false ) ;
112- portabilityUpdater . CreateShortcutsForExecutable ( exeName , ShortcutLocation . Desktop , false ) ;
113- portabilityUpdater . CreateShortcutsForExecutable ( exeName , ShortcutLocation . Startup , false ) ;
113+ using ( var portabilityUpdater = NewUpdateManager ( ) )
114+ {
115+ var exeName = Constant . Wox + ".exe" ;
116+ portabilityUpdater . CreateShortcutsForExecutable ( exeName , ShortcutLocation . StartMenu , false ) ;
117+ portabilityUpdater . CreateShortcutsForExecutable ( exeName , ShortcutLocation . Desktop , false ) ;
118+ portabilityUpdater . CreateShortcutsForExecutable ( exeName , ShortcutLocation . Startup , false ) ;
119+ }
114120 }
115121
116122 public void CreateUninstallerEntry ( )
@@ -125,7 +131,10 @@ public void CreateUninstallerEntry()
125131 . CreateSubKey ( uninstallRegSubKey + "\\ " + Constant . Wox , RegistryKeyPermissionCheck . ReadWriteSubTree ) ;
126132 key . SetValue ( "DisplayIcon" , Constant . ApplicationDirectory + "\\ app.ico" , RegistryValueKind . String ) ;
127133
128- portabilityUpdater . CreateUninstallerRegistryEntry ( ) ;
134+ using ( var portabilityUpdater = NewUpdateManager ( ) )
135+ {
136+ portabilityUpdater . CreateUninstallerRegistryEntry ( ) ;
137+ }
129138 }
130139
131140 internal void IndicateDeletion ( string filePathTodelete )
0 commit comments