public void Extract(BitDepths bitDepth) { var location = typeof(Program).Assembly.Location; var newLocation = Path.Combine(Path.GetDirectoryName(location), $"{Path.GetFileNameWithoutExtension(location)}.Extractor{Path.GetExtension(location)}"); File.Copy(location, newLocation, true); Process.Start(newLocation, $"-extractor {bitDepth} {Process.GetCurrentProcess().Id} \"{location}\""); }
public static void RunExtractor(BitDepths bitDepth, int?parentPid, string parentPath) { if (parentPid.HasValue) { WaitForParentExit(parentPid.Value); } if (!string.IsNullOrEmpty(parentPath)) { File.Delete(parentPath); } var exeFile = typeof(Program).Assembly.Location; var location = Path.GetDirectoryName(exeFile); var resourceHeaders = ResourceReader.GetResourceHeaders(bitDepth).ToList(); foreach (var resourceHeader in resourceHeaders) { Resource.CreateFromHeader(resourceHeader).WriteToPath(location); } foreach (var resourceHeader in resourceHeaders) { resourceHeader.SetDate(location); } RunNGen(); DeleteDelayed(exeFile); }
public static void Extract(BitDepths bitDepth) { var location = typeof(Program).Assembly.Location; var newLocation = Path.Combine(Path.GetDirectoryName(location), $"{Path.GetFileNameWithoutExtension(location)}.Extractor{Path.GetExtension(location)}"); File.Copy(location, newLocation, true); Process.Start(newLocation, $"-extractor {bitDepth} {Process.GetCurrentProcess().Id} \"{location}\""); }
/// <summary> /// Creates a new instance of PngHeader /// </summary> public PngHeader(int width, int height) { _width = width; _height = height; _bitdepth = BitDepths.Eight; _colortype = ColorTypes.TruecolorAlpha; _interlaceMethod = InterlaceMethods.NoInterlacing; }
public static IEnumerable <ResourceHeader> GetResourceHeaders(BitDepths bitDepth) { foreach (var resourceHeader in AllResourceHeaders) { if ((resourceHeader.BitDepth == bitDepth) || (resourceHeader.BitDepth == BitDepths.Any)) { yield return(resourceHeader); } } }
public static Resource CreateFromFile(string name, string fullPath, BitDepths bitDepth) { if ((string.IsNullOrWhiteSpace(fullPath)) || (!File.Exists(fullPath))) { return(null); } var rawData = File.ReadAllBytes(fullPath); var data = rawData; using (var output = new MemoryStream()) { using (var gz = new GZipStream(output, CompressionLevel.Optimal, true)) using (var input = new MemoryStream(data)) input.CopyTo(gz); data = output.ToArray(); } if (encryptionKey != null) { using (var alg = new AesCryptoServiceProvider { Key = encryptionKey }) using (var encryptor = alg.CreateEncryptor()) using (var ms = new MemoryStream()) { ms.Write(BitConverter.GetBytes(alg.IV.Length), 0, sizeof(int)); ms.Write(alg.IV, 0, alg.IV.Length); var encrypted = encryptor.TransformFinalBlock(data, 0, data.Length); ms.Write(encrypted, 0, encrypted.Length); data = ms.ToArray(); } } var peInfo = new PEInfo(rawData); var sha1 = BitConverter.ToString(new SHA1Managed().ComputeHash(rawData)).Replace("-", "").ToLower(); return(new Resource { Header = new ResourceHeader { Name = name, FileType = peInfo.FileType, WriteTime = File.GetLastWriteTimeUtc(fullPath), BitDepth = bitDepth, SHA1 = sha1, }, RawData = rawData, Data = data, }); }
/// <summary> /// Initializes a new instance of the <see cref="T:DesktopSprites.SpriteManagement.AnimatedImage`1"/> class from a given file. /// </summary> /// <param name="path">The path to the file which contains the image to be loaded.</param> /// <param name="staticImageFactory">The method that creates a TFrame object for a non-GIF file.</param> /// <param name="frameFactory">The method used to construct a TFrame object for each frame in a GIF animation.</param> /// <param name="allowableDepths">The allowable set of depths for the raw buffer. Use as many as your output format permits. The /// Indexed8Bpp format is required.</param> public AnimatedImage(string path, Func <string, T> staticImageFactory, BufferToImage <T> frameFactory, BitDepths allowableDepths) { FilePath = path; if (Path.GetExtension(path) == ".gif") { AnimatedImageFromGif(frameFactory, allowableDepths); } else { AnimatedImageFromStaticFormat(staticImageFactory); } }
public void RunExtractor(BitDepths bitDepth, int? parentPid, string parentPath) { if (parentPid.HasValue) WaitForParentExit(parentPid.Value); if (!string.IsNullOrEmpty(parentPath)) File.Delete(parentPath); var exeFile = typeof(Program).Assembly.Location; var location = Path.GetDirectoryName(exeFile); foreach (var resource in ResourceReader.GetResources(bitDepth)) resource.WriteToPath(location); foreach (var resource in ResourceReader.GetResources(bitDepth)) resource.SetDate(location); RunNGen(); DeleteDelayed(exeFile); }
/// <summary> /// Creates an <see cref="T:DesktopSprites.SpriteManagement.AnimatedImage`1"/> from a GIF file. /// </summary> /// <param name="frameFactory">The method used to construct a TFrame object for each frame in a GIF animation.</param> /// <param name="allowableDepths">The allowable set of depths for the raw buffer. Use as many as your output format permits. The /// Indexed8Bpp format is required.</param> private void AnimatedImageFromGif(BufferToImage <T> frameFactory, BitDepths allowableDepths) { GifImage <T> gifImage; using (FileStream imageStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) gifImage = new GifImage <T>(imageStream, frameFactory, allowableDepths); Size = gifImage.Size; LoopCount = gifImage.Iterations; ImageDuration = gifImage.Duration; int frameCount = gifImage.Frames.Length; var framesList = new List <T>(frameCount); var durationsList = new List <int>(frameCount); var frameIndexesList = new List <int>(frameCount); var frameHashesList = new List <int>(frameCount); for (int sourceFrame = 0; sourceFrame < frameCount; sourceFrame++) { int frameDuration = gifImage.Frames[sourceFrame].Duration; // Decoding the GIF may have produced frames of zero duration, we can safely drop these. // If the file has all-zero durations, we're into the land of undefined behavior for animations. // If we get to the last frame and we have nothing so far, we'll use that just so there is something to display. // Alternatively, in an image with only one frame, then only this frame ever need be displayed. if (frameDuration == 0 && !(ImageDuration == 0 && sourceFrame == frameCount - 1)) { // Dispose of unused frame. IDisposable disposable = gifImage.Frames[sourceFrame].Image as IDisposable; if (disposable != null) { disposable.Dispose(); } continue; } durationsList.Add(frameDuration); // Determine if all frames share the same duration. if (sourceFrame == 0) { commonFrameDuration = frameDuration; } else if (commonFrameDuration != frameDuration) { commonFrameDuration = -1; } // Calculate the frame hash to check if a duplicate frame exists. // This will update our collection and given hash list appropriately. AddOrReuseFrame(gifImage.Frames[sourceFrame], framesList, frameIndexesList, frameHashesList); } frames = framesList.ToImmutableArray(); if (frames.Length != frameIndexesList.Count) { frameIndexes = frameIndexesList.ToImmutableArray(); } if (commonFrameDuration == -1) { durations = durationsList.ToImmutableArray(); } }
public static IEnumerable<Resource> GetResources(BitDepths bitDepth) { foreach (var resource in AllResources) if ((resource.BitDepth == bitDepth) || (resource.BitDepth == BitDepths.Any)) yield return resource; }
public static Resource CreateFromFile(string name, string fullPath, BitDepths bitDepth) { if ((string.IsNullOrWhiteSpace(fullPath)) || (!File.Exists(fullPath))) return null; var data = File.ReadAllBytes(fullPath); var peInfo = new PEInfo(data); var sha1 = new SHA1Managed(); return new Resource { Name = name, FileType = peInfo.FileType, WriteTime = File.GetLastWriteTimeUtc(fullPath), BitDepth = bitDepth, Version = peInfo.Version, SHA1 = BitConverter.ToString(sha1.ComputeHash(data)).Replace("-", "").ToLower(), UncompressedData = data, }; }