Пример #1
0
        public void Read()
        {
            Logger.Trace("Reading header...");
            var header = Header.ReadFrom(_stream, OutputDirectory);

            Logger.Trace("Header was read:");
            Logger.Trace("Signature: {0}, Unknown: {1}, ParametersSize: {2}, IsValid: {3}", header.Signature,
                         header.Unknown,
                         header.ParametersSize, header.IsValid);
            if (!header.IsValid)
            {
                return;
            }

            Logger.Trace("Reading parameter offsets...");
            var parametersStream = StreamBlock(_stream, (int)header.ParametersSize);

            Logger.Trace("Parameter offsets were read from file");
            Logger.Trace("Reading parameters descriptor...");
            var mainParam = Parameter.ReadFrom(parametersStream);

            Logger.Trace("Parameters descriptor was read:");
            var parametrsTableLength = mainParam.Children[0].Value;
            var imagesCount          = mainParam.Children[1].Value;

            Logger.Trace($"ParametrsTableLength: {parametrsTableLength}, ImagesCount: {imagesCount}");

            Logger.Trace("Reading parameters locations...");
            var parametersLocations = Parameter.ReadList(parametersStream);

            Logger.Trace("Watch face parameters locations were read:");

            Parameters = ReadParameters(parametrsTableLength, parametersLocations);
            Resources  = new Resources.Reader(_stream).Read((uint)imagesCount);
        }
Пример #2
0
        public void Read()
        {
            Logger.Trace("阅读头文件...");
            var header = Header.ReadFrom(_stream);

            Logger.Trace("已读:");
            Logger.Trace("已签名: {0}, 未知: {1}, 参数大小: {2}, 错误(非法): {3}", header.Signature,
                         header.Unknown,
                         header.ParametersSize, header.IsValid);
            if (!header.IsValid)
            {
                return;
            }

            Logger.Trace("读取偏移参数...");
            var parametersStream = StreamBlock(_stream, (int)header.ParametersSize);

            Logger.Trace("偏移参数已从文件读取");

            Logger.Trace("读取参数标识符...");
            var mainParam = Parameter.ReadFrom(parametersStream);

            Logger.Trace("参数标识符已读取:");
            var parametrsTableLength = mainParam.Children[0].Value;
            var imagesCount          = mainParam.Children[1].Value;

            Logger.Trace($"参数表长: {parametrsTableLength}, 图像数: {imagesCount}");

            Logger.Trace("读取位置参数...");
            var parametersLocations = Parameter.ReadList(parametersStream);

            Logger.Trace("表盘位置参数读取已读取:");

            Parameters = ReadParameters(parametrsTableLength, parametersLocations);
            Resources  = new Resources.Reader(_stream).Read((uint)imagesCount);
        }
Пример #3
0
        public void Write(IList <Parameter> descriptor)
        {
            Logger.Trace("Encoding parameters...");
            var encodedParameters = new Dictionary <byte, MemoryStream>(descriptor.Count);

            foreach (var parameter in descriptor)
            {
                Logger.Trace("Parameter: {0}", parameter.Id);
                var memoryStream = new MemoryStream();
                foreach (var child in parameter.Children)
                {
                    child.Write(memoryStream);
                }
                encodedParameters[parameter.Id] = memoryStream;
            }

            Logger.Trace("Encoding offsets and lengths...");
            var parametersPositions = new List <Parameter>(descriptor.Count + 1);
            var offset = (long)0;

            foreach (var encodedParameter in encodedParameters)
            {
                var encodedParameterId     = encodedParameter.Key;
                var encodedParameterLength = encodedParameter.Value.Length;
                parametersPositions.Add(new Parameter(encodedParameterId, new List <Parameter>
                {
                    new Parameter(1, offset),
                    new Parameter(2, encodedParameterLength)
                }));
                offset += encodedParameterLength;
            }
            parametersPositions.Insert(0, new Parameter(1, new List <Parameter>
            {
                new Parameter(1, offset),
                new Parameter(2, _images.Count)
            }));

            var encodedParametersPositions = new MemoryStream();

            foreach (var parametersPosition in parametersPositions)
            {
                parametersPosition.Write(encodedParametersPositions);
            }

            Logger.Trace("Writing header...");
            var header = new Header
            {
                ParametersSize = (uint)encodedParametersPositions.Length,
                Unknown        = 0x159 // Maybe some kind of layers (the bigger number needed for more complex watch faces)
            };

            header.WriteTo(_stream);

            Logger.Trace("Writing parameters offsets and lengths...");
            encodedParametersPositions.Seek(0, SeekOrigin.Begin);
            encodedParametersPositions.WriteTo(_stream);

            Logger.Trace("Writing parameters...");
            foreach (var encodedParameter in encodedParameters)
            {
                var stream = encodedParameter.Value;
                stream.Seek(0, SeekOrigin.Begin);
                stream.WriteTo(_stream);
            }
            Logger.Trace("Writing images...");
            new Resources.Writer(_stream).Write(_images);
        }