Beispiel #1
0
 private void Save()
 {
     if (_fileName != null)
     {
         using (FileStream fs = new FileStream(_fileName, FileMode.OpenOrCreate)) {
             _hexView.ApplyEdits(fs);
             //_hexView.Source.Position = 0;
             //_hexView.Source.CopyTo (fs);
             //fs.Flush ();
         }
         _saved = true;
     }
     else
     {
         _hexView.ApplyEdits();
     }
 }
Beispiel #2
0
        public void AllowEdits_Edits_ApplyEdits()
        {
            var hv = new HexView(LoadStream(true))
            {
                Width  = 20,
                Height = 20
            };

            Assert.Empty(hv.Edits);
            hv.AllowEdits = false;
            Assert.True(hv.ProcessKey(new KeyEvent(Key.Home, new KeyModifiers())));
            Assert.False(hv.ProcessKey(new KeyEvent(Key.A, new KeyModifiers())));
            Assert.Empty(hv.Edits);
            Assert.Equal(126, hv.Source.Length);

            hv.AllowEdits = true;
            Assert.True(hv.ProcessKey(new KeyEvent(Key.D4, new KeyModifiers())));
            Assert.True(hv.ProcessKey(new KeyEvent(Key.D1, new KeyModifiers())));
            Assert.Single(hv.Edits);
            Assert.Equal(65, hv.Edits.ToList() [0].Value);
            Assert.Equal('A', (char)hv.Edits.ToList() [0].Value);
            Assert.Equal(126, hv.Source.Length);

            // Appends byte
            Assert.True(hv.ProcessKey(new KeyEvent(Key.End, new KeyModifiers())));
            Assert.True(hv.ProcessKey(new KeyEvent(Key.D4, new KeyModifiers())));
            Assert.True(hv.ProcessKey(new KeyEvent(Key.D2, new KeyModifiers())));
            Assert.Equal(2, hv.Edits.Count);
            Assert.Equal(66, hv.Edits.ToList() [1].Value);
            Assert.Equal('B', (char)hv.Edits.ToList() [1].Value);
            Assert.Equal(126, hv.Source.Length);

            hv.ApplyEdits();
            Assert.Empty(hv.Edits);
            Assert.Equal(127, hv.Source.Length);
        }
Beispiel #3
0
        public void ApplyEdits_With_Argument()
        {
            byte [] buffer   = Encoding.Default.GetBytes("Fest");
            var     original = new MemoryStream();

            original.Write(buffer, 0, buffer.Length);
            original.Flush();
            var copy = new MemoryStream();

            original.Position = 0;
            original.CopyTo(copy);
            copy.Flush();
            var hv = new HexView(copy)
            {
                Width = Dim.Fill(), Height = Dim.Fill()
            };

            byte [] readBuffer = new byte [hv.Source.Length];
            hv.Source.Position = 0;
            hv.Source.Read(readBuffer);
            Assert.Equal("Fest", Encoding.Default.GetString(readBuffer));

            Assert.True(hv.ProcessKey(new KeyEvent(Key.D5, new KeyModifiers())));
            Assert.True(hv.ProcessKey(new KeyEvent(Key.D4, new KeyModifiers())));
            readBuffer [hv.Edits.ToList() [0].Key] = hv.Edits.ToList() [0].Value;
            Assert.Equal("Test", Encoding.Default.GetString(readBuffer));

            hv.ApplyEdits(original);
            original.Position = 0;
            original.Read(buffer);
            copy.Position = 0;
            copy.Read(readBuffer);
            Assert.Equal("Test", Encoding.Default.GetString(buffer));
            Assert.Equal("Test", Encoding.Default.GetString(readBuffer));
            Assert.Equal(Encoding.Default.GetString(buffer), Encoding.Default.GetString(readBuffer));
        }