Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows default platform detection causes failed import #3

Open
JamesCaska opened this issue Jan 3, 2020 · 1 comment
Open

Windows default platform detection causes failed import #3

JamesCaska opened this issue Jan 3, 2020 · 1 comment

Comments

@JamesCaska
Copy link

On windows there seems to be some problems coming from the default platform location.

Looks like by default .arduino15/packages/ is expected but this seems unix centric which leads to currentPlatform = null. This ends up crashing the plugin with a NullPointer exception on startup because the boards don't populate in the board dialog.

Then when you select the package location it gets parsed incorrectly which leads to the package def being wrong because the createPlatformFromFile matches the wrong indexes. Below is a quick fix. Maybe it needs to be extended for other patterns.

  private static Platform createPlatformFromFile(Platform rootPlatform, Path platformFilePath) {
        // Pattern: /home/user/.arduino15/packages/{vendor}/hardware/{architecture}/x.x.x/platform.txt
        // Pattern: Program Files(x86)/Arduino/hardware/arduino/avr/platform.txt
        
        int hardwareIndex = -1;
        int arduino15Index = -1;
       
        for (int i = platformFilePath.getNameCount() - 1; i >= 0; i--) {
            if ("arduino15".equalsIgnoreCase(platformFilePath.getName(i).toString())) {
               arduino15Index = i;
            }
            if ("hardware".equalsIgnoreCase(platformFilePath.getName(i).toString())) {
                hardwareIndex = i;
                break;
            }
        }
        
        String vendor ;
        String architecture ;
            
        if( arduino15Index == -1){
            //Windows
              vendor = platformFilePath.getName(hardwareIndex + 1).toString();
              architecture = platformFilePath.getName(hardwareIndex + 2).toString();
        }else{
              vendor = platformFilePath.getName(hardwareIndex - 1).toString();
              architecture = platformFilePath.getName(hardwareIndex + 1).toString();
        }
 
        try {
            if (architecture.equalsIgnoreCase("pic32")) {
                return new PIC32Platform(rootPlatform, vendor, platformFilePath.getParent());
            } else {
                return new Platform(rootPlatform, vendor, architecture, platformFilePath.getParent());
            }
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, String.format("Failed to create a platform for %s / %s ", vendor, architecture), ex);
            return null;
        }

    }

@gholdys
Copy link
Collaborator

gholdys commented Jan 3, 2020

Thanks for that. I'll take a look at your suggested changes during this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants