Exemplo n.º 1
0
        static public void Refresh()
        {
            RefreshContext();
            string key = SECURITY_KEY + @"\" + SECURITY_TYPE;

            _userName = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "UserName", 0));
            _passwd   = Convert.ToString(RegHelper.GetDecryptedRegValueFromCurrentUser(key, "Passwd", 0));
            _dc       = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "DomainController", 0));
            _port     = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "Port", 0));
            if (_context.Equals(RtContextValue.JVCACHE))
            {
                _userdistinguishedName     = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "DistinguishedName", 0));
                _modifieddistinguishedName = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "ModifiedDistinguishedName", 0));
                _organizationUnit          = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "OrganizationUnit", 0));
                _searchBase       = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "SearchBase", 0));
                _modifiedUserName = Convert.ToString(RegHelper.GetRegValueFromCurrentUser(key, "ModifiedUserName", 0));
            }
            else
            {
                _userdistinguishedName     = "";
                _modifieddistinguishedName = "";
                _organizationUnit          = "";
                _searchBase       = "";
                _modifiedUserName = "";
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// 对比 Reg 文件和注册表,判断是否存在不同,如果不同就说明需要优化。
    /// </summary>
    public bool NeedOptimize()
    {
        var reader   = new RegFileReader(content);
        var expected = true;

        while (expected && reader.Read())
        {
            if (reader.IsKey)
            {
                var exists = RegHelper.KeyExists(reader.Key);
                expected = reader.IsDelete ^ exists;
            }
            else if (reader.IsDelete)
            {
                expected = Registry.GetValue(reader.Key, reader.Name, null) == null;
            }
            else
            {
                expected = CheckValueInDB(reader.Key,
                                          reader.Name, reader.Value, reader.Kind);
            }
        }

        return(!expected);
    }
Exemplo n.º 3
0
        public void ExecResourceSqls(string pattern, Assembly assem = null, string innerNameSpace = null)
        {
            if (assem == null)
            {
                assem = Assembly.GetCallingAssembly();
            }
            var names  = assem.GetManifestResourceNames();
            var sorted = names.OrderBy((k) => k);

            foreach (var name in sorted)
            {
                if (RegHelper.IsReg(name, pattern))
                {
                    SqlAnalyzer.ForeachSQLFromStream(assem.GetManifestResourceStream(name), _dbAccess
                                                     , (n) =>
                    {
                        n          = string.Format("{0}.{1}", innerNameSpace, n);
                        var stream = assem.GetManifestResourceStream(n);
                        if (stream == null)
                        {
                            throw new FileNotFoundException("未找到sql资源文件 - " + n);
                        }
                        return(stream);
                    });
                }
            }
        }
Exemplo n.º 4
0
        public PageUninstall(Control parent, InstallConfig config, Navigator navigator)
        {
            InitializeComponent();
            this.Visible = false;
            this.Parent  = parent;
            this.Dock    = DockStyle.Fill;
            _config      = config;
            _navigator   = navigator;

            string installFolder = RegHelper.GetRegInstallPath();

            if (string.IsNullOrWhiteSpace(installFolder))
            {
                textBoxInstallLocation.Text = string.Format(NotFound, AppInfo.Name);
                labelConfirm.Text           = string.Format(NoInstall, AppInfo.Name);
            }
            else
            {
                _config.InstallLocation     = installFolder;
                textBoxInstallLocation.Text = installFolder;

                labelConfirm.MaximumSize = new Size(460, 0);
                labelConfirm.Text        = string.Format(ConfirmUninstall, AppInfo.Name);

                flatButtonUninstall.Enabled = true;
                _installed = true;
            }
        }
Exemplo n.º 5
0
        public static void ValidateDonationAmount(Message m)
        {
            var input = m.Text.Replace("$", "");
            var amt   = 0;

            if (int.TryParse(input, out amt))
            {
                #if DEBUG
                var api = RegHelper.GetRegValue("DebugStripeTestAPI");
#elif BETA
                var api = RegHelper.GetRegValue("BetaStripeProdAPI");
#elif RELEASE
                var api = RegHelper.GetRegValue("MainStripeProdAPI");
                #endif
                Bot.Api.SendInvoiceAsync(m.From.Id, "Werewolf Donation",
                                         "Make a donation to Werewolf to help keep us online", "somepayloadtest", api,
                                         "startparam", "USD", new[] { new LabeledPrice {
                                                                          Amount = amt * 100, Label = "Donation"
                                                                      } });
            }
            else
            {
                Bot.Api.SendTextMessageAsync(m.From.Id,
                                             "Invalid input.\n" +
                                             "How much would you like to donate?  Please enter a whole number, in US Dollars (USD), in reply to this message",
                                             replyMarkup: new ForceReply {
                    Force = true
                });
            }
        }
Exemplo n.º 6
0
    static Rule ReadContextMenu(RuleFileReader reader)
    {
        var item        = reader.Read();
        var name        = reader.Read();
        var description = reader.Read();
        var directive   = reader.Read();

        IList <string> folders;

        if (directive == ":SEARCH")
        {
            var folder = reader.Read();
            var root   = Path.Combine("HKEY_CLASSES_ROOT", folder);

            folders = RegHelper.Search(root, item)
                      .Select(name => Path.Combine(folder, name))
                      .ToList();
        }
        else
        {
            folders = reader.Drain().ToList();
            folders.Add(directive);
        }

        return(new ContextMenuRule(item, folders, name, description));
    }
Exemplo n.º 7
0
        public void setFirstUser()
        {
            SiteInitHelper initHelper = ObjectContext.Create <SiteInitHelper>();

            if (initHelper.HasInit() == false)
            {
                initHelper.InitSite();
            }

            String name    = ctx.Post("name");
            String email   = ctx.Post("email");
            String pwd     = ctx.Post("pwd");
            String pageUrl = ctx.Post("url");

            User user = new User();

            user.Name  = name;
            user.Pwd   = pwd;
            user.Email = email;
            user.Url   = strUtil.IsNullOrEmpty(pageUrl) ? "admin" : pageUrl;

            user = userService.Register(user, ctx);
            if (ctx.HasErrors)
            {
                echoText(errors.ErrorsText);
            }
            else
            {
                RegHelper.CheckUserSpace(user, ctx);
                loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx);

                echoAjaxOk();
            }
        }
