Ejemplo n.º 1
0
        // private static List<InfoObject> m_Objects = new List<InfoObject>();
        // private static List<InfoPage> m_Pages = new List<InfoPage>();
        // private static List<byte[]> m_StringDatas = new List<byte[]>();
        // private static List<InfoString> m_Strings = new List<InfoString>();
        private bool readInfoApp(HmiApplication app, StreamReader reader)
        {
            List<InfoObject> m_Objects = new List<InfoObject>();
            List<InfoPage> m_Pages = new List<InfoPage>();
            List<byte[]> m_StringDatas = new List<byte[]>();
            List<InfoString> m_Strings = new List<InfoString>();

            InfoApp infoApp; // = new InfoApp();
            try
            {
                int idx;

                // Load Application Info
                reader.BaseStream.Position = 0L;
                byte[] buffer = new byte[HmiOptions.InfoAppSize];
                reader.BaseStream.Read(buffer, 0, buffer.Length);
                infoApp = Utility.ToStruct<InfoApp>(buffer);

                // Load Pictures and PictureImage
                app.Pictures.Clear();
                app.PictureImages.Clear();
                if (infoApp.PictureCount != 0)
                {
                    reader.BaseStream.Position = infoApp.PictureStart;
                    buffer = new byte[HmiOptions.InfoPictureSize];
                    for (idx = 0; idx < infoApp.PictureCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.Pictures.Add(Utility.ToStruct<InfoPicture>(buffer));
                    }

                    reader.BaseStream.Position = infoApp.PictureImageStart;
                    for (idx = 0; idx < app.Pictures.Count; idx++)
                    {
                        buffer = new byte[app.Pictures[idx].Size];
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.PictureImages.Add(buffer);
                    }
                }

                // Load Fonts with FontImage
                app.Fonts.Clear();
                app.FontImages.Clear();
                if (infoApp.FontCount != 0)
                {
                    reader.BaseStream.Position = infoApp.FontStart;
                    buffer = new byte[HmiOptions.InfoFontSize];
                    for (idx = 0; idx < infoApp.FontCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.Fonts.Add(Utility.ToStruct<InfoFont>(buffer));
                    }

                    reader.BaseStream.Position = infoApp.FontImageStart;
                    for (idx = 0; idx < app.Fonts.Count; idx++)
                    {
                        buffer = new byte[app.Fonts[idx].Size];
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.FontImages.Add(buffer);
                    }
                }

                if (infoApp.StringCount != 0)
                {
                    reader.BaseStream.Position = infoApp.StringStart;
                    buffer = new byte[HmiOptions.InfoStringSize];
                    for (idx = 0; idx < infoApp.StringCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_Strings.Add(Utility.ToStruct<InfoString>(buffer));
                    }

                    reader.BaseStream.Position = infoApp.StringDataStart;
                    for (idx = 0; idx < m_Strings.Count; idx++)
                    {
                        buffer = new byte[m_Strings[idx].Size];
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_StringDatas.Add(buffer);
                    }
                }

                if (infoApp.PageCount != 0)
                {
                    reader.BaseStream.Position = infoApp.PageStart;
                    buffer = new byte[HmiOptions.InfoPageSize];
                    for (idx = 0; idx < infoApp.PageCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_Pages.Add(Utility.ToStruct<InfoPage>(buffer));
                    }
                }

                if (infoApp.ObjectCount != 0)
                {
                    reader.BaseStream.Position = infoApp.ObjectStart;
                    buffer = new byte[HmiOptions.InfoObjectSize];
                    for (idx = 0; idx < infoApp.ObjectCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_Objects.Add(Utility.ToStruct<InfoObject>(buffer));
                    }
                }

                reader.Close();
                reader.Dispose();

                app.IsPotrait = (infoApp.IsPotrait == 1 ? true : false);
                app.LcdWidth = (app.IsPotrait ? infoApp.ScreenHeight : infoApp.ScreenWidth);
                app.LcdHeight = (app.IsPotrait ? infoApp.ScreenWidth : infoApp.ScreenHeight);

                if (infoApp.VersionMajor == 0 && infoApp.VersionMinor < 30)
                {
                    HmiOptions.OpenTransparent = false;
                    for (int j = 0; j < app.PictureImages.Count; j++)
                    {
                        idx = 0;
                        while (idx < (app.PictureImages[j].Length - 1))
                        {
                            if ((app.PictureImages[j][idx] == HmiOptions.ColorTransparent) && (app.PictureImages[j][idx + 1] == 0))
                                app.PictureImages[j][idx] = (byte)HmiOptions.ColorTransparentReplace;
                            idx += 2;
                        }
                    }
                }
                else
                    HmiOptions.OpenTransparent = false;

                app.HmiPages.Clear();
                List<byte[]> strings = new List<byte[]>();

                for (int i = 0; i < m_Pages.Count; i++)
                {
                    HmiPage hmiPage = new HmiPage(app)
                    {
                        Name = Utility.GetString(Utility.ToBytes(m_Pages[i].Name))
                    };

                    if (m_Pages[i].ObjStart != 0xffff && m_Pages[i].ObjEnd != 0xffff)
                    {
                        for (idx = m_Pages[i].ObjStart; idx <= m_Pages[i].ObjEnd; idx++)
                        {
                            HmiObject hmiObject = new HmiObject(app, hmiPage)
                            {
                                ObjInfo = m_Objects[idx],
                                ObjName = Utility.GetString(Utility.ToBytes(m_Objects[idx].Name))
                            };
                            strings.Clear();
                            for (int k = m_Objects[idx].StringInfoStart; k <= m_Objects[idx].StringInfoEnd; k++)
                                strings.Add(m_StringDatas[k]);

                            hmiObject.PutCodes(strings);
                            hmiPage.HmiObjects.Add(hmiObject);
                        }
                    }
                    app.HmiPages.Add(hmiPage);
                }

                app.RefreshAllId();
                if (infoApp.VersionMajor == 0 && infoApp.VersionMinor == 8)
                {
                    foreach (HmiPage mpage2 in app.HmiPages)
                        if (mpage2.HmiObjects[0].Attributes.Count == 4
                         && Utility.GetString(mpage2.HmiObjects[0].Attributes[2].Name) == "pco"
                            )
                            mpage2.HmiObjects[0].Attributes[2].Name = Utility.ToBytes("bco", 8);
                }
                return true;
            }
            catch (Exception ex)
            {
                reader.Close();
                reader.Dispose();
                MessageBox.Show(ex.Message);
                return false;
            }
        }