Example #1
0
        public static void convertZipInFileSystem(string zipfile)
        {
            FileStream _7zfile = File.Create(Path.GetFileNameWithoutExtension(zipfile) + ".7z");

            SevenZip.SevenZipExtractor ze = new SevenZip.SevenZipExtractor(zipfile);
            string tempdirectory          = Path.Combine(Environment.CurrentDirectory, zipfile + "7z");

            Directory.CreateDirectory(tempdirectory);
            ze.ExtractArchive(tempdirectory);
            ze.Dispose();

            SevenZip.SevenZipCompressor _7zc     = new SevenZip.SevenZipCompressor();
            Dictionary <string, string> newentry = new Dictionary <string, string>();

            _7zc.ArchiveFormat      = SevenZip.OutArchiveFormat.SevenZip;
            _7zc.CompressionLevel   = SevenZip.CompressionLevel.High;
            _7zc.CompressionMode    = SevenZip.CompressionMode.Create;
            _7zc.DirectoryStructure = true;
            _7zc.FastCompression    = true;
            Console.WriteLine("Beginning compression.  This will take a while...");
            _7zc.CompressDirectory(tempdirectory, _7zfile);


            _7zfile.Close();
            Directory.Delete(tempdirectory, true);
            Console.WriteLine("Done.");
        }