Exemplo n.º 8
0
        public void Load()
        {
            if (RuntimeContext.CurrentContext == RtContextValue.NCACHE)
            {
                try
                {
                    string USER_KEY = RegHelper.ROOT_KEY + @"\UserInfo";
                    _companyName = (string)RegHelper.GetRegValue(USER_KEY, "company", 0);
                }
                catch
                {
                }
            }


            if (RuntimeContext.CurrentContext == RtContextValue.NCACHE)
            {
                try
                {
                    string USER_KEY = RegHelper.ROOT_KEY + @"\UserInfo";
                    _firstName      = (string)RegHelper.GetRegValue(USER_KEY, "firstname", 0);
                    _lastName       = (string)RegHelper.GetRegValue(USER_KEY, "lastname", 0);
                    _registeredName = _firstName + " " + _lastName;
                }
                catch
                {
                }
            }


            if (RuntimeContext.CurrentContext == RtContextValue.NCACHE)
            {
                try
                {
                    string USER_KEY = RegHelper.ROOT_KEY + @"\UserInfo";
                    _email = (string)RegHelper.GetRegValue(USER_KEY, "email", 0);
                }
                catch
                {
                }
            }


#if NETCORE
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                try
                {
                    RegUtil.LoadRegistry();
                    _companyName    = RegUtil.LicenseProperties.UserInfo.Company;
                    _email          = RegUtil.LicenseProperties.UserInfo.Email;
                    _firstName      = RegUtil.LicenseProperties.UserInfo.FirstName;
                    _lastName       = RegUtil.LicenseProperties.UserInfo.LastName;
                    _registeredName = _firstName + " " + _lastName;
                }
                catch (Exception) {}
            }
#endif
        }
Exemplo n.º 9
0
    public void Import()
    {
        RegHelper.Import(@"Resources\Registry\ImportTest.reg");

        var value = Registry.GetValue(@"HKEY_CURRENT_USER\_Test_Import\Key", "StringValue", null);

        Assert.AreEqual("中文内容", value);
    }
Exemplo n.º 10
0
        public void setUserAndApp()
        {
            try {
                // 1)初始化网站基本信息
                SiteInitHelper initHelper = ObjectContext.Create <SiteInitHelper>();
                if (initHelper.HasInit() == false)
                {
                    initHelper.InitSite();
                }

                // 2)创建用户
                String name    = ctx.Post("name");
                String email   = ctx.Post("email");
                String pwd     = ctx.Post("pwd");
                String pageUrl = ctx.Post("url");

                User user = new User();
                user.Name  = name;
                user.Pwd   = pwd;
                user.Email = email;
                user.Url   = strUtil.IsNullOrEmpty(pageUrl) ? "admin" : pageUrl;

                user = userService.Register(user, ctx);
                if (ctx.HasErrors)
                {
                    echoText(errors.ErrorsText);
                    return;
                }

                RegHelper.CheckUserSpace(user, ctx);
                loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx);

                // 3)初始化owner/viewer
                initOwner(ctx);
                initViewer(ctx, user);

                // 4) 网站名称
                String siteName = ctx.Post("siteName");
                updateSiteName(siteName);

                // 5)安装app
                int siteType = ctx.PostInt("siteType");
                initSiteApp(siteType, user);

                echoAjaxOk();
            }
            catch (Exception ex) {
                logger.Fatal("安装出错。错误信息如下:" + Environment.NewLine +
                             "Message=" + ex.Message + Environment.NewLine +
                             "Source=" + ex.Source + Environment.NewLine +
                             "StackTrace=" + Environment.NewLine + ex.StackTrace + Environment.NewLine
                             );

                echoText("安装出错,请检查/framework/log/下日志");
            }
        }
Exemplo n.º 11
0
        private static void PrintUserInfo(IOutputConsole OutputProvider)
        {
            string USER_KEY  = RegHelper.ROOT_KEY + @"\UserInfo";
            string firstName = (string)RegHelper.GetRegValue(USER_KEY, "firstname", 0);
            string lastName  = (string)RegHelper.GetRegValue(USER_KEY, "lastname", 0);
            string company   = (string)RegHelper.GetRegValue(USER_KEY, "company", 0);
            string email     = (string)RegHelper.GetRegValue(USER_KEY, "email", 0);

            OutputProvider.WriteLine("This product is registered to \nUser\t:\t" + firstName + " " + lastName + "\nEmail\t:\t" + email + "\nCompany\t:\t" + company);
        }
Exemplo n.º 12
0
    public void Export()
    {
        using (var key = Registry.CurrentUser.CreateSubKey(@"_Test_Import\Key"))
        {
            key.SetValue("StringValue", "中文内容");
        }
        RegHelper.Export("ExportTest.reg", @"HKEY_CURRENT_USER\_Test_Import\Key");

        Assert.AreEqual(Resources.ImportTest, File.ReadAllText("ExportTest.reg"));
    }
Exemplo n.º 13
0
        private static string GetSettingsPath()
        {
            var settingsPath = RegHelper.GetRegInstallPath() ?? Environment.CurrentDirectory ?? null;

            if (string.IsNullOrWhiteSpace(settingsPath))
            {
                throw new DirectoryNotFoundException("Can't find settings directory");
            }

            return(Path.Combine(settingsPath, "Settings.json"));
        }
Exemplo n.º 14
0
        public static string GetAppSetting(string section, string key)
        {
            section = RegHelper.ROOT_KEY + section;

            object tempVal = RegHelper.GetRegValue(section, key, 0);

            if (!(tempVal is String))
            {
                return(Convert.ToString(tempVal));
            }
            return((String)tempVal);
        }
