Exemple #1
0
        public FileSystemMonitor(TorrentAPI t)
        {
            string            downloadDir    = "";
            string            downloadFolder = downloadDir.Substring(downloadDir.LastIndexOf('\\') + 1);
            FileSystemWatcher w = new FileSystemWatcher(downloadDir);

            w.Filter                = "*.torrent";
            w.NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName;
            w.EnableRaisingEvents   = true;
            w.IncludeSubdirectories = true;

            w.Created += (s, e) =>
            {
                FileInfo fi          = new FileInfo(e.FullPath);
                string   tmp         = fi.Directory.ToString();
                string   eventParent = tmp.Substring(tmp.LastIndexOf('\\') + 1);
                if (downloadFolder != eventParent)
                {
                    if (t.AddTorrent(e.FullPath, eventParent))
                    {
                        Path.ChangeExtension(e.FullPath, "loaded");
                    }
                }
            };
        }
Exemple #2
0
        public FileSystemMonitor(TorrentAPI t)
        {
            string downloadDir = "";
            string downloadFolder = downloadDir.Substring(downloadDir.LastIndexOf('\\') + 1);
            FileSystemWatcher w = new FileSystemWatcher(downloadDir);
            w.Filter = "*.torrent";
            w.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
            w.EnableRaisingEvents = true;
            w.IncludeSubdirectories = true;

            w.Created += (s, e) =>
            {
                FileInfo fi = new FileInfo(e.FullPath);
                string tmp = fi.Directory.ToString();
                string eventParent = tmp.Substring(tmp.LastIndexOf('\\') + 1);
                if (downloadFolder != eventParent)
                    if(t.AddTorrent(e.FullPath, eventParent))
                        Path.ChangeExtension(e.FullPath, "loaded");
            };
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");
            // This handler is for catching non-UI thread exceptions
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (settings.UserName == "" && settings.Password == "")
            {
                Console.WriteLine("This is your first time starting this application.");
                Console.WriteLine("Please provide some basic uTorrent settings.");
                Console.Write("Username: "******"Password: "******"Hostname (fx. localhost:8080): ");
                settings.Host = Console.ReadLine();
                settings.Host = settings.Host.Replace("localhost", "127.0.0.1");
                if (!settings.Host.Contains("127.0.0.1"))
                {
                    Console.WriteLine("You have chosen to run the labeller from an computer other than the one uTorrent is running on.");
                    Console.WriteLine("You have to specify which directory to look for torrents in.");
                    Console.Write("Dir: ");
                    settings.Dir = Console.ReadLine();
                    while (!Directory.Exists(settings.Dir))
                    {
                        Console.WriteLine("Invalid dir, try again.");
                        Console.Write("Dir: ");
                        settings.Dir = Console.ReadLine();
                    }
                }
                else
                {
                    settings.Dir = "";
                }
                Console.Write("Should automatically added torrents be stopped when done? (Y/N) ");
                settings.StopOnDone = Console.ReadLine();
                while (settings.StopOnDone.ToLower() != "y" && settings.StopOnDone.ToLower() != "n")
                {
                    Console.Write("Invalid input, only Y or N allowed. Try again: ");
                    settings.StopOnDone = Console.ReadLine();
                }
                settings.Save();
            }
            Console.Clear();
            Console.WriteLine("Connecting to " + settings.Host);

            try
            {
                var torrentAPI = new TorrentAPI(settings.Host, settings.UserName, settings.Password);
                if (settings.Dir == "")
                {
                    settings.Dir = torrentAPI.GetDownloadDir();
                }

                Console.WriteLine("Detecting label folders...");
                Console.WriteLine("Detected: ");
                Labels = new List <string>();
                DirectoryInfo d = new DirectoryInfo(settings.Dir);
                foreach (DirectoryInfo label in d.GetDirectories())
                {
                    Console.WriteLine(label.Name);
                    Labels.Add(label.Name);
                }
                TorrentFileSystemMonitor fs = new TorrentFileSystemMonitor((f, s) => { torrentAPI.AddTorrent(f, s); });
                Console.WriteLine("Connection successful!");
                LoggingAdapter.Info("Connection successful!");
            }
            catch (Exception ex)
            {
                LoggingAdapter.Error("Could not connect to uTorrent. Please exit this program, start uTorrent, and try again.", ex);
                Console.WriteLine("Could not connect to uTorrent. Please exit this program, start uTorrent, and try again.");
                Console.WriteLine("########");
                Console.WriteLine("# Error: " + ex.Message);
                Console.WriteLine("# Source: " + ex.Source);
                Console.WriteLine("########");
                Console.WriteLine();
            }

            Console.WriteLine("To reset your settings, type RESET. To exit the program, press ENTER");
            string reset = Console.ReadLine();

            if (reset == "RESET")
            {
                settings.Password   = "";
                settings.UserName   = "";
                settings.Host       = "";
                settings.Dir        = "";
                settings.StopOnDone = "";
                settings.Save();
                return;
            }
            settings.Save();
        }
Exemple #4
0
 private void Connect()
 {
     if (Properties.Settings.Default.validConnectionSettings)
     {
         try
         {
             _connecting = true;
             TorrentAPI ta = new TorrentAPI(Properties.Settings.Default.hostname, Properties.Settings.Default.username, Properties.Settings.Default.password);
             Properties.Settings.Default.torrentDir = ta.GetDownloadDir();
             _connecting = false;
             _connected = true;
         }
         catch (Exception ex)
         {
             _connecting = false;
             _connected = false;
         }
     }
 }
Exemple #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");
            if (settings.UserName == "" && settings.Password == "")
            {
                Console.WriteLine("This is your first time starting this application.");
                Console.WriteLine("Please provide some basic uTorrent settings.");
                Console.Write("Username: "******"Password: "******"Hostname (fx. localhost:8080): ");
                settings.Host = Console.ReadLine();
                settings.Host = settings.Host.Replace("localhost", "127.0.0.1");
                if (!settings.Host.Contains("127.0.0.1"))
                {
                    Console.WriteLine("You have chosen to run the labeller from an computer other than the one uTorrent is running on.");
                    Console.WriteLine("You have to specify which directory to look for torrents in.");
                    Console.Write("Dir: ");
                    settings.Dir = Console.ReadLine();
                    while (!Directory.Exists(settings.Dir))
                    {
                        Console.WriteLine("Invalid dir, try again.");
                        Console.Write("Dir: ");
                        settings.Dir = Console.ReadLine();
                    }
                }
                else
                {
                    settings.Dir = "";
                }
                Console.Write("Should automatically added torrents be stopped when done? (Y/N) ");
                settings.StopOnDone = Console.ReadLine();
                while (settings.StopOnDone.ToLower() != "y" && settings.StopOnDone.ToLower() != "n")
                {
                    Console.Write("Invalid input, only Y or N allowed. Try again: ");
                    settings.StopOnDone = Console.ReadLine();
                }
                settings.Save();
            }
            Console.Clear();
            Console.WriteLine("Connecting to " + settings.Host);

            try
            {
                t = new TorrentAPI(settings.Host, settings.UserName, settings.Password);
                if (settings.Dir == "")
                    settings.Dir = t.GetDownloadDir();

                Console.WriteLine("Detecting label folders...");
                Console.WriteLine("Detected: ");
                Labels = new List<string>();
                DirectoryInfo d = new DirectoryInfo(settings.Dir);
                foreach (DirectoryInfo label in d.GetDirectories())
                {
                    Console.WriteLine(label.Name);
                    Labels.Add(label.Name);
                }
                FileSystemMonitor fs = new FileSystemMonitor();
                Console.WriteLine("Connection successful!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not connect to uTorrent. Please exit this program, start uTorrent, and try again.");
                Console.WriteLine("########");
                Console.WriteLine("# Error: " + ex.Message);
                Console.WriteLine("# Source: " + ex.Source);
                Console.WriteLine("########");
                Console.WriteLine();
            }

            Console.WriteLine("To reset your settings, type RESET. To exit the program, press ENTER");
            string reset = Console.ReadLine();
            if (reset == "RESET")
            {
                settings.Password = "";
                settings.UserName = "";
                settings.Host = "";
                settings.Dir = "";
                settings.StopOnDone = "";
                settings.Save();
                return;
            }
            settings.Save();
        }