示例#1
0
        private void Segment_Finished()
        {
            if (CurrentSegment < Segments.Count - 1)
            {
                CurrentSegment++;
                Segments[CurrentSegment].Start();
            }
            else
            {
                AbortProgressMonitor();
                ProgressPercentage = 100;
                StatusUpdate?.Invoke(this, ProgressPercentage, 0, Status.Merging);
                string directory = Path.Combine(ConfigManager.GetSettings().DownloadPath, FilenameValidation(string.Format("[{0}]{1}", Description, Title)));
                Directory.CreateDirectory(directory);
                string filename = FilenameValidation($"{Index}-{Part}");
                string filepath = Path.Combine(directory, $"{filename}.{Segments[0].Extention}");

                // valid path length
                if (filepath.Length > MAX_PATH - 1)     // Reserve 1 char for <NULL>
                {
                    int truncateCount = filepath.Length - (MAX_PATH - 1);
                    if (truncateCount > filename.Length - 1)     // Least 1 char for filename
                    {
                        // Should never occur
                        throw new Exception($"无法创建合法文件名,截断失败: {filename} (截断计数: {truncateCount})");
                    }
                    filename = filename.Substring(0, filename.Length - truncateCount);
                    filepath = directory + $"{filename}.{Segments[0].Extention}";
                }

                int      count = Segments.Count;
                string[] paths = new string[count];
                for (int i = 0; i < count; i++)
                {
                    paths[i] = Segments[i].Filepath;
                }

                if (MergeRequired)
                {
                    FlvUtil.FlvMerge(paths, filepath);
                }
                else
                {
                    File.Copy(Segments[0].Filepath, filepath, true);
                }


                foreach (string path in paths)
                {
                    File.Delete(path);
                }
                IsFinished = true;
                IsRunning  = false;
                StatusUpdate?.Invoke(this, 100, 0, Status.Finished);

                DownloadFinishedNotification.SendNotification(this, filepath);

                Finished?.Invoke(this, filepath);
            }
        }
示例#2
0
        private void Segment_Finished()
        {
            if (CurrentSegment < Segments.Count - 1)
            {
                CurrentSegment++;
                Segments[CurrentSegment].Start();
            }
            else
            {
                AbortProgressMonitor();
                ProgressPercentage = 100;
                StatusUpdate?.Invoke(this, ProgressPercentage, 0, Status.Merging);
                string directory = ConfigManager.GetSettings().DownloadPath + "\\" + string.Format("[{0}]{1}", Description, Title) + "\\";
                Directory.CreateDirectory(directory);
                string filepath = directory + FilenameValidation(string.Format("[{0}]{1}_{2}-{3}.{4}", Description, Title, Index, Part, Segments[0].Extention));

                int      count = Segments.Count;
                string[] paths = new string[count];
                for (int i = 0; i < count; i++)
                {
                    paths[i] = Segments[i].Filepath;
                }

                if (MergeRequired)
                {
                    FlvUtil.FlvMerge(paths, filepath);
                }
                else
                {
                    File.Copy(Segments[0].Filepath, filepath, true);
                }


                foreach (string path in paths)
                {
                    File.Delete(path);
                }
                IsFinished = true;
                IsRunning  = false;
                StatusUpdate?.Invoke(this, 100, 0, Status.Finished);

                DownloadFinishedNotification.SendNotification(this, filepath);

                Finished?.Invoke(this, filepath);
            }
        }