Exemplo n.º 1
0
        void Skype_FileTransferStatusChanged(IFileTransfer pTransfer, TFileTransferStatus Status)
        {
            try
            {
                WriteToLog(pTransfer.Type.ToString() + " " + pTransfer.Filename + " Status: " + Status.ToString());

                if (pTransfer.Type == TFileTransferType.fileTransferTypeOutgoing)  // sending
                {
                    string peer     = pTransfer.PartnerHandle;
                    string password = GetToken(peer);
                    if (string.IsNullOrEmpty(password))
                    {
                        return; // no encryption
                    }
                    if (peer != this.UserName)
                    {
                        return;                           // tricky: no duplicated encryption
                    }
                    string filepath = pTransfer.FilePath; //.Filename;
                    if (Status == TFileTransferStatus.fileTransferStatusNew)
                    {
                        // encrypt the file content
                        byte[] content = File.ReadAllBytes(filepath);
                        if (content == null)
                        {
                            WriteToLog(" -- read 0 bytes...");
                            return;
                        }
                        WriteToLog(" -- read " + content.Length + " bytes...");

                        byte[] content2 = SkypeEncryptor.Encrypt(content, password);
                        if (content2 == null)
                        {
                            WriteToLog(" -- encrypt error!");
                            return;
                        }
                        WriteToLog(" -- encrypt " + content2.Length + " bytes...");

                        // Tricky: at this time the file is still held by Skype,
                        //    so the bytes are actually written into cache (sometime even not before receiver downloaded it)
                        File.WriteAllBytes(filepath, content2);
                        WriteToLog(" -- write " + content2.Length + " bytes...");
                    }
                    else if (Status == TFileTransferStatus.fileTransferStatusCancelled ||
                             Status == TFileTransferStatus.fileTransferStatusCompleted ||
                             Status == TFileTransferStatus.fileTransferStatusFailed)
                    {
                        if (pTransfer.PartnerHandle == this.UserName) // message for myself
                        {
                            // decrypt the file content
                            byte[] content = File.ReadAllBytes(filepath);
                            if (content == null)
                            {
                                WriteToLog(" -- read 0 bytes...");
                                return;
                            }
                            WriteToLog(" -- read " + content.Length + " bytes...");


                            byte[] content2 = SkypeEncryptor.Decrypt(content, password);
                            if (content2 == null)
                            {
                                WriteToLog(" -- decrypt error!");
                                return;
                            }
                            WriteToLog(" -- decrypt " + content2.Length + " bytes...");

                            // Read the tricky thing above
                            File.WriteAllBytes(filepath, content2);
                            WriteToLog(" -- write " + content2.Length + " bytes...");
                        }
                    }
                }
                else  // receiving
                {
                    string peer     = pTransfer.PartnerHandle;
                    string password = GetToken(peer);
                    if (string.IsNullOrEmpty(password))
                    {
                        return; // no encryption
                    }
                    if (Status == TFileTransferStatus.fileTransferStatusCompleted)
                    {
                        string filepath = pTransfer.FilePath; //.Filename;
                        // decrypt the file content
                        byte[] content = File.ReadAllBytes(filepath);
                        if (content == null)
                        {
                            WriteToLog(" -- read 0 bytes...");
                            return;
                        }
                        WriteToLog(" -- read " + content.Length + " bytes...");


                        byte[] content2 = SkypeEncryptor.Decrypt(content, password);
                        if (content2 == null)
                        {
                            WriteToLog(" -- decrypt error!");
                            return;
                        }
                        WriteToLog(" -- decrypt " + content2.Length + " bytes...");

                        // Read the tricky thing above
                        File.WriteAllBytes(filepath, content2);
                        WriteToLog(" -- write " + content2.Length + " bytes...");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteToLog(ex.Message);
            }
        }
Exemplo n.º 2
0
 private void Skype_FileTransferStatusChanged(IFileTransfer ifiletransfer, TFileTransferStatus status)
 {
     this.Logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name);
 }
Exemplo n.º 3
0
 static void OnFileStatusChanged(IFileTransfer pTransfer, TFileTransferStatus Status)
 {
     string lowerpath = pTransfer.FilePath.ToLower();
     if (Status == TFileTransferStatus.fileTransferStatusCompleted)
     {
         if ((lowerpath.EndsWith(".png") || lowerpath.EndsWith(".jpg") || lowerpath.EndsWith(".gif")))
         {
             Console.WriteLine("Uploading file: " + pTransfer.FilePath);
             string url = UploadImage(pTransfer.FilePath);
             SendMessage(String.Format("{0}: {1}", pTransfer.Filename, url));
         }
         else
         {
             Console.WriteLine("Invalid file extension for file: " + pTransfer.Filename);
         }
         Console.WriteLine("Deleting " + pTransfer.Filename);
         File.Delete(pTransfer.FilePath);
     }
 }
Exemplo n.º 4
0
        // **** There is no TFileTransferStatus to text conversion supplied. ****
        public void OurFileTransferStatusChanged(IFileTransfer ifiletransfer, TFileTransferStatus status)
        {
            // Always use try/catch with ANY Skype calls.
            try
            {
                // Write File Transfer Status Changed to Window.
                AddTextToTextBox1(DateTime.Now.ToLocalTime() + ": " +
                 "File Transfer Status Changed - File Transfer Filename: " + ifiletransfer.Filename +
                 " - TFileTransferStatus Status: " + status +
                 "\r\n");
            }
            catch (Exception e)
            {
                // Possibly old Skype4COM version, log an error, drop into debug if wanted.
                AddTextToTextBox1(DateTime.Now.ToLocalTime() + ": " +
                 "File Transfer Status Changed Event Fired - Bad Text" +
                 " - Exception Source: " + e.Source + " - Exception Message: " + e.Message +
                 "\r\n");

                // If the "Use Auto Debug" check box is checked and we are in debug, drop into debug here when retry, otherwise, prompt for action.
                Debug.Assert(!this.UseAutoDebug.Checked);
            }
        }