Ejemplo n.º 1
0
        private void buttonAttachGraphics_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title       = LanguageSettings.Current.Main.Menu.File.Open.RemoveChar('&');
            openFileDialog1.FileName    = string.Empty;
            openFileDialog1.Filter      = "Images|*" + string.Join(";*", _imageExtensions).TrimEnd('*');
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.Multiselect = true;
            var result = openFileDialog1.ShowDialog(this);

            if (result != DialogResult.OK || !File.Exists(openFileDialog1.FileName))
            {
                return;
            }

            foreach (var fileName in openFileDialog1.FileNames)
            {
                var attachmentFileName = Path.GetFileName(fileName);
                var attachmentContent  = UUEncoding.UUEncode(FileUtil.ReadAllBytesShared(fileName));
                AddToListView(attachmentFileName, attachmentContent, "[Graphics]");
                listViewAttachments.Items[listViewAttachments.Items.Count - 1].Selected = true;
                listViewAttachments.Items[listViewAttachments.Items.Count - 1].Focused  = true;
            }

            UpdateAfterListViewChange();
        }
Ejemplo n.º 2
0
Archivo: Program.cs Proyecto: b11p/Uue
        static void Main(string[] args)
        {
            Console.WriteLine("file path");
            string path = Console.ReadLine().Trim('"');

            byte[] data   = File.ReadAllBytes(path);
            string encode = UUEncoding.ToUUEncodingString(data, 0, data.Length, true, 80);

            File.WriteAllText(path + ".uue.txt", encode);
        }
Ejemplo n.º 3
0
        private static void AddToListIfNotEmpty(string attachmentContent, string attachmentFileName, List <AssaAttachment> attachments, string category)
        {
            var content = attachmentContent.Trim();

            if (!string.IsNullOrWhiteSpace(attachmentFileName) && !string.IsNullOrEmpty(content))
            {
                var bytes = UUEncoding.UUDecode(content);
                attachments.Add(new AssaAttachment {
                    FileName = attachmentFileName, Bytes = bytes, Category = category, Content = content
                });
            }
        }
Ejemplo n.º 4
0
        private void SaveFontNames(string attachmentFileName, string attachmentContent, string category)
        {
            var content = attachmentContent.Trim();

            if (string.IsNullOrEmpty(attachmentFileName) || content.Length == 0 || !attachmentFileName.EndsWith(".ttf", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            var bytes = UUEncoding.UUDecode(content);

            foreach (var fontName in GetFontNames(bytes))
            {
                _fontAttachments.Add(new AssaAttachmentFont {
                    FileName = attachmentFileName, FontName = fontName, Bytes = bytes, Category = category, Content = content
                });
            }
        }
Ejemplo n.º 5
0
        public void ForwardAndBackAgain()
        {
            var byteArray = new byte[byte.MaxValue];

            for (int i = byte.MinValue; i < byte.MaxValue; i++)
            {
                byteArray[i] = (byte)i;
            }

            var text     = UUEncoding.UUEncode(byteArray);
            var newBytes = UUEncoding.UUDecode(text);

            Assert.AreEqual(byteArray.Length, newBytes.Length);
            for (int i = byte.MinValue; i < byte.MaxValue; i++)
            {
                Assert.AreEqual(byteArray[i], newBytes[i]);
            }
        }
Ejemplo n.º 6
0
        private void AddToListView(string attachmentFileName, string attachmentContent, string category)
        {
            var content = attachmentContent.Trim();

            if (string.IsNullOrEmpty(attachmentFileName) || content.Length == 0)
            {
                return;
            }

            var item  = new ListViewItem(attachmentFileName);
            var bytes = UUEncoding.UUDecode(content);

            _attachments.Add(new AssaAttachment {
                FileName = attachmentFileName, Bytes = bytes, Category = category, Content = content
            });
            item.SubItems.Add(GetType(attachmentFileName));
            item.SubItems.Add(Utilities.FormatBytesToDisplayFileSize(bytes.Length));
            listViewAttachments.Items.Add(item);
        }
Ejemplo n.º 7
0
        private void buttonAttachFont_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title       = "Open...";
            openFileDialog1.FileName    = string.Empty;
            openFileDialog1.Filter      = "Font|*.ttf";
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.Multiselect = true;
            var result = openFileDialog1.ShowDialog(this);

            if (result != DialogResult.OK || !File.Exists(openFileDialog1.FileName))
            {
                return;
            }

            foreach (var fileName in openFileDialog1.FileNames)
            {
                var attachmentFileName = Path.GetFileName(fileName);
                var attachmentContent  = UUEncoding.UUEncode(FileUtil.ReadAllBytesShared(fileName));
                AddToListView(attachmentFileName, attachmentContent, "[Fonts]");
                listViewAttachments.Items[listViewAttachments.Items.Count - 1].Selected = true;
                listViewAttachments.Items[listViewAttachments.Items.Count - 1].Focused  = true;
            }
            UpdateAfterListViewChange();
        }
Ejemplo n.º 8
0
        public void Test1()
        {
            var emptyEncoding = UUEncoding.ToUUEncodingString(new byte[0], 0, 0, false);

            Assert.Equal(string.Empty, emptyEncoding);
        }
Ejemplo n.º 9
0
        private void buttonAttachFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title       = LanguageSettings.Current.Main.Menu.File.Open.RemoveChar('&');
            openFileDialog1.FileName    = string.Empty;
            openFileDialog1.Filter      = $"{LanguageSettings.Current.AssaAttachments.FontsAndImages}|*.ttf;*{string.Join(";*", _imageExtensions).TrimEnd('*')}|{LanguageSettings.Current.General.Fonts}|*.ttf|{LanguageSettings.Current.General.Images}|*{string.Join(";*", _imageExtensions).TrimEnd('*')}";
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.Multiselect = true;
            var result = openFileDialog1.ShowDialog(this);

            if (result != DialogResult.OK || !File.Exists(openFileDialog1.FileName))
            {
                return;
            }

            int skipCount      = 0;
            var skipFiles      = new List <string>();
            var newAttachments = new List <AssaAttachment>();

            foreach (var fileName in openFileDialog1.FileNames)
            {
                var attachmentFileName = Path.GetFileName(fileName);
                var attachmentContent  = UUEncoding.UUEncode(FileUtil.ReadAllBytesShared(fileName));
                var ext = Path.GetExtension(attachmentFileName)?.ToLowerInvariant();
                if (ext == ".ttf")
                {
                    AddToListIfNotEmpty(attachmentContent, attachmentFileName, newAttachments, GetType(attachmentFileName));
                }
                else if (_imageExtensions.Contains(ext))
                {
                    AddToListIfNotEmpty(attachmentContent, attachmentFileName, newAttachments, GetType(attachmentFileName));
                }
                else
                {
                    skipFiles.Add(attachmentFileName);
                    skipCount++;
                }
            }

            var first = true;

            foreach (var attachment in newAttachments)
            {
                _attachments.Add(attachment);
                AddToListView(attachment);
                var idx = listViewAttachments.Items.Count - 1;
                if (first)
                {
                    listViewAttachments.SelectedIndices.Clear();
                    listViewAttachments.EnsureVisible(idx);
                    listViewAttachments.Items[idx].Focused = true;
                    first = false;
                }
                listViewAttachments.Items[idx].Selected = true;
            }

            UpdateAfterListViewChange();
            if (skipCount > 0)
            {
                MessageBox.Show(string.Format(LanguageSettings.Current.AssaAttachments.FilesSkippedX, skipCount + Environment.NewLine +
                                              Environment.NewLine +
                                              string.Join(Environment.NewLine, skipFiles)));
            }
        }