Example #2
0
        /// <summary>
        /// 按案卷上报
        /// </summary>
        /// <returns></returns>
        private bool?ConfirmSplitForfrmArchive()
        {
            if (txtLoc.Text == "")
            {
                TXMessageBoxExtensions.Info("请选择导出文件的存储路径!");
                txtLoc.Focus();
                return(null);
            }
            string destFilename = Globals.Projectname;

            destFolder = txtLoc.Text;

            string dest_temp = Path.GetDirectoryName(txtLoc.Text);

            if (!Directory.Exists(dest_temp))
            {
                TXMessageBoxExtensions.Info("存储的路径不存在!");
                return(null);
            }

            double             projectSize = Convert.ToDouble(DirectoryInfoCommon.GetDirectorySpace(Application.StartupPath + "\\Project\\" + Globals.ProjectNO) / Convert.ToDouble(1024 * 1024 * 1024));
            ReadWriteAppConfig config      = new ReadWriteAppConfig();

            if (config.Read("Upload_ProjectSize") == "")
            {
                config.Write("Upload_ProjectSize", "4");
            }
            string upload_size = config.Read("Upload_ProjectSize");

            if (projectSize > Convert.ToDouble(upload_size))
            {
                DialogResult dresult = TXMessageBoxExtensions.Question("上报工程大于" + upload_size + "G,当前工程大小为:" + System.Math.Round(projectSize, 2) + "G \r\n\n 【温馨提示:工程太大,生成移交文件需要比较长得时间】  \r\n\n 是否继续生成移交?");
                if (dresult != DialogResult.OK)
                {
                    return(null);
                }
            }
            else if (MyCommon.CheckDisk(destFolder) < projectSize)
            {
                //硬盘空间不足
                TXMessageBoxExtensions.Info("上报工程大小为:" + System.Math.Round(projectSize, 2) + "G 保存目录硬盘空间不足,无法生成! \r\n 【温馨提示:请选择比较空闲的盘符】");
                txtLoc.Focus();
                return(null);
            }

            tempFullName = dest_temp + "\\" + Guid.NewGuid().ToString();
            if (System.IO.Directory.Exists(tempFullName))
            {
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
            }
            MyCommon.DeleteAndCreateEmptyDirectory(tempFullName);

            MyCommon.DeleteAndCreateEmptyDirectory(destFolder, false);
            MyCommon.DeleteAndCreateEmptyDirectory(destFolder, true);

            panelBottom.Visible = true;
            panelTop.Visible    = false;
            Application.DoEvents();
            butClose.Enabled = false;
            ERM.CBLL.CreateSip projectFactory = new ERM.CBLL.CreateSip(Globals.ProjectNO);
            //DataSet dsFinalArchive = projectFactory.GetListArchive(Globals.ProjectNO, "");
            DataSet dsFinalArchive = new Archive().pb_setXmlInfo();

            if (dsFinalArchive.Tables.Count < 1 || dsFinalArchive.Tables[0].Rows.Count < 1)
            {
                TXMessageBoxExtensions.Info("没有任何案卷可以移交!");
                return(false);
            }
            int  count_FinalArchive = dsFinalArchive.Tables[0].Rows.Count;
            bool checkfile_flag     = true;

            for (int i = 0; i < count_FinalArchive; i++)
            {
                BLL.T_FileList_BLL     fileBLL  = new ERM.BLL.T_FileList_BLL();
                IList <MDL.T_FileList> fileList = fileBLL.FindByArchiveID2(dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);
                foreach (MDL.T_FileList obj in fileList)
                {
                    if (obj.selected == 1 || obj.filepath == null || obj.filepath == "")
                    {
                        ConvertAllEFileToPDF(obj.FileID);
                    }
                    else
                    {
                        string tFilePath = obj.filepath.Replace("MPDF\\", "");
                        string sourMfile = Globals.ProjectPath + obj.filepath;
                        if (!System.IO.File.Exists(sourMfile))
                        {
                            ConvertAllEFileToPDF(obj.FileID);
                        }
                    }
                    IList <MDL.T_CellAndEFile> cellList   = (new ERM.BLL.T_CellAndEFile_BLL()).FindByGdFileID(obj.FileID, Globals.ProjectNO);
                    ERM.MDL.T_FileList         file_model = (new ERM.BLL.T_FileList_BLL()).Find(obj.FileID, Globals.ProjectNO);
                    if ((file_model.filepath == null || file_model.filepath == "") &&
                        cellList.Count > 0)
                    {
                        TXMessageBoxExtensions.Info("提示:文件【" + obj.gdwj + "】电子文件信息有误!无法移交,请审查");
                        checkfile_flag = false;
                        break;
                    }
                }
                if (!checkfile_flag)
                {
                    break;
                }
            }
            if (!checkfile_flag)
            {
                return(false);
            }

            progressBar2.Maximum = count_FinalArchive;
            progressBar2.Minimum = 0;
            progressBar2.MarqueeAnimationSpeed = 1000;
            progressBar2.Step = 1;
            lblMsg.Text       = "正在输出元数据信息...";
            Application.DoEvents();

            GetListArchiveXML(projectFactory, tempFullName);
            try
            {
                for (int i = 0; i < count_FinalArchive; i++)
                {
                    if (!Directory.Exists(tempFullName))
                    {
                        MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, true);
                    }
                    //20120530 屏蔽XML文件
                    GetProjectXML(projectFactory, tempFullName);

                    if (Convert.ToBoolean(Properties.Settings.Default.SipIncludeDoc))
                    {
                        //20120530 屏蔽XML文件
                        GetListArchiveXMLEx(dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), tempFullName);
                        GetDocumentXMLEx(dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), tempFullName);

                        BLL.T_FileList_BLL     fileBLL  = new ERM.BLL.T_FileList_BLL();
                        IList <MDL.T_FileList> fileList = fileBLL.FindByArchiveID2(dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);
                        foreach (MDL.T_FileList obj in fileList)
                        {
                            //20120530 屏蔽XML文件
                            //getDocModel(obj);
                            getDocModel_NEW(obj, tempFullName);
                        }
                    }
                    lblMsg.Text = "正在对数据包进行封装...";
                    Application.DoEvents();

                    if (System.IO.File.Exists(tempFullName + "\\index.dat"))//Application.StartupPath + "\\temp\\index.dat"
                    {
                        System.IO.File.Move(tempFullName + "\\index.dat", destFolder + "\\index.dat");

                        string gcInfo  = System.IO.File.ReadAllText(tempFullName + "\\a#sgwj_gc.xml", Encoding.GetEncoding("gb2312"));
                        string docList = System.IO.File.ReadAllText(destFolder + "\\index.dat");
                        gcInfo = gcInfo.Replace("</项目工程信息>", "<ArchiveFileList>" + docList + "</ArchiveFileList></项目工程信息>");
                        System.IO.File.WriteAllText(destFolder + "\\index.dat", gcInfo, Encoding.GetEncoding("gb2312"));
                    }

                    SevenZip.SevenZipCompressor.SetLibraryPath(Application.StartupPath + "\\7z.dll");
                    SevenZip.SevenZipCompressor tmp = new SevenZip.SevenZipCompressor();
                    {
                        tmp.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;
                        tmp.CompressDirectory(tempFullName, destFolder + "\\" + dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString() + ".sip");
                    }
                    MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                    progressBar2.Value = progressBar2.Value + 1;
                }
            }
            catch (Exception ex)
            {
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                TXMessageBoxExtensions.Info("封装数据时发生意外错误!错误002");
                MyCommon.WriteLog("生成移交文件时失败!错误信息:" + ex.Message);
                return(false);
            }
            butClose.Text    = "关闭";
            butClose.Enabled = true;
            TXMessageBoxExtensions.Info("已经成功生成上报文件!");
            return(true);
        }
