Read() public method

To read a registry key. input: KeyName (string) output: value (string)
public Read ( string KeyName ) : string
KeyName string
return string
Ejemplo n.º 1
0
        public bool IsNewFile(Stream inputStream)
        {
            using (MD5 md5Hash = MD5.Create())
            {
                string newHash = GetMd5Hash(md5Hash, inputStream);
                ModifyRegistry registry = new ModifyRegistry();
                registry.ShowError = false;

                string oldHash = registry.Read("Hash");
                if (String.IsNullOrEmpty(oldHash))
                {
                    registry.Write("Hash", "0");
                }

                bool result = !IsSame(newHash, oldHash);
                if (result) // if new file need to parse
                {
                    registry.Write("Hash", newHash);
                }
                return result;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the toolbar buttons and the context menu items.
        /// </summary>
        public void AddTemporaryUI()
        {
            const string VS_STANDARD_COMMANDBAR_NAME = "Standard";
            const string VS_CODE_WINDOW_COMMANDBAR_NAME = "Code Window";
            const string MY_TEMPORARY_TOOLBAR_CAPTION = "Sonar Toolbar";

            CommandBar standardCommandBar = null;
            CommandBar codeCommandBar = null;
            CommandBars commandBars = null;

            try
            {
                // Retrieve the collection of commandbars
                // Note:
                // - In VS.NET 2002/2003 (which uses the Office.dll reference)
                //   DTE.CommandBars returns directly a CommandBars type, so a cast
                //   to CommandBars is redundant
                // - In VS 2005 or higher (which uses the new Microsoft.VisualStudio.CommandBars.dll reference)
                //   DTE.CommandBars returns an Object type, so we do need a cast to CommandBars
                commandBars = (CommandBars)applicationObject.CommandBars;
                standardCommandBar = commandBars[VS_STANDARD_COMMANDBAR_NAME];
                codeCommandBar = commandBars[VS_CODE_WINDOW_COMMANDBAR_NAME];
                ModifyRegistry createRegistry = new ModifyRegistry(PLUGINKEY);

                temporaryToolbar = commandBars.Add(MY_TEMPORARY_TOOLBAR_CAPTION, MsoBarPosition.msoBarTop, System.Type.Missing, true);

                try
                {
                    int row_index = (int)createRegistry.Read(ROWINDEXKEY);
                    temporaryToolbar.RowIndex = row_index;
                }
                catch (System.Exception)
                {
                }

                FormatBarAndButtons(codeCommandBar);

                try
                {
                    bool visible = Convert.ToBoolean(createRegistry.Read(VISIBLEKEY));
                    temporaryToolbar.Visible = visible;
                }
                catch (System.Exception)
                {
                    temporaryToolbar.Visible = true;
                }

            }
            catch(System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Cannot Add ToolBar: " + e.StackTrace);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to find game pathes etc. in the registry or other places
        /// and stores them in a Dictionary.
        /// Must be called before pathes are accessed through GetPath.
        /// </summary>
        public void GatherPathes()
        {
            // =======================================
            // Misc
            // =======================================
            string pathToProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles");
            string pathToTempFiles    = Path.GetTempPath();
            string pathToAppData      = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string pathToAppDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string pathToDocuments    = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            dictPathIdentifiers.Add("%PROGRAM_FILES%", pathToProgramFiles);
            dictPathIdentifiers.Add("%TEMP%", pathToTempFiles);
            dictPathIdentifiers.Add("%APP_DATA%", pathToAppData);
            dictPathIdentifiers.Add("%APP_DATA_LOCAL%", pathToAppDataLocal);
            dictPathIdentifiers.Add("%DOCUMENTS%", pathToDocuments);

            // =======================================
            // STARCRAFT II
            // =======================================
            // Install Path + add modifyregistry

            string pathToStarcraft2Folder = "";
            ModifyRegistry mysc2Registry = new ModifyRegistry();
            mysc2Registry.SubKey = "Software\\Blizzard Entertainment\\Starcraft II\\";
            mysc2Registry.ShowError = true;

            // 1a. Try Registry LocalMachine
            pathToStarcraft2Folder = mysc2Registry.Read("InstallPath");

            // 1b. Try Registry CurrentUser
            if (string.IsNullOrEmpty(pathToStarcraft2Folder))
            {
                mysc2Registry.BaseRegistryKey = Registry.CurrentUser;
                pathToStarcraft2Folder = mysc2Registry.Read("InstallPath");
            }

            if (string.IsNullOrEmpty(pathToStarcraft2Folder))
            {
                pathToStarcraft2Folder = "";
            }

            // 2. Try Default Path
            if (string.IsNullOrEmpty(pathToStarcraft2Folder))
            {
                string sc2_defaultPath = pathToProgramFiles + "/" + "StarCraft II/";
                if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = sc2_defaultPath;
            }

            // 3. Try Default Path (Beta)
            if (string.IsNullOrEmpty(pathToStarcraft2Folder))
            {
                string defaultPath = pathToProgramFiles + "/" + "StarCraft II Beta/";
                if (File.Exists(pathToProgramFiles + "StarCraft II.exe")) pathToStarcraft2Folder = defaultPath;
            }

            dictPathIdentifiers.Add("%SC2_INSTALL_PATH%", pathToStarcraft2Folder);

            // =======================================
            // STARCRAFT I
            // (no registry key to my knowledge)
            // ^-- (well there is!)
            // =======================================
            //Installpath + modify reg

            string pathToStarcraft1Folder = "";
            ModifyRegistry mysc1Registry = new ModifyRegistry();
            mysc1Registry.SubKey = "Software\\Blizzard Entertainment\\Starcraft\\";
            mysc1Registry.ShowError = true;

            // 1a. Try Registry LocalMachine (no idea if localmachine is used, dont think so, but i let it stay)
            pathToStarcraft1Folder = mysc1Registry.Read("InstallPath");

            // 1b. Try Registry CurrentUser
            if (string.IsNullOrEmpty(pathToStarcraft1Folder))
            {
                mysc1Registry.BaseRegistryKey = Registry.CurrentUser;
                pathToStarcraft1Folder = mysc1Registry.Read("InstallPath");
            }

            if (string.IsNullOrEmpty(pathToStarcraft1Folder))
            {
                pathToStarcraft1Folder = "";
            }

            // 2. Try Default Path
            if (string.IsNullOrEmpty(pathToStarcraft1Folder))
            {
                string sc1_defaultPath = pathToProgramFiles + "/" + "StarCraft/";

                if (File.Exists(pathToProgramFiles + "StarCraft.exe")) pathToStarcraft1Folder = sc1_defaultPath;
            }

            dictPathIdentifiers.Add("%SC1_INSTALL_PATH%", pathToStarcraft1Folder);

            //=====================
            //Warcraft 3
            //=====================
            //Install path + modifyreg

            string pathToWarcraft3Folder = "";
            ModifyRegistry mywc3Registry = new ModifyRegistry();
            mywc3Registry.SubKey = "Software\\Blizzard Entertainment\\Warcraft III\\";
            mywc3Registry.ShowError = true;

            // 1a. Try Registry LocalMachine (no idea if localmachine is used, dont think so, but i let it stay)
            pathToWarcraft3Folder = mywc3Registry.Read("InstallPath");

            // 1b. Try Registry CurrentUser
            if (string.IsNullOrEmpty(pathToWarcraft3Folder))
            {
                mywc3Registry.BaseRegistryKey = Registry.CurrentUser;
                pathToWarcraft3Folder = mywc3Registry.Read("InstallPath");
            }

            if (string.IsNullOrEmpty(pathToWarcraft3Folder))
            {
                pathToWarcraft3Folder = "";
            }

            dictPathIdentifiers.Add("%WC3_INSTALL_PATH%", pathToWarcraft3Folder);
        }
Ejemplo n.º 4
0
        private void button4_Click(object sender, EventArgs e)
        {
            RegistryKey bk = Registry.ClassesRoot;
            RegistryKey sk = bk.CreateSubKey("*\\shell\\RightClickDeposit");
            ModifyRegistry reg = new ModifyRegistry();
            reg.BaseRegistryKey = bk;
            reg.SubKey = "*\\shell\\RightClickDeposit";
            reg.Write("MUIVerb", "Deposit to");
            string commandList = "";
            foreach(KeyValuePair<int,Profile> p in profiles)
            {
                if (p.Value.IsDefault())
                {
                    string commandName = "RightClickDeposit.deposit." + p.Value.GetId();
                    commandList += commandName + "; ";
                    RegistryKey cbk = Registry.LocalMachine;
                    RegistryKey ck = cbk.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\" + commandName);
                    ModifyRegistry regcmd = new ModifyRegistry();
                    regcmd.BaseRegistryKey = cbk;
                    regcmd.SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\" + commandName;
                    regcmd.Write("MUIVerb", p.Value.GetName());
                    MessageBox.Show(regcmd.Read("MUIVerb"));
                    RegistryKey cck = cbk.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\" + commandName + "\\command");
                    regcmd.SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\" + commandName + "\\command";
                    regcmd.Write("", "C:\\RightClickDeposit.exe " + p.Value.GetId() + " create \"%1\"");
                }
            }

            RegistryKey ubk = Registry.LocalMachine;
            RegistryKey uk = ubk.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\RightClickDeposit.update");
            ModifyRegistry regu = new ModifyRegistry();
            regu.BaseRegistryKey = ubk;
            regu.SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\RightClickDeposit.update";
            regu.Write("MUIVerb", "Update or delete previous deposit");

            RegistryKey cuk = ubk.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\RightClickDeposit.update\\command");
            regu.SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\RightClickDeposit.update\\command";
            regu.Write("", "C:\\RightClickDeposit.exe 0 update \"%1\"");

            commandList += "RightClickDeposit.update";

            reg.Write("SubCommands", commandList);
        }
Ejemplo n.º 5
0
        public bool init()
        {
            try
            {
                this.Text = "BeanfunLogin - v" + Properties.Settings.Default.currentVersion.ToString().Insert(1, ".").Insert(3, ".");
                this.AcceptButton = this.button1;
                this.bfClient = null;
                //Properties.Settings.Default.Reset(); //SetToDefault.                  

                // Handle settings.
                if (Properties.Settings.Default.rememberAccount == true)
                    this.textBox1.Text = Properties.Settings.Default.AccountID;
                if (Properties.Settings.Default.rememberPwd == true && Properties.Settings.Default.loginMethod != 2)
                {
                    this.checkBox1.Enabled = false;
                    // Load password.
                    if (File.Exists("UserState.dat"))
                    {
                        Byte[] cipher = File.ReadAllBytes("UserState.dat");
                        string entropy = Properties.Settings.Default.entropy;
                        byte[] plaintext = ProtectedData.Unprotect(cipher, Encoding.UTF8.GetBytes(entropy), DataProtectionScope.CurrentUser);
                        this.textBox2.Text = System.Text.Encoding.UTF8.GetString(plaintext);
                    }
                }
                if (Properties.Settings.Default.autoLogin == true && Properties.Settings.Default.loginMethod != 2 && Properties.Settings.Default.loginMethod != 4)
                {
                    this.UseWaitCursor = true;
                    this.panel2.Enabled = false;
                    this.button1.Text = "請稍後...";
                    this.backgroundWorker2.RunWorkerAsync(Properties.Settings.Default.loginMethod);
                }
                if (Properties.Settings.Default.gamePath == "")
                {
                    ModifyRegistry myRegistry = new ModifyRegistry();
                    myRegistry.BaseRegistryKey = Registry.CurrentUser;
                    myRegistry.SubKey = "Software\\Gamania\\MapleStory";
                    if (myRegistry.Read("Path") != "")
                        Properties.Settings.Default.gamePath = myRegistry.Read("Path");
                }

                this.comboBox1.SelectedIndex = Properties.Settings.Default.loginMethod;
                this.comboBox2.SelectedIndex = Properties.Settings.Default.loginGame;
                this.textBox3.Text = "";

                if (this.textBox1.Text == "")
                    this.ActiveControl = this.textBox1;
                else if (this.textBox2.Text == "")
                    this.ActiveControl = this.textBox2;

                // .NET textbox full mode bug.
                this.textBox1.ImeMode = ImeMode.OnHalf;
                this.textBox2.ImeMode = ImeMode.OnHalf;
                return true;
            }
            catch { return errexit("初始化失敗,未知的錯誤。", 0); }
        }
Ejemplo n.º 6
0
 //get the token from registry
 private string RetrieveToken(string keyName)
 {
     try
     {
         ModifyRegistry myRegistry = new ModifyRegistry();
         //myRegistry.SubKey = "SOFTWARE\\RTF_SHARP_EDIT\\RECENTFILES";
         myRegistry.ShowError = true;
         string token = myRegistry.Read(keyName);
         LogHelper.Debug(String.Format("Get token: {0} in registry with subkey: {1} and key name: {2}", token, myRegistry.SubKey, keyName));
         return token;
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
         return null;
     }
 }