Esempio n. 1
0
        private void registerBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.registerBtn.Enabled = false;
                SoftReg sr = new SoftReg();
                string  auth_code_by_textbox = this.serialTextBox.Text.Trim();
                string  auth_code            = sr.MD5Encrypt(sr.getRNum());
                if (auth_code_by_textbox == "")
                {
                    DialogResult result = MessageBox.Show("请输入序列号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    if (result == DialogResult.OK)
                    {
                    }
                    this.registerBtn.Enabled = true;
                    return;
                }

                if (auth_code_by_textbox == auth_code)
                {
                    string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
                                       Environment.OSVersion.Platform == PlatformID.MacOSX)
                        ? Environment.GetEnvironmentVariable("HOME")
                        : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

                    FileStream saveFile   = new FileStream(homePath + "/.ap_serial", FileMode.Create, FileAccess.ReadWrite);
                    string     write_str  = sr.MD5Encrypt(auth_code_by_textbox);
                    IFormatter serializer = new BinaryFormatter();
                    serializer.Serialize(saveFile, write_str);
                    saveFile.Close();

                    DialogResult result = MessageBox.Show("激活成功,请重新打开应用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (result == DialogResult.OK)
                    {
                        this.Close();
                        System.Environment.Exit(0);
                    }
                }
                else
                {
                    DialogResult result = MessageBox.Show("激活失败,请重新输入序列号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (result == DialogResult.OK)
                    {
                        this.serialTextBox.Text  = "";
                        this.registerBtn.Enabled = true;
                    }
                }
            }
            catch (IOException ee)
            {
                throw ee;
                DialogResult result = MessageBox.Show("激活时发生严重错误,请重启电脑后,重新激活!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (result == DialogResult.OK)
                {
                    this.Close();
                    System.Environment.Exit(0);
                }
            }
        }
Esempio n. 2
0
        public RegisterForm()
        {
            InitializeComponent();
            SoftReg sr   = new SoftReg();
            string  rnum = sr.getRNum();

            this.keyTextBox.Text = rnum;
        }
Esempio n. 3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //用于序列化和反序列化的对象
            IFormatter serializer = new BinaryFormatter();
            bool       isRegister = false;

            //反序列化
            try
            {
                string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
                                   Environment.OSVersion.Platform == PlatformID.MacOSX)
                      ? Environment.GetEnvironmentVariable("HOME")
                      : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

                if (File.Exists(homePath + "/.ap_serial"))
                {
                    FileStream loadFile          = new FileStream(homePath + "/.ap_serial", FileMode.Open, FileAccess.Read);
                    string     auth_code_by_file = serializer.Deserialize(loadFile) as string;
                    loadFile.Close();
                    SoftReg sr         = new SoftReg();
                    string  serialText = sr.getRNum();
                    string  auth_code  = sr.MD5Encrypt(sr.MD5Encrypt(serialText));

                    isRegister = auth_code_by_file == auth_code;
                }
                else
                {
                    isRegister = false;
                }
            }
            catch (FileNotFoundException e)
            {
                isRegister = false;
            }

            if (isRegister)
            {
                MainForm mainForm = new MainForm();
                Application.Run(mainForm);
            }
            else// 如果没有注册,则弹出注册对话框
            {
                RegisterForm mainForm = new RegisterForm();
                Application.Run(mainForm);
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            //用于序列化和反序列化的对象
            IFormatter serializer = new BinaryFormatter();

            //反序列化
            try
            {
                FileStream loadFile = new FileStream("serial", FileMode.Open, FileAccess.Read);
                string     tests2   = serializer.Deserialize(loadFile) as string;
                Console.WriteLine(tests2);
            }catch (FileNotFoundException e)
            {
            }

            //开始序列化
            FileStream saveFile  = new FileStream("serial", FileMode.Create, FileAccess.Write);
            SoftReg    sr        = new SoftReg();
            string     auth_code = "fc4be3a30def3b4821f893fff7ae63ce";
            string     write_str = sr.MD5Encrypt(auth_code);

            serializer.Serialize(saveFile, write_str);
            saveFile.Close();
        }