Ejemplo n.º 1
0
        public List <VZ_FileInfos> getFull(String basePath)
        {
            List <VZ_FileInfos> fileList = new List <VZ_FileInfos>();
            DirectoryInfo       dir      = new DirectoryInfo(basePath);

            FileInfo[]      files = dir.GetFiles();
            DirectoryInfo[] dirs  = dir.GetDirectories();

            foreach (FileInfo info in files)
            {
                if (info.FullName.EndsWith("VRZoneUpdater.exe"))
                {
                    continue;
                }
                VZ_FileInfos fs = new VZ_FileInfos();
                fs.name = info.Name;
                fs.path = info.FullName.Substring(basePath.Length + 1);
                fs.md5  = VZ_UpdateMethods.GetMD5HashFromFile(info.FullName);
                fs.url  = httpPath + info.FullName.Substring(basePath.Length + 1).Replace("\\", "/");
                fileList.Add(fs);
                Dispatcher.BeginInvoke((Action)(() => {
                    addLog(fs);
                }));
            }

            foreach (DirectoryInfo info in dirs)
            {
                fileList.AddRange(getFiles(info, basePath));
            }
            return(fileList);
        }
Ejemplo n.º 2
0
        public List <VZ_FileInfos> getFull(String basePath)
        {
            List <VZ_FileInfos> fileList = new List <VZ_FileInfos>();
            DirectoryInfo       dir      = new DirectoryInfo(basePath);

            FileInfo[]      files = dir.GetFiles();
            DirectoryInfo[] dirs  = dir.GetDirectories();

            foreach (FileInfo info in files)
            {
                VZ_FileInfos fs = new VZ_FileInfos();
                fs.name = info.Name;
                fs.path = info.FullName.Substring(basePath.Length);
                try
                {
                    fs.md5 = VZ_UpdateMethods.GetMD5HashFromFile(info.FullName);
                }
                catch
                {
                    continue;
                }
                fs.url = "";
                fileList.Add(fs);
            }

            foreach (DirectoryInfo info in dirs)
            {
                fileList.AddRange(getFiles(info, basePath));
            }
            return(fileList);
        }
Ejemplo n.º 3
0
 public void VZDownloadComplete(VZ_FileInfos info)
 {
     //throw new NotImplementedException();
     //Dispatcher.BeginInvoke((Action)(() =>
     //{
     //    tb_log.Text += ("complete:" + info.name + "  " + tb_log.Text);
     //    tb_log.Text += "\n";
     //    tb_log.ScrollToEnd();
     //}));
 }
Ejemplo n.º 4
0
 void addLog(VZ_FileInfos info)
 {
     tb_info.Text += info.name;
     tb_info.Text += "    ";
     tb_info.Text += info.md5;
     tb_info.Text += "    ";
     tb_info.Text += info.path;
     tb_info.Text += "\n";
     tb_info.ScrollToEnd();
 }
Ejemplo n.º 5
0
 public void VZDownloadProgress(VZ_FileInfos info, int progress)
 {
     //throw new NotImplementedException();
     //Dispatcher.BeginInvoke((Action)(() =>
     //{
     //    tb_log.Text += ("progress:" + progress + "  " + info.name + "  " + tb_log.Text);
     //    tb_log.Text += "\n";
     //    tb_log.ScrollToEnd();
     //}));
 }
Ejemplo n.º 6
0
        private List <VZ_FileInfos> getFiles(DirectoryInfo dir, String basePath)
        {
            List <VZ_FileInfos> fileList = new List <VZ_FileInfos>();

            if (noIndexDirList.Contains(dir.FullName))
            {
                return(fileList);
            }
            FileInfo[]      files = dir.GetFiles();
            DirectoryInfo[] dirs  = dir.GetDirectories();

            foreach (FileInfo info in files)
            {
                VZ_FileInfos fs = new VZ_FileInfos();
                if (info.FullName.EndsWith("ConfigInfo.json"))
                {
                    continue;
                }
                if (noIndexDirList.Contains(info.FullName))
                {
                    continue;
                }
                fs.name = info.Name;
                fs.path = info.FullName.Substring(basePath.Length + 1);
                fs.md5  = VZ_UpdateMethods.GetMD5HashFromFile(info.FullName);
                fs.url  = httpPath + info.FullName.Substring(basePath.Length + 1).Replace("\\", "/");
                fileList.Add(fs);
                Dispatcher.BeginInvoke((Action)(() => {
                    addLog(fs);
                }));
            }

            foreach (DirectoryInfo info in dirs)
            {
                fileList.AddRange(getFiles(info, basePath));
            }
            return(fileList);
        }
Ejemplo n.º 7
0
        private static List <VZ_FileInfos> getFiles(DirectoryInfo dir, String basePath)
        {
            List <VZ_FileInfos> fileList = new List <VZ_FileInfos>();

            FileInfo[]      files = dir.GetFiles();
            DirectoryInfo[] dirs  = dir.GetDirectories();

            foreach (FileInfo info in files)
            {
                VZ_FileInfos fs = new VZ_FileInfos();
                fs.name = info.Name;
                fs.path = info.FullName.Substring(basePath.Length);
                fs.md5  = GetMD5HashFromFile(info.FullName);
                fs.url  = "";
                fileList.Add(fs);
            }

            foreach (DirectoryInfo info in dirs)
            {
                fileList.AddRange(getFiles(info, basePath));
            }
            return(fileList);
        }
