示例#1
0
        public override void create()
        {
            RegistryKey key = BaseKey.CreateSubKey(Path);

            key.SetValue(Name, Value);
            key.Close();
        }
示例#2
0
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            CurrentUser = Registry.CurrentUser.CreateSubKey($@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\{Extension}");
            CurrentUser = CurrentUser.OpenSubKey("UserChoice", RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
            CurrentUser.SetValue("Progid", KeyName, RegistryValueKind.String);
            CurrentUser.Close();

            // Delete the key instead of trying to change it
            CurrentUser = Registry.CurrentUser.OpenSubKey($"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\{Extension}", true);
            CurrentUser.DeleteSubKey("UserChoice", false);
            CurrentUser.Close();

            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#3
0
        // http://stackoverflow.com/questions/2681878/associate-file-extension-with-application
        //[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            // The stuff that was above here is basically the same
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.CurrentUser.OpenSubKey("Software\\Classes", true).CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.CurrentUser.OpenSubKey("Software\\Classes", true).CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            // Delete the key instead of trying to change it
            CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
            CurrentUser.DeleteSubKey("UserChoice", false);
            CurrentUser.Close();

            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#4
0
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\code.png.ico");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
            CurrentUser.DeleteSubKey("UserChoice", false);
            CurrentUser.Close();
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
        /// <summary> 获取当前时间前的所有生产信息 </summary>
        public List <WELLCTRL> GetAllWellBeforeTime(BaseKey sch, DateTime time = default(DateTime))
        {
            if (time == default(DateTime))
            {
                time = DateTime.MaxValue;
            }


            // Todo :比当前时间小的所有WELL关键字
            var wells = sch.FindAll <WELLCTRL>(l =>
            {
                if (l.ParentKey != null && l.ParentKey is TIME)
                {
                    TIME t = l.ParentKey as TIME;

                    return(time.Date.Date <= time.Date);
                }
                else
                {
                    return(false);
                }
            });

            return(wells);
        }
示例#6
0
        public static void SetWeakFileAssociation(string Extension, string KeyName, string OpenWith, string FileDescription, bool Unset = false)
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;

            BaseKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\" + Extension, RegistryKeyPermissionCheck.ReadWriteSubTree);
            if (!Unset)
            {
                BaseKey.CreateSubKey("OpenWithProgids").SetValue(KeyName, "");
                OpenMethod = Registry.CurrentUser.CreateSubKey("Software\\Classes\\" + KeyName);
                OpenMethod.SetValue("", FileDescription);
                Shell = OpenMethod.CreateSubKey("Shell");
                Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
                OpenMethod.Close();
                Shell.Close();
            }
            else
            {
                RegistryKey ProgIds = BaseKey.OpenSubKey("OpenWithProgids", true);
                if (ProgIds != null)
                {
                    ProgIds.DeleteValue(KeyName, false);
                }
                Registry.CurrentUser.OpenSubKey("Software\\Classes\\", true).DeleteSubKeyTree(KeyName, false);
                ProgIds.Close();
            }
            BaseKey.Close();

            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
        private static bool AssociateBA2Extension()
        {
            try
            {
                RegistryKey BaseKey;
                RegistryKey OpenMethod;
                RegistryKey Shell;

                BaseKey = Registry.ClassesRoot.CreateSubKey(associateExtension);
                BaseKey.SetValue("", associateKeyName);

                OpenMethod = Registry.ClassesRoot.CreateSubKey(associateKeyName);
                OpenMethod.SetValue("", associateFriendlyName);
                OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + associateExePath + "\",0");
                Shell = OpenMethod.CreateSubKey("Shell");
                Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + associateExePath + "\"" + " \"%1\"");
                Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + associateExePath + "\"" + " \"%1\"");
                BaseKey.Close();
                OpenMethod.Close();
                Shell.Close();

                // Tell explorer the file association has been changed
                NativeMethods.SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);

                return(true);
            }
            catch (SecurityException)
            {
                return(false);
            }
        }
