Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!password.Equals(textBox1.Text) && !detectionDate())
            {
                return;
            }
            //清空消息框
            this.label7.Text = "";
            //封装参数
            formEntity = new FormEntity()
            {
                TXTPath         = this.comboBox1.Text,
                Workspace       = this.comboBox2.Text,
                OutFolder       = this.comboBox3.Text,
                OutFolderAdd    = this.comboBox4.Text,
                ReplaceSource   = this.comboBox5.Text,
                ReplaceTarget   = this.comboBox6.Text,
                GainClass       = this.checkBox1.Checked,
                RetainDirectory = this.checkBox2.Checked,
                GainTarGz       = this.checkBox3.Checked
            };
            formEntity.processPathOperation();
            //表单验证
            if (!validateFormEntity(formEntity))
            {
                return;
            }
            DirectoryInfo dirInfo = new DirectoryInfo(integrationFolder(formEntity.OutFolder, formEntity.OutFolderAdd));

            if (dirInfo.Exists)
            {
                delectDirChilds(integrationFolder(formEntity.OutFolder, formEntity.OutFolderAdd));
            }
            //读取txt文件,进行文件拷贝
            if (!readTxtAndCopyFile(formEntity))
            {
                return;
            }
            //压缩
            if (formEntity.GainTarGz && !new Targz().CreatTarGzArchiveEnvironment(integrationFolder(formEntity.OutFolder, formEntity.OutFolderAdd), projectName))
            {
                print("拷贝完成,压缩失败!");
                return;
            }
            //缓存控件内容
            cacheControl();
            print("拷贝完成");
        }
Beispiel #2
0
        //表单验证
        private Boolean validateFormEntity(FormEntity formEntity)
        {
            Boolean boo = false;

            if (formEntity.TXTPath == "" || !File.Exists(formEntity.TXTPath))
            {
                print("text文件不存在");
            }
            else if (formEntity.Workspace == "" || !Directory.Exists(formEntity.Workspace))
            {
                print("本地工作空间不存在");
            }
            else
            {
                boo = true;
            }
            return(boo);
        }
Beispiel #3
0
        //读取文件并进行文件拷贝
        private bool readTxtAndCopyFile(FormEntity formEntity)
        {
            Boolean      boo     = true;
            FileStream   fs      = new FileStream(formEntity.TXTPath, FileMode.Open);
            StreamReader sw      = new StreamReader(fs);
            string       lineStr = null;
            int          i       = 0;

            while ((lineStr = sw.ReadLine()) != null)
            {
                try
                {
                    lineStr = lineStr.Trim();
                    if ("--end".Equals(lineStr) || "end".Equals(lineStr))
                    {
                        break;
                    }
                    else if (lineStr == "" || lineStr.StartsWith("--"))
                    {
                        continue;
                    }
                    lineStr = lineStr.Replace("/", "\\");
                    //是否获取class
                    if (formEntity.GainClass)
                    {
                        lineStr = lineStr.Replace(formEntity.ReplaceSource, formEntity.ReplaceTarget);
                        lineStr = lineStr.Replace(".java", ".class");
                    }
                    string sourceFile = null;
                    if (Regex.IsMatch(lineStr, "^[A-Z:]"))
                    {
                        sourceFile = sourceFile.Replace(formEntity.Workspace, "");
                    }
                    sourceFile = integrationFolder(formEntity.Workspace, lineStr);
                    string tempStr = null;

                    if (lineStr.StartsWith("\\"))
                    {
                        tempStr = lineStr.Substring(1, lineStr.Length - 1);
                    }
                    projectName = tempStr.Substring(0, tempStr.IndexOf("\\"));
                    if (!File.Exists(sourceFile))
                    {
                        print("文件不存在,拷贝异常," + sourceFile);
                        boo = false;
                        break;
                    }
                    string filePath = lineStr;
                    if (!formEntity.RetainDirectory)
                    {
                        filePath = lineStr.Substring(lineStr.LastIndexOf("\\", lineStr.Length - 1));
                    }
                    string targetFile = integrationFolder(formEntity.OutFolder, formEntity.OutFolderAdd, filePath);
                    if (File.Exists(targetFile))
                    {
                        File.Delete(targetFile);
                    }
                    string outFolder = targetFile.Substring(0, targetFile.LastIndexOf("\\"));
                    if (!Directory.Exists(outFolder))
                    {
                        Directory.CreateDirectory(outFolder);
                    }
                    File.Copy(sourceFile, targetFile);
                    if (formEntity.GainClass)
                    {
                        //如果获取class,则copy所有内部类
                        List <string> filePaths = GetFilesByPath(sourceFile);
                        foreach (string fpath in filePaths)
                        {
                            targetFile = targetFile.Substring(0, targetFile.LastIndexOf("\\")) + fpath.Substring(fpath.LastIndexOf("\\"));
                            if (File.Exists(targetFile))
                            {
                                File.Delete(targetFile);
                            }
                            File.Copy(fpath, targetFile);
                        }
                    }
                    i++;
                }
                catch (OverflowException e)
                {
                    print("txt文件内容有误!!");
                    //throw e;
                    //MessageBox.Show(e.StackTrace);
                    sw.Close();
                    fs.Close();
                    return(false);
                }
            }
            sw.Close();
            fs.Close();
            if (i < 1)
            {
                print("没有可拷贝的文件");
                boo = false;
            }

            return(boo);
        }