Beispiel #1
0
        private void ThreadSingleDownload(object _value)
        {
            object[] _object = _value as object[];

            String strLocal  = _object[0] as String;
            String strTarget = _object[1] as String;

            Step.State state = (Step.State)_object[2];

            FtpProtocol protocol = _object[3] as FtpProtocol;

            Step.State failState = (Step.State)_object[4];

            if (!protocol.Download(strTarget, strLocal, true))
            {
                Step.CURRENT_STEP = failState;
                return;
            }
            Step.CURRENT_STEP = state;
        }
Beispiel #2
0
        /// <summary>
        /// 初始化窗口设置
        /// </summary>
        private void Init()
        {
            m_currentPath = Application.ExecutablePath.Replace('\\', '/');
            int len = m_currentPath.LastIndexOf(@"/");

            m_curDirectory = m_currentPath.Substring(0, len + 1);

            m_luncherOld  = m_curDirectory + App.m_lancherName + m_luncherOld;
            m_ftpThread   = new FTPThread();
            m_ftpProtocol = new FtpProtocol(FTPHost, FTPID, FTPPassword, this);

            m_downloadPath       = m_curDirectory + m_downloadPath;
            m_localServerVerPath = m_curDirectory + m_serverVerName;
            m_verPath            = m_curDirectory + m_clientVerName;

            m_luancherPath = m_curDirectory + App.m_lancherName + ".exe";
            string localMd5 = m_curDirectory + m_clientmd5Txt;

            m_clientServerDirectory = m_ftpPath + m_clientServerDirectory;
            //服务端文件、md5文件、旧启动器都要删除
            string[] deleteFiles = { m_localServerVerPath, m_luncherOld, localMd5 };
            foreach (string Path in deleteFiles)
            {
                if (File.Exists(Path))
                {
                    File.Delete(Path);
                }
            }
            if (Directory.Exists(m_downloadPath))
            {
                Directory.Delete(m_downloadPath, true);
            }
            CheckFIPSRegistValue();

            Label_Ver.Content = IniManager.GetINIValue(m_verPath, "Client", "ver");
        }
Beispiel #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;
        }