示例#1
0
        public static void AddWithFile(string key, ClipboardItem value)
        {
            // if CLIPBOARD file is missing or empty
            if (!LocalClipboard.ClipboardFile.Exists || LocalClipboard.ClipboardFile.Length == 0)
            {
                // create new file and prepare to write
                using (StreamWriter sw = LocalClipboard.ClipboardFile.CreateText())
                {
                    // write each item's FileChars to the CLIPBOARD file
                    for (int i = LocalClipboard.Keys.Count - 1; i >= 0; i--)
                    {
                        sw.Write(LocalClipboard.Dict[LocalClipboard.Keys[i]].FileChars);
                    }
                }
            }

            // append the item's FileChars to the CLIPBOARD file
            using (StreamWriter sw = LocalClipboard.ClipboardFile.AppendText())
            {
                sw.Write(value.FileChars);
            }

            // add to data structures in the local clipboard
            LocalClipboard.Add(key, value);
        }
示例#2
0
        public AudioItem(MainWindow mainWindow, ushort keyDiff, StringReader strRead)
            : base(mainWindow, TypeEnum.Audio, keyDiff)
        {
            // retrieving ByteLength and KeyText from the stream
            this.ByteLength = long.Parse(strRead.ReadLine());
            base.KeyText    = strRead.ReadLine();

            /// Char order:
            ///
            /// 1. Type
            /// 2. KeyDiff
            /// 3. ByteLength
            /// 4. KeyText
            ///

            base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine +
                             this.ByteLength.ToString() + Environment.NewLine + base.KeyText + Environment.NewLine;

            // if audio file is missing, remove item data from the CLIPBOARD file and return
            FileInfo audioFile = new FileInfo(Path.Combine(LocalClipboard.AudioFolder.FullName, base.KeyText));

            if (!audioFile.Exists)
            {
                LocalClipboard.RemoveFromFile(base.FileChars);
                return;
            }

            // add to local clipboard
            LocalClipboard.Add(base.KeyText, this);
        }
示例#3
0
        public FileItem(MainWindow mainWindow, ushort keyDiff, StringReader strRead)
            : base(mainWindow, TypeEnum.FileDropList, keyDiff)
        {
            // retrieve number of strings in FileDropList
            int listCount = int.Parse(strRead.ReadLine());

            // read each string into FileDropList
            this.FileDropList = new StringCollection();
            for (int i = 0; i < listCount; i++)
            {
                this.FileDropList.Add(strRead.ReadLine());
            }

            // if 1 file was copied, KeyText will store FileDropList[0]'s filename
            if (this.FileDropList.Count == 1)
            {
                base.KeyText = "File: " + Path.GetFileName(this.FileDropList[0]);
            }
            // else KeyText will store FileDropList[0]'s filename + how many more files there are
            else
            {
                base.KeyText = "Files: " + Path.GetFileName(this.FileDropList[0]) + " + " + (this.FileDropList.Count - 1) + " more";
            }

            // shorten KeyText to fit the character limit if needed
            if (base.KeyText.Length > LocalClipboard.CHAR_LIMIT)
            {
                base.KeyText = base.KeyText.Substring(0, LocalClipboard.CHAR_LIMIT) + "...";
            }

            // add KeyDiff to KeyText if needed
            if (base.KeyDiff != 0)
            {
                base.KeyText += base.KeyDiff;
            }

            /// Char order:
            ///
            /// 1. Type
            /// 2. KeyDiff
            /// 3. # strings in FileDropList
            /// 4. FileDropList
            ///

            base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine +
                             this.FileDropList.Count.ToString() + Environment.NewLine;

            foreach (string fileDir in this.FileDropList)
            {
                base.FileChars += fileDir + Environment.NewLine;
            }

            // add to local clipboard
            LocalClipboard.Add(base.KeyText, this);
        }
