Ejemplo n.º 1
0
 private bool Run(string[] args)
 {
     Torrent torrent = new Torrent(messages);
     try
     {
         for (int i = 0; i < args.Length; i++)
         {
             switch (args[i])
             {
                 case "-l":
                     torrent.PiecesLength = int.Parse(args[i + 1]);
                     i++;
                     Console.WriteLine("{0}: 2^{1}", messages.GetMessage("PieceLength"), torrent.PiecesLength);
                     break;
                 case "-p":
                     torrent.PrivateTorrent = true;
                     Console.WriteLine("{0}: {1}", messages.GetMessage("PrivateFlag"),
                         torrent.PrivateTorrent ? messages.GetMessage("StrTrue") : messages.GetMessage("StrFalse"));
                     break;
                 case "-movieonly":
                     torrent.MovieOnly = true;
                     Console.WriteLine(messages.GetMessage("MovieOnly"));
                     break;
                 case "-a":
                     torrent.AnnounceURL = args[i + 1];
                     i++;
                     Console.WriteLine("{0}: {1}", messages.GetMessage("Tracker"), torrent.AnnounceURL);
                     break;
                 case "-o":
                     torrent.TorrentFileName = args[i + 1];
                     i++;
                     Console.WriteLine("{0}: {1}", messages.GetMessage("FileName"), torrent.TorrentFileName);
                     break;
                 default:
                     if (args[i][args[i].Length - 1].Equals('"'))
                     {
                         args[i] = args[i].Substring(0, args[i].Length - 1);
                     }
                     if (args[i][args[i].Length - 1].Equals('\\'))
                     {
                         args[i] = args[i].Substring(0, args[i].Length - 1);
                     }
                     if (Directory.Exists(args[i]))
                     {
                         torrent.DirectoryName = args[i];
                         Console.WriteLine("{0}: {1}", messages.GetMessage("Folder"), torrent.DirectoryName);
                     }
                     else if (File.Exists(args[i]))
                     {
                         torrent.FileName = args[i];
                         Console.WriteLine("{0}: {1}", messages.GetMessage("File"), torrent.FileName);
                     }
                     break;
             }
         }
         if ((!torrent.DirectoryName.Equals("")) || (!torrent.FileName.Equals("")))
         {
             torrent.MakeTorrentData();
             torrent.SaveTorrentFile();
             torrent.CheckTracker();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("{0}: {1}", messages.GetMessage("ErrorMessage"), ex.Message);
     }
     return torrent.TorrentPrepared;
 }
Ejemplo n.º 2
0
        private bool Run(string[] args)
        {
            Torrent torrent = new Torrent(messages);

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-l":
                        torrent.PiecesLength = int.Parse(args[i + 1]);
                        i++;
                        Console.WriteLine("{0}: 2^{1}", messages.GetMessage("PieceLength"), torrent.PiecesLength);
                        break;

                    case "-p":
                        torrent.PrivateTorrent = true;
                        Console.WriteLine("{0}: {1}", messages.GetMessage("PrivateFlag"),
                                          torrent.PrivateTorrent ? messages.GetMessage("StrTrue") : messages.GetMessage("StrFalse"));
                        break;

                    case "-movieonly":
                        torrent.MovieOnly = true;
                        Console.WriteLine(messages.GetMessage("MovieOnly"));
                        break;

                    case "-a":
                        torrent.AnnounceURL = args[i + 1];
                        i++;
                        Console.WriteLine("{0}: {1}", messages.GetMessage("Tracker"), torrent.AnnounceURL);
                        break;

                    case "-o":
                        torrent.TorrentFileName = args[i + 1];
                        i++;
                        Console.WriteLine("{0}: {1}", messages.GetMessage("FileName"), torrent.TorrentFileName);
                        break;

                    default:
                        if (args[i][args[i].Length - 1].Equals('"'))
                        {
                            args[i] = args[i].Substring(0, args[i].Length - 1);
                        }
                        if (args[i][args[i].Length - 1].Equals('\\'))
                        {
                            args[i] = args[i].Substring(0, args[i].Length - 1);
                        }
                        if (Directory.Exists(args[i]))
                        {
                            torrent.DirectoryName = args[i];
                            Console.WriteLine("{0}: {1}", messages.GetMessage("Folder"), torrent.DirectoryName);
                        }
                        else if (File.Exists(args[i]))
                        {
                            torrent.FileName = args[i];
                            Console.WriteLine("{0}: {1}", messages.GetMessage("File"), torrent.FileName);
                        }
                        break;
                    }
                }
                if ((!torrent.DirectoryName.Equals("")) || (!torrent.FileName.Equals("")))
                {
                    torrent.MakeTorrentData();
                    torrent.SaveTorrentFile();
                    torrent.CheckTracker();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}: {1}", messages.GetMessage("ErrorMessage"), ex.Message);
            }
            return(torrent.TorrentPrepared);
        }