Exemple #1
0
        public void Start()
        {
            ListFileSavePath = Path.Combine(SaveFolderPath, ListFileName);

            _listFilePuller = new FilePuller(ListFileUrl, ListFileSavePathTmp, PullerMetaFolderPath, _addTicksQueryString);
            _listFilePuller.SetFinishCallback(OnListFileRequestFinish);
            _listFilePuller.Start();
        }
Exemple #2
0
        /// <summary>
        /// requester finished
        /// </summary>
        /// <param name="puller">Req.</param>
        void OnListFileRequestFinish(FilePuller puller)
        {
            if (puller.IsError)
            {
                Error       = puller.Error;
                ErrorPuller = puller;
                OnFinish();
                return;
            }
            if (!puller.HasDownloaded)
            {
                // 并没有下载,则认为.list文件压根没修改,不需要重复做下载工作了~
                OnFinish();
                return;
            }

            // begin download all files, mark the list file changed flag
            IsListFileChanged = true;
            if (BeforeFilesDownloadEvent != null)
            {
                BeforeFilesDownloadEvent(this);
            }

            // read a string list of files
            List = new List <string>();
            using (var reader = new StreamReader(puller.SavePath))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (!string.IsNullOrEmpty(line))
                    {
                        List.Add(line);
                    }
                }
            }

            // Start pull the list
            PullersList = new List <FilePuller>();
            foreach (var line in List)
            {
                string file;
                bool   toDelete = false;
                if (line.StartsWith("-"))
                {
                    file     = line.TrimStart('-').Trim();
                    toDelete = true; // 进入删除模式
                }
                else
                {
                    file = line.Trim();
                }

                var fileUrl  = UrlCombine(UrlPrefix, file);
                var savePath = Path.Combine(SaveFolderPath, file);

                if (toDelete)
                {
                    if (file == "*")
                    {
                        DeleteAllOthers();
                    }
                    else
                    {
                        // just delete, don't pull
                        if (File.Exists(savePath))
                        {
                            File.Delete(savePath);
                        }
                    }
                }
                else
                {
                    var filePuller = new FilePuller(fileUrl, savePath, PullerMetaFolderPath);
                    PullersList.Add(filePuller);
                    filePuller.Start();
                }
            }

            ThreadPool.QueueUserWorkItem(ThreadCheckDownloadList, null);
        }