1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- namespace BanTur.Utility
- {
- public static class Aria2Helper
- {
- private static string GetNoticeFilePath(int id)
- {
- return Path.Combine(BanTurRuntime.Config.WorkingDirectory, id + ".bat");
- }
- public static string GetLogFilePath(int id)
- {
- return Path.Combine(BanTurRuntime.Config.WorkingDirectory, id + ".log");
- }
- public static string CreateNoticeFile(int id)
- {
- var self = Process.GetCurrentProcess().MainModule.FileName;
- var selfDir = Path.GetDirectoryName(self);
- var path = GetNoticeFilePath(id);
- var content = $"cd /d {selfDir}{Environment.NewLine}{self} {BanTurRuntime.CmdComplete} {id} %3";
- if (Directory.Exists(BanTurRuntime.Config.WorkingDirectory) == false) Directory.CreateDirectory(BanTurRuntime.Config.WorkingDirectory);
- File.WriteAllText(path, content, Encoding.Default);
- return path;
- }
- public static void DeleteNoticeFile(int id)
- {
- var path = GetNoticeFilePath(id);
- File.Delete(path);
- }
- public static void StartBitTorrentDownload(string magnet, string downloadDirectory, string onBtDownloadComplete, string logFilePath)
- {
- if (Directory.Exists(downloadDirectory) == false) Directory.CreateDirectory(downloadDirectory);
- var p = new Process
- {
- StartInfo =
- {
- FileName = "aria2c",
- WorkingDirectory = downloadDirectory,
- Arguments = "--seed-time=30 --follow-torrent=mem --on-bt-download-complete=" + onBtDownloadComplete+" "+magnet ,
- UseShellExecute = true,
- WindowStyle = ProcessWindowStyle.Minimized,
- }
- };
- p.Start();
- }
- }
- }
|