private void UpdateDependencies(List <Dependency> updatedDependencies = null) { _repoPath = Path.Combine(Application.dataPath, "Repositories"); _rootDependenciesFile = Path.Combine(_repoPath, "Dependencies.json"); //Ensure to create directory structure and default dependencies if nothing exists Directory.CreateDirectory(_repoPath); if (!File.Exists(_rootDependenciesFile)) { File.WriteAllText(_rootDependenciesFile, JsonUtility.ToJson(new DependencyInfo(), true)); } string json = File.ReadAllText(_rootDependenciesFile); _dependencies = JsonUtility.FromJson <DependencyInfo>(json); //Sync file dependencies with in memory dependencies if (updatedDependencies != null) { //Remove no longer existing for (int i = _dependencies.Dependencies.Count - 1; i >= 0; i--) { var dep = _dependencies.Dependencies[i]; if (updatedDependencies.FindAll(d => d.Url == dep.Url).Count <= 0) { _dependencies.Dependencies.RemoveAt(i); } } //Add new foreach (var dep in updatedDependencies) { if (_dependencies.Dependencies.FindAll(d => d.Url == dep.Url).Count <= 0) { _dependencies.Dependencies.Add(dep); } } json = JsonUtility.ToJson(_dependencies, true); File.WriteAllText(_rootDependenciesFile, json); } //Update repo panels _repoPanels = new List <RepoPanel>(); foreach (Dependency dependency in _dependencies.Dependencies) { if (_repoPanels.FindAll(p => dependency.Url == p.DependencyInfo.Url).Count == 0) { RepoPanel panel = new RepoPanel(_repoPath, dependency, GetPlatformAuthentication()); panel.OnRemovalRequested += OnPanelRemovalRequested; panel.OnDeleteAssetsRequested += DeleteAssets; panel.OnCopyFinished += (assets, updatedRepos) => { UpdateAssetDatabaseForNewAssets(assets, EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true), updatedRepos); }; _repoPanels.Add(panel); } } Repaint(); }
private void OnPanelRemovalRequested(string name, string url, string repoPath, string copyPath) { for (int i = 0; i < _dependencies.Dependencies.Count; i++) { if (_dependencies.Dependencies[i].Name == name && _dependencies.Dependencies[i].Url == url) { RepoPanel panel = _repoPanels.Find(p => _dependencies.Dependencies[i].Url == p.DependencyInfo.Url); _dependencies.Dependencies.RemoveAt(i); Repository.Remove(url, repoPath, copyPath); } } //TODO: if we could referesh a folder only that would be nice. cant reimport assets that dont exists. AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); UpdateDependencies(_dependencies.Dependencies); }