/// <summary> /// 修改 CPU 使用的文件名称。 /// </summary> /// <param name="oldName">旧的文件名称。</param> /// <param name="newName">新的文件名称。</param> /// <returns>成功与否?</returns> public bool RenameFile(string oldName, string newName) { if (string.IsNullOrEmpty(oldName) || string.IsNullOrEmpty(newName)) { return(false); } if (!IsFileExist(oldName)) { return(false); } string oldKey = PCSFile.GetFileKey(oldName); string newKey = PCSFile.GetFileKey(newName); if (oldKey != newKey && IsFileExist(newName)) { return(false); } CPUFileType fileType = this.DTypes[oldKey]; string oldFile = this.DFiles[oldKey].File; PCSFile pcsFile = this.Project.GetPCSFile(newName); if (pcsFile == null && fileType != CPUFileType.TASKS) { pcsFile = new PCSFile(FileType.Variable, newName); } if (pcsFile == null) { return(false); } if (oldKey != newKey) { this.DFiles.Remove(oldKey); this.DTypes.Remove(oldKey); if (fileType == CPUFileType.TASKS) { this.DTasks.Remove(oldKey); } } if (fileType == CPUFileType.TASKS) { this.DTasks[pcsFile.Key] = new ViGETResTask(ResourceType.kCrdTuiTaskNode, pcsFile.Key, pcsFile.Key); } this.DFiles[pcsFile.Key] = pcsFile; this.DTypes[pcsFile.Key] = fileType; // this.UnloadPCDInfo(); ViGETVarFile.RenameFileInfo(new IniFile(this.MakeFile), fileType.ToString(), ViGETVarFile.GetSaveFileName(oldFile, this.Project.ProjectPath, false), ViGETVarFile.GetSaveFileName(pcsFile.File, this.Project.ProjectPath, false)); return(true); }
public virtual void Rename(string makFile) { this.CrdPath = PCSFile.GetFileKey(makFile); this.MakeFile = makFile; this.PCDFile = string.Format(@"{0}{1}\{1}.PCD", this.Project.ProjectGenPath, this.CrdPath); this.Name = makFile; this.ShownText = this.CrdPath; }
/// <summary> /// 构建对象。 /// </summary> /// <param name="project">CPU 所属的工程。</param> /// <param name="makFile">CPU 对应的 Makefile。</param> public ViGETCPUInfo(IViGETProjectInfo project, string makFile) { this.Type = ResourceType.kCrdExeNode; this.CrdPath = PCSFile.GetFileKey(makFile); this.Project = project; this.MakeFile = makFile; this.Name = makFile; this.Stage = CPUDataStage.Empty; this.LoadMakInfo(makFile); }
/// <summary> /// CPU 的文件是否包含指定的 TASK? /// </summary> /// <param name="task">TASK 名称。</param> /// <returns>是否包含?</returns> public bool IsTaskExist(string task) { if (string.IsNullOrEmpty(task)) { return(false); } //// make sure data is to stable stage //ToStableStage(); task = PCSFile.GetFileKey(task); return(DFiles.ContainsKey(task)); }
/// <summary> /// 文件发生改变时由外部调用。 /// </summary> /// <param name="file">发生改变的文件全路径名称。</param> public void OnFileChanged(string file) { if (Stage == CPUDataStage.Base) { return; } if (file.Equals(this.PCDFile) || file.Equals(this.MakeFile) || file.Equals(this.SettingFile) || this.DFiles.ContainsKey(PCSFile.GetFileKey(file))) { Stage = CPUDataStage.Base; UnloadPCDInfo(); } }
/// <summary> /// 指定文件在 CPU 中是否被使用? /// </summary> /// <param name="file">可以为文件名称、关键字,或者 PCSFile 对象。</param> /// <returns>指定文件在 CPU 中是否被使用?</returns> public bool IsFileExist(object file) { if (file == null) { return(false); } string key = null; if (file is PCSFile) { key = (file as PCSFile).Key; } else { key = PCSFile.GetFileKey(file.ToString()); } return(this.DFiles.ContainsKey(key)); }
/// <summary> /// 删除 CPU 使用的文件。 /// </summary> /// <param name="fileName">文件名称。</param> /// <returns>成功与否?</returns> public bool DeleteFile(string fileName) { if (!IsFileExist(fileName)) { return(false); } string fileKey = PCSFile.GetFileKey(fileName); fileName = this.DFiles[fileKey].File; CPUFileType fileType = this.DTypes[fileKey]; // this.DFiles.Remove(fileKey); this.DTypes.Remove(fileKey); this.DTasks.Remove(fileKey); // this.UnloadPCDInfo(); ViGETVarFile.DeleteFileInfo(new IniFile(this.MakeFile), fileType.ToString(), ViGETVarFile.GetSaveFileName(fileName, this.Project.ProjectPath, false)); return(true); }
protected void LoadMakInfo(string makFile) { IniFile iniFile = new IniFile(makFile); this.Stage = CPUDataStage.Base; this.ShownText = iniFile.GetValue(makSection, "SHOWNTEXT", PCSFile.GetFileKey(this.MakeFile)); this._station = iniFile.GetValue(makSection, "STATION", ""); this._hardware = iniFile.GetValue(makSection, "HARDWARE", ""); this._connection = iniFile.GetValue(makSection, "CONNECTION", ""); this.PCDFile = string.Format(@"{0}{1}\{1}.PCD", this.Project.ProjectGenPath, this.CrdPath); this.DFiles.Clear(); this.DTypes.Clear(); this.DTasks.Clear(); this.DCVariables.Clear(); if (this._DSVariables != null) { this._DSVariables.Clear(); } CPUFileType fileType = CPUFileType.TASKS; PCSFile pcsFile; ViGETResTask task; iniFile.LoopSections( (section) => { if (section.Equals("TASKS", StringComparison.OrdinalIgnoreCase)) { fileType = CPUFileType.TASKS; } else if (section.Equals("GLOBAL", StringComparison.OrdinalIgnoreCase)) { fileType = CPUFileType.GLOBAL; } else if (section.Equals("DIRECT_GLOBAL", StringComparison.OrdinalIgnoreCase)) { fileType = CPUFileType.DIRECT_GLOBAL; } else if (section.Equals("PIV_FILES", StringComparison.OrdinalIgnoreCase)) { fileType = CPUFileType.PIV_FILES; } else { return(false); } return(true); }, (key, value) => { if (key.IsPrefixIndex("FILE") && !string.IsNullOrEmpty(value)) { if (fileType != CPUFileType.TASKS) { pcsFile = new PCSFile(FileType.Variable, ViGETVarFile.GetFullFileName(value, this.Project.ProjectPath, ".POE")); } else { pcsFile = this.Project.GetPCSFile(value); } if (pcsFile != null) { key = PCSFile.GetFileKey(value); if (fileType == CPUFileType.TASKS) { task = new ViGETResTask(ResourceType.kCrdTuiTaskNode, key, key); task.File = pcsFile.File; this.DTasks[key] = task; } // this.DFiles[key] = pcsFile; this.DTypes[key] = fileType; } } return(true); }); }