예제 #1
0
        public bool Load(string file)
        {
            var DeSerializer = new XmlSerializer(typeof(PayloadClass));

            PayloadClass pc;

            using (var stream = File.OpenRead(FileName = file))
                try
                {
                    pc = (PayloadClass)DeSerializer.Deserialize(stream);
                }
                catch
                {
                    pc = new PayloadClass();
                }

            if (pc.Buttons.Count == 0 && pc.Priorities.Count != 0)
            {
                if (MessageBox.Show("The file you are trying to load doesn't contain any buttons, " +
                                    "but there are priority sets referencing them. Would you want me to try to " +
                                    "fill in buttons from the registry (from the old version of the button lists)?\n\n" +
                                    "This may not work and it might render the entire file unusable. Please " +
                                    "test it thoroughly before saving!",
                                    "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        var log = "";

                        var root = Registry.LocalMachine.OpenSubKey("software")
                                   .OpenSubKey("ss").OpenSubKey("button tester");
                        var n = (int)root.GetValue(null);

                        for (var i = 0; i < n; ++i)
                        {
                            var bt = new PayloadClass.ButtonType();
                            bt.Name  = (string)root.GetValue("name_" + i);
                            bt.PinID = (int)root.GetValue("pinid_" + i);

                            pc.Buttons.Add(bt);

                            log += bt.Name + " (" + bt.PinID + ")\n";
                        }

                        MessageBox.Show("Buttons found and loaded: " + log, "Import log", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);

                        Payload = pc;
                    }
                    catch
                    {
                        MessageBox.Show("Could not load the buttons from the registry.", "Import log", MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                if (pc.Version < ver && MessageBox.Show("The file you are trying to load is an from an older version " +
                                                        "of this program. It will most likely not work or work wrong. Are you sure you want to load it?",
                                                        "Old save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Payload = pc;
                }
                else if (pc.Version > ver && MessageBox.Show("The file you are trying to load is an from a newer (!) version " +
                                                             "of this program. It will most likely not work or work wrong. Are you sure you want to load it?",
                                                             "Newer save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Payload = pc;
                }
                else if (pc.Version == ver)
                {
                    Payload = pc;
                }
                else
                {
                    return(false);
                }
            }

            Payload.Version = ver;

            Dirty = false;

            return(true);
        }
예제 #2
0
        public bool Load(string file)
        {
            XmlSerializer DeSerializer = new XmlSerializer(typeof(PayloadClass));

            PayloadClass pc;
            using (FileStream stream = File.OpenRead(FileName = file))
                pc = (PayloadClass)DeSerializer.Deserialize(stream);

            if (pc.Buttons.Count == 0 && pc.Priorities.Count != 0)
            {
                if (MessageBox.Show("The file you are trying to load doesn't contain any buttons, " +
                    "but there are priority sets referencing them. Would you want me to try to " +
                    "fill in buttons from the registry (from the old version of the button lists)?\n\n"+
                    "This may not work and it might render the entire file unusable. Please "+
                    "test it thoroughly before saving!",
                    "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        string log = "";

                        RegistryKey root = Registry.LocalMachine.OpenSubKey("software")
                            .OpenSubKey("ss").OpenSubKey("button tester");
                        int n = (int)root.GetValue(null);

                        for (int i = 0; i < n; ++i)
                        {
                            PayloadClass.ButtonType bt = new PayloadClass.ButtonType();
                            bt.Name = (string)root.GetValue("name_" + i);
                            bt.PinID = (int)root.GetValue("pinid_" + i);

                            pc.Buttons.Add(bt);

                            log += bt.Name + " (" + bt.PinID + ")\n";
                        }

                        MessageBox.Show("Buttons found and loaded: " + log, "Import log", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

                        Payload = pc;
                    }
                    catch
                    {
                        MessageBox.Show("Could not load the buttons from the registry.", "Import log", MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                if (pc.Version < ver && MessageBox.Show("The file you are trying to load is an from an older version " +
                    "of this program. It will most likely not work or work wrong. Are you sure you want to load it?",
                    "Old save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    Payload = pc;
                else if (pc.Version > ver && MessageBox.Show("The file you are trying to load is an from a newer (!) version " +
                    "of this program. It will most likely not work or work wrong. Are you sure you want to load it?",
                    "Newer save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    Payload = pc;
                else if (pc.Version == ver)
                    Payload = pc;
                else
                    return false;
            }

            Payload.Version = ver;

            Dirty = false;

            return true;
        }