/// <summary> /// Embeds the related file into the specified package. /// </summary> /// <param name="package">The package.</param> /// <exception cref="AmlxCorruptedDocumentException">File not existing any more: + _location</exception> internal void Embed(Package package) { // check if the file was already embedded if (_part != null) { return; } if (!System.IO.File.Exists(_fullPath)) { throw new AmlxCorruptedDocumentException("File not existing any more: " + _location); } // create part and add content var mimetype = XMLMimeTypeMapper.GetMimeType(_fullPath); var uri = PackUriHelper.CreatePartUri(_location); _part = package.CreatePart(uri, mimetype, CompressionOption.Normal); if (_part == null) { throw new AmlxException("Cannot create part for mimetype " + mimetype); } using (var stream = _part.GetStream(FileMode.Create)) { using (var reader = new FileStream(_fullPath, FileMode.Open, FileAccess.Read)) { reader.CopyStreamTo(stream); } } // remove origin System.IO.File.Delete(_fullPath); }
public IEnumerable <Image> GetImageEnumerator() { if (!isWorking && File.Exists(CachePath) && indexList != null && indexList.Count > 0) { using (FileStream fsCache = new FileStream(CachePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { foreach (LocationInfo index in indexList) { using (MemoryStream ms = new MemoryStream()) { fsCache.CopyStreamTo(ms, (int)index.Location, (int)index.Length); yield return(Image.FromStream(ms)); } } } } }
public IEnumerable <Image> GetImageEnumerator() { if (!IsWorking && File.Exists(Options.OutputPath) && indexList != null && indexList.Count > 0) { using (FileStream fsCache = new FileStream(Options.OutputPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { foreach (LocationInfo index in indexList) { if (index.Location > int.MaxValue || index.Length > int.MaxValue) { MessageBox.Show(string.Format("Cache file size cannot exceed {0} Bytes.\r\nPlease use FFmpeg screen recording instead of GIF.", int.MaxValue), "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); yield break; } using (MemoryStream ms = new MemoryStream()) { fsCache.CopyStreamTo(ms, (int)index.Location, (int)index.Length); yield return(Image.FromStream(ms)); } } } } }
public IEnumerable <Image> GetImageEnumerator() { if (!IsWorking && File.Exists(Options.OutputPath) && indexList != null && indexList.Count > 0) { using (FileStream fsCache = new FileStream(Options.OutputPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { foreach (LocationInfo index in indexList) { if (index.Location > int.MaxValue || index.Length > int.MaxValue) { MessageBox.Show(string.Format(Resources.HardDiskCache_GetImageEnumerator_Cache_file_size_cannot_exceed, int.MaxValue), "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); yield break; } using (MemoryStream ms = new MemoryStream()) { fsCache.CopyStreamTo(ms, (int)index.Location, (int)index.Length); yield return(Image.FromStream(ms)); } } } } }