Example #1
0
 void ClipboardUpdated(object sender, EventArgs args)
 {
     if (!clip_freeze && config.Active && !config.Offline)
     {
         clip_dirty = (clip_data = ClipBuffer.FromClipboard()) != null;
     }
 }
Example #2
0
        void ThreadListener()
        {
            while (true)
            {
                if (config.Offline | config.Mute)
                {
                    Thread.Sleep(1000);
                }

                if (server.Active && server.Pending())
                {
                    Log(NotificationType.Receiving);

                    var stream = server.AcceptTcpClient().GetStream();

                    try
                    {
                        ClipBuffer f = BinFormatter.Deserialize(stream) as ClipBuffer;

                        if (f == null)
                        {
                            throw new InvalidOperationException("Can't listen to unrecognizable packet (suggest to switch port?)");
                        }

                        // Clip Freeze prevents the next copy buffer event makes problem.
                        clip_freeze = true;

                        if (f.Type == DataType.Files)
                        {
                            var files = f as FileBuffer;

                            Utility.SetupTemporaryFiles(files);

                            progresser.Init(files);

                            ListenToFiles(stream, files);

                            progresser.Done();

                            ListenBytes.Clean();
                        }

                        Invoke(new Action(f.ToClipboard));

                        Thread.Sleep(100);

                        Log(NotificationType.Received, f);
                    }

                    catch (Exception ex) { Log("Listening failed: " + ex.Message); continue; }

                    stream.Close();
                }

                Thread.Sleep(50);

                clip_freeze = false;
            }
        }