protected void InstallGenericFile(string root, string fileToInstall, PackageFileKind kind, string packageId) { string kindName = kind.ToString().ToLower(); string relativeKindRoot = Path.Combine(root, kindName); if (!Directory.Exists(relativeKindRoot)) { Directory.CreateDirectory(relativeKindRoot); } string shortName = fileToInstall.Substring(fileToInstall.IndexOf("/") + 1); string fullName = kindName + "/" + packageId + "/" + shortName; InstallingResolvedFile?.Invoke(this, new ResolvedFileEventArgs(packageId, kind, BuildConfiguration.Any, fullName)); string fullPath = PathUtils.FixPathSeparators(Path.Combine(root, fullName)); string fullDirPath = new FileInfo(fullPath).Directory.FullName; PathUtils.EnsureDirectoryExists(fullDirPath); if (File.Exists(fullPath)) { File.Delete(fullPath); } using (Stream df = File.Create(fullPath)) GetSourceStream(fileToInstall).CopyTo(df); }
protected void InstallLibrary(string packageId, string root, string fileToInstall, BuildConfiguration targetConfig) { var name = fileToInstall.Substring(fileToInstall.IndexOf("/") + 1); BuildConfiguration config = (BuildConfiguration)Enum.Parse(typeof(BuildConfiguration), name.Substring(0, name.IndexOf("/")), true); //var name = fileToInstall.Substring(fileToInstall.IndexOf("/") + 1); //var posFirstSlash = name.IndexOf("/"); //if (posFirstSlash < 0 || !Enum.TryParse(name.Substring(0, name.IndexOf("/")), out BuildConfiguration config)) // config = BuildConfiguration.Any; bool install = (targetConfig == BuildConfiguration.Any) || (config == BuildConfiguration.Any) || (config == BuildConfiguration.Debug && (targetConfig == BuildConfiguration.Any || targetConfig == BuildConfiguration.Debug)) || (config == BuildConfiguration.Release && (targetConfig == BuildConfiguration.Any || targetConfig == BuildConfiguration.Release)); if (install) { name = name.Substring(name.IndexOf("/") + 1); if (name.IndexOf('/') != -1 && name.StartsWith("net")) { name = name.Substring(name.IndexOf('/') + 1); } InstallingResolvedFile?.Invoke(null, new ResolvedFileEventArgs(packageId, PackageFileKind.Binary, config, name)); string targetPath = Path.Combine(root, "lib", name); try { var directoryName = Path.GetDirectoryName(targetPath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } else if (File.Exists(targetPath)) { File.Delete(targetPath); } using (Stream ts = File.Create(targetPath)) GetSourceStream(fileToInstall).CopyTo(ts); } catch (UnauthorizedAccessException) { if (Exceptional.IsVsDocFile(targetPath)) { } else { throw; } } } else { //_log.Debug("ignoring " + name); } }