Ejemplo n.º 1
0
        public static void FromFile()
        {
            // if CLIPBOARD file is missing or empty
            if (!LocalClipboard.ClipboardFile.Exists || LocalClipboard.ClipboardFile.Length == 0)
            {
                return;
            }

            // store the current contents of the clipboard file
            string clipboardString = LocalClipboard.GetClipboard();

            // update the backup file with clipboardString
            LocalClipboard.BackupClipboard(clipboardString);

            // traverse clipboardString via StringReader
            using (StringReader strRead = new StringReader(clipboardString))
            {
                // peek returns -1 if no more characters are available
                while (strRead.Peek() != -1)
                {
                    // Type
                    ClipboardItem.TypeEnum type = (ClipboardItem.TypeEnum)strRead.Read();

                    // KeyDiff
                    ushort keyDiff = ushort.Parse(strRead.ReadLine());

                    // remaining operations depend on the type of item
                    switch (type)
                    {
                    case ClipboardItem.TypeEnum.Text:
                        _ = new TextItem(LocalClipboard.MainWindow, keyDiff, strRead);

                        break;

                    case ClipboardItem.TypeEnum.FileDropList:
                        _ = new FileItem(LocalClipboard.MainWindow, keyDiff, strRead);

                        break;

                    case ClipboardItem.TypeEnum.Image:
                        _ = new ImageItem(LocalClipboard.MainWindow, keyDiff, strRead);

                        break;

                    case ClipboardItem.TypeEnum.Audio:
                        _ = new AudioItem(LocalClipboard.MainWindow, keyDiff, strRead);

                        break;

                    case ClipboardItem.TypeEnum.Custom:
                        _ = new CustomItem(LocalClipboard.MainWindow, keyDiff, strRead);

                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method writes the current contents of the clipboard file to
        /// the backup file.
        ///
        /// This is used when clearing the local clipboard and when reading
        /// from the clipboard file on program startup.
        /// </summary>
        private static void BackupClipboard()
        {
            // if CLIPBOARD file is missing or empty
            if (!LocalClipboard.ClipboardFile.Exists || LocalClipboard.ClipboardFile.Length == 0)
            {
                return;
            }

            // first, get contents of the clipboard file
            string clipboardString = LocalClipboard.GetClipboard();

            // call helper with clipboardString as an arg
            LocalClipboard.BackupClipboard(clipboardString);
        }