示例#4
0
        public TextItem(MainWindow mainWindow, ushort keyDiff, StringReader strRead)
            : base(mainWindow, TypeEnum.Text, keyDiff)
        {
            // retrieve number of chars in Text
            int textSize = int.Parse(strRead.ReadLine());

            // read textSize num chars from the file to a char array
            char[] textArr = new char[textSize];
            strRead.Read(textArr, 0, textSize);

            // store char array as Text
            this.Text = new string(textArr);

            // set beginning part of KeyText
            base.KeyText = "Text: ";

            // append to KeyText given Text
            if (this.Text.Length > LocalClipboard.CHAR_LIMIT - base.KeyText.Length)
            {
                base.KeyText += this.Text.Substring(0, LocalClipboard.CHAR_LIMIT - base.KeyText.Length) + "...";
            }
            else
            {
                base.KeyText += this.Text;
            }

            // add KeyDiff to KeyText if needed
            if (base.KeyDiff != 0)
            {
                base.KeyText += base.KeyDiff;
            }

            /// Char order:
            ///
            /// 1. Type
            /// 2. KeyDiff
            /// 3. Text.Length
            /// 4. Text
            ///
            string keyDiffStr = base.KeyDiff.ToString();
            string textLenStr = this.Text.Length.ToString();

            base.FileChars = (char)base.Type + keyDiffStr + Environment.NewLine +
                             textLenStr + Environment.NewLine + this.Text;

            // add to local clipboard
            LocalClipboard.Add(base.KeyText, this);
        }
示例#5
0
        public ImageItem(MainWindow mainWindow, ushort keyDiff, StringReader strRead)
            : base(mainWindow, TypeEnum.Image, keyDiff)
        {
            // retrieve width int
            int width = int.Parse(strRead.ReadLine());

            // retrieve height int
            int height = int.Parse(strRead.ReadLine());

            // init Size with width and height args
            this.Size = new Size(width, height);

            // set KeyText using image dimensions
            base.KeyText = "Image (" + this.Size.Width + " x " + this.Size.Height + ")";

            // add KeyDiff to KeyText if needed
            if (base.KeyDiff != 0)
            {
                base.KeyText += base.KeyDiff;
            }

            /// Char order:
            ///
            /// 1. Type
            /// 2. KeyDiff
            /// 3. Size.Width
            /// 4. Size.Height
            ///

            base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine +
                             this.Size.Width.ToString() + Environment.NewLine + this.Size.Height.ToString() +
                             Environment.NewLine;

            // if image file is missing, remove item data from the CLIPBOARD file and return
            FileInfo imageFile = new FileInfo(Path.Combine(LocalClipboard.ImageFolder.FullName, base.KeyText));

            if (!imageFile.Exists)
            {
                LocalClipboard.RemoveFromFile(base.FileChars);
                return;
            }

            // add to local clipboard
            LocalClipboard.Add(base.KeyText, this);
        }
示例#6
0
        public CustomItem(MainWindow mainWindow, ushort keyDiff, StringReader strRead)
            : base(mainWindow, TypeEnum.Custom, keyDiff)
        {
            // retrieving WritableFormat from the stream
            this.WritableFormat = strRead.ReadLine();

            // set KeyText using WritableFormat
            base.KeyText = "Custom (" + this.WritableFormat + ")";

            // add KeyDiff to KeyText if needed
            if (base.KeyDiff != 0)
            {
                base.KeyText += base.KeyDiff;
            }

            /// Char order:
            ///
            /// 1. Type
            /// 2. KeyDiff
            /// 3. WritableFormat
            ///

            base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine + this.WritableFormat + Environment.NewLine;

            // if custom file is missing, remove item data from the CLIPBOARD file and return
            FileInfo customFile = new FileInfo(Path.Combine(LocalClipboard.CustomFolder.FullName, base.KeyText));

            if (!customFile.Exists)
            {
                LocalClipboard.RemoveFromFile(base.FileChars);
                return;
            }

            // add to local clipboard
            LocalClipboard.Add(base.KeyText, this);
        }