@@ -22,14 +22,14 @@ abstract class BaseSetupCommand extends Command {
2222 return arch_;
2323 }
2424
25+ bool get force => argResults? .flag ("force" ) ?? false ;
2526 String get os => name;
2627
2728 Future <void > downloadAndExtract () async {
2829 // Detect dependencies
2930 // Assumed package root
3031 final root = Directory .current.uri;
31- print ('Building with assumed project root in:' );
32- print (root.toFilePath ());
32+ print ('Building with assumed project root in: ${root .toFilePath ()}' );
3333
3434 // Assumed package_config.json
3535 final packageConfigFile = File .fromUri (
@@ -64,22 +64,25 @@ abstract class BaseSetupCommand extends Command {
6464 final version = doc["binary_version" ] as String ;
6565 final libTarName = "libopencv_dart-$os -$arch .tar.gz" ;
6666
67- print ('Downloading prebuilt binary...' );
68- String url = "https://github.com/rainyl/opencv_dart/releases/download/v$version /$libTarName " ;
69-
70- final cacheTarPath = p.join (opencvRoot.toFilePath (), ".cache" , libTarName);
67+ final cacheTarPath = p.join (opencvRoot.toFilePath (), ".dart_tool" , ".cache" , libTarName);
7168 final saveFile = File (cacheTarPath);
72- if (! saveFile.parent.existsSync ()) saveFile.parent.createSync (recursive: true );
73-
74- print ("Downloading $url " );
75- final request = await HttpClient ().getUrl (Uri .parse (url));
76- final response = await request.close ();
77- if (response.statusCode == 200 ) {
78- await response.pipe (saveFile.openWrite ());
79- print ("Cached to $cacheTarPath " );
69+
70+ if (force || ! saveFile.existsSync ()) {
71+ if (! saveFile.parent.existsSync ()) saveFile.parent.createSync (recursive: true );
72+
73+ String url = "https://github.com/rainyl/opencv_dart/releases/download/v$version /$libTarName " ;
74+ print ("Downloading $url " );
75+ final request = await HttpClient ().getUrl (Uri .parse (url));
76+ final response = await request.close ();
77+ if (response.statusCode == 200 ) {
78+ await response.pipe (saveFile.openWrite ());
79+ print ("Cached to $cacheTarPath " );
80+ } else {
81+ print ("Download Failed with status: ${response .statusCode }" );
82+ exit (1 );
83+ }
8084 } else {
81- print ("Download Failed with status: ${response .statusCode }" );
82- exit (1 );
85+ print ("Using cached $cacheTarPath " );
8386 }
8487
8588 String extractPath = "" ;
@@ -132,6 +135,7 @@ class MacOsSetupCommand extends BaseSetupCommand {
132135 allowed: ["x64" , "arm64" ],
133136 mandatory: true ,
134137 );
138+ argParser.addFlag ("force" , abbr: "f" , defaultsTo: false , help: "Force download and extract" );
135139 }
136140}
137141
@@ -144,6 +148,7 @@ class WindowsSetupCommand extends BaseSetupCommand {
144148
145149 WindowsSetupCommand () {
146150 argParser.addOption ("arch" , abbr: "a" , allowed: ["x64" ], mandatory: true );
151+ argParser.addFlag ("force" , abbr: "f" , defaultsTo: false , help: "Force download and extract" );
147152 }
148153}
149154
@@ -156,6 +161,7 @@ class LinuxSetupCommand extends BaseSetupCommand {
156161
157162 LinuxSetupCommand () {
158163 argParser.addOption ("arch" , abbr: "a" , allowed: ["x64" ], mandatory: true );
164+ argParser.addFlag ("force" , abbr: "f" , defaultsTo: false , help: "Force download and extract" );
159165 }
160166}
161167
@@ -173,6 +179,7 @@ class AndroidSetupCommand extends BaseSetupCommand {
173179 allowed: ["x86_64" , "arm64-v8a" , "armeabi-v7a" ],
174180 mandatory: true ,
175181 );
182+ argParser.addFlag ("force" , abbr: "f" , defaultsTo: false , help: "Force download and extract" );
176183 }
177184}
178185
@@ -190,6 +197,7 @@ class IosSetupCommand extends BaseSetupCommand {
190197 allowed: ["x64" , "arm64" ],
191198 mandatory: true ,
192199 );
200+ argParser.addFlag ("force" , abbr: "f" , defaultsTo: false , help: "Force download and extract" );
193201 }
194202}
195203
0 commit comments