Exemplo n.º 15
0
        public static void RemoveCredentials(string host)
        {
            if (credentialsCache.ContainsKey(host))
            {
                credentialsCache.Remove(host);
            }

            if (!(String.IsNullOrEmpty(Convert.ToString(RegHelper.GetRegValue(CREDENTIALS_KEY, host, 0)))))
            {
                RegHelper.DeleteRegValue(CREDENTIALS_KEY, host);
            }
        }
Exemplo n.º 16
0
        public void PrintUserInfo()
        {
            string USER_KEY  = RegHelper.ROOT_KEY + @"\UserInfo";
            string firstName = (string)RegHelper.GetRegValue(USER_KEY, "firstname", 4);
            string lastName  = (string)RegHelper.GetRegValue(USER_KEY, "lastname", 4);
            string company   = (string)RegHelper.GetRegValue(USER_KEY, "company", 4);
            string email     = (string)RegHelper.GetRegValue(USER_KEY, "email", 4);

            WriteObject("This product is registered to \nUser\t:\t" + firstName + " " + lastName + "\nEmail\t:\t" + email + "\nCompany\t:\t" + company + "\n");

            // return LicenseManager.LicenseMode(null);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Set the java and .net editions are installed mode
        /// </summary>
        static AuthenticateFeature()
        {
            try
            {
                object dotNetInstallMode = RegHelper.GetRegValue(RegHelper.ROOT_KEY, DOTNET_INSTALL_MODE, 0);

                if (dotNetInstallMode != null)
                {
                    _dotNetInstallMode = (InstallModes)Convert.ToInt16(dotNetInstallMode);
                }
            }
            catch (Exception exception) {}
        }
Exemplo n.º 18
0
 public void Search()
 {
     RegHelper.Import(@"Resources\Registry\Search.reg");
     try
     {
         var result = RegHelper.Search(@"HKCR\测试项", "key");
         CollectionAssert.AreEquivalent(new string[] { "foo", "bar" }, result);
     }
     finally
     {
         Registry.ClassesRoot.DeleteSubKeyTree(@"测试项");
     }
 }
Exemplo n.º 19
0
    public void Save()
    {
        var reg = new RegHelper(this.Name);

        reg.SetProperty("Name", Name);
        reg.SetProperty("Notes", Notes);
        reg.SetProperty("NotesFromPlanner", NotesFromPlanner);
        reg.SetProperty("Project", Project);
        reg.SetProperty("DbLocation", DbLocation);
        reg.SetProperty("AssesmentToolVersion", AssesmentToolVersion);
        reg.SetProperty("ProjectCodes", ProjectCodes);
        reg.SetProperty("StraightToNew", StraightToNew);
    }
Exemplo n.º 20
0
        public void GetRegKeyLastWritetimeTest()
        {
            DateTime t1 = RegHelper.GetRegKeyLastWritetime(Microsoft.Win32.RegistryHive.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ILST_22_0_0");

            Console.WriteLine(t1.ToString());

            DateTime t2 = RegHelper.GetRegKeyLastWritetime(Microsoft.Win32.RegistryHive.LocalMachine, @"SOFTWARE\WinRAR");

            Console.WriteLine(t2.ToString());

            DateTime t3 = RegHelper.GetRegKeyLastWritetime(Microsoft.Win32.RegistryHive.LocalMachine, @"SOFTWARE\7-Zip");

            Console.WriteLine(t3.ToString());
        }
Exemplo n.º 21
0
        public void setUserAndApp()
        {
            // 1)初始化网站基本信息
            SiteInitHelper initHelper = ObjectContext.Create <SiteInitHelper>();

            if (initHelper.HasInit() == false)
            {
                initHelper.InitSite();
            }

            // 2)创建用户
            String name    = ctx.Post("name");
            String email   = ctx.Post("email");
            String pwd     = ctx.Post("pwd");
            String pageUrl = ctx.Post("url");

            User user = new User();

            user.Name  = name;
            user.Pwd   = pwd;
            user.Email = email;
            user.Url   = strUtil.IsNullOrEmpty(pageUrl) ? "admin" : pageUrl;

            user = userService.Register(user, ctx);
            if (ctx.HasErrors)
            {
                echoText(errors.ErrorsText);
                return;
            }

            RegHelper.CheckUserSpace(user, ctx);
            loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx);

            // 3)初始化owner/viewer
            initOwner(ctx);
            initViewer(ctx, user);

            // 4) 网站名称
            String siteName = ctx.Post("siteName");

            updateSiteName(siteName);

            // 5)安装app
            int siteType = ctx.PostInt("siteType");

            initSiteApp(siteType, user);

            echoAjaxOk();
        }
Exemplo n.º 22
0
    public static Favorite GetFavorite(string favoriteName)
    {
        var reg = new RegHelper(favoriteName);

        return(new Favorite(favoriteName)
        {
            Notes = reg.GetProperty("Notes"),
            NotesFromPlanner = reg.GetPropertyAsBool("NotesFromPlanner"),
            Project = reg.GetProperty("Project"),
            DbLocation = reg.GetProperty("DbLocation"),
            AssesmentToolVersion = reg.GetProperty("AssesmentToolVersion"),
            ProjectCodes = reg.GetProperty("ProjectCodes"),
            StraightToNew = reg.GetPropertyAsBool("StraightToNew"),
        });
    }
Exemplo n.º 23
0
 public void Optimize()
 {
     if (TargetState == ServiceState.Deleted)
     {
         Registry.LocalMachine.DeleteSubKeyTree(subPath);
         return;
     }
     try
     {
         ChaangeServiceStartupRegistry();
     }
     catch (SecurityException)
     {
         using var _ = RegHelper.Elevate(Registry.LocalMachine, subPath);
         ChaangeServiceStartupRegistry();
     }
 }
Exemplo n.º 24
0
        private void btnActive_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "激活文件(*.rts)|*.rts";
                if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string text = string.Empty;
                    using (StreamReader sr = new StreamReader(open.FileName, System.Text.Encoding.UTF8))
                    {
                        text = sr.ReadToEnd();
                    }

                    RegHelper reg = new RegHelper();
                    if (reg.IsCheckOut(text))
                    {
                        MessageBox.Show("注册成功", "提示");
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("注册失败,请检查注册信息", "提示");
                    }



                    //RegHelper helper = new RegHelper();
                    //string RegInfo = Register.DESEncrypt.Decrypt(text);
                    //helper.SetRegInfo(RegInfo.Split('|')[1], RegInfo.Split('|')[2], RegInfo.Split('|')[3], RegInfo.Split('|')[4]);
                    //if (helper.CheckInfo() && helper.IsValidity() && helper.IsCurrent())
                    //{
                    //    MessageBox.Show("注册成功", "提示");
                    //    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    //}
                    //else
                    //    MessageBox.Show("授权信息不正确,请确认注册信息!", "提示");
                }
            }
            catch
            {
                MessageBox.Show("授权信息不正确,请确认注册信息!", "提示");
            }
        }
