File tree Expand file tree Collapse file tree 5 files changed +70
-11
lines changed Expand file tree Collapse file tree 5 files changed +70
-11
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,17 @@ nanoff --listboards --platform stm32
313313
314314If you just use ` --listtargets ` switch, you'll get the list of all the stable packages for all targets.
315315
316+ ## Clear cache location
317+
318+ If needed one can clear the local cache from the firmware packages that are stored there.
319+ As an additional information the cache location is the directory ` -nanoFramework\fw_cache ` in the user folder.
320+
321+ When this option is included in the command no other options are processed.
322+
323+ ``` console
324+ nanoff --clearcache
325+ ```
326+
316327## Exit codes
317328
318329The exit codes can be checked in [ this source file] ( https://github.com/nanoframework/nanoFirmwareFlasher/blob/develop/nanoFirmwareFlasher/ExitCodes.cs ) .
Original file line number Diff line number Diff line change @@ -273,5 +273,12 @@ public enum ExitCodes
273273 /// </summary>
274274 [ Display ( Name = "Unsupported platform. Valid options are: esp32, stm32, cc13x2" ) ]
275275 E9013 = 9013 ,
276+
277+ /// <summary>
278+ /// Error clearing cache location.
279+ /// </summary>
280+ [ Display ( Name = "Error occured when clearing the firmware cache location." ) ]
281+ E9014 = 9014 ,
282+
276283 }
277284}
Original file line number Diff line number Diff line change @@ -37,6 +37,20 @@ internal abstract class FirmwarePackage : IDisposable
3737
3838 private const string _readmeContent = "This folder contains nanoFramework firmware files. Can safely be removed." ;
3939
40+ /// <summary>
41+ /// Path with the base location for firmware packages.
42+ /// </summary>
43+ public static string LocationPathBase
44+ {
45+ get
46+ {
47+ return Path . Combine (
48+ Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ,
49+ ".nanoFramework" ,
50+ "fw_cache" ) ;
51+ }
52+ }
53+
4054 /// <summary>
4155 /// Path with the location of the downloaded firmware.
4256 /// </summary>
@@ -153,26 +167,21 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
153167
154168 // setup download folder
155169 // set download path
156- LocationPath = Path . Combine (
157- Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ,
158- ".nanoFramework" ) ;
159-
160170 try
161171 {
162- // create home directory
163- Directory . CreateDirectory ( LocationPath ) ;
172+ // create " home" directory
173+ Directory . CreateDirectory ( LocationPathBase ) ;
164174
165175 // add readme file
166176 File . WriteAllText (
167177 Path . Combine (
168- LocationPath ,
178+ LocationPathBase ,
169179 "README.txt" ) ,
170180 _readmeContent ) ;
171181
172182 // set location path to target folder
173183 LocationPath = Path . Combine (
174- Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ,
175- ".nanoFramework" ,
184+ LocationPathBase ,
176185 _targetName ) ;
177186
178187 Directory . CreateDirectory ( LocationPath ) ;
@@ -531,6 +540,5 @@ void IDisposable.Dispose()
531540 }
532541
533542 #endregion
534-
535543 }
536544}
Original file line number Diff line number Diff line change @@ -292,6 +292,13 @@ public class Options
292292 HelpText = "List the all the COM ports on this machine." ) ]
293293 public bool ListComPorts { get ; set ; }
294294
295+ [ Option (
296+ "clearcache" ,
297+ Required = false ,
298+ Default = false ,
299+ HelpText = "Clear the cache folder with firmware images." ) ]
300+ public bool ClearCache { get ; set ; }
301+
295302 #endregion
296303
297304
Original file line number Diff line number Diff line change @@ -177,6 +177,32 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
177177
178178 Console . ForegroundColor = ConsoleColor . White ;
179179
180+ if ( o . ClearCache )
181+ {
182+ Console . WriteLine ( ) ;
183+
184+ if ( Directory . Exists ( FirmwarePackage . LocationPathBase ) )
185+ {
186+ Console . WriteLine ( "Clearing firmware cache location." ) ;
187+
188+ try
189+ {
190+ Directory . Delete ( FirmwarePackage . LocationPathBase ) ;
191+ }
192+ catch ( Exception ex )
193+ {
194+ _exitCode = ExitCodes . E9014 ;
195+ _extraMessage = ex . Message ;
196+ }
197+ }
198+ else
199+ {
200+ Console . WriteLine ( "Firmware cache location does not exist. Nothing to do." ) ;
201+ }
202+
203+ return ;
204+ }
205+
180206 if ( o . ListComPorts )
181207 {
182208 var ports = SerialPort . GetPortNames ( ) ;
@@ -188,7 +214,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
188214 {
189215 Console . WriteLine ( $ " { p } ") ;
190216 }
191- }
217+ }
192218 else
193219 {
194220 Console . ForegroundColor = ConsoleColor . Yellow ;
You can’t perform that action at this time.
0 commit comments