A skype history message viewer written in c#
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using SKYPE4COMLib;
  11. namespace Skype_History_Viewer
  12. {
  13. public partial class FrmMain : Form
  14. {
  15. private Boolean connected = false;
  16. private Skype skype = new Skype();
  17. public FrmMain()
  18. {
  19. InitializeComponent();
  20. connected = connectToSkype();
  21. }
  22. private void cmdAdd_Click(object sender, EventArgs e)
  23. {
  24. if(!connected)
  25. {
  26. errorMessage();
  27. }
  28. else
  29. {
  30. //displays the chat of selected user
  31. String name = lstUsers.GetItemText(lstUsers.SelectedItem);
  32. String display = "";
  33. foreach (Chat oChat in skype.Chats)
  34. {
  35. foreach (ChatMessage oMessage in oChat.Messages)
  36. {
  37. if(oMessage.Sender.FullName.Equals(name))
  38. {
  39. if (chTime.Checked) display = oMessage.Timestamp.ToString() + " ";
  40. if (chUser.Checked)
  41. {
  42. display += oMessage.Sender.FullName + " ";
  43. }
  44. display += oMessage.Body;
  45. lstChat.Items.Add(display);
  46. display = "";
  47. }
  48. }
  49. }
  50. }
  51. }
  52. private void errorMessage()
  53. {
  54. connected = connectToSkype();
  55. if(!connected)
  56. {
  57. MessageBox.Show("Could not connect to skype, please make sure that skype is running and this plugin is allowed.");
  58. }
  59. }
  60. private Boolean connectToSkype()
  61. {
  62. try
  63. {
  64. //attaches the program to skype
  65. skype.Attach();
  66. //adds all users to lstUsers
  67. if(!connected)
  68. {
  69. foreach (User user in skype.Friends)
  70. {
  71. lstUsers.Items.Add(user.FullName);
  72. }
  73. }
  74. return true;
  75. }
  76. catch
  77. {
  78. return false;
  79. }
  80. }
  81. private void cmdExport_Click(object sender, EventArgs e)
  82. {
  83. if (!connected)
  84. {
  85. errorMessage();
  86. }
  87. else
  88. {
  89. }
  90. }
  91. private void cmdExportAll_Click(object sender, EventArgs e)
  92. {
  93. if (!connected)
  94. {
  95. errorMessage();
  96. }
  97. else
  98. {
  99. //exports all skype history to a text file
  100. System.IO.StreamWriter file = new System.IO.StreamWriter("SkypeHistory.txt");
  101. String line = "";
  102. foreach (Chat oChat in skype.Chats)
  103. {
  104. foreach (ChatMessage oMessage in oChat.Messages)
  105. {
  106. if (chTime.Checked) line = oMessage.Timestamp.ToString() + " ";
  107. if (chUser.Checked) line += oMessage.Sender.FullName + " ";
  108. line += oMessage.Body;
  109. file.WriteLine(line);
  110. line = "";
  111. }
  112. }
  113. file.Close();
  114. }
  115. }
  116. private void cmdClear_Click(object sender, EventArgs e)
  117. {
  118. lstChat.Items.Clear();
  119. }
  120. }
  121. }