示例#8
0
        public static void SetAssociation(string KeyName = "ByteFlood", string Description = "TORRENT File", string Extension = ".torrent")
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.CurrentUser.OpenSubKey("Software\\Classes", true).CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.CurrentUser.OpenSubKey("Software\\Classes", true).CreateSubKey(KeyName);
            OpenMethod.SetValue("", Description);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.torrent", true);
            CurrentUser.DeleteSubKey("UserChoice", false);
            CurrentUser.Close();

            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#9
0
        public static bool Associated(string KeyName = "ByteFlood", string Description = "TORRENT File", string Extension = ".torrent")
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;

            BaseKey = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true);
            if (!BaseKey.GetSubKeyNames().Contains(Extension))
            {
                return(false);
            }
            BaseKey = BaseKey.OpenSubKey(Extension);

            OpenMethod = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true);
            if (!OpenMethod.GetSubKeyNames().Contains(KeyName))
            {
                return(false);
            }
            OpenMethod = OpenMethod.OpenSubKey(KeyName);
            Shell      = OpenMethod.OpenSubKey("Shell");
            if (!Shell.GetSubKeyNames().Contains("open"))
            {
                return(false);
            }
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();
            return(true);
        }
示例#10
0
        public Inventory Expand(BaseKey key)
        {
            var newInv = new Inventory(this);

            newInv.myKeys.Add(key);
            return(newInv);
        }
示例#11
0
        public Tuple <PrivateKey, PublicKey> GenerateKeyPair()
        {
            /*
             *  q = 11       # selected prime divisor
             *  p = 23       # computed prime modulus: (p-1) mod q = 0
             *  g = 4        # computed: 1 < g < p, g**q mod p = 1:
             #           and g = h**((p–1)/q) mod p
             #           4**11 mod 23 = 1: 4194304 mod 23 = 1
             #  x = 7        # selected: 0 < x < q
             #  y = 8        # computed: y = g**x mod p = 4**7 mod 23
             #  {23,11,4,8}  # the public key: {p,q,g,y}
             #  {23,11,4,7}  # the private key: {p,q,g,x}
             */

            var primeQ = 11;
            var primeP = 23;

            var randomH = GetRandom(RandomPosition.RandomH, 1, primeQ - 1);
            var baseG   = (int)Math.Pow(randomH, (primeP - 1) / primeQ);

            var privateX = GetRandom(RandomPosition.RandomX, 1, primeQ - 1);
            var publicY  = (int)Math.Pow(baseG, privateX) % primeP;

            return(BaseKey.ConstructKeyPair(primeQ, primeP, baseG, privateX, publicY));
        }
示例#12
0
        public void SetAssociation(string extension, string file = null)
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;

            RenameSubKey(Registry.ClassesRoot, extension, extension + "_back");
            SetStatus("SetAssociation:enter");
            BaseKey = Registry.ClassesRoot.CreateSubKey(extension);
            BaseKey.SetValue("", _keyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(_keyName);
            OpenMethod.SetValue("", _keyName);//_fileDescription);

            if (!string.IsNullOrEmpty(file))
            {
                _openWith = file;
            }

            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + _openWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + _openWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + _openWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#13
0
        internal void Write <T>(string property, T val)
        {
            var key = BaseKey.OpenSubKey(SubKeyName, true) ?? BaseKey.CreateSubKey(SubKeyName);

            key.SetValue(property, val);
            key.Close();
        }
示例#14
0
        public static void Associate()
        {
            /*
             * RegistryKey FileReg = Registry.ClassesRoot.CreateSubKey(".code");
             * RegistryKey AppReg = Registry.CurrentUser.CreateSubKey("Dot DeCode.exe");
             * //RegistryKey FileReg = Registry.CurrentUser.CreateSubKey("Software\\Classes\\.code");
             * // RegistryKey AppReg = Registry.CurrentUser.CreateSubKey("Software\\Classes\\Applications\\Dot DeCode.exe");
             * //  RegistryKey AssReg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.code");
             *
             *
             * string configFile = string.Empty; ;
             * string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
             * configFile = Path.Combine(appdata, configFile);
             *
             * FileReg.CreateSubKey("DefaultIcon").SetValue("", System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)+ "\\code.png.ico");
             *
             *
             * AppReg.CreateSubKey("shell\\open\\command").SetValue("", "\"" + System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Dot DeCode.exe"+"\"%1");
             * AppReg.CreateSubKey("DefaultIcon").SetValue("",  System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\code.png.ico");
             *
             * //AssReg.CreateSubKey("UserChoice").SetValue("Progid", "Applications\\Dot DeCode.exe");
             *
             * // RegistryKey CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + ".code", true);
             * // CurrentUser.DeleteSubKey("UserChoice", false);
             * // CurrentUser.Close();
             *
             * SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
             */

            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;
            string      KeyName = "Dot DeCode";

            BaseKey = Registry.ClassesRoot.CreateSubKey(".code");
            string configFile = string.Empty;;
            string appdata    = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            configFile = Path.Combine(appdata, configFile);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", "CoDe File");
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\code.png.ico");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Dot DeCode.exe" + "\"%1");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Dot DeCode.exe" + "\"%1");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            /*
             * CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + ".code", true);
             * CurrentUser.DeleteSubKey("UserChoice", false);
             * CurrentUser.Close();
             */

            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#15