Example #3
0
        private bool StartRemove(string saveLoc, System.ComponentModel.BackgroundWorker _bgWorker)
        {
            string destFilename = Globals.Projectname;

            destFolder = saveLoc;

            string dest_temp = Path.GetDirectoryName(saveLoc);

            tempFullName = dest_temp + "\\" + Guid.NewGuid().ToString();
            if (System.IO.Directory.Exists(tempFullName))
            {
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
            }
            MyCommon.DeleteAndCreateEmptyDirectory(tempFullName);

            MyCommon.DeleteAndCreateEmptyDirectory(destFolder, false);
            MyCommon.DeleteAndCreateEmptyDirectory(destFolder, true);

            if (Index_temp > 100)
            {
                Index_temp = 0;
            }
            _bgWorker.ReportProgress(Index_temp++);


            ERM.CBLL.CreateSip projectFactory = new ERM.CBLL.CreateSip(Globals.ProjectNO);
            // DataSet dsFinalArchive = projectFactory.GetListArchive(Globals.ProjectNO, "");
            DataSet dsFinalArchive = new Archive().pb_setXmlInfo();

            if (dsFinalArchive.Tables.Count < 1 || dsFinalArchive.Tables[0].Rows.Count < 1)
            {
                TXMessageBoxExtensions.Info("没有任何案卷可以移交!");
                return(false);
            }
            int count_FinalArchive = dsFinalArchive.Tables[0].Rows.Count;

            //DataSet dsFinalArchive_temp = projectFactory.GetListArchive(Globals.ProjectNO, "");
            DataSet dsFinalArchive_temp = dsFinalArchive;

            dsFinalArchive_temp.DataSetName         = "案卷信息";
            dsFinalArchive_temp.Tables[0].TableName = "记录";

            string       _filename = tempFullName + "\\index.dat";
            StreamWriter w1        = new StreamWriter(_filename, false, Encoding.Default);

            if (dsFinalArchive_temp != null && dsFinalArchive_temp.Tables.Count > 0 && dsFinalArchive_temp.Tables[0].Rows.Count > 0)
            {
                for (int i1 = 0; i1 < dsFinalArchive_temp.Tables[0].Rows.Count; i1++)
                {
                    w1.WriteLine("<FileList><File>" + dsFinalArchive_temp.Tables[0].Rows[i1][0].ToString() + ".sip</File>");
                    w1.WriteLine("<Title>" + dsFinalArchive_temp.Tables[0].Rows[i1]["案卷题名"].ToString() + "</Title></FileList>");
                }
            }
            w1.Flush();
            w1.Close();

            if (Index_temp > 100)
            {
                Index_temp = 0;
            }
            _bgWorker.ReportProgress(Index_temp++);

            try
            {
                for (int i = 0; i < count_FinalArchive; i++)
                {
                    if (Index_temp > 100)
                    {
                        Index_temp = 0;
                    }
                    _bgWorker.ReportProgress(Index_temp++);

                    if (!Directory.Exists(tempFullName))
                    {
                        MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, true);
                    }

                    StreamWriter gc = new StreamWriter(tempFullName + "\\a#sgwj_gc.xml", false, Encoding.Default);
                    gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
                    gc.WriteLine("<项目工程信息>");
                    gc.WriteLine("  <项目信息>");
                    DataSet   ds    = new Item().pb_setXmlInfo(new T_Projects_BLL().Find(Globals.ProjectNO).ItemID);
                    Hashtable _Item = new Hashtable();
                    if (ds.Tables.Count > 0)
                    {
                        for (int n = 0; n < ds.Tables[0].Rows.Count; n++)
                        {
                            for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                            {
                                _Item.Add(ds.Tables[0].Columns[j].ColumnName, ds.Tables[0].Rows[n][j].ToString());
                            }
                        }

                        foreach (System.Collections.DictionaryEntry objDE in _Item)
                        {
                            if (_Item[objDE.Key] != null)
                            {
                                if (_Item[objDE.Key].GetType() != typeof(System.String[]))
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + objDE.Value + "</" + objDE.Key + ">");
                                }
                                else
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + ((string[])_Item[objDE.Key])[0] + "</" + objDE.Key + ">");
                                }
                            }
                            else
                            {
                                gc.WriteLine("    <" + objDE.Key + "></" + objDE.Key + ">");
                            }
                        }
                    }
                    gc.WriteLine("  </项目信息>");
                    gc.WriteLine("  <工程信息>");
                    Hashtable _detail = new Hashtable();
                    DataSet   ds1     = new ERM.UI.Common.XmlMapping.Project().pb_setXmlInfo(new T_Projects_BLL().Find(Globals.ProjectNO).ProjectCategory);
                    if (ds1.Tables.Count > 0)
                    {
                        for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)
                        {
                            for (int j = 0; j < ds1.Tables[0].Columns.Count; j++)
                            {
                                _detail.Add(ds1.Tables[0].Columns[j].ColumnName, ds1.Tables[0].Rows[n][j].ToString());
                            }
                        }

                        foreach (System.Collections.DictionaryEntry objDE in _detail)
                        {
                            if (_detail[objDE.Key] != null)
                            {
                                if (_detail[objDE.Key].GetType() != typeof(System.String[]))
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + objDE.Value + "</" + objDE.Key + ">");
                                }
                                else
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + ((string[])_detail[objDE.Key])[0] + "</" + objDE.Key + ">");
                                }
                            }
                            else
                            {
                                gc.WriteLine("    <" + objDE.Key + "></" + objDE.Key + ">");
                            }
                        }
                        gc.WriteLine("  </工程信息>");
                        gc.WriteLine("</项目工程信息>");
                        gc.Flush();
                        gc.Close();
                    }

                    if (Convert.ToBoolean(Properties.Settings.Default.SipIncludeDoc))
                    {
                        #region ==================================
                        //20120530 屏蔽XML文件

                        //DataSet dsFinalArchive_temp1 = projectFactory.GetListArchive(Globals.ProjectNO, dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString());
                        DataSet dsFinalArchive_temp1 = new Archive().pb_setXmlInfo(Globals.ProjectNO, dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString());
                        dsFinalArchive_temp1.DataSetName         = "案卷信息";
                        dsFinalArchive_temp1.Tables[0].TableName = "记录";

                        _filename = tempFullName + "\\a#sgwj_file.xml";
                        if (System.IO.File.Exists(_filename))
                        {
                            try
                            {
                                System.IO.File.Delete(_filename);
                            }
                            catch { }
                        }

                        gc = new StreamWriter(_filename, true, Encoding.Default);
                        gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
                        gc.Flush();
                        gc.Close();
                        System.IO.FileStream     stream_archive    = new System.IO.FileStream(_filename, System.IO.FileMode.Append);
                        System.Xml.XmlTextWriter xmlWriter_archive = new System.Xml.XmlTextWriter(stream_archive, System.Text.Encoding.Default);
                        dsFinalArchive_temp1.WriteXml(xmlWriter_archive);
                        xmlWriter_archive.Close();

                        #endregion

                        #region ===========================

                        //DataSet dsFinalFile = projectFactory.GetListFile(Globals.ProjectNO,
                        //  dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString());
                        DataSet dsFinalFile = new ERM.UI.Common.XmlMapping.File().pb_setXmlInfo("pb_queryByFileNo", dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);

                        dsFinalFile.DataSetName         = "文件信息";
                        dsFinalFile.Tables[0].TableName = "记录";

                        _filename = tempFullName + "\\a#sgwj_document.xml";
                        if (System.IO.File.Exists(_filename))
                        {
                            try
                            {
                                System.IO.File.Delete(_filename);
                            }
                            catch { }
                        }

                        gc = new StreamWriter(_filename, true, Encoding.Default);
                        gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
                        gc.Flush();
                        gc.Close();
                        System.IO.FileStream     stream_file    = new System.IO.FileStream(_filename, System.IO.FileMode.Append);
                        System.Xml.XmlTextWriter xmlWriter_file = new System.Xml.XmlTextWriter(stream_file, System.Text.Encoding.Default);
                        dsFinalFile.WriteXml(xmlWriter_file);
                        xmlWriter_file.Close();

                        #endregion

                        BLL.T_FileList_BLL fileBLL = new ERM.BLL.T_FileList_BLL();
                        //IList<MDL.T_FileList> fileList = fileBLL.FindByArchiveID2(dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);
                        DataSet fileList = new ERM.UI.Common.XmlMapping.File().pb_setXmlInfo("pb_FindByArchiveID2", dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);
                        if (fileList.Tables.Count > 0)
                        {
                            for (int j = 0; j < fileList.Tables[0].Rows.Count; j++)
                            {
                                DataRow obj = fileList.Tables[0].Rows[j];
                                if (Index_temp > 100)
                                {
                                    Index_temp = 0;
                                }
                                _bgWorker.ReportProgress(Index_temp++);

                                string FileID = obj["FileID"].ToString();
                                if (obj["filepath"] != null)
                                {
                                    string tFilePath = obj["filepath"].ToString().Replace("MPDF\\", "");
                                    string decMfile  = tempFullName + "\\" + tFilePath;
                                    string sourMfile = Globals.ProjectPath + obj["filepath"];
                                    try
                                    {
                                        if (System.IO.File.Exists(sourMfile))
                                        {
                                            System.IO.File.Copy(sourMfile, decMfile, true);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MyCommon.WriteLog("生成移交文件时,拷贝文件失败!错误信息:" + ex.Message);
                                    }
                                }
                                BLL.T_CellAndEFile_BLL     cellBLL  = new ERM.BLL.T_CellAndEFile_BLL();
                                IList <MDL.T_CellAndEFile> cellList = cellBLL.FindByFileID(FileID, Globals.ProjectNO, 1);

                                foreach (MDL.T_CellAndEFile obj2 in cellList)
                                {
                                    string yswjpath = obj2.filepath.Replace("ODOC\\", "");

                                    string dec  = tempFullName + "\\" + yswjpath;
                                    string sour = Globals.ProjectPath + obj2.filepath;
                                    try
                                    {
                                        if (System.IO.File.Exists(sour))
                                        {
                                            System.IO.File.Copy(sour, dec, true);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MyCommon.WriteLog("生成移交文件时,拷贝原文件失败!错误信息:" + ex.Message);
                                    }
                                }
                            }
                        }
                    }
                    if (System.IO.File.Exists(tempFullName + "\\index.dat"))
                    {
                        System.IO.File.Move(tempFullName + "\\index.dat", destFolder + "\\index.dat");

                        string gcInfo  = System.IO.File.ReadAllText(tempFullName + "\\a#sgwj_gc.xml", Encoding.GetEncoding("gb2312"));
                        string docList = System.IO.File.ReadAllText(destFolder + "\\index.dat");
                        gcInfo = gcInfo.Replace("</项目工程信息>", "<ArchiveFileList>" + docList + "</ArchiveFileList></项目工程信息>");
                        System.IO.File.WriteAllText(destFolder + "\\index.dat", gcInfo, Encoding.GetEncoding("gb2312"));
                    }
                    SevenZip.SevenZipCompressor.SetLibraryPath(Application.StartupPath + "\\7z.dll");
                    SevenZip.SevenZipCompressor tmp = new SevenZip.SevenZipCompressor();
                    tmp.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;
                    tmp.CompressDirectory(tempFullName, destFolder + "\\" + dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString() + ".sip");

                    MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                }
            }
            catch (Exception ex)
            {
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                TXMessageBoxExtensions.Info("封装数据时发生意外错误!错误002");
                MyCommon.WriteLog("生成移交文件时失败!错误信息:" + ex.Message);
                return(false);
            }
            return(true);
        }
