Exemple #1
0
        /// <summary>
        /// 复制更新文件并签出编辑
        /// </summary>
        private bool CopyUpdateFile(TFSHelper tfsHelper)
        {
            //复制文件
            List <FileInfo> removeFiles      = new List <FileInfo>();
            List <FileInfo> undoFiles        = new List <FileInfo>();
            decimal         progressAddValue = 10M / this._updateFiles.Count;

            foreach (var updateFile in this._updateFiles)
            {
                progressValue += progressAddValue;
                this.worker.ReportProgress((int)progressValue, "开始复制文件" + updateFile.Name + ",请稍后.....");
                var directoryName = updateFile.DirectoryName.Replace(rootProductPath + "\\", "");
                if (directoryName.Contains(rootProductPath))
                {
                    directoryName = updateFile.DirectoryName.Replace(rootProductPath, "");
                }
                var fileName = Path.Combine(customizePath, directoryName, updateFile.Name);

                if (File.Exists(fileName))
                {
                    FileInfo fi = new FileInfo(fileName);
                    //修改文件只读
                    if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        fi.Attributes = FileAttributes.Normal;
                    }
                    //如果相同文件没有修改过
                    if (MD5Helper.CompareFile(updateFile.FullName, fileName) && _addFiles.FirstOrDefault(n => n == updateFile) == null)
                    {
                        removeFiles.Add(updateFile);
                        //撤销签出编辑
                        undoFiles.Add(new FileInfo(fileName));
                        JoeyLog.Logging.WriteLog("撤销签出编辑文件:" + fileName);
                        continue;
                    }
                }
                try
                {
                    File.Copy(updateFile.FullName, fileName, true);
                    JoeyLog.Logging.WriteLog("复制编辑签出文件:" + fileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return(false);
                }
            }
            if (undoFiles.Count > 0)
            {
                tfsHelper.Undo(undoFiles);
                foreach (var item in removeFiles)
                {
                    this._updateFiles.Remove(item);
                }
            }
            this.worker.ReportProgress(100, "完成");
            return(true);
        }