Esempio n. 1
0
        public static void SetClipboardText(IWin32Window owner, string text, bool sensitiveData)
        {
            var data = new DataObject();

            if (text.Length > 0)
            {
                data.SetText(text, TextDataFormat.UnicodeText);
            }

            PauseMonitor();

            try {
                Debug.WriteLine("Clipboard: SetData (text)");
                Clipboard.SetDataObject(data, false, 5, 100);
            } catch (ExternalException ex) {
                Medo.MessageBox.ShowError(owner, "Cannot copy to clipboard!\n\n" + ex.Message);
                return;
            }

            if (sensitiveData || (Settings.AutoClearClipboardForSensitiveDataOnly == false))
            {
                StartMonitor();
                ClipboardClearThread.ScheduleClear();
            }
        }
Esempio n. 2
0
        public static void Cancel()
        {
            PauseMonitor();

            Debug.WriteLine("Clipboard: Clear (cancel)");
            Clipboard.Clear();
            ClipboardClearThread.Terminate();
        }
Esempio n. 3
0
        private static void ClipboardMonitor_ClipboardChanged(object sender, ClipboardChangedEventArgs e)
        {
            Debug.WriteLine("Clipboard: Monitor Changed");
            ClipboardClearThread.UnscheduleClear();

            if (ClipboardMonitor != null)
            {
                Debug.WriteLine("Clipboard: Monitor Pause (change)");
                ClipboardMonitor.ClipboardChanged -= ClipboardMonitor_ClipboardChanged;
            }
        }
Esempio n. 4
0
        public static void SetClipboardData(IWin32Window owner, IEnumerable <Entry> entries, bool sensitiveData)
        {
            var bytes  = new List <byte>();
            var buffer = new byte[0];

            try {
                foreach (var entry in entries)
                {
                    foreach (var record in entry.Records)
                    {
                        var dataBytes = record.GetBytesSilently(); //to avoid modifications to access time
                        try {
                            bytes.AddRange(BitConverter.GetBytes((int)record.RecordType));
                            bytes.AddRange(BitConverter.GetBytes(dataBytes.Length));
                            bytes.AddRange(dataBytes);
                        } finally {
                            Array.Clear(dataBytes, 0, dataBytes.Length);
                        }
                    }

                    //add entry separator
                    bytes.AddRange(new byte[] { 0, 0, 0, 0 }); //RecordType=0
                    bytes.AddRange(new byte[] { 0, 0, 0, 0 }); //Length=0
                }
                buffer = bytes.ToArray();

                var protectedBuffer = ProtectedData.Protect(buffer, null, DataProtectionScope.CurrentUser);

                var data = new DataObject();
                data.SetData(FormatName, protectedBuffer);

                PauseMonitor();

                try {
                    Debug.WriteLine("Clipboard: SetData (object)");
                    Clipboard.SetDataObject(data, false, 5, 100);
                } catch (ExternalException ex) {
                    Medo.MessageBox.ShowError(owner, "Cannot copy to clipboard!\n\n" + ex.Message);
                }

                if (sensitiveData || (Settings.AutoClearClipboardForSensitiveDataOnly == false))
                {
                    StartMonitor();
                    ClipboardClearThread.ScheduleClear();
                }
            } finally {
                for (var i = 0; i < bytes.Count; i++)
                {
                    bytes[i] = 0;
                }
                Array.Clear(buffer, 0, buffer.Length);
            }
        }