* Resolves the path location of a STM32CubeIDE plugin irrespective of version number. * Works for most recent version STM32CubeIDE_1.4.0 and STM32CubeIDE_1.5.0.
(dirSegments: string[], regex: RegExp, suffix: string, executable = '')
| 35 | * Works for most recent version STM32CubeIDE_1.4.0 and STM32CubeIDE_1.5.0. |
| 36 | */ |
| 37 | function resolveCubePath(dirSegments: string[], regex: RegExp, suffix: string, executable = '') |
| 38 | { |
| 39 | const dir = path.join(...dirSegments); |
| 40 | let resolvedDir: string; |
| 41 | try { |
| 42 | for (const subDir of fs.readdirSync(dir).sort()) { |
| 43 | const fullPath = path.join(dir, subDir); |
| 44 | const stats = fs.statSync(fullPath); |
| 45 | if (!stats.isDirectory()) { |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | const match = subDir.match(regex); |
| 50 | if (match) { |
| 51 | const fullPath = path.join(dir, match[0], suffix, executable); |
| 52 | if (fs.existsSync(fullPath)) { |
| 53 | if (!resolvedDir || (resolvedDir.localeCompare(fullPath, undefined, {sensitivity: 'base', numeric: true})) < 0) { |
| 54 | resolvedDir = fullPath; // Many times, multiple versions exist. Take latest. Hopefully!! |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | catch (error) { |
| 61 | // Ignore |
| 62 | } |
| 63 | return resolvedDir ? resolvedDir : executable; |
| 64 | } |
| 65 | |
| 66 | export class STLinkServerController extends EventEmitter implements GDBServerController { |
| 67 | public readonly name: string = 'ST-LINK'; |
no outgoing calls
no test coverage detected