diff --git a/Amazfit.sln b/Amazfit.sln index 7752d2b..1b44524 100644 --- a/Amazfit.sln +++ b/Amazfit.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27130.0 +VisualStudioVersion = 15.0.27130.2026 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchFace.Parser", "WatchFace.Parser\WatchFace.Parser.csproj", "{8D2E0224-DE7F-4EC9-AD23-9904B9D7B409}" EndProject @@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchFace", "WatchFace\Watc EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resources", "Resources\Resources.csproj", "{EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fonts", "Fonts\Fonts.csproj", "{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwFonts", "FwFonts\FwFonts.csproj", "{E50E8437-0511-4A94-808A-AD5F3105D060}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -69,6 +75,54 @@ Global {EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}.Release|x64.Build.0 = Release|Any CPU {EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}.Release|x86.ActiveCfg = Release|Any CPU {EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}.Release|x86.Build.0 = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|Any CPU.Build.0 = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|ARM.ActiveCfg = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|ARM.Build.0 = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x64.ActiveCfg = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x64.Build.0 = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x86.ActiveCfg = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x86.Build.0 = Debug|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|Any CPU.ActiveCfg = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|Any CPU.Build.0 = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|ARM.ActiveCfg = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|ARM.Build.0 = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x64.ActiveCfg = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x64.Build.0 = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x86.ActiveCfg = Release|Any CPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x86.Build.0 = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|ARM.ActiveCfg = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|ARM.Build.0 = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x64.ActiveCfg = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x64.Build.0 = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x86.ActiveCfg = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x86.Build.0 = Debug|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|Any CPU.Build.0 = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|ARM.ActiveCfg = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|ARM.Build.0 = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x64.ActiveCfg = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x64.Build.0 = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x86.ActiveCfg = Release|Any CPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x86.Build.0 = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|ARM.ActiveCfg = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|ARM.Build.0 = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x64.ActiveCfg = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x64.Build.0 = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x86.ActiveCfg = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x86.Build.0 = Debug|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|Any CPU.Build.0 = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|ARM.ActiveCfg = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|ARM.Build.0 = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x64.ActiveCfg = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x64.Build.0 = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x86.ActiveCfg = Release|Any CPU + {E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Fonts/FileReader.cs b/Fonts/FileReader.cs new file mode 100644 index 0000000..3c54bb6 --- /dev/null +++ b/Fonts/FileReader.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; +using System.Runtime.Remoting.Messaging; +using System.Text; +using Fonts.Models; +using NLog; + +namespace Fonts +{ + public class FileReader + { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + public static FileDescriptor Read(Stream stream) + { + var binaryReader = new BinaryReader(stream); + + var signature = Encoding.ASCII.GetString(binaryReader.ReadBytes(4)); + Logger.Trace("Font signature was read:"); + stream.Seek(0, SeekOrigin.Begin); + Logger.Trace("Signature: {0}", signature); + + NewHeader header; + switch (signature) { + case NewHeader.ResSignature: + header = NewHeader.ReadFrom(binaryReader); + break; + default: + throw new ArgumentException($"Signature '{signature}' is no recognized."); + } + + Logger.Trace("Font header was read:"); + Logger.Trace("Version: {0}, BlocksCount: {1}", header.Version, header.BlocksCount); + + var blocks = new Reader(stream).Read(header.BlocksCount); + return new FileDescriptor + { + HasNewHeader = true, + BlocksCount = header.BlocksCount, + Version = header.Version, + Unknown = header.Unknown, + Blocks = blocks, + Images = new Reader(stream).Read(blocks) + }; + } + } +} \ No newline at end of file diff --git a/Fonts/Fonts.csproj b/Fonts/Fonts.csproj new file mode 100644 index 0000000..0961332 --- /dev/null +++ b/Fonts/Fonts.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682} + Library + Properties + Fonts + Fonts + v4.0 + 512 + Client + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Bumpkit.1.0.2\lib\BumpKit.dll + + + ..\packages\NLog.4.4.12\lib\net40\NLog.dll + + + + + + + + + + + + + + + + + + + + {20e6917a-be26-43d6-a2dc-0f32759c4e9b} + Utils + + + + \ No newline at end of file diff --git a/Fonts/GlyphReader.cs b/Fonts/GlyphReader.cs new file mode 100644 index 0000000..67ea871 --- /dev/null +++ b/Fonts/GlyphReader.cs @@ -0,0 +1,37 @@ +using System.Drawing; +using System.IO; +using BumpKit; +using Utils; + +namespace Fonts +{ + public class GlyphReader + { + private readonly BinaryReader _reader; + + public GlyphReader(Stream stream) + { + _reader = new BinaryReader(stream); + } + + public Bitmap Read(int width, int height) + { + var image = new Bitmap(width, height); + using (var context = image.CreateUnsafeContext()) + { + for (var y = 0; y < height; y++) + { + var rowBytes = _reader.ReadBytes(width / 8); + var bitReader = new BitReader(rowBytes); + for (var x = 0; x < width; x++) + { + var pixelValue = bitReader.ReadBits(1); + var color = pixelValue == 1 ? Color.Black : Color.White; + context.SetPixel(x, y, color); + } + } + } + return image; + } + } +} \ No newline at end of file diff --git a/Fonts/Models/BlockDescriptor.cs b/Fonts/Models/BlockDescriptor.cs new file mode 100644 index 0000000..322bfd0 --- /dev/null +++ b/Fonts/Models/BlockDescriptor.cs @@ -0,0 +1,9 @@ +namespace Fonts.Models +{ + public class BlockDescriptor + { + public char StartSymbol { get; set; } + public char EndSymbol { get; set; } + public int Offset { get; set; } + } +} \ No newline at end of file diff --git a/Fonts/Models/FileDescriptor.cs b/Fonts/Models/FileDescriptor.cs new file mode 100644 index 0000000..4794353 --- /dev/null +++ b/Fonts/Models/FileDescriptor.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Runtime.Serialization; + +namespace Fonts.Models +{ + public class FileDescriptor + { + public bool HasNewHeader { get; set; } + public uint? BlocksCount { get; set; } + public uint? Unknown { get; set; } + public byte? Version { get; set; } + + [IgnoreDataMember] + public List Blocks { get; set; } = new List(); + + [IgnoreDataMember] + public Dictionary Images { get; set; } = new Dictionary(); + } +} \ No newline at end of file diff --git a/Fonts/Models/NewHeader.cs b/Fonts/Models/NewHeader.cs new file mode 100644 index 0000000..b5d2862 --- /dev/null +++ b/Fonts/Models/NewHeader.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using System.Text; + +namespace Fonts.Models +{ + public class NewHeader + { + public const int HeaderSize = 0x22; + public const string ResSignature = "NEZK"; + + public string Signature { get; protected set; } = ResSignature; + public byte Version { get; set; } + public ushort BlocksCount { get; set; } + + public uint Unknown { get; set; } + + public void WriteTo(BinaryWriter writer) + { + var buffer = new byte[HeaderSize]; + for (var i = 0; i < buffer.Length; i++) buffer[i] = 0xff; + + Encoding.ASCII.GetBytes(ResSignature).CopyTo(buffer, 0); + buffer[0x4] = Version; + BitConverter.GetBytes(Unknown).CopyTo(buffer, 0xa); + BitConverter.GetBytes(BlocksCount).CopyTo(buffer, 0x20); + writer.Write(buffer); + } + + public static NewHeader ReadFrom(BinaryReader reader) + { + var buffer = reader.ReadBytes(HeaderSize); + return new NewHeader + { + Signature = Encoding.ASCII.GetString(buffer, 0, 0x4), + Version = buffer[0x4], + Unknown = BitConverter.ToUInt32(buffer, 0xa), + BlocksCount = BitConverter.ToUInt16(buffer, 0x20) + }; + } + } +} diff --git a/Fonts/Properties/AssemblyInfo.cs b/Fonts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cc1e4f4 --- /dev/null +++ b/Fonts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Fonts")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Fonts")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("390eaf2d-9fa8-4dc1-8d4f-ea565ad3c682")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Fonts/Reader.cs b/Fonts/Reader.cs new file mode 100644 index 0000000..59f4efd --- /dev/null +++ b/Fonts/Reader.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using Fonts.Models; +using NLog; + +namespace Fonts +{ + public class Reader + { + private const int BlockDescriptorLength = 6; + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + private readonly BinaryReader _binaryReader; + private readonly Stream _stream; + + public Reader(Stream stream) + { + _stream = stream; + _binaryReader = new BinaryReader(_stream); + } + + public List Read(uint blocksCount) + { + var descriptorsTableLength = (int) (blocksCount * BlockDescriptorLength); + Logger.Trace("Reading font descriptors table with {0} elements ({1} bytes)", + blocksCount, descriptorsTableLength + ); + var descriptors = _binaryReader.ReadBytes(descriptorsTableLength); + var blocks = new List(); + for (var i = 0; i < blocksCount; i++) + { + blocks.Add(new BlockDescriptor + { + StartSymbol = BitConverter.ToChar(descriptors, i * BlockDescriptorLength), + EndSymbol = BitConverter.ToChar(descriptors, i * BlockDescriptorLength + 2), + Offset = BitConverter.ToUInt16(descriptors, i * BlockDescriptorLength + 4) + }); + } + + return blocks; + } + + public Dictionary Read(List blocks) + { + var imagesOffset = _stream.Position; + Logger.Debug("Reading {0} images...", blocks.Count); + var images = new Dictionary(); + for (var i = 0; i < blocks.Count; i++) + { + var block = blocks[i]; + var blockOffset = block.Offset; + var realOffset = blockOffset + imagesOffset; + Logger.Trace("Glyphs block {0} offset is {1}...", i, blockOffset); + if (_stream.Position != realOffset) + { + var bytesGap = realOffset - _stream.Position; + Logger.Warn("Found {0} bytes gap before block number {1}", bytesGap, i); + _stream.Seek(realOffset, SeekOrigin.Begin); + } + Logger.Debug("Reading block {0}...", i); + + for (var ch = block.StartSymbol; ch <= block.EndSymbol; ch++) + { + images[ch] = new GlyphReader(_stream).Read(16, 16); +// images[ch].Save($"1\\{(int)ch:X4}.png", ImageFormat.Png); + var crc = _stream.ReadByte(); + } + } + return images; + } + } +} \ No newline at end of file diff --git a/Fonts/packages.config b/Fonts/packages.config new file mode 100644 index 0000000..e7a2a3e --- /dev/null +++ b/Fonts/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/FwFonts/FwFonts.csproj b/FwFonts/FwFonts.csproj new file mode 100644 index 0000000..109ca46 --- /dev/null +++ b/FwFonts/FwFonts.csproj @@ -0,0 +1,45 @@ + + + + + Debug + AnyCPU + {E50E8437-0511-4A94-808A-AD5F3105D060} + Library + Properties + FwFonts + FwFonts + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + {20e6917a-be26-43d6-a2dc-0f32759c4e9b} + Utils + + + + \ No newline at end of file diff --git a/FwFonts/Properties/AssemblyInfo.cs b/FwFonts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..db74400 --- /dev/null +++ b/FwFonts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FwFonts")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FwFonts")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e50e8437-0511-4a94-808a-ad5f3105d060")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Resources/Image/Reader.cs b/Resources/Image/Reader.cs index 8e1e4fb..f5281da 100644 --- a/Resources/Image/Reader.cs +++ b/Resources/Image/Reader.cs @@ -3,7 +3,7 @@ using System.Drawing; using System.IO; using BumpKit; using NLog; -using Resources.Utils; +using Utils; namespace Resources.Image { diff --git a/Resources/Image/Writer.cs b/Resources/Image/Writer.cs index 07028af..2ee1e0d 100644 --- a/Resources/Image/Writer.cs +++ b/Resources/Image/Writer.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.Drawing.Imaging; using System.IO; using BumpKit; using NLog; -using Resources.Utils; +using Utils; namespace Resources.Image { diff --git a/Resources/Resources.csproj b/Resources/Resources.csproj index 79d0b28..d8af0ec 100644 --- a/Resources/Resources.csproj +++ b/Resources/Resources.csproj @@ -38,22 +38,14 @@ ..\packages\NLog.4.4.12\lib\net40\NLog.dll - - - - - - - - @@ -69,5 +61,11 @@ + + + {20e6917a-be26-43d6-a2dc-0f32759c4e9b} + Utils + + \ No newline at end of file diff --git a/Resources/Utils/BitReader.cs b/Utils/BitReader.cs similarity index 98% rename from Resources/Utils/BitReader.cs rename to Utils/BitReader.cs index 937b226..a7f3fc5 100644 --- a/Resources/Utils/BitReader.cs +++ b/Utils/BitReader.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace Resources.Utils +namespace Utils { public class BitReader { diff --git a/Resources/Utils/BitWriter.cs b/Utils/BitWriter.cs similarity index 98% rename from Resources/Utils/BitWriter.cs rename to Utils/BitWriter.cs index ca9e63d..871679e 100644 --- a/Resources/Utils/BitWriter.cs +++ b/Utils/BitWriter.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace Resources.Utils +namespace Utils { public class BitWriter { diff --git a/Utils/Properties/AssemblyInfo.cs b/Utils/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cc4dc3a --- /dev/null +++ b/Utils/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Utils")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Utils")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("20e6917a-be26-43d6-a2dc-0f32759c4e9b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Utils/Utils.csproj b/Utils/Utils.csproj new file mode 100644 index 0000000..e35b067 --- /dev/null +++ b/Utils/Utils.csproj @@ -0,0 +1,42 @@ + + + + + Debug + AnyCPU + {20E6917A-BE26-43D6-A2DC-0F32759C4E9B} + Library + Properties + Utils + Utils + v4.0 + 512 + Client + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + \ No newline at end of file diff --git a/WatchFace/Program.cs b/WatchFace/Program.cs index f12e2f4..0c84f90 100644 --- a/WatchFace/Program.cs +++ b/WatchFace/Program.cs @@ -81,6 +81,10 @@ namespace WatchFace case ".res": UnpackResources(inputFileName); break; + case ".ft": + case ".latin": + UnpackFont(inputFileName); + break; default: Console.WriteLine("The app doesn't support files with extension {0}.", inputFileExtension); Console.WriteLine("Only 'bin', 'res' and 'json' files are supported at this time."); @@ -202,6 +206,21 @@ namespace WatchFace } } + private static void UnpackFont(string inputFileName) + { + var outputDirectory = CreateOutputDirectory(inputFileName); + var baseName = Path.GetFileNameWithoutExtension(inputFileName); + SetupLogger(Path.Combine(outputDirectory, $"{baseName}.log")); + + Fonts.Models.FileDescriptor resDescriptor; + using (var stream = File.OpenRead(inputFileName)) + { + resDescriptor = Fonts.FileReader.Read(stream); + } + + ExportFontConfig(resDescriptor, Path.Combine(outputDirectory, "header.json")); + } + private static void UnpackResources(string inputFileName) { var outputDirectory = CreateOutputDirectory(inputFileName); @@ -360,6 +379,25 @@ namespace WatchFace } } + private static void ExportFontConfig(Fonts.Models.FileDescriptor resDescriptor, string jsonFileName) + { + Logger.Debug("Exporting resources config..."); + try + { + using (var fileStream = File.OpenWrite(jsonFileName)) + using (var writer = new StreamWriter(fileStream)) + { + writer.Write(JsonConvert.SerializeObject(resDescriptor, Formatting.Indented, + new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); + writer.Flush(); + } + } + catch (Exception e) + { + Logger.Fatal(e); + } + } + private static void ExportResConfig(FileDescriptor resDescriptor, string jsonFileName) { Logger.Debug("Exporting resources config..."); diff --git a/WatchFace/WatchFace.csproj b/WatchFace/WatchFace.csproj index 652baca..a516e21 100644 --- a/WatchFace/WatchFace.csproj +++ b/WatchFace/WatchFace.csproj @@ -58,6 +58,10 @@ + + {390eaf2d-9fa8-4dc1-8d4f-ea565ad3c682} + Fonts + {edd55d5d-9e80-451b-ac8a-0746ba6dc6e9} Resources