├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── ThunderSDK.sln ├── ThunderSdk ├── DownFileInfo.cs ├── DownloadManager.cs ├── Properties │ └── AssemblyInfo.cs ├── ThunderSdk.csproj ├── ThunderSdk.csproj.DotSettings ├── XL.cs ├── download │ ├── MiniThunderPlatform.exe │ ├── XLBugHandler.dll │ ├── XLBugReport.exe │ ├── atl71.dll │ ├── dl_peer_id.dll │ ├── download_engine.dll │ ├── id.dat │ ├── minizip.dll │ ├── msvcp71.dll │ ├── msvcr71.dll │ └── zlib1.dll └── xldl.dll └── ThunderSdkDemo ├── Program.cs ├── Properties └── AssemblyInfo.cs └── ThunderSdkDemo.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 玮仔Wayne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ThunderSdk 2 | 迅雷开放平台SDK封装 3 | -------------------------------------------------------------------------------- /ThunderSDK.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2027 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThunderSdkDemo", "ThunderSdkDemo\ThunderSdkDemo.csproj", "{7635124F-4568-4BF1-AF45-3419E0CC560A}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThunderSdk", "ThunderSdk\ThunderSdk.csproj", "{6CDC89B8-7708-490F-A0FE-80FCCF703288}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Debug|x64.Build.0 = Debug|Any CPU 24 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Debug|x86.ActiveCfg = Debug|x86 25 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Debug|x86.Build.0 = Debug|x86 26 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Release|x64.ActiveCfg = Release|Any CPU 29 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Release|x64.Build.0 = Release|Any CPU 30 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Release|x86.ActiveCfg = Release|Any CPU 31 | {7635124F-4568-4BF1-AF45-3419E0CC560A}.Release|x86.Build.0 = Release|Any CPU 32 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Debug|x64.Build.0 = Debug|Any CPU 36 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Debug|x86.ActiveCfg = Debug|x86 37 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Debug|x86.Build.0 = Debug|x86 38 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Release|x64.ActiveCfg = Release|Any CPU 41 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Release|x64.Build.0 = Release|Any CPU 42 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Release|x86.ActiveCfg = Release|x86 43 | {6CDC89B8-7708-490F-A0FE-80FCCF703288}.Release|x86.Build.0 = Release|x86 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {0BC70FEF-D78A-4BF5-A3E8-24B04380DBD5} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /ThunderSdk/DownFileInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace ThunderSdk 5 | { 6 | public class DownFileInfo 7 | { 8 | private ThunderSdk.TaskInfo _taskInfo; 9 | public event EventHandler TaskInfoChanged; 10 | 11 | static DownFileInfo() 12 | { 13 | ThunderSdk.Init(); 14 | } 15 | 16 | 17 | public DownFileInfo(string sourceUrl, string fileName, string savePath, string cookies = "", bool autoStart = true, string refUrl = "", bool isOnlyOriginal = true, bool disableAutoRename = false, bool isResume = true) 18 | { 19 | SourceUrl = sourceUrl; 20 | //FileName = fileName; 21 | SavePath = savePath; 22 | DisableAutoRename = disableAutoRename; 23 | IsResume = isResume; 24 | IsOnlyOriginal = isOnlyOriginal; 25 | CreateTime = DateTime.Now; 26 | Id = ThunderSdk.CreateTask(new ThunderSdk.DownTaskParam 27 | { 28 | TaskUrl = sourceUrl, 29 | FileName = fileName, 30 | SavePath = savePath, 31 | Cookies = cookies, 32 | RefUrl = refUrl, 33 | IsOnlyOriginal = isOnlyOriginal, 34 | DisableAutoRename = disableAutoRename, 35 | IsResume = isResume 36 | }); 37 | if (autoStart) 38 | StartTaskInfoRefreasher(); 39 | } 40 | 41 | //private bool _needToRefreshTaskInfo = false; 42 | 43 | public string SourceUrl { get; } 44 | 45 | public string FileName 46 | { 47 | get => TaskInfo.FileName; 48 | } 49 | 50 | public string SavePath { get; } 51 | 52 | public DateTime CreateTime { get; } 53 | 54 | internal TimeSpan _wasteTime = TimeSpan.MinValue; 55 | public TimeSpan WasteTime => _wasteTime == TimeSpan.MinValue ? DateTime.Now - CreateTime : _wasteTime; 56 | 57 | 58 | public bool IsOnlyOriginal { get; } = true; 59 | 60 | public bool DisableAutoRename { get; } = false; 61 | 62 | public bool IsResume { get; } = true; 63 | 64 | public ThunderSdk.TaskInfo TaskInfo 65 | { 66 | get 67 | { 68 | if (_taskInfo == null) 69 | _taskInfo = new ThunderSdk.TaskInfo(); 70 | ThunderSdk.QueryTaskInfoEx(Id, _taskInfo); 71 | return _taskInfo; 72 | } 73 | } 74 | 75 | public IntPtr Id { get; set; } 76 | 77 | private Thread InfoRefresher { get; set; } 78 | 79 | public bool StartTask() => ThunderSdk.StartTask(Id); 80 | 81 | public bool StopTask() => ThunderSdk.StopTask(Id); 82 | 83 | public bool DeleteTask() => ThunderSdk.DeleteTask(Id); 84 | 85 | public void StartTaskInfoRefreasher() 86 | { 87 | InfoRefresher = new Thread(() => 88 | { 89 | 90 | while (ThunderSdk.QueryTaskInfoEx(Id, TaskInfo)) 91 | { 92 | OnPropertyChanged(new EventArgs()); 93 | if (TaskInfo.State != ThunderSdk.TaskStatus.Complete) 94 | { 95 | Thread.Sleep(33); 96 | } 97 | else 98 | { 99 | _wasteTime = DateTime.Now - CreateTime; 100 | return; 101 | } 102 | } 103 | }) 104 | { IsBackground = true }; 105 | 106 | InfoRefresher.Start(); 107 | } 108 | 109 | private void OnPropertyChanged(EventArgs eventArgs) 110 | { 111 | TaskInfoChanged?.Invoke(this, eventArgs); 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /ThunderSdk/DownloadManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | 6 | namespace ThunderSdk 7 | { 8 | public class DownloadManager 9 | { 10 | private int _downloadSpeedLimit; 11 | private int _uploadSpeedLimit; 12 | 13 | static DownloadManager() 14 | { 15 | ThunderSdk.Init(); 16 | } 17 | 18 | public List DownloadNow { get; set; } 19 | private Queue WaitingDownload { get; set; } = new Queue(); 20 | public List AllDownLoad { get; set; } = new List(); 21 | public string SavePath { get; } 22 | 23 | private int DownloadSpeedLimit 24 | { 25 | get => _downloadSpeedLimit; 26 | set 27 | { 28 | if (value <= 0) value = int.MaxValue; 29 | _downloadSpeedLimit = value; 30 | ThunderSdk.SetSpeedLimit(value); 31 | } 32 | } 33 | 34 | private int UploadSpeedLimit 35 | { 36 | get => _uploadSpeedLimit; 37 | set 38 | { 39 | if (value <= 0) value = int.MaxValue; 40 | _uploadSpeedLimit = value; 41 | ThunderSdk.SetUploadSpeedLimit(value, value); 42 | } 43 | } 44 | public event EventHandler TaskInfoChanged; 45 | public event EventHandler TaskCompleted; 46 | public event EventHandler TaskNoitem; 47 | public event EventHandler TaskError; 48 | public event EventHandler TaskDownload; 49 | public event EventHandler TaskPause; 50 | 51 | public int ParallelDownloadCount { get; set; } 52 | 53 | public int CreateNewTask(string sourceUrl, string fileName, string savePath = "", string cookies = "", string refUrl = "", bool isOnlyOriginal = true, bool disableAutoRename = false, bool isResume = true) 54 | { 55 | if (string.IsNullOrEmpty(savePath)) 56 | savePath = SavePath; 57 | var task = new DownFileInfo(sourceUrl, fileName, savePath, cookies, false, refUrl, isOnlyOriginal, disableAutoRename, 58 | isResume); 59 | var index = -1; 60 | lock (AllDownLoad) 61 | { 62 | AllDownLoad.Add(task); 63 | index = AllDownLoad.Count - 1; 64 | } 65 | lock (DownloadNow) 66 | { 67 | lock (WaitingDownload) 68 | { 69 | if (DownloadNow.Count < ParallelDownloadCount && WaitingDownload.Count == 0) 70 | { 71 | DownloadNow.Add(task); 72 | task.StartTask(); 73 | } 74 | else 75 | { 76 | WaitingDownload.Enqueue(task); 77 | } 78 | } 79 | } 80 | return index; 81 | } 82 | 83 | public bool PauseAllTask() => DownloadNow.All(task => ThunderSdk.StopTask(task.Id)); 84 | public bool StartAllTask() => DownloadNow.All(task => ThunderSdk.StartTask(task.Id)); 85 | 86 | 87 | public Thread Processor { get; set; } 88 | 89 | public DownloadManager(int parallelCount, string savePath = "") 90 | { 91 | ParallelDownloadCount = parallelCount; 92 | if (string.IsNullOrEmpty(savePath)) savePath = AppDomain.CurrentDomain.BaseDirectory; 93 | SavePath = savePath; 94 | DownloadNow = new List(); 95 | Processor = new Thread(() => 96 | { 97 | while (true) 98 | { 99 | if (DownloadNow.Count > 0) 100 | if ((DownloadNow.Count == ParallelDownloadCount && WaitingDownload.Count > 0) || (DownloadNow.Count > 0 && WaitingDownload.Count == 0)) 101 | for (var i = 0; i < DownloadNow.Count; i++) 102 | { 103 | var info = DownloadNow[i]; 104 | if (ThunderSdk.QueryTaskInfoEx(info.Id, info.TaskInfo)) 105 | { 106 | OnTaskInfoChanged(info, new EventArgs()); 107 | if (info.TaskInfo.State == ThunderSdk.TaskStatus.Complete) 108 | { 109 | info._wasteTime = DateTime.Now - info.CreateTime; 110 | info.TaskInfo.Percent = 1; 111 | OnTaskCompleted(info, new EventArgs()); 112 | DownloadNow.Remove(info); 113 | if (WaitingDownload.Count <= 0) continue; 114 | lock (DownloadNow) 115 | { 116 | lock (WaitingDownload) 117 | { 118 | var task = WaitingDownload.Dequeue(); 119 | DownloadNow.Add(task); 120 | i--; 121 | task.StartTask(); 122 | } 123 | break; 124 | } 125 | } 126 | else if (info.TaskInfo.State == ThunderSdk.TaskStatus.Noitem) 127 | { 128 | info._wasteTime = DateTime.Now - info.CreateTime; 129 | OnTaskNoitem(info, new EventArgs()); 130 | DownloadNow.Remove(info); 131 | if (WaitingDownload.Count <= 0) continue; 132 | lock (DownloadNow) 133 | { 134 | lock (WaitingDownload) 135 | { 136 | var task = WaitingDownload.Dequeue(); 137 | DownloadNow.Add(task); 138 | i--; 139 | task.StartTask(); 140 | } 141 | break; 142 | } 143 | } 144 | else if (info.TaskInfo.State == ThunderSdk.TaskStatus.Error) 145 | { 146 | info._wasteTime = DateTime.Now - info.CreateTime; 147 | OnTaskError(info, new EventArgs()); 148 | DownloadNow.Remove(info); 149 | if (WaitingDownload.Count <= 0) continue; 150 | lock (DownloadNow) 151 | { 152 | lock (WaitingDownload) 153 | { 154 | var task = WaitingDownload.Dequeue(); 155 | DownloadNow.Add(task); 156 | i--; 157 | task.StartTask(); 158 | } 159 | break; 160 | } 161 | } 162 | else if (info.TaskInfo.State == ThunderSdk.TaskStatus.Download) 163 | { 164 | OnTaskDownload(info, new EventArgs()); 165 | } 166 | else if (info.TaskInfo.State == ThunderSdk.TaskStatus.Pause) 167 | { 168 | OnTaskPause(info, new EventArgs()); 169 | } 170 | } 171 | } 172 | else if (WaitingDownload.Count > 0) 173 | { 174 | lock (WaitingDownload) 175 | { 176 | var task = WaitingDownload.Dequeue(); 177 | DownloadNow.Add(task); 178 | task.StartTask(); 179 | } 180 | } 181 | Thread.Sleep(33); 182 | } 183 | }) 184 | { IsBackground = true }; 185 | Processor.Start(); 186 | } 187 | private void OnTaskInfoChanged(DownFileInfo info, EventArgs eventArgs) 188 | { 189 | TaskInfoChanged?.Invoke(info, eventArgs); 190 | } 191 | 192 | private void OnTaskCompleted(DownFileInfo info, EventArgs eventArgs) 193 | { 194 | TaskCompleted?.Invoke(info, eventArgs); 195 | } 196 | public void OnTaskNoitem(DownFileInfo info, EventArgs eventArgs) 197 | { 198 | TaskNoitem?.Invoke(info, eventArgs); 199 | } 200 | public void OnTaskError(DownFileInfo info, EventArgs eventArgs) 201 | { 202 | TaskError?.Invoke(info, eventArgs); 203 | } 204 | public void OnTaskDownload(DownFileInfo info, EventArgs eventArgs) 205 | { 206 | TaskDownload?.Invoke(info, eventArgs); 207 | } 208 | public void OnTaskPause(DownFileInfo info, EventArgs eventArgs) 209 | { 210 | TaskPause?.Invoke(info, eventArgs); 211 | } 212 | } 213 | } -------------------------------------------------------------------------------- /ThunderSdk/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("XLDownload")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Guangdong Medical University")] 12 | [assembly: AssemblyProduct("XLDownload")] 13 | [assembly: AssemblyCopyright("Copyright © Guangdong Medical University 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("6cdc89b8-7708-490f-a0fe-80fccf703288")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ThunderSdk/ThunderSdk.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6CDC89B8-7708-490F-A0FE-80FCCF703288} 8 | Library 9 | Properties 10 | ThunderSdk 11 | ThunderSdk 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | true 35 | bin\x86\Debug\ 36 | DEBUG;TRACE 37 | full 38 | x86 39 | prompt 40 | MinimumRecommendedRules.ruleset 41 | 42 | 43 | bin\x86\Release\ 44 | TRACE 45 | true 46 | pdbonly 47 | x86 48 | prompt 49 | MinimumRecommendedRules.ruleset 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Always 69 | 70 | 71 | Always 72 | 73 | 74 | Always 75 | 76 | 77 | Always 78 | 79 | 80 | Always 81 | 82 | 83 | Always 84 | 85 | 86 | Always 87 | 88 | 89 | Always 90 | 91 | 92 | Always 93 | 94 | 95 | Always 96 | 97 | 98 | Always 99 | 100 | 101 | 102 | 103 | Always 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /ThunderSdk/ThunderSdk.csproj.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True -------------------------------------------------------------------------------- /ThunderSdk/XL.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace ThunderSdk 5 | { 6 | /// 7 | /// API 8 | /// 9 | public static class ThunderSdk 10 | { 11 | private const string DllName = "xldl.dll"; 12 | 13 | /// 14 | /// 初始化迅雷下载引擎 15 | /// 16 | /// 初始化是否成功 17 | [DllImport(DllName, EntryPoint = "XL_Init")] 18 | [return: MarshalAs(UnmanagedType.Bool)] 19 | public static extern bool Init(); 20 | 21 | /// 22 | /// 卸载迅雷下载引擎 23 | /// 24 | /// 卸载是否成功 25 | [DllImport(DllName, EntryPoint = "XL_UnInit")] 26 | [return: MarshalAs(UnmanagedType.Bool)] 27 | public static extern bool UnInit(); 28 | 29 | /// 30 | /// 新建下载任务 31 | /// 32 | /// 任务参数 33 | /// 任务句柄,null表示失败 34 | [DllImport(DllName, EntryPoint = "XL_CreateTask", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] 35 | public static extern IntPtr CreateTask([In()]DownTaskParam param); 36 | 37 | /// 38 | /// 启动下载任务 39 | /// 40 | /// 任务句柄 41 | /// 是否成功启动任务 42 | [DllImport(DllName, EntryPoint = "XL_StartTask", CallingConvention = CallingConvention.Cdecl)] 43 | [return: MarshalAs(UnmanagedType.Bool)] 44 | public static extern bool StartTask(IntPtr task); 45 | 46 | /// 47 | /// 停止下载任务 48 | /// 49 | /// 任务句柄 50 | /// 是否成功停止了任务 51 | [DllImport(DllName, EntryPoint = "XL_StopTask", CallingConvention = CallingConvention.Cdecl)] 52 | [return: MarshalAs(UnmanagedType.Bool)] 53 | public static extern bool StopTask(IntPtr task); 54 | 55 | /// 56 | /// 设置全局下载速度 57 | /// 58 | /// 限制速度(KB) 59 | [DllImport(DllName, EntryPoint = "XL_SetSpeedLimit", CallingConvention = CallingConvention.Cdecl)] 60 | public static extern void SetSpeedLimit(int nKBps); 61 | 62 | /// 63 | /// 设置全局上传速度 64 | /// 65 | /// 66 | /// 67 | /// 68 | [DllImport(DllName, EntryPoint = "XL_SetUploadSpeedLimit", CallingConvention = CallingConvention.Cdecl)] 69 | public static extern void SetUploadSpeedLimit(int nTcpKBps, int nOtherKBps); 70 | 71 | /// 72 | /// 查询任务信息 73 | /// 74 | /// 任务句柄 75 | /// 任务信息 76 | /// 查询是否成功 77 | [DllImport(DllName, EntryPoint = "XL_QueryTaskInfoEx", CallingConvention = CallingConvention.Cdecl)] 78 | [return: MarshalAs(UnmanagedType.Bool)] 79 | public static extern bool QueryTaskInfoEx(IntPtr task, [Out()]TaskInfo taskInfo); 80 | 81 | /// 82 | /// 释放任务 83 | /// 84 | /// 任务句柄 85 | /// 是否移除成功 86 | [DllImport(DllName, EntryPoint = "XL_DeleteTask", CallingConvention = CallingConvention.Cdecl)] 87 | public static extern bool DeleteTask(IntPtr task); 88 | 89 | /// 90 | /// 删除任务数据文件 91 | /// 92 | /// 仅需要填充SavePath和FileName两个字段 93 | /// 94 | [DllImport(DllName, EntryPoint = "XL_DelTempFile", CallingConvention = CallingConvention.Cdecl)] 95 | [return: MarshalAs(UnmanagedType.Bool)] 96 | public static extern bool DelTempFile([In()]DownTaskParam param); 97 | 98 | /// 99 | /// 下载任务参数结构 100 | /// 101 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)] 102 | public class DownTaskParam 103 | { 104 | public int Reserved0; 105 | 106 | /// 107 | /// 下载地址 108 | /// 109 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2084)] 110 | public string TaskUrl; 111 | 112 | /// 113 | /// 引用页 114 | /// 115 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2084)] 116 | public string RefUrl; 117 | 118 | /// 119 | /// 浏览器Cookie 120 | /// 121 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4096)] 122 | public string Cookies; 123 | 124 | /// 125 | /// 本地保存文件名 126 | /// 127 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 128 | public string FileName; 129 | 130 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 131 | public string Reserved1; 132 | 133 | /// 134 | /// 文件保存目录 135 | /// 136 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 137 | public string SavePath; 138 | 139 | public IntPtr Reserved2; 140 | 141 | public int Reserved3 = 0; 142 | 143 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 144 | public string Reserved4; 145 | 146 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 147 | public string Reserved5; 148 | 149 | /// 150 | /// 是否只从原始地址下载 151 | /// 152 | public bool IsOnlyOriginal = true; 153 | 154 | public uint Reserved6 = 5; 155 | 156 | /// 157 | /// 禁止智能命名 158 | /// 159 | public bool DisableAutoRename = false; 160 | 161 | /// 162 | /// 是否用续传 163 | /// 164 | public bool IsResume = true; 165 | 166 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2048, ArraySubType = UnmanagedType.U4)] 167 | public uint[] Reserved7; 168 | } 169 | 170 | /// 171 | /// 任务状态码 172 | /// 173 | public enum TaskStatus 174 | { 175 | Noitem = 0, 176 | 177 | /// 178 | /// 下载出错 179 | /// 180 | Error, 181 | 182 | /// 183 | /// 下载已暂停 184 | /// 185 | Pause, 186 | 187 | /// 188 | /// 下载中 189 | /// 190 | Download, 191 | 192 | /// 193 | /// 下载成功 194 | /// 195 | Complete, 196 | 197 | /// 198 | /// 任务启动中 199 | /// 200 | Startpending, 201 | 202 | /// 203 | /// 任务停止中 204 | /// 205 | Stoppending 206 | } 207 | 208 | /// 209 | /// 错误码 210 | /// 211 | public enum ErrorCode 212 | { 213 | Unknown = 0, 214 | DiskCreate = 1, 215 | DiskWrite = 2, 216 | DiskRead = 3, 217 | DiskRename = 4, 218 | DiskPiecehash = 5, 219 | DiskFilehash = 6, 220 | DiskDelete = 7, 221 | DownInvalid = 16, 222 | ProxyAuthTypeUnkown = 32, 223 | ProxyAuthTypeFailed = 33, 224 | HttpmgrNotIp = 48, 225 | Timeout = 64, 226 | Cancel = 65, 227 | TpCrashed = 66, 228 | IdInvalid = 67 229 | } 230 | 231 | /// 232 | /// 任务信息 233 | /// 234 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 235 | public class TaskInfo 236 | { 237 | public TaskStatus State; 238 | public ErrorCode FailCode; 239 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 240 | public string FileName; 241 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 242 | public string Reserved0; 243 | public long TotalSize; 244 | public long TotalDownload; 245 | public float Percent; 246 | public int Reserved1; 247 | public int SrcTotal; 248 | public int SrcUsing; 249 | public int Reserved2; 250 | public int Reserved3; 251 | public int Reserved4; 252 | public int Reserved5; 253 | public long Reserved6; 254 | public long DonationP2P; 255 | public long Reserved7; 256 | public long DonationOrgin; 257 | public long DonationP2S; 258 | public long Reserved8; 259 | public long Reserved9; 260 | public int Speed; 261 | public int SpeedP2S; 262 | public int SpeedP2P; 263 | public bool IsOriginUsable; 264 | public float HashPercent; 265 | public int IsCreatingFile; 266 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64, ArraySubType = UnmanagedType.U4)] 267 | public uint[] Reserved10; 268 | } 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /ThunderSdk/download/MiniThunderPlatform.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/MiniThunderPlatform.exe -------------------------------------------------------------------------------- /ThunderSdk/download/XLBugHandler.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/XLBugHandler.dll -------------------------------------------------------------------------------- /ThunderSdk/download/XLBugReport.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/XLBugReport.exe -------------------------------------------------------------------------------- /ThunderSdk/download/atl71.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/atl71.dll -------------------------------------------------------------------------------- /ThunderSdk/download/dl_peer_id.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/dl_peer_id.dll -------------------------------------------------------------------------------- /ThunderSdk/download/download_engine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/download_engine.dll -------------------------------------------------------------------------------- /ThunderSdk/download/id.dat: -------------------------------------------------------------------------------- 1 | [partner] 2 | id=80000108 3 | ver = 3.2.1.36 4 | -------------------------------------------------------------------------------- /ThunderSdk/download/minizip.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/minizip.dll -------------------------------------------------------------------------------- /ThunderSdk/download/msvcp71.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/msvcp71.dll -------------------------------------------------------------------------------- /ThunderSdk/download/msvcr71.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/msvcr71.dll -------------------------------------------------------------------------------- /ThunderSdk/download/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/download/zlib1.dll -------------------------------------------------------------------------------- /ThunderSdk/xldl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WayneShao/ThunderSdk/8b16b6f9912e22d2ed70f44247d2e170860f4917/ThunderSdk/xldl.dll -------------------------------------------------------------------------------- /ThunderSdkDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ThunderSdk; 3 | 4 | namespace ThunderSdkDemo 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var manager = new DownloadManager(1, @"D:\"); 11 | manager.CreateNewTask("https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=770549720,375505130&fm=173&s=612A66F94AA394CE4A84E71B030050D7&w=218&h=146&img.JPEG", 12 | "2018-1-30-5ZD6R0BZZ.rar"); 13 | 14 | manager.TaskDownload += (s, e) => 15 | { 16 | if (!(s is DownFileInfo info)) return; 17 | 18 | Console.WriteLine(info.TaskInfo.Percent); 19 | }; 20 | 21 | manager.TaskCompleted += (s, e) => 22 | { 23 | if (!(s is DownFileInfo info)) return; 24 | 25 | Console.WriteLine(info.FileName + "下载完成"); 26 | }; 27 | 28 | manager.StartAllTask(); 29 | 30 | Console.ReadKey(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ThunderSdkDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ThunderSdkDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ThunderSdkDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("7635124f-4568-4bf1-af45-3419e0cc560a")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ThunderSdkDemo/ThunderSdkDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7635124F-4568-4BF1-AF45-3419E0CC560A} 8 | Exe 9 | ThunderSdkDemo 10 | ThunderSdkDemo 11 | v4.0 12 | 512 13 | 14 | 15 | AnyCPU 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | AnyCPU 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | true 35 | bin\x86\Debug\ 36 | DEBUG;TRACE 37 | full 38 | x86 39 | prompt 40 | MinimumRecommendedRules.ruleset 41 | 42 | 43 | bin\x86\Release\ 44 | TRACE 45 | true 46 | pdbonly 47 | x86 48 | prompt 49 | MinimumRecommendedRules.ruleset 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | {6cdc89b8-7708-490f-a0fe-80fccf703288} 67 | ThunderSdk 68 | 69 | 70 | 71 | --------------------------------------------------------------------------------