Example #4
0
        private void btnSendDebug_Click(object sender, EventArgs e)
        {
            string szdll = "";

            if (Environment.Is64BitProcess)
            {
                szdll = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll");
            }
            else
            {
                szdll = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z32.dll");
            }


            if (btnSendDebug.Text != "Fetch data") //If not in receive mode
            {
                string password = Guid.NewGuid().ToString().Replace("-", "").Replace("{", "").Replace("}", "").ToUpper();

                string relativedir  = Directory.GetCurrentDirectory();
                string tempdebugdir = Path.Combine(relativedir, "debug");
                string tempzipfile  = tempdebugdir + ".7z";

                if (!Directory.Exists(tempdebugdir))
                {
                    Directory.CreateDirectory(tempdebugdir);
                }

                string[] debugFiles = Directory.GetFiles(tempdebugdir);
                foreach (string file in debugFiles)
                {
                    File.Delete(file);
                }

                if (File.Exists(tempzipfile))
                {
                    File.Delete(tempzipfile);
                }

                //Exporting side
                string sideFile = Path.Combine(tempdebugdir, "SIDE.txt");
                File.WriteAllText(sideFile, System.Diagnostics.Process.GetCurrentProcess().ProcessName);

                //Exporting Stacktrace
                var           _ex = ex;
                StringBuilder sb  = new StringBuilder();
                sb.AppendLine($"Exception: {ex.Message}\n{ex.StackTrace}");
                while (_ex.InnerException != null)
                {
                    sb.AppendLine();
                    sb.AppendLine($"Inner Exception: {ex.Message}\n{ex.StackTrace}");
                    _ex = _ex.InnerException;
                }
                tbStackTrace.Text = sb.ToString();
                string stacktracefile = Path.Combine(tempdebugdir, "STACKTRACE.TXT");
                File.WriteAllText(stacktracefile, sb.ToString());

                //Exporting data
                string data = Path.Combine(tempdebugdir, "DATA.TXT");
                sb = new StringBuilder();
                foreach (var key in ex.Data.Keys)
                {
                    sb.AppendLine(key + " : " + ex.Data[key]);
                }
                File.WriteAllText(data, sb.ToString());

                //Exporting Specs from RTC's perspective
                string rtcfile = Path.Combine(tempdebugdir, "RTC_PERSPECTIVE.TXT");
                File.WriteAllText(rtcfile, getRTCInfo());

                //Exporting Specs from the Emu's perspective
                string emufile = Path.Combine(tempdebugdir, "EMU_PERSPECTIVE.txt");
                File.WriteAllText(emufile, getEmuInfo());

                //Copying the log files
                if (AllSpec.CorruptCoreSpec?["RTCDIR"] is string rtcdir)
                {
                    string rtcLog       = Path.Combine(rtcdir, "RTC_LOG.txt");
                    string rtcLogOutput = Path.Combine(tempdebugdir, "RTC_LOG.txt");
                    //lock (NetCore_Extensions.ConsoleHelper.con.FileWriter)
                    //{
                    if (File.Exists(rtcLog))
                    {
                        File.Copy(rtcLog, rtcLogOutput, true);
                    }
                    //}
                }

                if (AllSpec.VanguardSpec?["EMUDIR"] is string emudir)
                {
                    string emuLog       = Path.Combine(emudir, "EMU_LOG.txt");
                    string emuLogOutput = Path.Combine(tempdebugdir, "EMU_LOG.txt");
                    //lock (NetCore_Extensions.ConsoleHelper.con.FileWriter)
                    //{
                    if (File.Exists(emuLog))
                    {
                        File.Copy(emuLog, emuLogOutput, true);
                    }
                    //}
                }

                SevenZip.SevenZipBase.SetLibraryPath(szdll);
                var comp = new SevenZip.SevenZipCompressor
                {
                    CompressionMode = SevenZip.CompressionMode.Create,
                    TempFolderPath  = Path.GetTempPath(),
                    ArchiveFormat   = SevenZip.OutArchiveFormat.SevenZip
                };
                comp.CompressDirectory(tempdebugdir, tempzipfile, false, password);

                string filename = CloudTransfer.CloudSave(tempzipfile);
                tbKey.Text = filename + "-" + password;

                btnSendDebug.Enabled = false;

                if (File.Exists(tempzipfile))
                {
                    File.Delete(tempzipfile);
                }
            }
            else
            {
                if (tbKey.Text.Length != 65)
                {
                    MessageBox.Show("Invalid key");
                    return;
                }

                string[] keyparts = tbKey.Text.Split('-');
                string   filename = keyparts[0];
                string   password = keyparts[1];

                string downloadfilepath = CloudTransfer.CloudLoad(filename, password);

                if (downloadfilepath == null)
                {
                    return;
                }

                string extractpath = downloadfilepath.Replace(".7z", "");

                if (!Directory.Exists(extractpath))
                {
                    Directory.CreateDirectory(extractpath);
                }

                string[] debugFiles = Directory.GetFiles(extractpath);
                foreach (string file in debugFiles)
                {
                    File.Delete(file);
                }


                SevenZip.SevenZipCompressor.SetLibraryPath(szdll);
                var decomp = new SevenZip.SevenZipExtractor(downloadfilepath, password, SevenZip.InArchiveFormat.SevenZip);
                decomp.ExtractArchive(extractpath);

                File.Delete(downloadfilepath);
                Process.Start(extractpath);
            }
        }
