Exemple #1
0
        public void StartDeal()
        {
            if (pptPathList.Count <= 0)
            {
                return;
            }

            foreach (var path in pptPathList)
            {
                fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); //获取文件名,没有扩展名的文件名
                fileNameWithExtension    = Path.GetFileName(path);                 //获取文件名
                singlePath = targetPath + @"\" + fileNameWithoutExtension + @"\";
                if (Directory.Exists(singlePath))
                {
                    DirectoryInfo subdir = new DirectoryInfo(singlePath);
                    subdir.Delete(true);
                }
                ppt.PPTOpen(path);//打开PPT
                if (ppt.objApp == null || ppt.objPresSet == null)
                {
                    string tarFName      = Path.GetFileName(path);
                    string errorFullName = errorPath + @"\" + tarFName;
                    if (File.Exists(path))
                    {
                        if (!Directory.Exists(errorPath))
                        {
                            Directory.CreateDirectory(errorPath);
                        }
                        File.Move(path, errorFullName);
                    }
                    continue;
                }
                if (IsOnlyRead(path))
                {
                    try
                    {
                        string tarFName      = Path.GetFileName(path);
                        string errorFullName = errorPath + @"\" + tarFName;
                        if (File.Exists(path))
                        {
                            if (!Directory.Exists(errorPath))
                            {
                                Directory.CreateDirectory(errorPath);
                            }
                            if (File.Exists(errorFullName))
                            {
                                File.Delete(errorFullName);
                            }
                            File.Move(path, errorFullName);
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.ToString());
                    }
                    continue;
                }
                if (!Directory.Exists(singlePath))
                {
                    Directory.CreateDirectory(singlePath);
                }

                string pptTitle   = "" + fileNameWithoutExtension + " - Microsoft PowerPoint";
                IntPtr m_hGameWnd = User32API.FindWindow("PPTFrameClass", null);
                if (m_hGameWnd != IntPtr.Zero)
                {
                    StringBuilder s        = new StringBuilder(512);
                    int           intTitle = User32API.GetWindowText(m_hGameWnd, s, s.Capacity); //把this.handle换成你需要的句柄
                    string        strTitle = intTitle.ToString();
                    if (strTitle.Contains("受保护的视图"))
                    {
                        if (File.Exists(path))
                        {
                            if (!Directory.Exists(errorPath))
                            {
                                Directory.CreateDirectory(errorPath);
                            }
                            string tarFName      = Path.GetFileName(path);
                            string errorFullName = errorPath + @"\" + tarFName;
                            File.Move(path, errorFullName);
                        }
                        //MouseClick(105, 80);
                        continue;
                    }
                }
                SetUploadDetails();  //生成一个txt,保存上传信息

                TextReplacement();   //第一步,文字替换

                ChangeToPic(path);   //第二步,转换成图片

                ppt.PPTClose();      //关闭PPT,释放资源

                ToCompressPPT(path); //第三步,压缩PPT

                PPTToFlash(path);    //第四步,PPT转换成flash

                if (File.Exists(path))
                {
                    if (!Directory.Exists(successPath))
                    {
                        Directory.CreateDirectory(successPath);
                    }
                    string starFName       = Path.GetFileName(path);
                    string successFullName = successPath + @"\" + starFName;
                    if (File.Exists(successFullName))
                    {
                        File.Delete(successFullName);
                    }
                    File.Move(path, successFullName);
                }
            }
        }