Exemplo n.º 1
0
        public static string CleanseName(string name)
        {
            int length = 0;

            name = new string(Bookmarks.EscapeText(name, out length), 0, length);
            if (name.Length > 40)
            {
                return(name.Substring(0, 40));
            }
            return(name);
        }
Exemplo n.º 2
0
 public void AddBookmark(string name, int cp)
 {
     this.m_names.Add(Bookmarks.CleanseName(name));
     this.m_offsets.Add(cp);
 }
Exemplo n.º 3
0
        public static void WriteHyperlink(Stream dataStream, string target, LinkType type)
        {
            int num = 4 + HyperlinkWriter.EMPTY_PIC.Length + 1 + HyperlinkWriter.MAGIC_NUM1.Length + 4 + 4;

            switch (type)
            {
            case LinkType.File:
                num += HyperlinkWriter.MAGIC_NUM3.Length + 4 + target.Length + 1 + HyperlinkWriter.MAGIC_NUM4.Length + 4 + 4 + 2 + (target.Length + 1) * 2;
                break;

            case LinkType.Hyperlink:
                num += HyperlinkWriter.MAGIC_NUM2.Length + 4 + (target.Length + 1) * 2;
                break;

            case LinkType.Bookmark:
                target = Bookmarks.CleanseName(target);
                num   += 4 + (target.Length + 1) * 2;
                break;
            }
            BinaryWriter binaryWriter = new BinaryWriter(dataStream);

            binaryWriter.Write(num);
            binaryWriter.Write(HyperlinkWriter.EMPTY_PIC, 0, HyperlinkWriter.EMPTY_PIC.Length);
            if (type == LinkType.Bookmark)
            {
                binaryWriter.Write((byte)8);
            }
            else
            {
                binaryWriter.Write((byte)0);
            }
            binaryWriter.Flush();
            binaryWriter.Write(HyperlinkWriter.MAGIC_NUM1, 0, HyperlinkWriter.MAGIC_NUM1.Length);
            binaryWriter.Write(2);
            if (type == LinkType.Bookmark)
            {
                binaryWriter.Write(8);
            }
            else
            {
                binaryWriter.Write(3);
            }
            binaryWriter.Flush();
            switch (type)
            {
            case LinkType.File:
            {
                binaryWriter.Write(HyperlinkWriter.MAGIC_NUM3, 0, HyperlinkWriter.MAGIC_NUM3.Length);
                byte[] bytes3 = Encoding.ASCII.GetBytes(target);
                binaryWriter.Write(bytes3.Length + 1);
                binaryWriter.Write(bytes3, 0, bytes3.Length);
                binaryWriter.Write((byte)0);
                binaryWriter.Write(HyperlinkWriter.MAGIC_NUM4, 0, HyperlinkWriter.MAGIC_NUM4.Length);
                binaryWriter.Write(target.Length * 2 + 6);
                binaryWriter.Write(target.Length * 2);
                binaryWriter.Write((short)3);
                bytes3 = Encoding.Unicode.GetBytes(target);
                binaryWriter.Write(bytes3, 0, bytes3.Length);
                binaryWriter.Write((short)0);
                break;
            }

            case LinkType.Hyperlink:
            {
                binaryWriter.Write(HyperlinkWriter.MAGIC_NUM2, 0, HyperlinkWriter.MAGIC_NUM2.Length);
                binaryWriter.Write((target.Length + 1) * 2);
                binaryWriter.Flush();
                byte[] bytes2 = Encoding.Unicode.GetBytes(target);
                binaryWriter.Write(bytes2);
                binaryWriter.Write((short)0);
                break;
            }

            case LinkType.Bookmark:
            {
                binaryWriter.Write(target.Length + 1);
                byte[] bytes = Encoding.Unicode.GetBytes(target);
                binaryWriter.Write(bytes);
                binaryWriter.Write((short)0);
                break;
            }
            }
            binaryWriter.Write(0);
            binaryWriter.Flush();
        }