Exemplo n.º 25
0
        public PageLocation(Control parent, InstallConfig config, Navigator navigator)
        {
            InitializeComponent();
            this.Visible = false;
            this.Parent  = parent;
            this.Dock    = DockStyle.Fill;
            _config      = config;
            _navigator   = navigator;

            string installFolder = RegHelper.GetRegInstallPath();

            if (string.IsNullOrWhiteSpace(installFolder))
            {
                installFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                installFolder = Path.Combine(installFolder, AppInfo.Name);
            }
            textBoxInstallLocation.Text = installFolder;
            textBoxInstallLocation.Select(textBoxInstallLocation.Text.Length, 0);
        }
Exemplo n.º 26
0
        public static void AddCredentials(string host, Credentials credentials)
        {
            Credentials existingCredentials;
            bool        found = credentialsCache.TryGetValue(host, out existingCredentials);

            if (found && existingCredentials.ConnectionFailed)
            {
                credentialsCache.Remove(host);
            }

            credentialsCache[host] = credentials;

            if (!(RegHelper.IsRegKeyExist(CREDENTIALS_KEY)))
            {
                RegHelper.NewKey(CREDENTIALS_KEY);
            }

            RegHelper.SetRegValue(CREDENTIALS_KEY, credentials.Host, credentials.SSHPort, 0);
        }
