Esempio n. 1
0
        private void PostHeader_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            string url = e.Url.OriginalString;

            if (GuiUtils.IsRunningOnMono() && url.StartsWith("wyciwyg"))
            {
                return;
            }

            url = url.Replace("http://", "");
            url = url.TrimEnd('/');

            string[] parts = url.Split('/');

            if (parts.Length < 1)
            {
                return;
            }

            if (parts[0] == "about")
            {
                return;
            }

            if (PostView.SelectedNodes.Count == 0)
            {
                return;
            }

            PostViewNode node = PostView.SelectedNodes[0] as PostViewNode;

            if (node == null || node.Post == null)
            {
                return;
            }

            OpPost post = node.Post;

            if (parts[0] == "reply")
            {
                // replies are directed at parent
                PostViewNode parent = node.ParentNode() as PostViewNode;

                if (parent != null)
                {
                    post = parent.Post;
                }

                ReplyPost(post);
            }
            if (parts[0] == "edit")
            {
                EditPost(post);
            }

            if (parts[0] == "archive")
            {
                Boards.Archive(post, true);
            }

            if (parts[0] == "restore")
            {
                Boards.Archive(post, false);
            }

            if (parts[0] == "attach" && parts.Length > 1)
            {
                int index = int.Parse(parts[1]);

                if (index < post.Attached.Count)
                {
                    string path = Core.User.RootPath + Path.DirectorySeparatorChar +
                                  "Downloads" + Path.DirectorySeparatorChar + post.Attached[index].Name;

                    try
                    {
                        if (!File.Exists(path))
                        {
                            Utilities.ExtractAttachedFile(Boards.GetPostPath(post.Header),
                                                          post.Header.FileKey,
                                                          post.Header.FileStart,
                                                          post.Attached.Select(a => a.Size).ToArray(),
                                                          index,
                                                          path);
                        }

                        Process.Start(path);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "Error Opening Attachment: " + ex.Message);
                    }
                }
            }

            e.Cancel = true;
        }