Пример #1
0
 private void saveTo_Click(object sender, EventArgs e)
 {
     try
     {
         Template template = new Template();
         template.TemplateName      = templateName.Text;
         template.UsingImage        = usingImage.Checked;
         template.UseDeviceName     = useDeviceName.Checked;
         template.LoopAnimation     = loop.Checked;
         template.AssetLocation     = assetLocation.Text;
         template.DefaultDeviceName = defaultName.Text;
         template.ButtonText        = buttonText.Text;
         template.WindowBackground  = HexConverter(windowBackground.BackColor);
         template.WindowForeground  = HexConverter(windowForeground.BackColor);
         template.ButtonBackground  = HexConverter(buttonBackground.BackColor);
         template.ButtonForeground  = HexConverter(buttonForeground.BackColor);
         template.Tint = HexConverter(tint.BackColor);
         string result = Serialize1.ToJson(template);
         using (StreamWriter sw = new StreamWriter(mfm.TemplateLocations[templateList.SelectedIndex]))
             sw.WriteLine(result);
         refreshTemplates_Click(null, null);
     }
     catch (Exception ee)
     {
         MessageBox.Show("Unable to save template", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #2
0
        private async void save_Click(object sender, EventArgs e)
        {
            Template template = new Template();

            template.TemplateName      = templateName.Text;
            template.UsingImage        = usingImage.Checked;
            template.UseDeviceName     = useDeviceName.Checked;
            template.LoopAnimation     = loop.Checked;
            template.AssetLocation     = assetLocation.Text;
            template.DefaultDeviceName = defaultName.Text;
            template.ButtonText        = buttonText.Text;
            template.WindowBackground  = HexConverter(windowBackground.BackColor);
            template.WindowForeground  = HexConverter(windowForeground.BackColor);
            template.ButtonBackground  = HexConverter(buttonBackground.BackColor);
            template.ButtonForeground  = HexConverter(buttonForeground.BackColor);
            template.Tint = HexConverter(tint.BackColor);
            string result = Serialize1.ToJson(template);

            string path = mfm.CombinePaths(mfm.appDocs, "Templates\\" + RemoveIllegalCharacters(template.TemplateName) + ".json");

            string fileName = Save.NextAvailableFilename(path);

            using (StreamWriter sw = new StreamWriter(fileName))
            {
                await sw.WriteLineAsync(result);
            }
            MessageBox.Show("Saved at " + fileName + "!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }