Exemplo n.º 1
0
        public void MergeLauncher()
        {
            label_File_Info_String.Content = "合并启动器中...";
            Step.CURRENT_STEP = Step.State.___waittt;

#if DEBUG
            Step.CURRENT_STEP = Step.State._ProcessState_CheckVer;
#else
            try
            {
                string tempLauncherPath = m_downloadPath + "/" + App.m_lancherName + ".exe";
                //var launcherMd5name = UpdateHelper.Instance().m_launcherMD5;

                if (File.Exists(m_luancherPath) && File.Exists(tempLauncherPath))
                {
                    var downloadlaunchermd5 = FileMatchUp.ComputeMD5Hash(tempLauncherPath);
                    if (downloadlaunchermd5 == launcherMd5)
                    {
                        FileInfo fi = new FileInfo(m_luancherPath);
                        //将当前启动器改为旧的
                        fi.MoveTo(m_luancherPath + ".old");
                        //temp文件夹里的移动到当前文件夹下
                        File.Move(tempLauncherPath, m_luancherPath);
                        //Process.Start(destFileName, "new");

                        ProcessStartInfo psi = new ProcessStartInfo("cmd.exe",
                                                                    "/C ping 127.0.0.1 -n " + 3 + " -w 1000 > Nul & " + m_luancherPath);
                        psi.WindowStyle    = ProcessWindowStyle.Hidden;
                        psi.CreateNoWindow = true;
                        Process.Start(psi);

                        AppEnd();
                    }
                    else
                    {
                        MessageBox.Show("下载的启动器与最新版本的启动器不匹配,请待服务器资源同步完成后再启动!", "LMD5Error", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    MessageBox.Show("启动器替换失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("启动自我升级异常原因如下: " + ex.Message);
                AppEnd();
            }
#endif
        }
Exemplo n.º 2
0
        public void CheckMD5()
        {
            //label_Total_Info_string.Content = "检查当前启动器版本中";
            Step.CURRENT_STEP = Step.State.___waittt;
            //读取serverVer.ini的启动器版本号
            launcherMd5 = IniManager.GetINIValue(m_localServerVerPath, "LauncherMd5", "md5");

            if (File.Exists(m_luancherPath))   //存在启动器则检查
            {
                string computeMd5Hash = FileMatchUp.ComputeMD5Hash(m_luancherPath);
                //Todo 启动器md5相同的话就启动版本号检测是否要更新客户端
                //不相同的话就更新启动器
                if (computeMd5Hash == launcherMd5)
                {
                    Step.CURRENT_STEP = Step.State._ProcessState_CheckVer;
                    return;
                }
            }
            //  启动器下载
            Step.CURRENT_STEP = Step.State.__DownLoadLauncher;
        }
Exemplo n.º 3
0
        private void DownloadGameFile(object _value)
        {
            object[]    _object   = _value as object[];
            String[]    pathArray = _object[0] as String[];
            Step.State  nextState = (Step.State)_object[1];
            FtpProtocol protocol  = _object[2] as FtpProtocol;
            string      downloadLocalDirectory = _object[3] as String; //本地的保存地址
            string      sourceDirectory        = _object[4] as String; //服务端的下载地址

            List <string> failFile = new List <string>();              //更新过程中出现更新失败的文件

            FTPUpdateValue.CurrentFileDownloadBytes = 0;
            FTPUpdateValue.CurrentFileByte          = 0;
            //FTPUpdateValue.maxByte = FTPUpdateValue.maxByte - FTPUpdateValue.CurrentFileByte;
            //FTPUpdateValue.CurrentAccumlatereadByte =Math.Max(0, FTPUpdateValue.CurrentAccumlatereadByte- FTPUpdateValue.CurrentFileDownloadBytes);
            FTPUpdateValue.maxfileCount += pathArray.Length;

            //TODO 此处开始获取新资源大小
            for (int i = 0; i < pathArray.Length; i++)
            {
                string strTarget = protocol.mainform.m_clientServerDirectory + pathArray[i];
                string text      = string.Format("当前更新{0}/{1}个文件", i, FTPUpdateValue.maxfileCount);

                long sizeI = protocol.GetFileSize(strTarget);
                if (sizeI >= 0)
                {
                    FTPUpdateValue.maxByte += sizeI;
                }
                else
                {
                    //todo 获取文件大小的文件暂时不处理
                    continue;
                }
            }

            Step.CURRENT_STEP = Step.State.__StartNeedDownLoadListing;

            //todo 此处开始下载资源。更新下载进度
            for (int i = 0; i < pathArray.Length; i++)
            {
                var    filepath = pathArray[i];
                string strLocal = downloadLocalDirectory + filepath;
                strLocal = strLocal.Replace('\\', '/');
                string strSource = sourceDirectory + filepath;
                FTPUpdateValue.downloadIndex++;
                if (!protocol.Download(strSource, strLocal, true))
                {
                    //todo下载失败
                    failFile.Add(filepath);
                    continue;
                }
                else
                {
                    //每次下载完校验md5后移动到本地的最终位置
                    bool isLocalEx = File.Exists(strLocal);
                    bool isServer  = UpdateHelper.Instance()._ServerUpdateStructs.ContainsKey(filepath);
                    if (isLocalEx && isServer)
                    {
                        var computeMd5Hash     = FileMatchUp.ComputeMD5Hash(strLocal);
                        var serverUpdateStruct = UpdateHelper.Instance()._ServerUpdateStructs[filepath].Md5;
                        if (computeMd5Hash == serverUpdateStruct)
                        {
                            if (UpdateHelper.Instance()._ClientUpdateStructs.ContainsKey(filepath))
                            {
                                UpdateHelper.Instance()._ClientUpdateStructs[filepath].Md5 = computeMd5Hash;
                            }
                            else
                            {
                                var myUpdateStruct = new MyUpdateStruct();
                                myUpdateStruct.PathKey = filepath;
                                myUpdateStruct.Md5     = computeMd5Hash;
                                UpdateHelper.Instance()._ClientUpdateStructs.Add(myUpdateStruct.PathKey, myUpdateStruct);
                            }
                            string tarPath = protocol.mainform.m_curDirectory + filepath;

                            if (File.Exists(tarPath))
                            {
                                File.Delete(tarPath);
                            }

                            if (filepath.Contains('/'))
                            {
                                var    strings = filepath.Split('/');
                                string curpath = "";

                                for (var i1 = 0; i1 < strings.Length; i1++)
                                {
                                    if (i1 != strings.Length - 1)
                                    {
                                        curpath = curpath + "/" + strings[i1];

                                        if (!Directory.Exists(protocol.mainform.m_curDirectory + curpath))
                                        {
                                            Directory.CreateDirectory(protocol.mainform.m_curDirectory + curpath);
                                        }
                                    }
                                }
                            }
                            // 将下载好的文件挪出去
                            File.Move(strLocal, tarPath);
                        }
                    }
                }
            }
            if (failFile.Count > 0)
            {
                string text = "更新失败的文件有:";
                foreach (string var  in  failFile)
                {
                    text = text + var + " , ";
                }
            }
            Step.CURRENT_STEP = nextState;
        }