Exemple #1
0
 internal static void Run()
 {
     Console.Clear();
     if (printResult)
     {
         Console.BackgroundColor = ConsoleColor.Yellow;
         Console.ForegroundColor = ConsoleColor.DarkRed;
         Console.WriteLine("ADVANCED MODE ENABLED: This will print detailed output while importing the chat.\n\n");
         Console.ResetColor();
     }
     Console.BackgroundColor = ConsoleColor.Blue;
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine("HELLO! WELCOME TO TELEGRAM CHAT IMPORTER!\n\nThis app will import your TXT conversations from third-party apps (like WhatsApp) into your existing Telegram Chat with your partner. \nRead all the documentation on the GitHub page (https://github.com/TelegramTools/TLImporter/wiki) for all the important information.\n\nPress ENTER to continue");
     Console.ReadLine();
     Console.ForegroundColor = ConsoleColor.White;
     Console.BackgroundColor = ConsoleColor.DarkCyan;
     AskConfirmation("\nWARNING: Telegram allows only a specific and unknown amount of messages within a specific timeframe for security reasons. You might not be able to message friends for a small period of time.\nThis is known as a 'flood limitation'.\n\nThus, I suggest you to do this at night or in a period of time that you do not need to use Telegram. Check https://github.com/TelegramTools/TLImporter/wiki/Before-starting for more information.\n\nType, exactly, 'I UNDERSTOOD', to continue:", true, true, "I UNDERSTOOD");
     ConfirmationConfirmed = false;
     Console.ResetColor();
     Console.WriteLine("Logging you in Telegram...");
     Auth.AuthUser1().Wait();
     AskConfirmation("Do you want to import a conversation using two users, in a 1:1 format? Otherwise, the chat will be imported inside your 'Saved Messages'. [y/n]: ", false);
     if (ConfirmationConfirmed)
     {
         SoloImporting         = false;
         ConfirmationConfirmed = false;
     }
     else
     {
         SoloImporting         = true;
         ConfirmationConfirmed = false;
     }
     if (!SoloImporting)
     {
         Auth.AuthUser2().Wait();
     }
     while (!AllIsImported)
     {
         NotChosenUser = false;
         Console.Write("\n\nNow, please, type the complete path of the TXT file you want to import. You can also drag-and-drop it here.\n\nFILEPATH MUST NOT INCLUDE SPACES: ");
         filePath = Console.ReadLine();
         while (filePath.Contains(" "))
         {
             Console.Write("\n\nThe filepath contains an space. Please, make sure that there aren't spaces in the filepath and try again: ");
             filePath = Console.ReadLine();
             if (!filePath.Contains(" "))
             {
                 break;
             }
         }
         CheckUsers();
         while (!ImporterApp.FileIsValid)
         {
             Console.BackgroundColor = ConsoleColor.Red;
             Console.ForegroundColor = ConsoleColor.Black;
             Console.WriteLine("We couldn't find " + NameUser1 + " and " + NameUser2 + " in this file.\n\nPlease, check the documentation at https://github.com/TelegramTools/TLImporter to make sure that you are doing eveything right.\n\n");
             Console.ResetColor();
             AskConfirmation("Do you want to try again or close the app? (Yes (y), for trying again. No (n), for closing the app) [y/n]: ", false);
             if (!ConfirmationConfirmed)
             {
                 Environment.Exit(0);
             }
             else
             {
                 CheckUsers();
                 ConfirmationConfirmed = false;
             }
         }
         Console.BackgroundColor = ConsoleColor.Green;
         Console.ForegroundColor = ConsoleColor.Black;
         Console.WriteLine("\nThis file is valid to be imported. Counting the number of messages...");
         Console.ResetColor();
         TextHandler.TotalLines();
         Console.WriteLine("The file has " + TextHandler.TotalCount + " lines.");
         TextHandler.UserLines(NameUser1, false);
         Console.WriteLine("\n" + NameUser1 + " has " + TextHandler.CountedLines1 + " messages.");
         TextHandler.UserLines(NameUser2, true);
         Console.WriteLine(NameUser2 + " has " + TextHandler.CountedLines2 + " messages.");
         AskConfirmation("Do you also want to upload to the chat the TXT file used? [y/n]: ", false);
         if (ConfirmationConfirmed)
         {
             UploadTXT             = true;
             ConfirmationConfirmed = false;
         }
         else
         {
             UploadTXT             = false;
             ConfirmationConfirmed = false;
         }
         ConfirmationConfirmed = false;
         Console.WriteLine("Making sure that everything is ready for the import process... This will take nanoseconds :)");
         {
             if (NameUser1.Contains(":"))
             {
                 NameUser1.Replace(":", "");
             }
             if (NameUser2.Contains(":"))
             {
                 NameUser2.Replace(":", "");
             }
             TextHandler.CurrentMessage = 0;
             if (SoloImporting)
             {
                 if (filePath == null | TextHandler.TotalCount == null | TextHandler.CountedLines1 == null | TextHandler.CountedLines2 == null | NameUser1 == null | NameUser2 == null | Auth.phone1 == null | Messaging.User1Id == 0 | FileIsValid == false | ConfirmationConfirmed == true | AllIsImported == true)
                 {
                     Console.WriteLine("\nSomething went wrong and the app can't recover the process. You will need to start over. Press ENTER to exit and try again.");
                     Console.ReadLine();
                     Environment.Exit(0);
                 }
             }
             else if (filePath == null | TextHandler.TotalCount == null | TextHandler.CountedLines1 == null | TextHandler.CountedLines2 == null | NameUser1 == null | NameUser2 == null | Auth.phone1 == null | Auth.phone2 == null | Messaging.User1Id == 0 | Messaging.User2Id == 0 | FileIsValid == false | ConfirmationConfirmed == true | AllIsImported == true)
             {
                 Console.WriteLine("\nSomething went wrong and the app can't recover the process. You will need to start over. Press ENTER to exit and try again.");
                 Console.ReadLine();
                 Environment.Exit(0);
             }
             AskConfirmation("\nEverything is ready for the import process.\nREMEMBER: You might trigger flood limits in your account. Read https://github.com/TelegramTools/TLImporter/wiki/Before-starting for more information.\n\nStart? [y/n]: ", true);
             ConfirmationConfirmed = false;
             Console.WriteLine("");
             Messaging.MessageUser2("BEGINNING OF THE IMPORT OF " + filePath, false).Wait();
             TextHandler.ParseStrings();
             Messaging.MessageUser2("END OF THE IMPORT OF " + filePath + "\n\nA total of " + TextHandler.TotalCount + " messages were imported successfully.\n\n" + NameUser1 + " has " + TextHandler.CountedLines1 + " imported messages.\n" + NameUser2 + " has " + TextHandler.CountedLines2 + " imported messages.\n\nImported using Telegram Chat Importer. Available at https://github.com/TelegramTools/TLImporter", false).Wait();
             if (UploadTXT)
             {
                 Messaging.UploadFile().Wait();
             }
             if (!SoloImporting)
             {
                 Messaging.MarkMessagesAsRead().Wait();
             }
             Console.WriteLine("\n\n\nSUCCESS!! All the messages were imported succesfully!");
             AskConfirmation("\n\nDo you want to import another file?. Otherwise, data will be cleared. [y/n]: ", false);
             if (ConfirmationConfirmed)
             {
                 ChooseUsers();
                 ConfirmationConfirmed = false;
             }
             else
             {
                 if (File.Exists(@"sessionUser1.dat"))
                 {
                     File.Delete(@"sessionUser1.dat");
                 }
                 if (File.Exists(@"sessionUser2.dat"))
                 {
                     File.Delete(@"sessionUser2.dat");
                 }
                 AllIsImported = true;
             }
             ConfirmationConfirmed = false;
         }
     }
     Console.WriteLine("\nAll the data has been cleared and your session revoked. Now, you can log out the session on your mobile device or Telegram Desktop if you want.");
     Console.BackgroundColor = ConsoleColor.Cyan;
     Console.WriteLine("\n\nThank you for using this app. If you like it, please, star the GitHub repository :D at https://github.com/TelegramTools/TLImporter \n\nPress ENTER to exit.");
     Console.ReadLine();
     Environment.Exit(0);
 }