コード例 #1
0
 /// <summary>
 /// Check if the given file path is a .gma file.
 /// </summary>
 /// <param name="path">File path</param>
 /// <returns>Whenever the file is a .gma file.</returns>
 private bool CheckGMA(string path)
 {
     if (!(StringPath.GetExtension(path) == ".gma"))
     {
         Notification.Error($"File '{path}' isn't a .gma file! Please specify a correct file path!");
         return(false);
     }
     return(true);
 }
コード例 #2
0
        private void button_actions_generate_Click(object sender, EventArgs e)
        {
            //  > Checks
            if (!(StringPath.GetExtension(textbox_settings_path.Text).Length == 0))
            {
                Notification.Error($"File '{textbox_settings_path.Text}' isn't a directory! Please specify a valid directory!");
                return;
            }

            Addon addon;

            try
            {
                addon = new Addon
                {
                    title = textbox_settings_title.Text,
                    type  = combobox_settings_type.SelectedItem.ToString(),
                    tags  = new string[]
                    {
                        combobox_settings_tag1.SelectedItem.ToString(),
                            combobox_settings_tag2.SelectedItem.ToString(),
                    },
                    ignore = ignore.ToArray(),
                };
            }
            catch (NullReferenceException)
            {
                Notification.Error("You didn't specified all fields, unable to generate the JSON file.");
                return;
            }

            string path = textbox_settings_path.Text + "/addon.json";
            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented = true,
            };

            File.WriteAllText(path, JsonSerializer.Serialize(addon, options));

            if (File.Exists(path))
            {
                Notification.Information("Success! File 'addon.json' has been generated!");
            }
        }