/// <summary>
        /// 创建文件夹
        /// (创建:[项目文件夹]、[Bug文件夹]、[记录文件夹]、[图片文件夹]、[备份文件夹])
        /// </summary>
        /// <param name="_saveFolderPath">保存文件夹的路径</param>
        /// <param name="_toolType">工具的类型</param>
        /// <returns>项目文件夹的路径</returns>
        public string CreateFolders(string _saveFolderPath, ToolType _toolType = ToolType.Convert)
        {
            /* 判断[项目]文件夹是否存在,不存在就创建 */
            DirectoryInfo _directoryInfo = new DirectoryInfo(_saveFolderPath);//文件夹的信息

            if (_directoryInfo.Exists == false)
            {
                _directoryInfo.Create();
            }


            /* 创建文件和文件夹 */
            //创建[项目]文件夹(XXXXX/Convert - 202002041325/)
            DirectoryInfo _projectDirectoryInfo = new DirectoryInfo(_saveFolderPath + "/" + _toolType.ToString() + " - " + DateTimeTool.DateTimeToString(DateTime.Now, TimeFormatType.YearMonthDayHourMinuteSecondMillisecond));

            if (_projectDirectoryInfo.Exists == false)
            {
                _projectDirectoryInfo.Create();
            }

            //创建bug文件夹(_projectFolderPath/Bug/)
            DirectoryInfo _bugDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Bug");

            if (_bugDirectoryInfo.Exists == false)
            {
                _bugDirectoryInfo.Create();
            }

            //创建[Record]文件夹(_projectFolderPath/Record/)
            DirectoryInfo _recordDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Record");

            if (_recordDirectoryInfo.Exists == false)
            {
                _recordDirectoryInfo.Create();
            }

            //创建[Image]文件夹(_projectFolderPath/Image/)
            DirectoryInfo _imageDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Image");

            if (_imageDirectoryInfo.Exists == false)
            {
                _imageDirectoryInfo.Create();
            }

            //创建[Backup]文件夹(_projectFolderPath/Backup/)
            DirectoryInfo _backupDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Backup");

            if (_backupDirectoryInfo.Exists == false)
            {
                _backupDirectoryInfo.Create();
            }



            /*创建[Backup]文件夹(_projectFolderPath/Backup/)*/
            DirectoryInfo _projectBackupDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Backup/Project");

            //如果没有文件夹,就创建文件夹
            if (_projectBackupDirectoryInfo.Exists == false)
            {
                _projectBackupDirectoryInfo.Create();
            }

            /*创建[Backup/Bug]文件夹(_projectFolderPath/Backup/Bug/)*/
            DirectoryInfo _bugBackupDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Backup/Bug");

            //如果没有文件夹,就创建文件夹
            if (_bugBackupDirectoryInfo.Exists == false)
            {
                _bugBackupDirectoryInfo.Create();
            }

            /*创建[Backup/Record]文件夹(_projectFolderPath/Backup/Record/)*/
            DirectoryInfo _recordBackupDirectoryInfo = new DirectoryInfo(_projectDirectoryInfo + "/Backup/Record");

            //如果没有文件夹,就创建文件夹
            if (_recordBackupDirectoryInfo.Exists == false)
            {
                _recordBackupDirectoryInfo.Create();
            }



            return(_projectDirectoryInfo.FullName);
        }
Example #2
0
        /// <summary>
        /// 修复项目
        /// </summary>
        /// <param name="_projectFilePath">项目文件的路径</param>
        /// <param name="_saveFolderPath">保存文件夹的路径</param>
        /// <returns>转换后的文件夹</returns>
        public string Repair(string _projectFilePath, string _saveFolderPath)
        {
            try
            {
                /* 读取所有的Backup文件 */
                List <ProjectBaseData>  _projectFileDatas; //项目文件的路径
                List <BugBaseData[]>    _bugFileDatas;     //读取到的项目数据
                List <RecordBaseData[]> _recordFileDatas;  //读取到的Record数据
                LoadData(_projectFilePath, out _projectFileDatas, out _bugFileDatas, out _recordFileDatas);



                /* 修复数据 */
                //修复的数据
                ProjectBaseData       _projectBaseData = null;                        //修复的Project
                List <BugBaseData>    _bugBaseDatas    = new List <BugBaseData>();    //修复的Bug
                List <RecordBaseData> _recordBaseDatas = new List <RecordBaseData>(); //修复的Record


                /* 修复Project数据 */
                //从最后一个开始
                for (int i = _projectFileDatas.Count - 1; i >= 0; i--)
                {
                    //进行验证
                    bool _isVerifyOk = VerifyProjectIntegrity(_projectFileDatas[i]);

                    //如果验证成功
                    if (_isVerifyOk == true)
                    {
                        _projectBaseData = _projectFileDatas[i];
                        break;
                    }
                }



                /* 修复Bug数据 */
                List <BugBaseData> _allBugBaseDatas = new List <BugBaseData>();

                //从最后一个开始
                for (int i = _bugFileDatas.Count - 1; i >= 0; i--)
                {
                    if (_bugFileDatas[i] != null)
                    {
                        //从后到前,保存所有的数据
                        for (int j = 0; j < _bugFileDatas[i].Length; j++)
                        {
                            _allBugBaseDatas.Add(_bugFileDatas[i][j]);
                        }
                    }
                }

                //遍历所有的数据
                Dictionary <long, BugBaseData> _repairBugBaseDatas = new Dictionary <long, BugBaseData>();//所有修复好的数据
                for (int i = 0; i < _allBugBaseDatas.Count; i++)
                {
                    if (_allBugBaseDatas[i] != null)
                    {
                        BugBaseData _bugBaseData = null;
                        bool        _isHave      = _repairBugBaseDatas.TryGetValue(_allBugBaseDatas[i].Id, out _bugBaseData);

                        //如果这个Bug还不存在
                        if (_isHave == false)
                        {
                            //验证Bug的完整性
                            if (VerifyBugIntegrity(_allBugBaseDatas[i]) == true)
                            {
                                //加入到字典中
                                _repairBugBaseDatas.Add(_allBugBaseDatas[i].Id, _allBugBaseDatas[i]);
                            }
                        }
                    }
                }

                //把修复的数据加到列表中
                foreach (BugBaseData _bugBaseData in _repairBugBaseDatas.Values)
                {
                    _bugBaseDatas.Add(_bugBaseData);
                }



                /* 修复Record数据 */
                List <RecordBaseData> _allRecordBaseDatas = new List <RecordBaseData>();

                //从最后一个开始
                for (int i = _recordFileDatas.Count - 1; i >= 0; i--)
                {
                    if (_recordFileDatas[i] != null)
                    {
                        //从后到前,保存所有的数据
                        for (int j = 0; j < _recordFileDatas[i].Length; j++)
                        {
                            _allRecordBaseDatas.Add(_recordFileDatas[i][j]);
                        }
                    }
                }

                //遍历所有的数据
                Dictionary <long, RecordBaseData> _repairRecordBaseDatas = new Dictionary <long, RecordBaseData>();//所有修复好的数据
                for (int i = 0; i < _allRecordBaseDatas.Count; i++)
                {
                    if (_allRecordBaseDatas[i] != null)
                    {
                        RecordBaseData _recordBaseData = null;
                        bool           _isHave         = _repairRecordBaseDatas.TryGetValue(_allRecordBaseDatas[i].Id, out _recordBaseData);

                        //如果这个Record还不存在
                        if (_isHave == false)
                        {
                            //验证Record的完整性
                            if (VerifyRecordIntegrity(_allRecordBaseDatas[i]) == true)
                            {
                                //加入到字典中
                                _repairRecordBaseDatas.Add(_allRecordBaseDatas[i].Id, _allRecordBaseDatas[i]);
                            }
                        }
                    }
                }

                //把修复的数据加到列表中
                foreach (RecordBaseData _recordBaseData in _repairRecordBaseDatas.Values)
                {
                    _recordBaseDatas.Add(_recordBaseData);
                }



                /* 创建文件夹 */
                string _newProjectFolderPath = AppManager.Systems.ConvertSystem.CreateFolders(_saveFolderPath, ToolType.Repair);
                string _oldProjectFolderPath = new FileInfo(_projectFilePath).DirectoryName;

                /* 保存数据 */
                //如果没有项目
                if (_projectBaseData == null)
                {
                    _projectBaseData          = new ProjectBaseData();
                    _projectBaseData.ModeType = 1;
                    _projectBaseData.Id       = DateTimeTool.DateTimeToLong(DateTime.UtcNow, TimeFormatType.YearMonthDayHourMinuteSecondMillisecond);
                    _projectBaseData.Name     = " ";

                    //尝试给Project附上名字
                    FileInfo _oldProjectFileInfo = new FileInfo(_projectFilePath);
                    if (_oldProjectFileInfo.Exists == true)
                    {
                        _projectBaseData.Name = Path.GetFileNameWithoutExtension(_oldProjectFileInfo.FullName);
                    }
                }
                //保存数据
                AppManager.Systems.ConvertSystem.SaveData(_oldProjectFolderPath, _newProjectFolderPath, (ModeType)_projectBaseData.ModeType,
                                                          _projectBaseData, _bugBaseDatas, _recordBaseDatas);


                //返回值
                return(_newProjectFolderPath);
            }
            catch (Exception e)
            {
                return("");
            }
        }