Ejemplo n.º 1
0
        public static void PerformOperation(string title, bool showImmediately, Action action)
        {
            LongRunningActionForm form = new LongRunningActionForm
            {
                Text = title
            };

            try
            {
                Program.TheForm.Enabled = false;
                form._startTime         = DateTime.Now;
                if (showImmediately)
                {
                    form.MakeVisible();
                }
                Instance = form;
                action();
            }
            finally
            {
                if (form.Visible)
                {
                    form.Done = true;
                    form.Invoke((MethodInvoker) delegate
                    {
                        form.Close();
                    });
                }
                Instance = null;
                Program.TheForm.Enabled = true;
            }
        }
Ejemplo n.º 2
0
        public static X509Certificate2 SelectCertificate()
        {
            X509Store x509Store = new X509Store();
            X509Certificate2Collection privateCollection = new X509Certificate2Collection();

            try
            {
                x509Store.Open(OpenFlags.OpenExistingOnly);
                X509Certificate2Collection certificates    = x509Store.Certificates;
                X509Certificate2Collection foundCollection = certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, validOnly: false);
                LongRunningActionForm.PerformOperation("检查有效证书", showImmediately: true, delegate
                {
                    X509Certificate2Enumerator enumerator = foundCollection.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        X509Certificate2 current = enumerator.Current;
                        try
                        {
                            if (DecryptStringUsingCertificate(current, EncryptStringUsingCertificate(current, "test")) == "test")
                            {
                                privateCollection.Add(current);
                            }
                        }
                        catch
                        {
                        }
                        LongRunningActionForm.Instance.UpdateStatus(current.SimpleName());
                    }
                });
            }
            finally
            {
                x509Store.Close();
            }
            X509Certificate2Collection x509Certificate2Collection = X509Certificate2UI.SelectFromCollection(privateCollection, "选择证书", "选择用于安全密码存储的证书", X509SelectionFlag.SingleSelection, Program.TheForm.Handle);

            if (x509Certificate2Collection.Count != 1)
            {
                return(null);
            }
            return(x509Certificate2Collection[0]);
        }
Ejemplo n.º 3
0
        private static bool ReadXml(XmlNode topNode, FileGroup fileGroup, ICollection <string> errors)
        {
            string text = "unknown";
            int    num  = 0;

            try
            {
                XmlNode namedItem = topNode.Attributes.GetNamedItem("programVersion");
                text = namedItem.InnerText;
            }
            catch
            {
            }
            try
            {
                XmlNode namedItem2 = topNode.Attributes.GetNamedItem("schemaVersion");
                num = int.Parse(namedItem2.InnerText);
            }
            catch
            {
            }
            fileGroup.SchemaVersion = num;
            if (num > 3)
            {
                DialogResult dialogResult = FormTools.YesNoDialog("{0} was written by a newer version of RDCMan ({1}). It may not load properly. If it does and is saved by this version, it will revert to the older file schema possibly losing information. Continue?".CultureFormat(fileGroup.GetFilename(), text));
                if (dialogResult == DialogResult.No)
                {
                    return(false);
                }
            }
            GroupBase.SchemaVersion = num;
            if (GroupBase.SchemaVersion <= 2)
            {
                fileGroup.EncryptionSettings.InheritSettingsType.Mode = InheritanceMode.None;
            }
            Dictionary <string, Helpers.ReadXmlDelegate> nodeActions = new Dictionary <string, Helpers.ReadXmlDelegate>();

            nodeActions["file"] = delegate(XmlNode childNode, RdcTreeNode group, ICollection <string> errors2)
            {
                (group as GroupBase).ReadXml(childNode, errors2);
            };
            foreach (IBuiltInVirtualGroup virtualGroup in Program.BuiltInVirtualGroups.Where((IBuiltInVirtualGroup v) => !string.IsNullOrEmpty(v.XmlNodeName)))
            {
                Helpers.ReadXmlDelegate readXmlDelegate2 = nodeActions[virtualGroup.XmlNodeName] = delegate(XmlNode childNode, RdcTreeNode group, ICollection <string> errors2)
                {
                    virtualGroup.ReadXml(childNode, fileGroup, errors2);
                };
            }
            nodeActions["version"] = delegate
            {
            };
            LongRunningActionForm.PerformOperation("Opening " + fileGroup.Pathname, showImmediately: false, delegate
            {
                foreach (XmlNode childNode in topNode.ChildNodes)
                {
                    if (nodeActions.TryGetValue(childNode.Name, out Helpers.ReadXmlDelegate value))
                    {
                        value(childNode, fileGroup, errors);
                    }
                    else
                    {
                        errors.Add("Unexpected Xml node {0} in '{1}'".CultureFormat(childNode.GetFullPath(), fileGroup.GetFilename()));
                    }
                }
            });