0
 internal override void SerializeParams(IDictionary <ParamName, object> valueSet)
 {
     valueSet.Add(ParamName.RegistryBaseKey, BaseKey.ToString());
     valueSet.Add(ParamName.RegistryKey, Key);
     valueSet.Add(ParamName.RegistryValueName, ValueName);
     valueSet.Add(ParamName.RegistryDefaultValue, DefaultValue);
 }
示例#16
0
        public static void SetECLPFileOpenHandler()
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;
            RegistryKey hkcuClasses     = Registry.CurrentUser.OpenSubKey(@"Software\Classes", true);
            string      Extension       = ".eclp";
            string      KeyName         = "ECLProfile";
            string      OpenWith        = System.Reflection.Assembly.GetEntryAssembly().Location;
            string      FileDescription = "EVE Custom Launcher profile";

            BaseKey = hkcuClasses.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = hkcuClasses.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "" + OpenWith + ",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"/profile:%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
            if (CurrentUser != null)
            {
                CurrentUser.DeleteSubKey("UserChoice", false);
                CurrentUser.Close();
            }

            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#17
0
        //Thanks StackOverflow https://stackoverflow.com/questions/2681878/associate-file-extension-with-application
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            CurrentUser = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + Extension);
            CurrentUser.DeleteSubKey("UserChoice", false);
            CurrentUser.SetValue("Progid", KeyName, RegistryValueKind.String);
            CurrentUser.Close();

            //Notify Explorer
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#18
0
        //START -- Association | .gs
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            if (!UacHelper.IsUacEnabled || !UacHelper.IsProcessElevated)
            {
                return;
            }

            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
            CurrentUser.DeleteSubKey("UserChoice", false);
            CurrentUser.Close();

            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#19
