示例#1
0
        public RepositoryIndexJson(string name, string path)
        {
            this.name = name;
            this.path = path;

            libraries = LibraryReader.parseLibrary_Index_Json(path);
        }
示例#2
0
        public void openProject(string projectPath)
        {
            path = projectPath;

            _configurations.Clear();

            var vsTeensyJson = Path.Combine(projectPath, ".vsteensy", "vsteensy.json");

            if (!File.Exists(vsTeensyJson))
            {
                buildSystem = BuildSystem.makefile;
                target      = Target.vsCode;

                var sc = Configuration.getDefault(setup);
                _selectedConfiguration = sc; // Configuration.getDefault(setup);
                _configurations.Add(sc);     // selectedConfiguration);
                return;
            }

            try
            {
                string jsonString = File.ReadAllText(vsTeensyJson);
                //log.Debug("vsTeensy.json content:\n" + jsonString);

                var fileContent = JsonConvert.DeserializeObject <projectTransferData>(jsonString);

                if (fileContent?.version == "1" && fileContent.configurations.Count > 0)
                {
                    buildSystem = fileContent.buildSystem;
                    target      = fileContent.target;

                    foreach (var cfg in fileContent.configurations)
                    {
                        var configuration = new Configuration()
                        {
                            setupType = cfg.setupType,  // remove from config

                            name = cfg.name,
                            guid = cfg.guid != null ? cfg.guid : Guid.NewGuid().ToString(),

                            compilerBase      = cfg.compilerBase,
                            makefileExtension = cfg.makefileExtension,
                            boardTxtPath      = cfg.boardTxtPath, //.StartsWith("\\") ? Path.Combine(projectPath, cfg.boardTxtPath.Substring(1)) : cfg.boardTxtPath,
                            coreBase          = cfg.coreBase,     //.StartsWith("\\") ? Path.Combine(projectPath, cfg.coreBase.Substring(1)) : cfg.coreBase,
                        };

                        if (cfg.sharedLibraries != null)
                        {
                            var sharedLibraries = libManager.sharedRepository.libraries.Select(version => version.FirstOrDefault()); //flatten out list by selecting first version. Shared libraries  can only have one version
                            foreach (var cfgSharedLib in cfg.sharedLibraries)
                            {
                                var library = sharedLibraries.FirstOrDefault(lib => lib.path == cfgSharedLib); // find the corresponding lib
                                if (library != null)
                                {
                                    configuration.sharedLibs.Add(library);
                                }
                            }
                        }

                        if (cfg.localLibraries != null)
                        {
                            var localLibraries = LibraryReader.parseLibraryLocal(Path.Combine(projectPath, "lib")).Select(version => version.FirstOrDefault());
                            foreach (var cfgLocalLib in cfg.localLibraries)
                            {
                                var library = localLibraries.FirstOrDefault(lib => lib.path == cfgLocalLib);
                                if (library != null)
                                {
                                    configuration.localLibs.Add(library);
                                }
                            }
                        }

                        configuration.parseBoardsTxt(configuration.setupType == SetupTypes.quick ? setup.arduinoBoardsTxt : null);

                        configuration.selectedBoard = configuration.boards?.FirstOrDefault(b => b.name == cfg.board.name);
                        if (configuration.selectedBoard != null)
                        {
                            foreach (var option in cfg.board.options)
                            {
                                var optionSet = configuration.selectedBoard.optionSets.FirstOrDefault(x => x.name == option.Key);
                                if (optionSet != null)
                                {
                                    optionSet.selectedOption = optionSet.options.FirstOrDefault(x => x.name == option.Value);
                                }
                            }
                        }
                        _configurations.Add(configuration);
                        // _configs.Add(configuration);
                    }
                    _selectedConfiguration = _configurations.FirstOrDefault();
                    //log.Info($"{vsTeensyJson} read sucessfully");
                }
                else
                {
                    var sc = Configuration.getDefault(setup);
                    _selectedConfiguration = sc; // Configuration.getDefault(setup);
                    _configurations.Add(sc);     //selectedConfiguration);
                    //_configs.Add(selectedConfiguration);
                    //log.Info($"{vsTeensyJson} parse error, using default configuration");
                }
                //  generateFiles();
            }
            catch //(Exception ex)
            {
                //log.Warn($"config file {vsTeensyJson} does not exist");
                var sc = Configuration.getDefault(setup);
                _selectedConfiguration = sc; // Configuration.getDefault(setup);
                _configurations.Add(sc);     //electedConfiguration);
                                             //_configs.Add(selectedConfiguration);
                                             //   generateFiles();
                return;
            }
        }
示例#3
0
 public RepositoryLocal(string name, string path = null)
 {
     this.name = name;
     this.path = path;
     libraries = LibraryReader.parseLibraryLocal(path);
 }