Example #5
0
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            txtLoc.Text = txtLoc.Text.Trim();
            if (txtLoc.Text == "")
            {
                TXMessageBoxExtensions.Info("提示:请选择导出文件的存储路径!");
                txtLoc.Focus();
                return;
            }
            string destFilename = MyCommon.GetFileShortName(txtLoc.Text);
            string destFolder   = Path.GetDirectoryName(txtLoc.Text);

            if (!Directory.Exists(destFolder))
            {
                TXMessageBoxExtensions.Info("存储的路径不存在!");
                return;
            }
            /// <summary>
            /// 导出功能涉及的文件临时存放目录
            /// </summary>
            string tempFullName =
                Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\ERM\\OutDataTemp";

            try
            {
                btnCancel.Enabled   = false;
                btnConfirm.Enabled  = false;
                btnExplorer.Enabled = false;

                if (System.IO.Directory.Exists(tempFullName))
                {
                    MyCommon.DeleteFilesAndFolders(tempFullName);
                }
                Directory.CreateDirectory(tempFullName);
                // MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                //MyCommon.DeleteAndCreateEmptyDirectory(tempFullName);

                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName + "\\" + TheNode.Name + "\\T_GdList\\");
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName + "\\" + TheNode.Name + "\\T_FileList\\");
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName + "\\" + TheNode.Name + "\\T_CellAndEFile\\");
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName + "\\" + TheNode.Name + "\\T_CellAndEFile\\ODOC\\"); //原文
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName + "\\" + TheNode.Name + "\\T_CellAndEFile\\PDF\\");  //原文的PDF文件
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName + "\\" + TheNode.Name + "\\T_CellAndEFile\\MPDF\\"); //文件级电子文件,带章

                int sumCount = 0;
                GetNodesCount(TheNode, ref sumCount);
                GetChildToFileCount(TheNode, ref sumCount);
                progressBar1.Maximum = sumCount;

                ParentToFile(TheNode, tempFullName + "\\" + TheNode.Name);
                ChildToFile(TheNode, tempFullName + "\\" + TheNode.Name);

                lblTitle.Text      = @"正在压缩导出数据....";
                progressBar1.Value = progressBar1.Maximum / 2;
                Application.DoEvents();

                //Common.ZipFile zip = new Common.ZipFile(tempFullName + "\\", txtLoc.Text);
                //zip.StartZip();

                SevenZip.SevenZipCompressor.SetLibraryPath(Application.StartupPath + "\\7z.dll");
                SevenZip.SevenZipCompressor tmp = new SevenZip.SevenZipCompressor();
                tmp.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;
                tmp.CompressDirectory(tempFullName + "\\", txtLoc.Text);

                System.Threading.Thread.Sleep(1000);

                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);//删除文件夹

                lblTitle.Text = @"导出完成!";
                Application.DoEvents();

                this.DialogResult   = DialogResult.OK;
                btnCancel.Enabled   = true;
                btnConfirm.Enabled  = true;
                btnExplorer.Enabled = true;
            }
            catch (Exception ex)
            {
                TXMessageBoxExtensions.Info(ex.Message);
                this.DialogResult = DialogResult.Cancel;
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);//删除文件夹
            }
        }