private int Save5000GuideAsXML(bool shareReceived, bool showHDTV)
        {
            XmlTextWriter writer = new XmlTextWriter(this.guideXMLFile, Encoding.UTF8);

            writer.Formatting = Formatting.Indented;
            writer.WriteStartElement("result");
            int[]      numArray = new int[] { 0, 0 };
            FileStream stream   = File.OpenRead(this.guideFile);

            byte[] array = new byte[(int)stream.Length];
            stream.Read(array, 0, (int)stream.Length);
            stream.Close();
            bool       flag         = true;
            SortedList categoryList = new SortedList();

            categoryList = this.Build5000Categories(array);
            writer.WriteStartElement("category-list");
            for (int i = 0; i < categoryList.Count; i++)
            {
                writer.WriteStartElement("category");
                writer.WriteAttributeString("categoryID", null, categoryList.GetKey(i).ToString());
                writer.WriteAttributeString("categoryName", null, categoryList.GetByIndex(i).ToString());
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            SortedList list2 = new SortedList();

            list2 = this.Build5000Channels(array, categoryList);
            writer.WriteStartElement("channel-list");
            try
            {
                int    num2             = 0;
                int    length           = array.Length;
                int    num4             = length - (840 + (0x2c8 * ReplayHelper.ReplayByteToInt(array, 0x10, 4)));
                byte[] destinationArray = new byte[num4];
                byte[] buffer3          = new byte[0x200];
                Array.Copy(array, 840 + (0x2c8 * ReplayHelper.ReplayByteToInt(array, 0x10, 4)), destinationArray, 0, num4);
                byte[] buffer4 = null;
                byte[] buffer5 = null;
                byte[] buffer6 = null;
                for (int j = 0; (num4 - (0x200 * j)) >= 0x200; j++)
                {
                    string text5;
                    Array.Copy(destinationArray, 0x200 * j, buffer3, 0, 0x200);
                    DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, 0);
                    long     num6 = ReplayHelper.ReplayByteToLong(buffer3, 120, 4);
                    int      num7 = 0;
                    if ((num6 & 0x40) > 0)
                    {
                        num7 += 4;
                    }
                    if ((num6 & 0x20) > 0)
                    {
                        num7 += 8;
                    }
                    int num8 = ReplayHelper.ReplayByteToInt(buffer3, 0, 4);
                    int num9 = ReplayHelper.ReplayByteToInt(buffer3, 4, 4);
                    buffer4 = new byte[ReplayHelper.ReplayByteToInt(buffer3, 140, 1) - 1];
                    buffer5 = new byte[ReplayHelper.ReplayByteToInt(buffer3, 0x8d, 1) - 1];
                    buffer6 = new byte[ReplayHelper.ReplayByteToInt(buffer3, 0x8e, 1) - 1];
                    int    qualityCode = ReplayHelper.ReplayByteToInt(buffer3, 12, 4);
                    string quality     = this.GetQuality(qualityCode);
                    int    num11       = ReplayHelper.ReplayByteToInt(buffer3, 0x188, 4);
                    int    num12       = num11 / 60;
                    if ((num11 % 60) >= 30)
                    {
                        num12++;
                    }
                    string text2 = num12.ToString();
                    int    num13 = ReplayHelper.ReplayByteToInt(buffer3, 0x7c, 4);
                    int    num14 = ReplayHelper.ReplayByteToInt(buffer3, 380, 4);
                    int    num15 = ReplayHelper.ReplayByteToInt(buffer3, 0x184, 4);
                    string text3 = time.AddSeconds((double)num13).ToString("yyyy-MM-dd HH:mm:ss.000", DateTimeFormatInfo.InvariantInfo);
                    Array.Copy(buffer3, 0x94 + num7, buffer4, 0, buffer4.Length);
                    Array.Copy(buffer3, ((0x94 + num7) + buffer4.Length) + 1, buffer5, 0, buffer5.Length);
                    Array.Copy(buffer3, ((((0x94 + num7) + buffer4.Length) + 1) + buffer5.Length) + 1, buffer6, 0, buffer6.Length);
                    ReplayChannelGuide guide        = (ReplayChannelGuide)list2[num8];
                    string             channelTitle = guide.channelTitle;
                    switch (guide.channelType)
                    {
                    case 1:
                        text5 = "Recurring";
                        break;

                    case 2:
                        text5 = "Theme";
                        break;

                    case 3:
                        text5 = "Single";
                        break;

                    case 4:
                        text5 = "Zone";
                        break;

                    default:
                        text5 = "";
                        break;
                    }
                    int    channelCategory = guide.channelCategory;
                    string channelCatName  = guide.channelCatName;
                    string text7           = ReplayHelper.ReplaceUTF8InString(this.encoding.GetString(buffer4));
                    string text8           = ReplayHelper.ReplaceUTF8InString(this.encoding.GetString(buffer6));
                    string text9           = ReplayHelper.ReplaceUTF8InString(this.encoding.GetString(buffer5));
                    if (shareReceived || ((num14 == 0) && (num15 < 15)))
                    {
                        if (num8 != num2)
                        {
                            if (flag)
                            {
                                flag = false;
                            }
                            else
                            {
                                writer.WriteEndElement();
                            }
                            writer.WriteStartElement("channel");
                            writer.WriteAttributeString("title", null, channelTitle);
                            writer.WriteAttributeString("channelID", null, num8.ToString());
                            writer.WriteAttributeString("channelType", null, text5);
                            writer.WriteAttributeString("categoryID", null, channelCategory.ToString());
                            writer.WriteAttributeString("categoryName", null, channelCatName);
                            guide.channelDone = true;
                        }
                        writer.WriteStartElement("show");
                        if (shareReceived && (num14 != 0))
                        {
                            writer.WriteAttributeString("title", null, text7);
                        }
                        else if (text5.Equals("Single") || text5.Equals("Recurring"))
                        {
                            writer.WriteAttributeString("title", null, channelTitle);
                        }
                        else
                        {
                            writer.WriteAttributeString("title", null, text7);
                        }
                        writer.WriteAttributeString("description", null, text8);
                        if (!showHDTV && text9.StartsWith("(HDTV) "))
                        {
                            text9 = text9.Remove(0, 7);
                        }
                        if (text9.Equals(""))
                        {
                            if (text8.Equals(""))
                            {
                                writer.WriteAttributeString("episodeTitle", null, text7);
                            }
                            else
                            {
                                if (text8.Length > 0x23)
                                {
                                    text8 = text8.Substring(0, 0x20);
                                    if (text8.LastIndexOf(" ") >= 0)
                                    {
                                        text8 = text8.Substring(0, text8.LastIndexOf(" ")) + "...";
                                    }
                                }
                                writer.WriteAttributeString("episodeTitle", null, text8);
                            }
                        }
                        else
                        {
                            writer.WriteAttributeString("episodeTitle", null, text9);
                        }
                        writer.WriteAttributeString("startTimeGMT", null, text3);
                        writer.WriteAttributeString("durationInMinutes", null, text2);
                        writer.WriteAttributeString("quality", null, quality);
                        writer.WriteAttributeString("showID", null, num9.ToString());
                        writer.WriteEndElement();
                    }
                    num2 = num8;
                }
                if (!flag)
                {
                    writer.WriteEndElement();
                }
                IList keyList = list2.GetKeyList();
                for (int k = 0; k < list2.Count; k++)
                {
                    string             text11;
                    ReplayChannelGuide guide2 = (ReplayChannelGuide)list2[keyList[k]];
                    string             text10 = guide2.channelTitle;
                    switch (guide2.channelType)
                    {
                    case 1:
                        text11 = "Recurring";
                        break;

                    case 2:
                        text11 = "Theme";
                        break;

                    case 3:
                        text11 = "Single";
                        break;

                    case 4:
                        text11 = "Zone";
                        break;

                    default:
                        text11 = "";
                        break;
                    }
                    int    num18  = guide2.channelCategory;
                    string text12 = guide2.channelCatName;
                    if (!guide2.channelDone)
                    {
                        writer.WriteStartElement("channel");
                        writer.WriteAttributeString("title", null, text10);
                        writer.WriteAttributeString("channelID", null, keyList[k].ToString());
                        writer.WriteAttributeString("channelType", null, text11);
                        writer.WriteAttributeString("categoryID", null, num18.ToString());
                        writer.WriteAttributeString("categoryName", null, text12);
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            catch (Exception exception)
            {
                ReplayLogger.Log("Save5000GuideAsXML Exception" + exception.ToString());
                if (!flag)
                {
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.Flush();
                writer.Close();
                return(-1);
            }
            writer.Flush();
            writer.Close();
            return(1);
        }
        private void LogSend(string showID)
        {
            this.recipientDevice.ivsNickname = "n/a";
            try
            {
                string xml = null;
                xml = HTTPClient.GetAsString("http://" + this.recipientDevice.ip + ":" + this.recipientDevice.port + "/ivs-IVSGetUnitInfo");
                XmlDocument document = new XmlDocument();
                document.LoadXml(xml);
                foreach (XmlNode node in document.SelectNodes("/UnitInfo"))
                {
                    XmlElement element = node as XmlElement;
                    if (element != null)
                    {
                        this.recipientDevice.ivsNickname = element.GetAttribute("nickname");
                    }
                }
            }
            catch
            {
                ReplayLogger.Log("Send logging: Unable to query remote replay for ivsNickname");
            }
            string      text2     = "n/a";
            string      text3     = "n/a";
            string      text4     = "n/a";
            XmlDocument document2 = new XmlDocument();
            string      path      = ReplayHelper.MakePathAndFile(this.theDevice.serialNumber + ".xml");

            if (System.IO.File.Exists(path))
            {
                document2.Load(path);
                XmlElement element2 = document2.SelectSingleNode(string.Format("/result/channel-list/channel/show[@showID=\"{0}\"]", showID)) as XmlElement;
                if (element2 != null)
                {
                    text2 = element2.GetAttribute("title");
                    text3 = element2.GetAttribute("episodeTitle");
                    text4 = element2.GetAttribute("startTimeGMT");
                }
                else
                {
                    ReplayLogger.Log("showID not found in guide xml file: " + showID);
                }
            }
            else
            {
                ReplayLogger.Log("guide xml file not found.");
            }
            string      filename  = ReplayHelper.MakePathAndFile("sendlog.xml");
            XmlDocument document3 = new XmlDocument();

            try
            {
                document3.Load(filename);
            }
            catch (FileNotFoundException)
            {
                XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("sendlog");
                writer.Close();
                document3.Load(filename);
            }
            try
            {
                XmlElement   newChild = document3.CreateElement("send");
                XmlAttribute newAttr  = document3.CreateAttribute("show");
                newAttr.Value = text2;
                XmlAttribute attribute2 = document3.CreateAttribute("episode");
                attribute2.Value = text3;
                XmlAttribute attribute3 = document3.CreateAttribute("showdate");
                attribute3.Value = text4;
                XmlAttribute attribute4 = document3.CreateAttribute("isn");
                attribute4.Value = this.recipientDevice.isn;
                XmlAttribute attribute5 = document3.CreateAttribute("ivsname");
                attribute5.Value = this.recipientDevice.ivsNickname;
                XmlAttribute attribute6 = document3.CreateAttribute("senddate");
                attribute6.Value = DateTime.Now.ToString();
                XmlAttribute attribute7 = document3.CreateAttribute("unit");
                attribute7.Value = this.theDevice.friendlyName;
                newChild.SetAttributeNode(newAttr);
                newChild.SetAttributeNode(attribute2);
                newChild.SetAttributeNode(attribute3);
                newChild.SetAttributeNode(attribute4);
                newChild.SetAttributeNode(attribute5);
                newChild.SetAttributeNode(attribute6);
                newChild.SetAttributeNode(attribute7);
                document3.DocumentElement.InsertBefore(newChild, document3.DocumentElement.FirstChild);
                document3.Save(filename);
            }
            catch (Exception exception)
            {
                ReplayLogger.Log("Send Log write exception: " + exception.ToString());
            }
        }