0
        public static void SetAssociation(string Extension, string KeyName, string FileDescription)
        {
            if (!requestPrivilege())
            {
                return;
            }

            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;
            string      OpenWith = Application.ExecutablePath;


            BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();

            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#20
0
        void tv_all_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
        {
            BaseKey bk = this.tv_all.SelectedItem as BaseKey;

            string ss = string.Empty;

            this.property.SelectedObject = bk;
        }
示例#21
0
        private void DeleteKey(BaseKey key)
        {
            var affectedLockNodes  = SaveManager.Data.Nodes.Where(node => node is LockNode).Select(node => node as LockNode).Where(node => node.myRequirement.ContainsKey(key.Id));
            var affectedEventNodes = SaveManager.Data.Nodes.Where(node => node is EventKeyNode).Select(node => node as EventKeyNode).Where(node => node.myKeyId == key.Id);

            if (affectedLockNodes.Any() ||
                affectedEventNodes.Any())
            {
                var deleteActions = new DeleteReplaceForm();
                deleteActions.StartPosition = FormStartPosition.CenterParent;
                deleteActions.ShowDialog(key.Name);

                if (deleteActions.Result == DeleteResult.Cancel)
                {
                    return;
                }

                if (deleteActions.Result == DeleteResult.Delete)
                {
                    foreach (var lockNode in affectedLockNodes)
                    {
                        lockNode.myRequirement.RemoveKey(key.Id);
                    }

                    foreach (var node in affectedEventNodes)
                    {
                        node.myKeyId = null;
                    }
                }

                if (deleteActions.Result == DeleteResult.Replace)
                {
                    foreach (var lockNode in affectedLockNodes)
                    {
                        lockNode.myRequirement.ReplaceKey(key.Id, deleteActions.ReplaceId);
                    }

                    foreach (var node in affectedEventNodes.Where(node => node.myKeyId == key.Id))
                    {
                        if (KeyManager.GetEventKeys().Any(eventKey => eventKey.Id == deleteActions.ReplaceId))
                        {
                            node.myKeyId = deleteActions.ReplaceId;
                        }
                        else                         // New Key is not an event
                        {
                            node.myKeyId = Guid.Empty;
                        }
                    }
                }
            }

            KeyManager.DeleteKey(key.Id);

            SaveManager.Dirty = true;

            GenerateLists();
        }
示例#22
0
        bool SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            try
            {
                BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
                BaseKey.SetValue("", KeyName);
                BaseKey.Flush();
                BaseKey.Close();

                OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
                OpenMethod.SetValue("", FileDescription);
                OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
                OpenMethod.Flush();

                Shell = OpenMethod.CreateSubKey("Shell");
                Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
                Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
                Shell.Flush();
                Shell.Close();
                OpenMethod.Close();

                // Delete the key instead of trying to change it
                CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
                if (CurrentUser != null)
                {
                    CurrentUser.DeleteSubKey("UserChoice", false);
                    CurrentUser.Flush();
                    CurrentUser.Close();
                }
            }
            catch (Exception ex)
            {
                if (ex is System.Security.SecurityException || ex is UnauthorizedAccessException)
                {
                    MessageBox.Show("Please restart this program with administrative privileges to set file associations!");
                    return(false);
                }
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
                return(false);
            }


            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);

            return(true);
        }
示例#23
0
        /// <summary>Displays the Modifier and key in extended format.
        /// </summary>
        /// <returns>The key and modifier in string.</returns>
        public string Info()
        {
            string info = "";

            foreach (Modifiers mod in new HotKeyShared.ParseModifier((int)BaseModifier))
            {
                info += mod + " + ";
            }

            info += BaseKey.ToString();
            return(info);
        }
示例#24
0
		/// <summary>
		/// Gets value from a registry key under base key.
		/// </summary>
        /// <param name="keyBase">Base key</param>
		/// <param name="keyName">Key name</param>
		/// <param name="valueName">Value name</param>
		/// <param name="defaultValue">Default value</param>
		/// <returns></returns>
		public static object GetValueFromRegKey(BaseKey keyBase, string keyName, string valueName, object defaultValue) {
			
            RegistryKey _Key = (keyBase == BaseKey.Default) ?
                Registry.CurrentUser.OpenSubKey(keyName) : Registry.LocalMachine.OpenSubKey(keyName);

			if ( _Key != null && Array.IndexOf(_Key.GetValueNames(), valueName) > -1) {  
				object value =  _Key.GetValue(valueName);
				if (value != null) {
					return value;
				}
			} 
			return defaultValue;
		}
示例#25
0
 public override void delete()
 {
     if (Name != "")
     {
         RegistryKey key = BaseKey.CreateSubKey(Path);
         key.DeleteValue(Name);
         key.Close();
     }
     else
     {
         BaseKey.DeleteSubKey(Path);
     }
 }
