private void on_form_show(object sender, EventArgs e) { if ((null != m_target) && (null != m_desc)) { m_new_options = m_desc.create_options(); l_file_name.Text = Path.GetFileName(m_target.path); int opt_panel_width = p_options_panel.Width - (System.Windows.Forms.SystemInformation.VerticalScrollBarWidth + 2); int opt_panel_top = 1; int opt_panel_hwidth = (opt_panel_width - 4) / 2; for (int id = 0; m_desc.count > id; id++) { conv_core.cOptionDesc op_desc = m_desc[id]; int op_id = op_desc.id; int val = op_desc.def_value; if (null != m_target.options) { val = m_target.options[op_id].value; } ; m_new_options[op_id].value = val; Panel p = new Panel(); p.Location = new Point(1, opt_panel_top); p.Size = new Size(opt_panel_width, 25); p.BorderStyle = BorderStyle.FixedSingle; opt_panel_top += 28; Label l = new Label(); l.AutoSize = false; l.Location = new Point(1, 1); l.Size = new Size(opt_panel_hwidth, 21); l.TextAlign = ContentAlignment.MiddleRight; l.Text = op_desc.name + " :"; p.Controls.Add(l); p_options_panel.Controls.Add(p); switch (op_desc.type) { case conv_core.OptionType.BOOL: { CheckBox ch = new CheckBox(); ch.Location = new Point(opt_panel_hwidth + 2, 1); ch.Size = new Size(opt_panel_hwidth, 21); ch.Text = ""; ch.Checked = 1 == val; ch.Tag = m_new_options[op_id]; ch.CheckedChanged += on_checkbox; p.Controls.Add(ch); } break; case conv_core.OptionType.ENUM: { ComboBox cb = new ComboBox(); cb.Location = new Point(opt_panel_hwidth + 2, 1); cb.Size = new Size(opt_panel_hwidth, 21); if (0 < op_desc.names.Count) { foreach (string n in op_desc.names) { cb.Items.Add(n); } ; cb.DropDownStyle = ComboBoxStyle.DropDownList; cb.SelectedIndex = ((0 <= val) && (cb.Items.Count > val))? val : 0; } ; cb.Tag = m_new_options[op_id]; cb.SelectedIndexChanged += on_combobox; p.Controls.Add(cb); } break; case conv_core.OptionType.SINT: case conv_core.OptionType.UINT: { NumericUpDown se = new NumericUpDown(); se.Location = new Point(opt_panel_hwidth + 2, 1); se.Size = new Size(opt_panel_hwidth, 21); se.Minimum = op_desc.min_value; se.Maximum = op_desc.max_value; se.Value = val; se.Tag = m_new_options[op_id]; se.ValueChanged += on_numedit; p.Controls.Add(se); } break; case conv_core.OptionType.STRING: { TextBox tb = new TextBox(); tb.Location = new Point(opt_panel_hwidth + 2, 1); tb.Size = new Size(opt_panel_hwidth, 21); tb.MaxLength = op_desc.max_value; tb.Tag = m_new_options[op_id]; tb.TextChanged += on_textbox; if (null != m_target.options) { m_new_options[op_id].value_str = m_target.options[op_id].value_str; } ; tb.Text = m_new_options[op_id].value_str; p.Controls.Add(tb); } break; } ; } ; } ; }
public static bool save(string path, MainForm form) { try{ XmlDocument file = new XmlDocument(); string base_dir = form.t_base_dir.Text; if ('\\' == base_dir.Last()) { base_dir = base_dir.Remove(base_dir.Length - 1); } ; XmlElement prj = file.AppendChild(file.CreateElement("project")) as XmlElement; prj.SetAttribute("destination", base_dir); base_dir += '\\'; XmlElement formats = prj.AppendChild(file.CreateElement("formats")) as XmlElement; foreach (ColumnHeader hdr in form.m_formats) { XmlElement format = formats.AppendChild(file.CreateElement("format")) as XmlElement; format.SetAttribute("name", hdr.Text); } ; XmlElement files = prj.AppendChild(file.CreateElement("files")) as XmlElement; foreach (ListViewItem li in form.lv_files.Items) { conv_core.cImageFile fid = li.Tag as conv_core.cImageFile; XmlElement fd = files.AppendChild(file.CreateElement("file")) as XmlElement; fd.SetAttribute("file.path", fid.path); fd.SetAttribute("file.enabled", Convert.ToString(fid.enabled)); fd.SetAttribute("file.format", Convert.ToString(null != fid.options)); fd.SetAttribute("file.crc", Convert.ToString(fid.crc)); if (null != fid.options) { for (int op_id = 0; fid.options.desc.count > op_id; op_id++) { conv_core.cOptionDesc desc = fid.options.desc[op_id]; switch (desc.type) { case conv_core.OptionType.STRING: fd.SetAttribute("format." + desc.name, fid.options[desc.id].value_str); break; default: fd.SetAttribute("format." + desc.name, Convert.ToString(fid.options[desc.id].value)); break; } ; } ; } ; foreach (ColumnHeader hdr in form.m_formats) { ListViewItem.ListViewSubItem lsi = li.SubItems[hdr.Index]; conv_core.cImageFile img = lsi.Tag as conv_core.cImageFile; XmlElement conv = fd.AppendChild(file.CreateElement("convert")) as XmlElement; string conv_name = conv_core.workbench.relative_path(base_dir, img.path); while (('.' == conv_name[0]) || ('\\' == conv_name[0])) { conv_name = conv_name.Remove(0, 1); } ; conv.SetAttribute("format", hdr.Text); conv.SetAttribute("destination", conv_name); conv.SetAttribute("enabled", Convert.ToString(img.enabled)); if (null != img.options) { for (int op_id = 0; img.options.desc.count > op_id; op_id++) { conv_core.cOptionDesc desc = img.options.desc[op_id]; string op_name = desc.name; XmlElement opt = conv.AppendChild(file.CreateElement("property")) as XmlElement; opt.SetAttribute("name", op_name); switch (desc.type) { case conv_core.OptionType.STRING: opt.SetAttribute("value", img.options[op_name].value_str); break; default: opt.SetAttribute("value", Convert.ToString(img.options[op_name].value)); break; } ; } ; } ; } ; } ; file.Save(path); }catch (Exception) { return(false); }; return(true); }