Beispiel #1
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);
        }
Beispiel #2
0
        public static void Remove(string key, ClipboardItem value)
        {
            // first, remove the item's FileChars from the CLIPBOARD file
            LocalClipboard.RemoveFromFile(value.FileChars);

            // remove item by its key
            LocalClipboard.MainWindow.ListBox.Items.Remove(key);
            LocalClipboard.Keys.Remove(key);
            LocalClipboard.Dict.Remove(key);

            // determine if we need to delete any files along with the item
            DirectoryInfo folder = null;

            if (value is ImageItem)
            {
                folder = LocalClipboard.ImageFolder;
            }
            else if (value is AudioItem)
            {
                folder = LocalClipboard.AudioFolder;
            }
            else if (value is CustomItem)
            {
                folder = LocalClipboard.CustomFolder;
            }

            // nothing to do if folder is null or missing
            if (folder == null || !folder.Exists)
            {
                return;
            }

            // delete image/audio/custom file if it exists
            FileInfo fileToDelete = new FileInfo(Path.Combine(folder.FullName, key));

            if (fileToDelete.Exists)
            {
                fileToDelete.Delete();
            }

            // delete the folder if it's empty, i.e. contains 0 files
            FileInfo[] fileInfos = folder.GetFiles();
            if (fileInfos.Length == 0)
            {
                folder.Delete();
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }