public loadPackageContent()

in src/arduino/boardManager.ts [194:246]


    public loadPackageContent(indexFile: string): void {
        const indexFileName = this.getIndexFileName(indexFile);
        if (!util.fileExistsSync(path.join(this._settings.packagePath, indexFileName))) {
            return;
        }
        const packageContent = fs.readFileSync(path.join(this._settings.packagePath, indexFileName), "utf8");
        if (!packageContent) {
            return;
        }

        let rawModel = null;
        try {
            rawModel = JSON.parse(packageContent);
        } catch (ex) {
            arduinoChannel.error(`Invalid json file "${path.join(this._settings.packagePath, indexFileName)}".
            Suggest to remove it manually and allow boardmanager to re-download it.`);
            return;
        }

        if (!rawModel || !rawModel.packages || !rawModel.packages.length) {
            return;
        }

        this._packages = this._packages.concat(rawModel.packages);

        rawModel.packages.forEach((pkg) => {
            pkg.platforms.forEach((plat) => {
                plat.package = pkg;
                const addedPlatform = this._platforms
                    .find((_plat) => _plat.architecture === plat.architecture && _plat.package.name === plat.package.name);
                if (addedPlatform) {
                    // union boards from all versions.
                    // We should not union boards: https://github.com/Microsoft/vscode-arduino/issues/414
                    // addedPlatform.boards = util.union(addedPlatform.boards, plat.boards, (a, b) => {
                    //     return a.name === b.name;
                    // });
                    if (addedPlatform.name === plat.name) {
                        addedPlatform.versions.push(plat.version);
                        // Check if this is the latest version. Platforms typically support more boards in later versions.
                        addedPlatform.versions.sort(versionCompare);
                        if (plat.version === addedPlatform.versions[addedPlatform.versions.length - 1]) {
                            addedPlatform.boards = plat.boards;
                        }
                    }
                } else {
                    plat.versions = [plat.version];
                    // Clear the version information since the plat will be used to contain all supported versions.
                    plat.version = "";
                    this._platforms.push(plat);
                }
            });
        });
    }