public override string Execute(params string[] args) { FileInfo npdmFile = new FileInfo(GetValue <string>(args, 0, "npdmFilePath")); string descFilePath = GetValue <string>(args, 1); FileInfo descFile = new FileInfo(string.IsNullOrEmpty(descFilePath) ? Path.ChangeExtension(npdmFile.FullName, ".desc") : descFilePath); if (!npdmFile.Exists) { throw new CommandException("Npdm Not Found"); } if (!descFile.Exists && Directory.Exists(descFile.FullName) && descFile.Attributes.HasFlag(FileAttributes.Directory)) { descFile = new FileInfo(Path.Combine(descFile.FullName, Path.ChangeExtension(npdmFile.Name, ".desc"))); } try { DescModel desc = DescModel.FromNpdm(npdmFile.FullName).Result; File.WriteAllText(descFile.FullName, desc.XMLSerialize()); } catch (Exception ex) { throw new CommandException(ex.Message); } return($"Done {descFile.FullName}"); }
public override string Execute(params string[] args) { FileInfo descFile = new FileInfo(GetValue <string>(args, 0, "descFile")); string metaFilePath = GetValue <string>(args, 1); if (!descFile.Exists) { throw new CommandException("Desc Not Found"); } try { DescModel desc = DescModel.FromXml(descFile.FullName); MetaModel meta = (File.Exists(metaFilePath)) ? MetaModel.FromXml(metaFilePath) : null; desc.Acid = Convert.ToBase64String(NpdmGenerator.GetAcidBytes(desc, meta)); File.WriteAllText(descFile.FullName, desc.XMLSerialize()); } catch (Exception ex) { throw new CommandException(ex.Message); } return($"Done {descFile.FullName}"); }
private async void MB_NpdmToDesc_Click(object sender, EventArgs e) { using (OpenFileDialog oFD = new OpenFileDialog { Filter = "NPDM files|*.npdm", RestoreDirectory = true }) { if (oFD.ShowDialog() == DialogResult.OK) { FileInfo inputFile = new FileInfo(oFD.FileName); if (inputFile.Extension == ".npdm") { DescModel desc = await DescModel.FromNpdm(oFD.FileName); using (SaveFileDialog sFD = new SaveFileDialog { Filter = "DESC files|*.desc|All Files|*.*", RestoreDirectory = true, FileName = Path.ChangeExtension(inputFile.FullName, ".desc") }) { if (sFD.ShowDialog() == DialogResult.OK) { File.WriteAllText(sFD.FileName, desc.XMLSerialize()); } } } else { MessageBox.Show("The file format is not yet supported"); } } } }