@@ -13,12 +13,17 @@ namespace Wox.Core.Configuration
13
13
{
14
14
public class Portable : IPortable
15
15
{
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
+ }
17
24
18
25
public void DisablePortableMode ( )
19
26
{
20
- portabilityUpdater = new UpdateManager ( string . Empty , Constant . Wox , Constant . RootDirectory ) ;
21
-
22
27
try
23
28
{
24
29
MoveUserDataFolder ( DataLocation . PortableDataPath , DataLocation . RoamingDataPath ) ;
@@ -34,13 +39,10 @@ public void DisablePortableMode()
34
39
MessageBox . Show ( "Wox needs to restart to finish disabling portable mode, " +
35
40
"after the restart your portable data profile will be deleted and roaming data profile kept" ) ;
36
41
37
- portabilityUpdater . Dispose ( ) ;
38
-
39
42
UpdateManager . RestartApp ( ) ;
40
43
}
41
44
catch ( Exception e )
42
45
{
43
- portabilityUpdater . Dispose ( ) ;
44
46
#if ! DEBUG
45
47
Log . Exception ( "Portable" , "Error occured while disabling portable mode" , e ) ;
46
48
#endif
@@ -50,8 +52,6 @@ public void DisablePortableMode()
50
52
51
53
public void EnablePortableMode ( )
52
54
{
53
- portabilityUpdater = new UpdateManager ( string . Empty , Constant . Wox , Constant . RootDirectory ) ;
54
-
55
55
try
56
56
{
57
57
MoveUserDataFolder ( DataLocation . RoamingDataPath , DataLocation . PortableDataPath ) ;
@@ -67,13 +67,10 @@ public void EnablePortableMode()
67
67
MessageBox . Show ( "Wox needs to restart to finish enabling portable mode, " +
68
68
"after the restart your roaming data profile will be deleted and portable data profile kept" ) ;
69
69
70
- portabilityUpdater . Dispose ( ) ;
71
-
72
70
UpdateManager . RestartApp ( ) ;
73
71
}
74
72
catch ( Exception e )
75
73
{
76
- portabilityUpdater . Dispose ( ) ;
77
74
#if ! DEBUG
78
75
Log . Exception ( "Portable" , "Error occured while enabling portable mode" , e ) ;
79
76
#endif
@@ -83,15 +80,21 @@ public void EnablePortableMode()
83
80
84
81
public void RemoveShortcuts ( )
85
82
{
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
+ }
90
90
}
91
91
92
92
public void RemoveUninstallerEntry ( )
93
93
{
94
- portabilityUpdater . RemoveUninstallerRegistryEntry ( ) ;
94
+ using ( var portabilityUpdater = NewUpdateManager ( ) )
95
+ {
96
+ portabilityUpdater . RemoveUninstallerRegistryEntry ( ) ;
97
+ }
95
98
}
96
99
97
100
public void MoveUserDataFolder ( string fromLocation , string toLocation )
@@ -107,10 +110,13 @@ public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
107
110
108
111
public void CreateShortcuts ( )
109
112
{
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
+ }
114
120
}
115
121
116
122
public void CreateUninstallerEntry ( )
@@ -125,7 +131,10 @@ public void CreateUninstallerEntry()
125
131
. CreateSubKey ( uninstallRegSubKey + "\\ " + Constant . Wox , RegistryKeyPermissionCheck . ReadWriteSubTree ) ;
126
132
key . SetValue ( "DisplayIcon" , Constant . ApplicationDirectory + "\\ app.ico" , RegistryValueKind . String ) ;
127
133
128
- portabilityUpdater . CreateUninstallerRegistryEntry ( ) ;
134
+ using ( var portabilityUpdater = NewUpdateManager ( ) )
135
+ {
136
+ portabilityUpdater . CreateUninstallerRegistryEntry ( ) ;
137
+ }
129
138
}
130
139
131
140
internal void IndicateDeletion ( string filePathTodelete )
0 commit comments