|
38 | 38 | import java.nio.file.Files; |
39 | 39 | import java.nio.file.Path; |
40 | 40 | import java.nio.file.Paths; |
| 41 | +import java.nio.file.StandardCopyOption; |
41 | 42 | import java.text.SimpleDateFormat; |
42 | 43 | import java.util.ArrayList; |
43 | 44 | import java.util.Arrays; |
@@ -2436,7 +2437,30 @@ private String findChromiumScanPage() { |
2436 | 2437 | return path.toString(); |
2437 | 2438 | } |
2438 | 2439 | } |
2439 | | - return null; |
| 2440 | + return copyClasspathResourceToTempFile( |
| 2441 | + "qrscan_chromium.html", |
| 2442 | + "qrscan_chromium_", |
| 2443 | + ".html"); |
| 2444 | + } |
| 2445 | + |
| 2446 | + private String copyClasspathResourceToTempFile(String resourceName, |
| 2447 | + String tempPrefix, |
| 2448 | + String tempSuffix) { |
| 2449 | + try (InputStream stream = CandidateImageFile.class |
| 2450 | + .getClassLoader() |
| 2451 | + .getResourceAsStream(resourceName)) { |
| 2452 | + if (stream == null) { |
| 2453 | + return null; |
| 2454 | + } |
| 2455 | + Path tempFile = Files.createTempFile(tempPrefix, tempSuffix); |
| 2456 | + Files.copy(stream, tempFile, StandardCopyOption.REPLACE_EXISTING); |
| 2457 | + tempFile.toFile().deleteOnExit(); |
| 2458 | + return tempFile.toString(); |
| 2459 | + } catch (IOException e) { |
| 2460 | + log.debug("Unable to stage classpath resource {}: {}", resourceName, |
| 2461 | + e.getMessage()); |
| 2462 | + return null; |
| 2463 | + } |
2440 | 2464 | } |
2441 | 2465 |
|
2442 | 2466 | private String getOsKey() { |
@@ -2624,8 +2648,11 @@ private String findPythonScript() { |
2624 | 2648 | return path; |
2625 | 2649 | } |
2626 | 2650 | } |
2627 | | - |
2628 | | - return null; |
| 2651 | + |
| 2652 | + return copyClasspathResourceToTempFile( |
| 2653 | + "qrscan_using_python.py", |
| 2654 | + "qrscan_using_python_", |
| 2655 | + ".py"); |
2629 | 2656 | } |
2630 | 2657 |
|
2631 | 2658 | /** |
|
0 commit comments