Exemplo n.º 27
0
        static public void Apply()
        {
            RefreshContext();
            string key = SECURITY_KEY + @"\" + SECURITY_TYPE;

            RegHelper.SetRegValueInCurrentUser(key, "UserName", _userName, 0);
            RegHelper.SetEncryptedRegValueInCurrentUser(key, "Passwd", _passwd);
            RegHelper.SetRegValueInCurrentUser(key, "DomainController", _dc, 0);
            RegHelper.SetRegValueInCurrentUser(key, "Port", _port, 0);

            if (_context.Equals(RtContextValue.JVCACHE))
            {
                RegHelper.SetRegValueInCurrentUser(key, "DistinguishedName", _userdistinguishedName, 0);
                RegHelper.SetRegValueInCurrentUser(key, "OrganizationUnit", _organizationUnit, 0);

                RegHelper.SetRegValueInCurrentUser(key, "ModifiedDistinguishedName", _modifieddistinguishedName, 0);
                RegHelper.SetRegValueInCurrentUser(key, "SearchBase", _searchBase, 0);
                RegHelper.SetRegValueInCurrentUser(key, "ModifiedUserName", _modifiedUserName, 0);
            }
        }
Exemplo n.º 28
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new FrmMain());
            RegHelper reg = new RegHelper();

            if (reg.CheckRegInfo())
            {
                Application.Run(new FrmMain());
            }
            else
            {
                MessageBox.Show("授权到期或授权无效,请进行注册", "提示");
                if (new FrmReg().ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new FrmMain());
                }
            }
        }
Exemplo n.º 29
0
    /// <summary>
    /// 检查 Reg 文件里的一个值是否已经存在于注册表中。
    /// </summary>
    /// <param name="key">键路径</param>
    /// <param name="name">值名</param>
    /// <param name="valueStr">Reg文件里字符串形式的值</param>
    /// <param name="kind">值类型</param>
    bool CheckValueInDB(string key, string name, object expected, RegistryValueKind kind)
    {
        using var keyObj = RegHelper.OpenKey(key);
        var valueInDB = keyObj.GetValue(name, null, RegistryValueOptions.DoNotExpandEnvironmentNames);

        // Binary 和 MultiString 返回的是数组,需要用 SequenceEqual 对比。
        bool ConvertAndCheck <T>()
        {
            if (valueInDB is not T[] || valueInDB == null)
            {
                return(false);
            }
            return(((T[])expected).SequenceEqual((T[])valueInDB));
        }

        return(kind switch
        {
            RegistryValueKind.MultiString => ConvertAndCheck <string>(),
            RegistryValueKind.Binary => ConvertAndCheck <byte>(),
            RegistryValueKind.Unknown or RegistryValueKind.None => throw new Exception("无效的值类型"),
            _ => expected.Equals(valueInDB),
        });
Exemplo n.º 30
0
        public static bool TryGetCredentials(string host, out Credentials credentials)
        {
            bool found = credentialsCache.TryGetValue(host, out credentials);

            if (!found)
            {
                //If credentials are not found in cache, we should try to at least get the port from registry if there.
                object port = RegHelper.GetRegValue(CREDENTIALS_KEY, host, 0);
                if (port == null)
                {
                    return(false);
                }

                int  sshPort;
                bool parsed = int.TryParse(port.ToString(), out sshPort);
                if (parsed)
                {
                    credentials = new Credentials(host, sshPort, string.Empty, string.Empty);
                }
            }

            return(found);
        }