private void ExpandCryPkgToDirectory(CryPkgDecoder crypkg, string diskCurrent, string current) { foreach (string file in crypkg.ListDirectory(current, true, false)) { string pkgPath = current == "." ? file : (current + "/" + file); string diskPath = Path.Join(diskCurrent, file); byte[] data = crypkg.ReadFileBytes(pkgPath); FileUtil.WriteFileBytes(diskPath, data); } foreach (string dir in crypkg.ListDirectory(current, false, true)) { string pkgPath = current == "." ? dir : (current + "/" + dir); string diskPath = Path.Join(diskCurrent, dir); FileUtil.EnsureFolderExists(diskPath); ExpandCryPkgToDirectory(crypkg, diskPath, pkgPath); } }
public Pair <FetchAssemblyStatus, RemoteAssemblyState> FetchNewAssembly(RemoteAssemblyManifest manifest, string urlAndVersion) { RemoteAssemblyUrl structuredUrl = RemoteAssemblyUrl.FromUrl(urlAndVersion); if (!structuredUrl.IsValid) { return(new Pair <FetchAssemblyStatus, RemoteAssemblyState>(FetchAssemblyStatus.INVALID_URL, null)); } HttpRequest requestSender = new HttpRequest("GET", structuredUrl.Url) .SetHeader("CrayonLib-Component-Type", "source") .SetHeader("User-Agent", Common.VersionInfo.UserAgent); if (!structuredUrl.IsLatestStableVersionRequested) { requestSender.SetHeader("CrayonLib-Version-Info", structuredUrl.VersionInfo); } HttpResponse response = requestSender.Send(); Pair <FetchAssemblyStatus, RemoteAssemblyState> error = CheckForBasicErrors(response, structuredUrl.LibraryName); if (error != null) { return(error); } string versionInfo = response.GetHeader("CrayonLib-Version-Info"); // Not used. Not sure why this is returned. // string componentType = response.GetHeader("CrayonLib-Component-Type"); bool hasNativeInterface = response.GetHeaderAsBoolean("CrayonLib-Has-Native-Interface"); string[] platformsSupported = response.GetHeaderAsList("CrayonLib-Platforms-Supported"); string libraryName = response.GetHeader("CrayonLib-Library-Name"); bool isStable = response.GetHeaderAsBoolean(("CrayonLib-Is-Stable")); string directoryName = this.CreateNewDirectoryForLibrary(manifest.Directory, libraryName, versionInfo); byte[] crypkg = response.Content; CryPkgDecoder crypkgDecoder = new CryPkgDecoder(response.Content); // TODO: crypkgDecoder.IsValid this.ExpandCryPkgToDirectory(crypkgDecoder, Path.Join(manifest.Directory, directoryName, libraryName)); int now = CommonUtil.DateTime.Time.UnixTimeNow; RemoteAssemblyState ras = new RemoteAssemblyState(manifest) { HasCni = hasNativeInterface, Id = libraryName, IsStable = isStable, IsLatestStable = structuredUrl.IsLatestStableVersionRequested, LastUsed = now, LastLatestCheck = now, LocalDirectory = directoryName, RuntimeIsDownloaded = false, Url = structuredUrl.Url, Version = versionInfo, }; foreach (string platformSupported in platformsSupported) { ras.IndicatePlatformSupport(platformSupported); } return(new Pair <FetchAssemblyStatus, RemoteAssemblyState>(FetchAssemblyStatus.SUCCESS, ras)); }
private void ExpandCryPkgToDirectory(CryPkgDecoder crypkg, string dir) { ExpandCryPkgToDirectory(crypkg, dir, "."); }