/// <summary> /// Gets the list of sample project files (project templates) available. /// This will look in the %appdata%\Roaming\HydroDesktop and also in the %hydrodesktop_sample_projects% directory. /// </summary> public List <SampleProjectInfo> FindSampleProjectFiles() { //create the AbsolutePathToExtensions directory in case this directory doesn't exist if (!Directory.Exists(AppManager.AbsolutePathToExtensions)) { Directory.CreateDirectory(AppManager.AbsolutePathToExtensions); } List <SampleProjectInfo> sampleProjectList = new List <SampleProjectInfo>(); foreach (string absolutePath in Directory.EnumerateFiles(AppManager.AbsolutePathToExtensions, "*.dspx", SearchOption.AllDirectories)) { var sample = new SampleProjectInfo(); sample.AbsolutePathToProjectFile = absolutePath; sample.Name = Path.GetFileNameWithoutExtension(absolutePath); sample.Description = "description"; sample.Version = "1.0"; sampleProjectList.Add(sample); } return(sampleProjectList); }
public IEnumerable <ISampleProject> SetupInstalledSampleProjects(List <SampleProjectInfo> downloadedSampleProjects) { List <ISampleProject> allSampleProjects = new List <ISampleProject>(); List <ISampleProject> resultList = new List <ISampleProject>(); //this is usually C:\users\{username}\Documents\AppData\Roaming\{HydroDesktop version number}\extensions\packages. //this is usually a hiddden folder that doesn't show up in windows explorer. string absolutePathToExtensionsInAppdata = AppManager.AbsolutePathToExtensions; List <string> sampleProjectFilesToInstall = new List <string>(); List <string> installedSampleProjectNames = new List <string>(); foreach (SampleProjectInfo p in downloadedSampleProjects) { installedSampleProjectNames.Add(Path.GetFileNameWithoutExtension(p.AbsolutePathToProjectFile)); allSampleProjects.Add(p); } //step 1: check list of shipped sample projects in [Program Files]\HydroDesktop\hydrodesktop_sample_projects //also add the project files from hd_sample_projects folder string projDir = Properties.Settings.Default.SampleProjectsDirectory; string shippedSampleProjectDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, projDir); //step 2: find names of shipped sample projects that should be copied to the %appdata% folder //this excludes shpipped sample projects that have the same name as sample projects in %appdata% folder if (Directory.Exists(shippedSampleProjectDir)) { string[] filesInShippedDir = Directory.GetFiles(shippedSampleProjectDir, "*.dspx", SearchOption.AllDirectories); foreach (string shippedFile in filesInShippedDir) { string shippedProjectName = Path.GetFileNameWithoutExtension(shippedFile); if (!installedSampleProjectNames.Contains(shippedProjectName)) { sampleProjectFilesToInstall.Add(shippedFile); } } //step 3: copy each sample project to target directory string defaultTargetBaseDir = AppManager.AbsolutePathToExtensions; string packagesDir = Path.Combine(AppManager.AbsolutePathToExtensions, "Packages"); foreach (string spf in sampleProjectFilesToInstall) { //attempt to create target directory string targDirName = Path.Combine(packagesDir, Path.GetFileNameWithoutExtension(spf)); try { string targetDir = TryToCreateTargetDirectory(targDirName); string newFullPath = CopyShippedSampleProject(spf, targetDir); SampleProjectInfo spi = new SampleProjectInfo(); spi.AbsolutePathToProjectFile = newFullPath; spi.Description = Path.GetFileNameWithoutExtension(spi.AbsolutePathToProjectFile); spi.Name = spi.Description; resultList.Add(spi); } catch (Exception ex) { Trace.Write("Error copying project files: " + ex.Message); } } } if (allSampleProjects.Count >= 3) { if (allSampleProjects.ElementAt(0).Name == "Europe Map" && allSampleProjects.ElementAt(1).Name == "North America Map" && allSampleProjects.ElementAt(2).Name == "World Map") { SampleProjectInfo europe = allSampleProjects.ElementAt(0) as SampleProjectInfo; allSampleProjects.RemoveAt(0); allSampleProjects.Insert(2, europe); } } resultList.AddRange(allSampleProjects); return(resultList); }