예제 #1
0
파일: CursorGroup.cs 프로젝트: zzfeed/pe
        public async Task SaveAsync(string fileName, ResourceLanguage language, CursorGroupSaveFormat saveFormat)
        {
            using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                await SaveAsync(file, language, saveFormat).ConfigureAwait(false);

                await file.FlushAsync().ConfigureAwait(false);
            }
        }
예제 #2
0
파일: CursorGroup.cs 프로젝트: zzfeed/pe
        public async Task SaveAsync(Stream stream, ResourceLanguage language, CursorGroupSaveFormat saveFormat)
        {
            if (saveFormat == CursorGroupSaveFormat.Raw)
            {
                var buffer = await _resource.GetBytesAsync(language).ConfigureAwait(false);

                await stream.WriteBytesAsync(buffer).ConfigureAwait(false);
            }
            else
            {
                var group = await _resource.GetGroupAsync(language).ConfigureAwait(false);

                var cursorsInfo = new List <Tuple <ushort, ushort, ushort, byte[]> >(group.Count);

                for (var i = 0; i < group.Count; i++)
                {
                    var entry      = group[i];
                    var cursors    = _resource.Type.Resources.First(type => type.Id == ResourceType.Cursor);
                    var resource   = cursors.First(cur => cur.Id == entry.CursorId);
                    var cursorData = await resource.GetBytesAsync(language).ConfigureAwait(false);

                    ushort hotspotX = 0;
                    ushort hotspotY = 0;
                    var    dib      = new byte[0];

                    using (var mem = new MemoryStream(cursorData))
                    {
                        hotspotX = await mem.ReadUInt16Async().ConfigureAwait(false);

                        hotspotY = await mem.ReadUInt16Async().ConfigureAwait(false);

                        using (var dibMem = new MemoryStream())
                        {
                            mem.CopyTo(dibMem, 4096);

                            dib = dibMem.ToArray();
                        }
                    }

                    cursorsInfo.Add(new Tuple <ushort, ushort, ushort, byte[]>(entry.CursorId, hotspotX, hotspotY, dib));
                }

                var offsets = new uint[group.Count];
                var offset  = (6 + (16 * offsets.Length)).ToUInt32();

                for (var i = 0; i < group.Count; i++)
                {
                    var info = cursorsInfo[i];

                    offsets[i] = offset;
                    offset    += info.Item4.Length.ToUInt32();
                }

                await stream.WriteUInt16Async(0).ConfigureAwait(false);

                await stream.WriteUInt16Async(2).ConfigureAwait(false);

                await stream.WriteUInt16Async(group.Count.ToUInt16()).ConfigureAwait(false);

                for (var i = 0; i < group.Count; i++)
                {
                    var entry = group[i];
                    var info  = cursorsInfo[i];

                    await stream.WriteByteAsync(Convert.ToByte(entry.Width)).ConfigureAwait(false);

                    await stream.WriteByteAsync(Convert.ToByte(entry.Height)).ConfigureAwait(false);

                    await stream.WriteByteAsync(Convert.ToByte(entry.BitCount)).ConfigureAwait(false);

                    await stream.WriteByteAsync(0).ConfigureAwait(false);

                    await stream.WriteUInt16Async(info.Item2).ConfigureAwait(false);

                    await stream.WriteUInt16Async(info.Item3).ConfigureAwait(false);

                    await stream.WriteInt32Async(info.Item4.Length).ConfigureAwait(false);

                    await stream.WriteUInt32Async(offsets[i]).ConfigureAwait(false);
                }

                for (var i = 0; i < group.Count; i++)
                {
                    var info = cursorsInfo[i];

                    await stream.WriteBytesAsync(info.Item4).ConfigureAwait(false);
                }
            }
        }
예제 #3
0
파일: CursorGroup.cs 프로젝트: zzfeed/pe
 public void Save(string fileName, ResourceLanguage language, CursorGroupSaveFormat saveFormat)
 {
     SaveAsync(fileName, language, saveFormat).GetAwaiter().GetResult();
 }
예제 #4
0
파일: CursorGroup.cs 프로젝트: zzfeed/pe
 public void Save(Stream stream, ResourceLanguage language, CursorGroupSaveFormat saveFormat)
 {
     SaveAsync(stream, language, saveFormat).GetAwaiter().GetResult();
 }