示例#26
0
        /// <summary>
        /// Sets value to a registry key under base key.
        /// </summary>
        /// <param name="keyBase">Base key</param>
        /// <param name="keyName">Key name</param>
        /// <param name="valueName">Value name</param>
        /// <param name="newValue">New value</param>
        public static void SetValueToRegKey(BaseKey keyBase, string keyName, string valueName, object newValue)
        {
            if (null == newValue)
            {
                throw new ArgumentException("new value cannot be null");
            }
            RegistryKey _Key = (keyBase == BaseKey.Default) ? 
                Registry.CurrentUser.OpenSubKey(keyName, true) : Registry.LocalMachine.OpenSubKey(keyName, true);

            if (_Key == null)
            {
                _Key = (keyBase == BaseKey.Default) ? 
                    Registry.CurrentUser.CreateSubKey(keyName) : Registry.LocalMachine.CreateSubKey(keyName);
            }
            _Key.SetValue(valueName, newValue);   
        }
示例#27
0
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string OpenWithParameter, string IconIndex, string FileDescription)
        {
            try
            {
                RegistryKey key   = Registry.ClassesRoot.OpenSubKey(Extension);
                string      temp1 = key.GetValue(null, "").ToString();
                if (temp1.Trim().Length > 0)
                {
                    Registry.ClassesRoot.DeleteSubKeyTree(temp1);
                }

                Registry.ClassesRoot.DeleteSubKeyTree(Extension);
            }
            catch
            {
            }

            RegistryKey BaseKey;
            RegistryKey OpenMethod;
            RegistryKey Shell;
            RegistryKey CurrentUser;

            BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
            BaseKey.SetValue("", KeyName);

            OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
            OpenMethod.SetValue("", FileDescription);
            OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\"," + IconIndex);
            Shell = OpenMethod.CreateSubKey("Shell");
            Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"" + OpenWithParameter + "\" \"%1\"");
            Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"" + OpenWithParameter + "\" \"%1\"");
            BaseKey.Close();
            OpenMethod.Close();
            Shell.Close();
            try
            {
                CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
                CurrentUser.DeleteSubKey("UserChoice", false);
                CurrentUser.Close();
            }
            catch
            {
            }
            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#28
0
        private static void setFileAssociation(RegistryKey key)
        {
            Microsoft.Win32.RegistryKey BaseKey;
            Microsoft.Win32.RegistryKey shell;
            Microsoft.Win32.RegistryKey currentUser;


            BaseKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension);
            BaseKey.SetValue("", keyName);

            // only create if not changing existing value
            if (key == null)
            {
                key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(keyName);
            }
            else
            {
                // can only open to edit post-priveledge escalation
                key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(keyName, true);
            }

            key.SetValue("", fileDescription);
            key.CreateSubKey("DefaultIcon").SetValue("", "\"" + opensWith + "\",1");
            shell = key.CreateSubKey("Shell");
            shell.CreateSubKey("edit").CreateSubKey(commandString).SetValue("", commandValue);
            shell.CreateSubKey("open").CreateSubKey(commandString).SetValue("", commandValue);
            BaseKey.Close();
            key.Close();
            shell.Close();

            currentUser = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ucs");
            currentUser = currentUser.OpenSubKey("UserChoice", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);

            if (currentUser != null)
            {
                currentUser.SetValue("Progid", keyName, Microsoft.Win32.RegistryValueKind.String);
                currentUser.Close();

                Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + extension, true);
                currentUser.DeleteSubKey("UserChoice", false);
                currentUser.Close();
            }

            // Tell explorer the file association has been changed
            SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
        }
示例#29
0
        public BaseKey Build(List <string> newStr, BaseKey last, BaseKey per)
        {
            if (this.DateTime.Equals(default(DateTime)))
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < newStr.Count; i++)
                {
                    sb.Append(newStr[i] + " ");
                }

                this.DateTime = DatesKeyService.Instance.GetDateTime(sb.ToString());

                return(this);
            }
            else
            {
                if (this.ParentKey == null)
                {
                    return(null);
                }

                //   兼容格式
                //   DATES
                //   31 'DEC' 2015/
                //   31 'DEC' 2016/

                DATES newDates = new DATES("DATES");

                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < newStr.Count; i++)
                {
                    sb.Append(newStr[i] + " ");
                }

                newDates.DateTime = DatesKeyService.Instance.GetDateTime(sb.ToString());

                this.ParentKey.Add(newDates);

                //  上一节点指向新建的时间节点
                return(newDates);
            }
        }
