private void cmiAddExistingPult_Click(object sender, EventArgs e) { ControllerProgramSolution solution = ((ControllerProgramSolutionTreeNode)this.tvSolutionExplorer.SelectedNode).Solution; this.openFileDialog1.Filter = "Файлы пультов (*.fpr, *.plt)|*.fpr;*.plt|Все файлы|*.*"; if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { string FileName = this.openFileDialog1.FileName.Replace(".fpr", "").Replace(".plt", "").Replace(".bak", "bak") + ".plt"; if (File.Exists(solution.DirectoryName + "\\" + Path.GetFileName(FileName)) && Path.GetDirectoryName(FileName) != solution.DirectoryName && Utils.QuestionMessage("Файл \"" + Path.GetFileName(FileName) + "\" уже существует в каталоге проекта. Перезаписать ?", "Relkon") != DialogResult.Yes) { return; } try { RelkonPultModel pult = RelkonPultModel.FromFile(this.openFileDialog1.FileName); pult.Save(FileName); this.AddFileToRelkonSolution((ControllerProgramSolutionTreeNode)this.tvSolutionExplorer.SelectedNode, FileName); } catch (Exception ex) { Utils.ErrorMessage(ex.Message); } } }
/// <summary> /// Загружает настройки проекта из указанного файла пультов /// </summary> //private void LoadParamsToSolutionFromPult(ControllerProgramSolution solution, string FileName) //{ // PultFileVersion version = RelkonPultModel.GetPultFileVersion(FileName); // switch (version) // { // case PultFileVersion.v37: // this.LoadParamsToSolutionFromPlt37(solution, FileName); // break; // } // solution.ComputeMultibyteEmbeddedVarsValues(); //} /// <summary> /// Загружает настройки в проект из fpr-файла /// </summary> //private void LoadParamsToSolutionFromFpr(AT89C51ED2Solution solution, string FileName) //{ // solution.Vars.EmbeddedVars.Clear(); // solution.Vars.EmbeddedVars.AddRange(RelkonPultModel.GetEmbeddedVarsFromFpr(FileName)); // using (StreamReader reader = new StreamReader(FileName, Encoding.Default)) // { // solution.BaudRate = int.Parse(reader.ReadLine()); //считывание скорости // solution.Protocol = reader.ReadLine() == "1" ? ProtocolType.RC51BIN : ProtocolType.RC51ASCII; // solution.ReadPassword = reader.ReadLine(); //пароль на чтение // solution.WritePassword = reader.ReadLine(); //пароль на запись // } //} /// <summary> /// Загружает настройки в проект из plt-файла версии 3.7 /// </summary> //private void LoadParamsToSolutionFromPlt37(ControllerProgramSolution solution, string FileName) //{ // solution.Vars.EmbeddedVars.Clear(); // solution.Vars.EmbeddedVars.AddRange(RelkonPultModel.GetEmbeddedVarsFromPlt37(FileName)); // if (File.ReadAllText(FileName).Contains("Fujitsu")) // this.LoadParamsToMB90F347SolutionFromPlt37((MB90F347Solution)solution, FileName); // else // this.LoadParamsToAT89C51ED2SolutionFromPlt37((AT89C51ED2Solution)solution, FileName); //} /// <summary> /// Загружает настройки в проект AT89C51ED2 из plt-файла версии 3.7 /// </summary> //private void LoadParamsToAT89C51ED2SolutionFromPlt37(AT89C51ED2Solution solution, string FileName) //{ // XPathDocument xpDoc = new XPathDocument(FileName); // XPathNavigator xpNav = ((IXPathNavigable)xpDoc).CreateNavigator(); // XPathNodeIterator xpList = xpNav.Select("/fpultProject"); // xpList.MoveNext(); // solution.ControllerAddress = int.Parse(xpList.Current.GetAttribute("number", "")); // solution.Protocol = (xpList.Current.GetAttribute("protocol", "") == "RC51BIN") ? ProtocolType.RC51BIN : ProtocolType.RC51ASCII; // solution.ReadPassword = xpList.Current.GetAttribute("readPass", ""); // solution.WritePassword = xpList.Current.GetAttribute("writePass", ""); // solution.BaudRate = int.Parse(xpList.Current.GetAttribute("speed", "")); //} /// <summary> /// Загружает настройки в проект MB90F347 из plt-файла версии 3.7 /// </summary> //private void LoadParamsToMB90F347SolutionFromPlt37(MB90F347Solution solution, string FileName) //{ // XPathDocument xpDoc = new XPathDocument(FileName); // XPathNavigator xpNav = ((IXPathNavigable)xpDoc).CreateNavigator(); // XPathNodeIterator xpList = xpNav.Select("/fpultProject"); // xpList.MoveNext(); // solution.ControllerAddress = int.Parse(xpList.Current.GetAttribute("number", "")); // XPathNodeIterator xpPortOptions = xpNav.Select("/fpultProject/portOptions"); // int index = 0; // while (xpPortOptions.MoveNext()) // { // if (int.Parse(xpPortOptions.Current.GetAttribute("index", "")) == 1) // continue; // solution.Uarts[index].ReadPassword = xpPortOptions.Current.GetAttribute("readPassword", ""); // solution.Uarts[index].WritePassword = xpPortOptions.Current.GetAttribute("writePassword", ""); // solution.Uarts[index].ParseParametersByte(byte.Parse(xpPortOptions.Current.GetAttribute("parameters", ""))); // int start = int.Parse(xpPortOptions.Current.GetAttribute("rxStart", "")); // int end = int.Parse(xpPortOptions.Current.GetAttribute("rxEnd", "")); // solution.Uarts[index].BufferSize = end - start + 1; // start = int.Parse(xpPortOptions.Current.GetAttribute("txStart", "")); // end = int.Parse(xpPortOptions.Current.GetAttribute("txEnd", "")); // solution.Uarts[index].BufferSize = end - start + 1; // index++; // } // XPathNodeIterator xpConnectionSettings = xpNav.Select("/fpultProject/connectionSettings"); // while (xpConnectionSettings.MoveNext()) // { // solution.SearchedControllerAddress = int.Parse(xpConnectionSettings.Current.GetAttribute("searchingControllerAddress", "")); // solution.DispatcherPhone1 = xpConnectionSettings.Current.GetAttribute("modemPhone1", ""); // solution.DispatcherPhone1 = xpConnectionSettings.Current.GetAttribute("modemPhone2", ""); // solution.DispatcherPhone1 = xpConnectionSettings.Current.GetAttribute("modemPhone3", ""); // solution.SmsPhone1 = xpConnectionSettings.Current.GetAttribute("smsPhone1", ""); // solution.SmsPhone1 = xpConnectionSettings.Current.GetAttribute("smsPhone2", ""); // solution.SmsPhone1 = xpConnectionSettings.Current.GetAttribute("smsPhone3", ""); // solution.ModemInitializationString = xpConnectionSettings.Current.GetAttribute("modemInitString", ""); // solution.DenyProgrammingThrowProtocol = bool.Parse(xpConnectionSettings.Current.GetAttribute("denyProgramming", "")); // } //} /// <summary> /// На основании указаных файла программы и файла пультов создает новый проект /// </summary> /// <param name="ProgramFileName">Имя файла программы</param> /// <param name="PultFileName">Имя файла пультов</param> /// <param name="DirectoryName">Имя каталога, в котором должен быть создан проект</param> /// <param name="CreateDirectoryForSolution"> /// Если true, то в каталоге DirectoryName будет создан каталог для проекта, /// причем имя каталога будет именем файла пультов /// </param> private ControllerProgramSolution CreateSolution(string ProgramFileName, string PultFileName, bool CreateDirectoryForSolution) { ControllerProgramSolution res = File.ReadAllText(ProgramFileName).Contains("f347") ? ControllerProgramSolution.Create(ProcessorType.MB90F347) : ControllerProgramSolution.Create(ProcessorType.AT89C51ED2); RelkonPultModel pult = RelkonPultModel.FromFile(PultFileName); if (Array.IndexOf(res.PultParams.AvailablePultTypes, pult.Type) == -1) { throw new Exception("Тип пульта файла " + Path.GetFileName(PultFileName) + " не совместим с типом процессора программы " + Path.GetFileName(ProgramFileName)); } string SolutionDirectoryName = Path.GetDirectoryName(this.tbProgramFileName.Text) + (CreateDirectoryForSolution ? "\\" + Path.GetFileNameWithoutExtension(PultFileName) : ""); if (CreateDirectoryForSolution && !Directory.Exists(SolutionDirectoryName)) { Directory.CreateDirectory(SolutionDirectoryName); } //this.LoadParamsToSolutionFromPult(res, PultFileName); string SolutionProgramFileName = SolutionDirectoryName + "\\" + Path.GetFileNameWithoutExtension(ProgramFileName) + ".kon"; string SolutionPultFileName = SolutionDirectoryName + "\\" + Path.GetFileNameWithoutExtension(PultFileName) + ".plt"; File.Copy(ProgramFileName, SolutionProgramFileName); // Удаление из файла строки с типом процессора string[] s = File.ReadAllLines(SolutionProgramFileName, Encoding.Default); if (s.Length > 1 && (s[1].Contains("f347") || s[1].ToLower().Contains("тип контроллера"))) { s[1] = ""; } File.WriteAllLines(SolutionProgramFileName, s, Encoding.Default); /////////////////////////////////////////////// pult.Save(SolutionPultFileName); res.ProgramFileName = SolutionProgramFileName; res.PultFileName = SolutionPultFileName; res.Files.Add(SolutionProgramFileName); res.Files.Add(SolutionPultFileName); res.OpenedFiles.Add(SolutionProgramFileName); res.OpenedFiles.Add(SolutionPultFileName); res.SaveAs(SolutionDirectoryName + "\\" + Path.GetFileNameWithoutExtension(ProgramFileName) + ".rp6"); return(res); }