/// <summary> /// Extracts all the file resources to the specified base path. /// </summary> public static void ExtractAll() { var basePath = Runtime.EntryAssemblyDirectory; var executablePermissions = Standard.StringToInteger("0777", IntPtr.Zero, 8); foreach (var resourceName in ResourceNames) { var filename = resourceName.Substring($"{typeof(EmbeddedResources).Namespace}.".Length); var targetPath = Path.Combine(basePath, filename); if (File.Exists(targetPath)) { return; } using (var stream = typeof(EmbeddedResources).Assembly() .GetManifestResourceStream($"{typeof(EmbeddedResources).Namespace}.{filename}")) { using (var outputStream = File.OpenWrite(targetPath)) { stream?.CopyTo(outputStream); } try { Standard.Chmod(targetPath, (uint)executablePermissions); } catch { /* Ignore */ } } } }
/// <summary> /// Extracts all the file resources to the specified base path. /// </summary> /// <param name="basePath">The base path.</param> public static void Extract(string resource, string basePath = null, bool replace = false, bool executable = false) { if (string.IsNullOrWhiteSpace(basePath)) { basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); } var targetPath = Path.Combine(basePath, resource); if (!replace && File.Exists(targetPath)) { return; } using (var stream = typeof(EmbeddedResources).Assembly .GetManifestResourceStream(resource)) { using (var outputStream = File.OpenWrite(targetPath)) { stream?.CopyTo(outputStream); } if (executable) { try { var executablePermissions = Standard.StringToInteger("0777", IntPtr.Zero, 8); Standard.Chmod(targetPath, (uint)executablePermissions); } catch { /* Ignore */ } } } }