示例#1
0
        private void ImportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool worry = false;

            if (sccount > 0)
            {
                worry |= ((HDSCGrouping)specialCasePanel.Controls[0]).NumOfFiles != 0 || ((HDSCGrouping)specialCasePanel.Controls[0]).NumOfFolders != 0 || ((HDSCGrouping)specialCasePanel.Controls[0]).NumOfUUIDs != 0;
            }
            if (frcount > 0)
            {
                worry |= ((HDFolderRuleGrouping)folderPanel.Controls[0]).Folder != "" || ((HDFolderRuleGrouping)folderPanel.Controls[0]).Bep != "";
            }
            if (fircount > 0)
            {
                worry |= ((HDFileRuleGrouping)filePanel.Controls[0]).File != "" || ((HDFileRuleGrouping)filePanel.Controls[0]).Bep != "";
            }
            if (worry)
            {
                worry = !(MessageBox.Show("Importing will clear any items you have entered already. Are you sure you want to continue?", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes);
            }
            if (!worry)
            {
                OpenFileDialog d = new OpenFileDialog
                {
                    Filter   = "Json (*.json)|*.json",
                    FileName = "RuleSet.json",
                    Title    = "Choose your rules file"
                };
                DialogResult res = d.ShowDialog();
                if (res == DialogResult.OK)
                {
                    ClearAll();
                    StreamReader sr = new StreamReader(d.OpenFile());
                    HDJson       j  = JsonConvert.DeserializeObject <HDJson>(sr.ReadToEnd());
                    sr.Close();
                    sr.Dispose();
                    foreach (HDSCJson sc in j.SpecialCases)
                    {
                        AddFilledSpecialCase(sc);
                    }
                    foreach (KeyValuePair <string, string> kvp in j.Folders)
                    {
                        AddFilledFolderRule(kvp.Key, kvp.Value);
                    }
                    foreach (KeyValuePair <string, string> kvp in j.Files)
                    {
                        AddFilledFileRule(kvp.Key, kvp.Value);
                    }
                    this.uuidTextBox.Lines = j.Exclusions.ToArray();
                }
                d.Dispose();
            }
        }
示例#2
0
        private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HDJson j = new HDJson()
            {
                Exclusions = new List <string>(uuidTextBox.Lines)
            };

            foreach (HDSCGrouping sc in specialCasePanel.Controls)
            {
                if (!sc.IsEmpty)
                {
                    j.SpecialCases.Add(new HDSCJson {
                        Files = sc.Files, Folders = sc.Folders, UUIDS = sc.UUIDS, Name = sc.Text, PickOneOfX = sc.PickOne, PickOptions = sc.PickOptions
                    });
                }
            }
            foreach (HDFileRuleGrouping fi in filePanel.Controls)
            {
                if (!fi.IsEmpty)
                {
                    j.Files.Add(fi.File, fi.Bep);
                }
            }
            foreach (HDFolderRuleGrouping fo in folderPanel.Controls)
            {
                if (!fo.IsEmpty)
                {
                    j.Folders.Add(fo.Folder, fo.Bep);
                }
            }
            SaveFileDialog d = new SaveFileDialog
            {
                Filter   = "Json (*.json)|*.json",
                FileName = "RuleSet.json",
                Title    = "Save your rules file"
            };
            DialogResult res = d.ShowDialog();

            if (res == DialogResult.OK)
            {
                StreamWriter sw = new StreamWriter(d.OpenFile());
                sw.WriteLine(JsonConvert.SerializeObject(j, Formatting.Indented));
                sw.Close();
                sw.Dispose();
            }
            d.Dispose();
        }