示例#30
0
        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
        {
            try
            {
                RegistryKey CurrentUser;


                // The stuff that was above here is basically the same
                RegistryKey BaseKey;
                RegistryKey OpenMethod;
                RegistryKey Shell;


                BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
                BaseKey.SetValue("", KeyName);

                OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
                OpenMethod.SetValue("", FileDescription);
                OpenMethod.CreateSubKey("DefaultIcon").SetValue("", Application.StartupPath + "\\bcicons.dll" + ",0");
                Shell = OpenMethod.CreateSubKey("Shell");
                Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
                Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
                BaseKey.Close();
                OpenMethod.Close();
                Shell.Close();


                // Delete the key instead of trying to change it
                CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Extension, true);
                CurrentUser.DeleteSubKey("UserChoice", false);

                CurrentUser.Close();

                // Tell explorer the file association has been changed
                SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);

                MessageBox.Show("Registry File Association Done", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Registry File Association Error" + Environment.NewLine + ex.Message + ex.Source, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#31
0
    //TODO Create array of strings to be used for weapon info
    //TODO Read a JSON or XML File of weapons
    //private string[] keyNames = new String[x]; //Test code for creating the array

    public void CreateKey()
    {
        newKey = new BaseKey();

        //Name
        newKey.ItemName = "Test Key Name";
        //newKey.ItemName = keyNames[x]

        //Description
        newKey.ItemDescription = "This is a new Key";

        //ID
        newKey.ItemID = Random.Range(301, 401);

        //ItemType
        newKey.ItemType = BaseItem.ItemTypes.KEY;

        //Effect ID
        newKey.EffectID = Random.Range(1, 20);
    }
        /// <summary> 获取当前时间前的所有完井信息 包含最后一个时间的井类型 </summary>
        public List <WellLocation> GetAllLocationOfBeforeTime(BaseKey sch, DateTime time = default(DateTime))
        {
            if (time == default(DateTime))
            {
                time = DateTime.MaxValue;
            }

            // Todo :比当前时间小的所有WELL关键字
            List <WELLCTRL> wells = this.GetAllWellBeforeTime(sch, time);

            // Todo :获取不重复井名
            var wellNames = wells.Select(l => l.WellName0).Distinct();

            List <WellLocation> wellLocations = new List <WellLocation>();

            foreach (var item in wellNames)
            {
                WellLocation wl = new WellLocation();
                wl.WellName = item;

                List <Point <int> > ps = new List <Point <int> >();

                Tuple <List <PERF>, SimONProductType> perf = this.GetAllLoaction(wells, item);

                wl.WellType = perf.Item2;

                foreach (var it in perf.Item1)
                {
                    Point <int> p = new Point <int>();
                    p.X = it.I0.ToInt();
                    p.Y = it.J1.ToInt();
                    p.Z = it.K12.ToInt();
                    ps.Add(p);
                }
                wl.Location = ps;

                wellLocations.Add(wl);
            }

            return(wellLocations);
        }
示例#33
0
        /// <summary>
        /// Removes a value from a registry key under base key.
        /// </summary>
        /// <param name="keyBase">Base key</param>
        /// <param name="keyName">Key name</param>
        /// <param name="valueName">Value name</param>
        public static void RemoveValueFromRegKey(BaseKey keyBase, string keyName, string valueName)
        {
            RegistryKey _Key = (keyBase == BaseKey.Default) ?
                Registry.CurrentUser.OpenSubKey(keyName, true) : Registry.LocalMachine.OpenSubKey(keyName, true);

            if (_Key != null && Array.IndexOf(_Key.GetValueNames(), valueName) > -1)
            {
                _Key.DeleteValue(valueName, false);
            }
        }