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.

177 lines
5.6 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. String name = lstUsers.GetItemText(lstUsers.SelectedItem);
  90. String path = saveFileDialog("Skype_History_" + name + ".txt");
  91. if(path != null)
  92. {
  93. System.IO.StreamWriter file = new System.IO.StreamWriter(path);
  94. String line = "";
  95. foreach (Chat oChat in skype.Chats)
  96. {
  97. foreach (ChatMessage oMessage in oChat.Messages)
  98. {
  99. if(oMessage.Sender.FullName.Equals(name))
  100. {
  101. if (chTime.Checked) line = oMessage.Timestamp.ToString() + " ";
  102. if (chUser.Checked) line += oMessage.Sender.FullName + " ";
  103. line += oMessage.Body;
  104. file.WriteLine(line);
  105. line = "";
  106. }
  107. }
  108. }
  109. file.Close();
  110. MessageBox.Show("Save Complete");
  111. }
  112. }
  113. }
  114. private void cmdExportAll_Click(object sender, EventArgs e)
  115. {
  116. if (!connected)
  117. {
  118. errorMessage();
  119. }
  120. else
  121. {
  122. String path = saveFileDialog("SkypeHistory.txt");
  123. if(path != null) //makes sure that user did not click on cancle on save file dialog
  124. {
  125. System.IO.StreamWriter file = new System.IO.StreamWriter(path);
  126. String line = "";
  127. //exports all skype history to a text file
  128. foreach (Chat oChat in skype.Chats)
  129. {
  130. foreach (ChatMessage oMessage in oChat.Messages)
  131. {
  132. if (chTime.Checked) line = oMessage.Timestamp.ToString() + " ";
  133. if (chUser.Checked) line += oMessage.Sender.FullName + " ";
  134. line += oMessage.Body;
  135. file.WriteLine(line);
  136. line = "";
  137. }
  138. }
  139. file.Close();
  140. MessageBox.Show("Save Complete");
  141. }
  142. }
  143. }
  144. private void cmdClear_Click(object sender, EventArgs e)
  145. {
  146. lstChat.Items.Clear();
  147. }
  148. private String saveFileDialog(String text)
  149. {
  150. SaveFileDialog saveFile = new SaveFileDialog();
  151. saveFile.FileName = text;
  152. saveFile.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
  153. if(saveFile.ShowDialog() == DialogResult.OK)
  154. {
  155. return saveFile.FileName;
  156. }
  157. return null;
  158. }
  159. }
  160. }