Esempio n. 1
0
        private void ucBtnExt_Hwid_BtnClick(object sender, EventArgs e)
        {
            string ret = Verify.HwidReset(key, IpConfig.GetMac());

            if (ret == "1")
            {
                //解绑成功,查询剩余时间
                expiredTimeS = Verify.GetExpired(key);
                DateTime expiredTime  = Convert.ToDateTime(expiredTimeS);
                TimeSpan ts           = expiredTime.Subtract(DateTime.Now);
                string   expiredTimes = String.Format("{0}{1}天{2}时{3}分", "卡密剩余时间:", ts.Days.ToString(), ts.Hours.ToString(), ts.Minutes.ToString());
                FrmDialog.ShowDialog(this, "当前卡密已成功解绑,您可在此台电脑上正常登录\n\n解绑后" + expiredTimes + "\n\n点击\"确定\"按钮返回登录界面", "Ares - 卡密解绑");
                Close();
            }
            else
            {
                //解绑失败,报错
                FrmDialog.ShowDialog(this, "当前卡密解绑失败\n\n失败原因:" + ErrorCodeTranslation.Get(ret) + "\n\n点击\"确定\"按钮返回登录界面", "Ares - 卡密解绑");
                Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 登录按钮被点击
        /// </summary>
        private void ucBtnExt_Login_BtnClick(object sender, EventArgs e)
        {
            ucBtnExt_Login.FillColor = Color.FromArgb(155, 155, 155);
            ucBtnExt_Login.Enabled   = false;

            string ret = Verify.Login(ucTextBoxEx_Key.InputText, localVersion, IpConfig.GetMac());

            if (ret.Length == 32)//登录成功
            {
                //登录按钮消失,进度条取代,进行必要的变量的声明
                ucBtnExt_Login.Visible = false;
                ucProcessLine.Visible  = true;
                ucProcessLine.Location = ucBtnExt_Login.Location;
                string expiredTimeS     = null;
                string diskSerialNumber = SystemConfig.GetDiskSerialNumber();
                bool   isDownload       = false;

                Thread loginSuccessThread = new Thread(() =>
                {
                    //对userLoginData进行赋值
                    userLoginData.Key          = ucTextBoxEx_Key.InputText;
                    userLoginData.StatusCode   = ret;
                    expiredTimeS               = Verify.GetExpired(userLoginData.Key);
                    userLoginData.ExpiredTimeS = expiredTimeS;
                    DateTime expiredTime       = Convert.ToDateTime(userLoginData.ExpiredTimeS);
                    userLoginData.ExpiredTime  = expiredTime;

                    //取到期时间的时间间隔
                    TimeSpan ts = expiredTime.Subtract(Convert.ToDateTime(GetData.GetNetDateTime()));   //用网络时间进行计算

                    label_Status.ForeColor = Color.FromArgb(66, 66, 66);
                    label_Status.Text      = String.Format("{0}{1}天{2}时{3}分", "卡密剩余时间:", ts.Days.ToString(), ts.Hours.ToString(), ts.Minutes.ToString());

                    //写配置文件保存卡密
                    OperateIniFile.WriteIniData("Ares", "Key", Encrypt.DES(userLoginData.Key, "areskeys"), "logindata.ini");

                    //核心数据取COS下载数据并解析
                    string appCode = Verify.GetAppCore(userLoginData.StatusCode, userLoginData.Key);
                    if (appCode == "-1")
                    {
                        FrmDialog.ShowDialog(this, "Ares无法下载核心云端数据\n\n点击\"确定\"按钮退出Ares软件", "Ares - 致命错误");
                        Environment.Exit(0);
                    }
                    if (appCode.Length <= 10)
                    {
                        FrmDialog.ShowDialog(this, "Ares下载的核心云端数据不合法\n\n点击\"确定\"按钮退出Ares软件", "Ares - 致命错误");
                        Environment.Exit(0);
                    }
                    DllDownloadData dllDownloadData = JsonConvert.DeserializeObject <DllDownloadData>(appCode);

                    //判断文档中的 TencentCos 文件夹是否存在,不存在就新建一个
                    if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber) != true)
                    {
                        try
                        {
                            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber);
                        }
                        catch
                        {
                            FrmDialog.ShowDialog(this, "Ares申请的读写目录权限申请失败\n\n点击\"确定\"按钮退出Ares软件", "Ares - 致命错误");
                            Environment.Exit(0);
                        }
                        Console.WriteLine("TencentCos文件夹不存在,已经新建完毕");
                    }

                    //文件是否已经存在,存在就不再下载,节省流量
                    if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber + "\\" + Decrypt.DES(dllDownloadData.LocalFileName, Decrypt.DES(webApiUrlData.Key, "actingnb"))) == true)
                    {
                        //文件存在,进行MD5校验,校验通过就不重新下载了
                        string existFileMD5 = MD5.GetMD5HashFromFile(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber + "\\" + Decrypt.DES(dllDownloadData.LocalFileName, Decrypt.DES(webApiUrlData.Key, "actingnb")));
                        if (existFileMD5 != "-1")                                                                             //验证是否成功取到MD5
                        {
                            if (existFileMD5 == Decrypt.DES(dllDownloadData.MD5, Decrypt.DES(webApiUrlData.Key, "actingnb"))) //验证MD5是否与服务器的相符
                            {
                                isDownload          = false;                                                                  //MD5相符,不需要重新下载
                                ucProcessLine.Value = 100;
                                Console.WriteLine("MD5相符,不需要重新下载");
                            }
                            else
                            {
                                isDownload = true;//MD5不符,需要重新下载
                                Console.WriteLine("MD5不符,需要重新下载");
                            }
                        }
                    }
                    else
                    {
                        isDownload = true;//文件不存在,进行下载
                        Console.WriteLine("文件不存在,进行下载");
                    }

                    //云下载DLL
                    if (isDownload == true)
                    {
                        string secretId  = Decrypt.DES(dllDownloadData.SecretId, Decrypt.DES(webApiUrlData.Key, "actingnb"));  // API SecretId
                        string secretKey = Decrypt.DES(dllDownloadData.SecretKey, Decrypt.DES(webApiUrlData.Key, "actingnb")); // API SecretKey
                        string region    = Decrypt.DES(dllDownloadData.Region, Decrypt.DES(webApiUrlData.Key, "actingnb"));    // 存储桶所在地域

                        CosXmlConfig config = new CosXmlConfig.Builder()                                                       //普通初始化方式
                                              .IsHttps(true)                                                                   //设置默认 HTTPS 请求
                                              .SetRegion(region)
                                              .SetDebugLog(true)
                                              .Build();

                        long durationSecond = 600;  //每次请求签名有效时长,单位为秒
                        QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond);

                        CosXml cosXml = new CosXmlServer(config, cosCredentialProvider);

                        try
                        {
                            string bucket            = Decrypt.DES(dllDownloadData.Bucket, Decrypt.DES(webApiUrlData.Key, "actingnb"));            //存储桶,格式:BucketName-APPID
                            string key               = Decrypt.DES(dllDownloadData.Key, Decrypt.DES(webApiUrlData.Key, "actingnb"));               //对象键
                            string localDir          = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber; //下载到的目录 不需要文件名
                            string localFileName     = Decrypt.DES(dllDownloadData.LocalFileName, Decrypt.DES(webApiUrlData.Key, "actingnb"));     //指定本地保存的文件名
                            GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName);
                            //设置进度回调
                            request.SetCosProgressCallback(delegate(long completed, long total)
                            {
                                //Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
                                ucProcessLine.Value = Convert.ToInt32(completed * 100.0 / total);
                            });
                            //执行请求
                            GetObjectResult result = cosXml.GetObject(request);
                            //请求成功
                            Console.WriteLine(result.GetResultInfo());
                        }
                        catch (CosClientException clientEx)
                        {
                            //请求失败
                            //MessageBox.Show("CosClientException: " + clientEx);
                            FrmDialog.ShowDialog(this, "Ares无法下载核心云端文件\n\n点击\"确定\"按钮退出Ares软件" + "CosClientException: " + clientEx, "Ares - 致命错误");
                            Environment.Exit(0);
                        }
                        catch (CosServerException serverEx)
                        {
                            //请求失败
                            //MessageBox.Show("CosServerException: " + serverEx.GetInfo());
                            FrmDialog.ShowDialog(this, "Ares无法下载核心云端文件\n\n点击\"确定\"按钮退出Ares软件" + "CosServerException: " + serverEx.GetInfo(), "Ares - 致命错误");
                            Environment.Exit(0);
                        }

                        //下载完成后判断文件是否已经存在,不存在就是下载失败
                        if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber + "\\" + Decrypt.DES(dllDownloadData.LocalFileName, Decrypt.DES(webApiUrlData.Key, "actingnb"))) == true)
                        {
                            //文件存在,进行MD5校验,校验通过就不重新下载了
                            string existFileMD5 = MD5.GetMD5HashFromFile(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + diskSerialNumber + "\\" + Decrypt.DES(dllDownloadData.LocalFileName, Decrypt.DES(webApiUrlData.Key, "actingnb")));
                            if (existFileMD5 != "-1")                                                                             //验证是否成功取到MD5
                            {
                                if (existFileMD5 != Decrypt.DES(dllDownloadData.MD5, Decrypt.DES(webApiUrlData.Key, "actingnb"))) //验证MD5是否与服务器的相符
                                {
                                    FrmDialog.ShowDialog(this, "Ares下载的核心云端文件与服务器不符\n\n点击\"确定\"按钮退出Ares软件", "Ares - 致命错误");
                                    Console.WriteLine("下载的文件MD5不符");
                                    Environment.Exit(0);
                                }
                            }
                        }
                        else
                        {
                            FrmDialog.ShowDialog(this, "Ares未能成功下载核心云端文件\n\n点击\"确定\"按钮退出Ares软件", "Ares - 致命错误"); //下载的文件不存在
                            Console.WriteLine("下载的文件不存在");
                            Environment.Exit(0);
                        }
                    }
                    //设置用户数据,上传用户的QQ和硬件信息
                    List <string> onlineQQList = GetQQNumber.GetOnlineQQ();//获取在线QQ
                    string onlineQQ            = string.Empty;
                    if (onlineQQList.Count > 0)
                    {
                        foreach (string i in onlineQQList)
                        {
                            onlineQQ = onlineQQ + i + "  ";
                        }
                    }
                    else
                    {
                        onlineQQ = "None";
                    }

                    UserUpdateData userUpdateData = new UserUpdateData()
                    {
                        OnlineQQ         = onlineQQ,
                        DiskSerialNumber = SystemConfig.GetDiskSerialNumber(),
                        CpuID            = SystemConfig.GetCpuID(),
                        BoardId          = SystemConfig.GetBoardId()
                    };
                    string setRetCode = Verify.SetUserData(userLoginData.StatusCode, userLoginData.Key, JsonConvert.SerializeObject(userUpdateData));


                    //载入主窗口
                    this.Visible = false;
                    Application.Run(new MainForm(userLoginData));
                });
                loginSuccessThread.Start();
            }
            else
            {
                //登录失败
                if (ret == "-402")//判断是否需要解绑
                {
                    if (FrmDialog.ShowDialog(this, "当前卡密未在绑定的电脑上登录\n\n点击\"确定\"按钮为您打开解绑窗口来解绑新的机器码\n\n点击\"取消\"按钮取消解绑操作并回到主界面", "Ares - 卡密解绑", true) == DialogResult.OK)
                    {
                        HwidResetForm hwidResetForm = new HwidResetForm(Verify, ucTextBoxEx_Key.InputText, Root.HwidResetContent.Replace("*", Environment.NewLine));
                        hwidResetForm.ShowDialog();
                        ucBtnExt_Login.FillColor = Color.FromArgb(221, 31, 50);
                        ucBtnExt_Login.Enabled   = true;
                    }
                    else
                    {
                        ucBtnExt_Login.FillColor = Color.FromArgb(221, 31, 50);
                        ucBtnExt_Login.Enabled   = true;
                        label_Status.ForeColor   = Color.FromArgb(239, 51, 42);
                        label_Status.Text        = "卡密未在绑定的电脑上登录且未解绑";
                    }
                }
                else
                {
                    ucBtnExt_Login.FillColor = Color.FromArgb(221, 31, 50);
                    ucBtnExt_Login.Enabled   = true;
                    label_Status.ForeColor   = Color.FromArgb(239, 51, 42);
                    label_Status.Text        = ErrorCodeTranslation.Get(ret);
                }
            }
        }