Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ShowHelpMsg();
            }
            else if (args.Length == 2)
            {
                if (args[1].ToLower() == "getHtml".ToLower())
                {
                    IsGetHtml = true;
                }
                if (args[1].ToLower() == "getImg".ToLower())
                {
                    IsGetImg = true;
                }
                if (IsGetHtml || IsGetImg)
                {
                    string strFilePath = args[0];
                    if (File.Exists(strFilePath))
                    {
                        QqMhtToHtml.FileLength = FileLength;
                        QqMhtToHtml.ImgDirName = ImgDirName;
                        QqMhtToHtml.IsGetHtml  = IsGetHtml;
                        QqMhtToHtml.IsGetImg   = IsGetImg;
                        QqMhtToHtml.OutputPath = OutputPath;

                        QqMhtToHtml.DoConvert(strFilePath);
                    }
                    else
                    {
                        Console.WriteLine("文件 " + strFilePath + " 不存在,按任意键退出");
                        Console.ReadKey();
                    }
                }
                else
                {
                    if (!IsGetHtml && !IsGetImg)
                    {
                        Console.WriteLine("参数填写错误,按任意键退出...");
                    }
                    Console.ReadKey();
                }
            }
            else
            {
                if (!IsGetHtml && !IsGetImg)
                {
                    Console.WriteLine("参数数量错误,按任意键退出...");
                }
                Console.ReadKey();
            }
        }
        private void Button_Start_Click(object sender, RoutedEventArgs e)
        {
            string path = mhtPathTextBox.Text.Trim();

            //生成HTML的正文,第二步进行
            bool IsGetHtml;

            //生成消息附件中的图片,第一步进行
            bool IsGetImg;

            string OutputPath = @"";

            if (checkBox_tosourcedir.IsChecked.Value)
            {
                try
                {
                    outputPathTextBox.Text = System.IO.Path.GetDirectoryName(path);
                }
                catch (Exception)
                {
                    ;
                }
            }
            OutputPath = outputPathTextBox.Text.Trim() + "\\";

            string ImgDirName = "img";

            ImgDirName = textBox_imgdirname.Text.Trim();

            //多少条记录换一个新文件继续输出
            int FileLength = 50000;

            if (path == "" || !File.Exists(path))
            {
                MessageBox.Show("请输入正确的路径,您也可以将文件拖放到窗口。");
                return;
            }
            boader.IsEnabled = false;

            try
            {
                FileLength = Int32.Parse(textBox_filelength.Text);
            }
            catch
            {
                FileLength = 0;
            }


            QqMhtToHtml.FileLength = FileLength;
            QqMhtToHtml.ImgDirName = ImgDirName;

            QqMhtToHtml.OutputPath = OutputPath;

            if (checkBox_outputPic.IsChecked.Value)
            {
                QqMhtToHtml.IsGetImg  = true;
                QqMhtToHtml.IsGetHtml = false;
                QqMhtToHtml.DoConvert(path);
            }

            QqMhtToHtml.IsGetImg  = false;
            QqMhtToHtml.IsGetHtml = true;
            QqMhtToHtml.DoConvert(path);

            if (checkBox_opendir.IsChecked.Value)
            {
                ExplorePath(OutputPath);
            }

            if (checkBox_openwebbroswer.IsChecked.Value)
            {
                System.Diagnostics.Process.Start("file://" +
                                                 OutputPath + System.IO.Path.GetFileNameWithoutExtension(path) + ".html");
            }


            if (checkBox_del.IsChecked.Value)
            {
                File.Delete(path);
            }

            MessageBox.Show("任务完成了哈。");
            boader.IsEnabled = true;
        }