Ejemplo n.º 1
0
        private void LicenseForm_Load(object sender, EventArgs e)
        {
            tbFingerPrint.Text = Security.FingerPrint.Value();

            RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", false);

            if (key.ContainsSubKey(appName))
            {
                key = key.OpenSubKey(appName);
                object value = key.GetValue(serialKey);
                if (value != null)
                {
                    string strSavedLicenseKey = value.ToString();
                    if (strSavedLicenseKey == strLicenseKey)
                    {
                        this.DialogResult = DialogResult.OK;
                        Close();
                    }
                    else
                    {
                        tbSerialKey.Text = strSavedLicenseKey;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to create the desired sub key to the specified parent.
        /// </summary>
        /// <param name="parentPath">The path to the parent for which to create the sub-key on.</param>
        /// <param name="name">output parameter that holds the name of the sub-key that was create.</param>
        /// <param name="errorMsg">output parameter that contians possible error message.</param>
        /// <returns>Returns true if action succeeded.</returns>
        public static bool CreateRegistryKey(string parentPath, out string name, out string errorMsg)
        {
            name = "";
            try
            {
                RegistryKey parent = GetWritableRegistryKey(parentPath);


                //Invalid can not open parent
                if (parent == null)
                {
                    errorMsg = "You do not have write access to registry: " + parentPath + ", try running client as administrator";
                    return(false);
                }

                //Try to find available names
                int    i        = 1;
                string testName = String.Format("New Key #{0}", i);

                while (parent.ContainsSubKey(testName))
                {
                    i++;
                    testName = String.Format("New Key #{0}", i);
                }
                name = testName;

                using (RegistryKey child = parent.CreateSubKeySafe(name))
                {
                    //Child could not be created
                    if (child == null)
                    {
                        errorMsg = REGISTRY_KEY_CREATE_ERROR;
                        return(false);
                    }
                }

                //Child was successfully created
                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 3
0
        private void btnActive_Click(object sender, EventArgs e)
        {
            if (tbSerialKey.Text == strLicenseKey)
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true);
                key = !key.ContainsSubKey(appName) ? key.CreateSubKey(appName) : key.OpenSubKey(appName, true);
                key.SetValue(serialKey, strLicenseKey);

                MessageBox.Show(Lang._("Activated Successful!"), "BowTie Presenter");
                this.DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                MessageBox.Show(Lang._("Invalid Serial Key!"), "BowTie Presenter");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to delete the desired sub-key from the specified parent.
        /// </summary>
        /// <param name="name">The name of the sub-key to delete.</param>
        /// <param name="parentPath">The path to the parent for which to delete the sub-key on.</param>
        /// <param name="errorMsg">output parameter that contians possible error message.</param>
        /// <returns>Returns true if the operation succeeded.</returns>
        public static bool DeleteRegistryKey(string name, string parentPath, out string errorMsg)
        {
            try
            {
                RegistryKey parent = GetWritableRegistryKey(parentPath);

                //Invalid can not open parent
                if (parent == null)
                {
                    errorMsg = "You do not have write access to registry: " + parentPath + ", try running client as administrator";
                    return(false);
                }

                //Child does not exist
                if (!parent.ContainsSubKey(name))
                {
                    errorMsg = "The registry: " + name + " does not exist in: " + parentPath;
                    //If child does not exists then the action has already succeeded
                    return(true);
                }

                bool success = parent.DeleteSubKeyTreeSafe(name);

                //Child could not be deleted
                if (!success)
                {
                    errorMsg = REGISTRY_KEY_DELETE_ERROR;
                    return(false);
                }

                //Child was successfully deleted
                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Attempts to rename the desired key.
        /// </summary>
        /// <param name="oldName">The name of the key to rename.</param>
        /// <param name="newName">The name to use for renaming.</param>
        /// <param name="parentPath">The path of the parent for which to rename the key.</param>
        /// <param name="errorMsg">output parameter that contians possible error message.</param>
        /// <returns>Returns true if the operation succeeded.</returns>
        public static bool RenameRegistryKey(string oldName, string newName, string parentPath, out string errorMsg)
        {
            try
            {
                RegistryKey parent = GetWritableRegistryKey(parentPath);

                //Invalid can not open parent
                if (parent == null)
                {
                    errorMsg = "You do not have write access to registry: " + parentPath + ", try running client as administrator";
                    return(false);
                }

                //Child does not exist
                if (!parent.ContainsSubKey(oldName))
                {
                    errorMsg = "The registry: " + oldName + " does not exist in: " + parentPath;
                    return(false);
                }

                bool success = parent.RenameSubKeySafe(oldName, newName);

                //Child could not be renamed
                if (!success)
                {
                    errorMsg = REGISTRY_KEY_RENAME_ERROR;
                    return(false);
                }

                //Child was successfully renamed
                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static bool DeleteRegistryKey(string name, string parentPath, out string errorMsg)
        {
            try
            {
                RegistryKey parent = GetWritableRegistryKey(parentPath);

                if (parent == null)
                {
                    errorMsg = "Bu kayıdı açmak için izniniz yoktur: " + parentPath +
                               ", clientin yönetici olarak çalıştırılması gerekiyor.";
                    return(false);
                }

                if (!parent.ContainsSubKey(name))
                {
                    errorMsg = "Bu kayıt: " + name + " bu dizinde bulunmamaktadır: " + parentPath;
                    return(true);
                }

                var success = parent.DeleteSubKeyTreeSafe(name);

                if (!success)
                {
                    errorMsg = REGISTRY_KEY_DELETE_ERROR;
                    return(false);
                }

                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 7
0
        static void Main(params string[] args)
        {
            if (PreProcessApplicationArgs(args))
            {
                return;
            }

            // 如果需要打开文件, 偿试寻找是否有已经存在的应用实例打开
            if (!args.IsNullOrEmpty() && TryOpenByOtherInstance(args))
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IsRunTime = true;

            Options.Current.OpitonsChanged += Current_OpitonsChanged;
            Options.Current.Load(args);

            //D.Message("ProgramEnvironment.RunMode is {0}", ProgramEnvironment.RunMode);
            //D.Message("ApplicationDataDirectory is {0}", ProgramEnvironment.ApplicationDataDirectory);
            //D.Message(new string('-', 40));

            UIColorThemeManage.Initialize();
            //D.Message("LanguageManage.Initialize");
            LanguageManage.Initialize();
            RecentFilesManage.Default.Initialize();

            Current_OpitonsChanged(null, EventArgs.Empty);

            LicenseForm licForm = new LicenseForm();

            if (licForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (false)
            {
                // Check trial period => 10 days
                bool        bTrialExpired = true;
                string      appName       = "WinRAR NT";
                string      subKey        = "General";
                string      firstRunKey   = "FRT";
                string      lastRunKey    = "LRT";
                int         nMaxTrialDays = 10;
                RegistryKey key           = Registry.CurrentUser.OpenSubKey("Software", true);
                bool        bKeyExists    = key.ContainsSubKey(appName);
                TimeSpan    elapsedSpan   = new TimeSpan();
                if (!bKeyExists)
                {
                    key.CreateSubKey(appName);
                    key = key.OpenSubKey(appName, true);
                    key.CreateSubKey(subKey);
                    key = key.OpenSubKey(subKey, true);
                    key.SetValue(firstRunKey, DateTime.Now.Ticks.ToString());
                    bTrialExpired = false;
                }
                else
                {
                    if (key.ContainsSubKey(appName))
                    {
                        key = key.OpenSubKey(appName);
                        if (key.ContainsSubKey(subKey))
                        {
                            key = key.OpenSubKey(subKey);
                            object value = key.GetValue(firstRunKey);
                            if (value != null)
                            {
                                long firstTicks = Convert.ToInt64(value.ToString());
                                long currTicks  = DateTime.Now.Ticks;
                                if (currTicks > firstTicks)
                                {
                                    elapsedSpan = new TimeSpan(currTicks - firstTicks);
                                    if (elapsedSpan.TotalDays <= nMaxTrialDays)
                                    {
                                        value = key.GetValue(lastRunKey);
                                        if (value != null)
                                        {
                                            long lastTicks = Convert.ToInt64(value.ToString());
                                            if (currTicks >= lastTicks)
                                            {
                                                bTrialExpired = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (bTrialExpired)
                {
                    MessageBox.Show(Lang._("Your trial is expired!"), "BowTie Presenter");
                    return;
                }
                MessageBox.Show(String.Format(Lang._("Your trial version will expire in {0} days."), nMaxTrialDays - Convert.ToInt32(elapsedSpan.TotalDays)), "BowTie Presenter");

                Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey(appName, true)
                .OpenSubKey(subKey, true).SetValue(lastRunKey, DateTime.Now.Ticks);
            }

#if DEBUG
            //            NotesWidget nw = new NotesWidget()
            //            {
            //                Remark = @"
            //<P><STRONG>发布时间:<SPAN>2014年4月29日</SPAN> </STRONG></P>
            //<DIV>
            //<P>美国总统奥巴马8天4国的亚太之行,在今天画上句点。美国与日本、韩国、马来西亚以及<WBR>&shy;
            //菲律宾等亚太盟国的关系是否更加紧密,亚太局势是否取得平衡?奥巴马极力推动的跨太平<WBR>&shy;洋伙伴协议TPP是否有所进展?
            //而虽然不在奥巴马的访问行程之内,但正如中国外交部发<WBR>&shy;言人秦刚所说:&quot 你来,或者不来,我就在这里&quot,中国就像&quot房间里的大象&quot,
            //            是美国与盟国即使不直接说<WBR>&shy;明白,却也无法视而不见的议题。奥巴马此行取得哪些成果?我们邀请到两位嘉宾来为我们<WBR>&shy;
            //            解读。一位是香港亚洲周刊资深特派员纪硕鸣先生,另外一位是中国复旦大学美国研究中心<WBR>&shy;沈丁立教授。</P></DIV>"
            //            };
            //            var dlg = new RemarkDialog();
            //            dlg.ShowInTaskbar = true;
            //            dlg.Widget = nw;
            //            dlg.ShowDialog();

            //            dlg.Widget = new NotesWidget()
            //            {
            //                Remark = "abc"
            //            };

            //            dlg.ShowDialog();

            MainForm = new MainForm(args);
            Application.Run(MainForm);
#else
            MainForm = new MainForm(args);
            Application.Run(MainForm);
#endif
            Blumind.Configuration.Options.Current.Save();
        }