Ejemplo n.º 8
0
 public void start(VZDownloadCallback l)
 {
     updatePath = AppDomain.CurrentDomain.BaseDirectory + @"\Update\" + VZ_AppHelper.GetInstance().systemInfo.updateBuild + @"\";
     if (l != null)
     {
         callback = l;
     }
     if (fileList != null && fileList.Count > 0)
     {
         if (downloadThread == null)
         {
             downloadThread = new Thread(new ThreadStart(() =>
             {
                 int progress = 0;
                 for (;;)
                 {
                     if (fileList.Count <= 0)
                     {
                         //Properties.Settings.Default.isUpdateReady = true;
                         //Properties.Settings.Default.updatelist = "";
                         //Properties.Settings.Default.Save();
                         if (callback != null)
                         {
                             callback.VZDownloadAllComplete();
                         }
                         break;
                     }
                     else
                     {
                         VZ_FileInfos infos = fileList[0];
                         try
                         {
                             if (oldFileDic.ContainsKey(infos.path))
                             {
                                 if (oldFileDic[infos.path].Equals(infos.md5))
                                 {
                                     if (callback != null)
                                     {
                                         callback.VZDownloadComplete(infos);
                                     }
                                     fileList.Remove(infos);
                                     continue;
                                 }
                             }
                             downloadFile(infos, infos.url, updatePath + infos.path, ref progress);
                         }
                         catch (Exception ex)
                         {
                             Scratch.Log.LogConfig.Logger.Error("出错:", ex);
                             break;
                         }
                         fileList.Remove(infos);
                     }
                 }
             }));
             downloadThread.Start();
         }
         else
         {
             return;
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 下载文件(同步)  支持断点续传
        /// </summary>
        /// <param name="url">文件url</param>
        /// <param name="savePath">本地保存路径</param>
        /// <param name="size">下载文件大小</param>
        void downloadFile(VZ_FileInfos info, String url, String savePath, ref int progress, long size = 0)
        {
            //打开上次下载的文件
            long       lStartPos = 0;
            FileStream fs;

            if (File.Exists(savePath))
            {
                fs        = File.OpenWrite(savePath);
                lStartPos = fs.Length;
                fs.Seek(lStartPos, SeekOrigin.Current);//移动文件流中的当前指针
            }
            else
            {
                string direName = Path.GetDirectoryName(savePath);
                if (!Directory.Exists(direName))//如果不存在保存文件夹路径,新建文件夹
                {
                    Directory.CreateDirectory(direName);
                }
                fs        = new FileStream(savePath, FileMode.Create);
                lStartPos = 0;
            }

            HttpWebRequest request = null;

            try
            {
                if (size == 0)
                {
                    size = GetFileContentLength(url);
                }
                if (size != 0 && size == lStartPos)
                {
                    //下载完成
                    fs.Close();
                    return;
                }

                request = (HttpWebRequest)WebRequest.Create(url);
                request.ReadWriteTimeout = ReadWriteTimeOut;
                request.Timeout          = TimeOutWait;
                if (lStartPos > 0)
                {
                    request.AddRange((int)lStartPos);//设置Range值,断点续传
                }
                //向服务器请求,获得服务器回应数据流
                WebResponse respone   = request.GetResponse();
                long        totalSize = respone.ContentLength + lStartPos;
                long        curSize   = lStartPos;
                progress = (int)(curSize / totalSize * 100.0f);

                Stream ns = respone.GetResponseStream();

                byte[] nbytes    = new byte[bytebuff];
                int    nReadSize = ns.Read(nbytes, 0, bytebuff);
                curSize += nReadSize;
                while (nReadSize > 0)
                {
                    fs.Write(nbytes, 0, nReadSize);
                    nReadSize = ns.Read(nbytes, 0, bytebuff);

                    curSize += nReadSize;
                    //下载进度计算
                    if (progress < (int)((double)curSize / totalSize * 100))
                    {
                        progress = (int)((double)curSize / totalSize * 100);
                    }
                    if (callback != null)
                    {
                        callback.VZDownloadProgress(info, progress);
                    }
                }
                fs.Flush();
                ns.Close();
                fs.Close();
                if (curSize != totalSize && totalSize != -1)//文件长度不等于下载长度,下载出错
                {
                    throw new Exception();
                }
                if (callback != null)
                {
                    callback.VZDownloadComplete(info);
                }
                if (request != null)
                {
                    request.Abort();
                }
                TryNumDic.Remove(url);
                //下载完毕
            }
            catch (Exception ex)
            {
                Scratch.Log.LogConfig.Logger.Error("出错:", ex);
                if (request != null)
                {
                    request.Abort();
                }

                fs.Close();
                if (TryNumDic.ContainsKey(url))
                {
                    if (TryNumDic[url] > MaxTryTime)
                    {
                        TryNumDic.Remove(url);
                        if (callback != null)
                        {
                            callback.VZDownloadError(info);
                        }
                        throw new Exception();
                    }
                    else
                    {
                        TryNumDic[url]++;
                    }
                }
                else
                {
                    TryNumDic.Add(url, 1);
                }
                downloadFile(info, url, savePath, ref progress, size);
            }
        }