示例#1
0
            private void Run()
            {
                while (!isExit)
                {
                    Debug.LogFormat("[LoadThread]", "Run Doing Before {0}, httpDownload.waitBlockList.Count={1}", this, httpDownload.waitBlockList.Count);

                    lock (httpDownload.waitBlockList)
                    {
                        if (httpDownload.waitBlockList.Count <= 0)
                        {
                            break;
                        }

                        block = httpDownload.waitBlockList[0];
                        httpDownload.waitBlockList.RemoveAt(0);
                    }

                    block.Load(this);
                    block = null;

                    Debug.LogFormat("[LoadThread]", "Run Doing After {0}, httpDownload.waitBlockList.Count={1}, block={2}", this, httpDownload.waitBlockList.Count, block);
                }

                state  = StateType.End;
                thread = null;

                Debug.LogFormat("[LoadThread]", "Run End {0}", this);
            }
示例#2
0
        public void OnLoadBlock(HttpDownloadFileBlock block)
        {
            bool isAllComplete = true;

            for (int i = 0; i < blockList.Count; i++)
            {
                if (!blockList[i].IsComplete)
                {
                    isAllComplete = false;
                    break;
                }
            }

            if (isAllComplete)
            {
                MergeFile();
            }
        }
示例#3
0
            public void Exit()
            {
                Debug.LogFormat("[LoadThread]", "Exit Before {0}", this);

                if (block != null)
                {
                    block.Abort();
                    block = null;
                }

                if (thread != null)
                {
                    thread.Abort();
                    thread = null;
                }


                state  = StateType.End;
                isExit = true;

                Debug.LogFormat("[LoadThread]", "Exit After {0}", this);
            }
示例#4
0
        public void Cut()
        {
            blockList.Clear();
            loadedSize = 0;


            CheckDir(localPath);

            string localTmpPath = null;

            //检测是否有未下载完毕的临时文件
            for (int i = 0; i < ProcessorCount; i++)
            {
                if (File.Exists(GetTmpPath(i)))
                {
                    localTmpPath = GetTmpPath(i);
                    break;
                }
            }

            if (size <= 0)
            {
                if (!string.IsNullOrEmpty(localTmpPath))
                {
                    File.Delete(localTmpPath);
                }

                localTmpPath = GetTmpPath(0);
                blockList.Add(new HttpDownloadFileBlock(this, 0, 0, 0, localTmpPath));
                return;
            }


            //文件块大小
            long blockSize = size / ProcessorCount;
            //余数
            long modSize = size % ProcessorCount;


            FileStream            inStream;
            HttpDownloadFileBlock fileBlock;


            if (!string.IsNullOrEmpty(localTmpPath))
            {
                if (size < singleTmpFileSize)
                {
                    inStream = new FileStream(localTmpPath, FileMode.Open);
                    blockList.Add(new HttpDownloadFileBlock(this, 0, size - 1, inStream.Length, localTmpPath));
                    inStream.Close();
                }
                else
                {
                    for (int i = 0; i < ProcessorCount; i++)
                    {
                        localTmpPath = GetTmpPath(i);
                        if (File.Exists(localTmpPath))
                        {
                            inStream = new FileStream(localTmpPath, FileMode.Open);

                            fileBlock = new HttpDownloadFileBlock(this, i * blockSize, (i + 1) * blockSize - 1, inStream.Length, localTmpPath);
                            if (i == ProcessorCount - 1)
                            {
                                fileBlock.end += modSize;
                            }
                            blockList.Add(fileBlock);
                            inStream.Close();
                        }
                        else
                        {
                            fileBlock = new HttpDownloadFileBlock(this, i * blockSize, (i + 1) * blockSize - 1, 0, localTmpPath);
                            if (i == ProcessorCount - 1)
                            {
                                fileBlock.end += modSize;
                            }
                            blockList.Add(fileBlock);
                        }
                    }
                }
            }
            else
            {
                if (size < singleTmpFileSize)
                {
                    localTmpPath = GetTmpPath(0);
                    blockList.Add(new HttpDownloadFileBlock(this, 0, size - 1, 0, localTmpPath));
                }
                else
                {
                    for (int i = 0; i < ProcessorCount; i++)
                    {
                        localTmpPath = GetTmpPath(i);

                        fileBlock = new HttpDownloadFileBlock(this, i * blockSize, (i + 1) * blockSize - 1, 0, localTmpPath);
                        if (i == ProcessorCount - 1)
                        {
                            fileBlock.end += modSize;
                        }
                        blockList.Add(fileBlock);
                    }
                }
            }
        }