This commit is contained in:
Michael Becker 2014-07-18 08:49:11 -04:00
parent f7e935dbda
commit 6ed850767f
20 changed files with 1148 additions and 1148 deletions

View File

@ -15,8 +15,8 @@ namespace UniversalEditor.Compression
Gzip,
LZMA,
LZMASolid,
LZSS,
LZH,
LZSS,
LZH,
LZW,
LZX,
PPPMd,

View File

@ -6,18 +6,18 @@ using System.Text;
namespace UniversalEditor.Compression
{
public static class CompressionModules
{
{
private static Modules.Bzip2.Bzip2CompressionModule mvarBzip2 = new Modules.Bzip2.Bzip2CompressionModule();
public static Modules.Bzip2.Bzip2CompressionModule Bzip2 { get { return mvarBzip2; } }
private static Modules.Bzip2.Bzip2CompressionModule mvarBzip2 = new Modules.Bzip2.Bzip2CompressionModule();
public static Modules.Bzip2.Bzip2CompressionModule Bzip2 { get { return mvarBzip2; } }
private static Modules.Deflate.DeflateCompressionModule mvarDeflate = new Modules.Deflate.DeflateCompressionModule();
public static Modules.Deflate.DeflateCompressionModule Deflate { get { return mvarDeflate; } }
private static Modules.Deflate.DeflateCompressionModule mvarDeflate = new Modules.Deflate.DeflateCompressionModule();
public static Modules.Deflate.DeflateCompressionModule Deflate { get { return mvarDeflate; } }
private static Modules.Gzip.GzipCompressionModule mvarGzip = new Modules.Gzip.GzipCompressionModule();
public static Modules.Gzip.GzipCompressionModule Gzip { get { return mvarGzip; } }
public static Modules.Gzip.GzipCompressionModule Gzip { get { return mvarGzip; } }
private static Modules.Zlib.ZlibCompressionModule mvarZlib = new Modules.Zlib.ZlibCompressionModule();
public static Modules.Zlib.ZlibCompressionModule Zlib { get { return mvarZlib; } }
private static Modules.Zlib.ZlibCompressionModule mvarZlib = new Modules.Zlib.ZlibCompressionModule();
public static Modules.Zlib.ZlibCompressionModule Zlib { get { return mvarZlib; } }
}
}

View File

@ -6,147 +6,147 @@ using UniversalEditor.Accessors;
namespace UniversalEditor.Compression.RLEW
{
public class RLEWCompressionModule : CompressionModule
{
public override string Name
{
get { return "RLEW"; }
}
public class RLEWCompressionModule : CompressionModule
{
public override string Name
{
get { return "RLEW"; }
}
private short mvarRLEWTag = 0;
public short RLEWTag { get { return mvarRLEWTag; } set { mvarRLEWTag = value; } }
private short mvarRLEWTag = 0;
public short RLEWTag { get { return mvarRLEWTag; } set { mvarRLEWTag = value; } }
protected override void CompressInternal(System.IO.Stream inputStream, System.IO.Stream outputStream)
{
IO.Reader br = new IO.Reader(new StreamAccessor(inputStream));
IO.Writer bw = new IO.Writer(new StreamAccessor(outputStream));
short lastWord = 0;
short wordCount = 0;
bool hasLastWord = false;
{
IO.Reader br = new IO.Reader(new StreamAccessor(inputStream));
IO.Writer bw = new IO.Writer(new StreamAccessor(outputStream));
short lastWord = 0;
short wordCount = 0;
bool hasLastWord = false;
while (!br.EndOfStream)
{
// to make this work efficiently, we need to have at least four equal words
// (RLEWtag + count + value = 3 words)
while (!br.EndOfStream)
{
// to make this work efficiently, we need to have at least four equal words
// (RLEWtag + count + value = 3 words)
// read the next value in
short word = 0;
if (br.Remaining == 0)
{
break;
}
else if (br.Remaining == 1)
{
word = br.ReadByte();
}
else if (br.Remaining >= 2)
{
word = br.ReadInt16();
}
// read the next value in
short word = 0;
if (br.Remaining == 0)
{
break;
}
else if (br.Remaining == 1)
{
word = br.ReadByte();
}
else if (br.Remaining >= 2)
{
word = br.ReadInt16();
}
if (!hasLastWord)
{
lastWord = word;
hasLastWord = true;
wordCount++;
continue;
}
if (!hasLastWord)
{
lastWord = word;
hasLastWord = true;
wordCount++;
continue;
}
if (word == lastWord)
{
// it's equal to the last word, so increment our word count
wordCount++;
if (word == lastWord)
{
// it's equal to the last word, so increment our word count
wordCount++;
if (wordCount == 4)
{
// we have at least four equal words, so push out an RLEWtag...
bw.WriteInt16(mvarRLEWTag);
}
}
else
{
// word is not equal, flush the remaining words...
if (wordCount <= 3)
{
// we do not have at least four equal words, it would be more efficient to
// just store the values as-is, so flush the remaining words
for (ushort i = 0; i < wordCount; i++)
{
bw.WriteInt16(word);
}
if (wordCount == 4)
{
// we have at least four equal words, so push out an RLEWtag...
bw.WriteInt16(mvarRLEWTag);
}
}
else
{
// word is not equal, flush the remaining words...
if (wordCount <= 3)
{
// we do not have at least four equal words, it would be more efficient to
// just store the values as-is, so flush the remaining words
for (ushort i = 0; i < wordCount; i++)
{
bw.WriteInt16(word);
}
bw.WriteInt16(lastWord);
bw.WriteInt16(lastWord);
lastWord = 0;
wordCount = 0;
}
else
{
bw.WriteInt16(wordCount);
bw.WriteInt16(lastWord);
}
lastWord = 0;
wordCount = 0;
}
else
{
bw.WriteInt16(wordCount);
bw.WriteInt16(lastWord);
}
// ... and clear the word count
lastWord = 0;
wordCount = 0;
// ... and clear the word count
lastWord = 0;
wordCount = 0;
// finally, set the last word to the current word
lastWord = word;
}
}
// finally, set the last word to the current word
lastWord = word;
}
}
// word is not equal, flush the remaining words...
if (wordCount <= 3)
{
// we do not have at least four equal words, it would be more efficient to
// just store the values as-is, so flush the remaining words
for (ushort i = 0; i < wordCount; i++)
{
bw.WriteInt16(lastWord);
}
// word is not equal, flush the remaining words...
if (wordCount <= 3)
{
// we do not have at least four equal words, it would be more efficient to
// just store the values as-is, so flush the remaining words
for (ushort i = 0; i < wordCount; i++)
{
bw.WriteInt16(lastWord);
}
lastWord = 0;
wordCount = 0;
}
else
{
bw.WriteInt16(wordCount);
bw.WriteInt16(lastWord);
}
lastWord = 0;
wordCount = 0;
}
else
{
bw.WriteInt16(wordCount);
bw.WriteInt16(lastWord);
}
bw.Flush();
}
bw.Flush();
}
protected override void DecompressInternal(System.IO.Stream inputStream, System.IO.Stream outputStream, int inputLength, int outputLength)
{
IO.Reader br = new IO.Reader(new StreamAccessor(inputStream));
IO.Writer bw = new IO.Writer(new StreamAccessor(outputStream));
while (!br.EndOfStream)
{
// read one word from compressed block
short word = br.ReadInt16();
if (word == mvarRLEWTag)
{
// next two words are a compressed run of data, first word is number
// of words to write
short count = br.ReadInt16();
short value = br.ReadInt16();
for (short i = 0; i < count; i++)
{
bw.WriteInt16(value);
}
}
else
{
// if word is not equal to RLEWtag, then simply write that word out
bw.WriteInt16(word);
}
}
{
IO.Reader br = new IO.Reader(new StreamAccessor(inputStream));
IO.Writer bw = new IO.Writer(new StreamAccessor(outputStream));
while (!br.EndOfStream)
{
// read one word from compressed block
short word = br.ReadInt16();
if (word == mvarRLEWTag)
{
// next two words are a compressed run of data, first word is number
// of words to write
short count = br.ReadInt16();
short value = br.ReadInt16();
for (short i = 0; i < count; i++)
{
bw.WriteInt16(value);
}
}
else
{
// if word is not equal to RLEWtag, then simply write that word out
bw.WriteInt16(word);
}
}
bw.Flush();
bw.Close();
}
}
bw.Flush();
bw.Close();
}
}
}

View File

@ -7,74 +7,74 @@ using System.Diagnostics;
namespace UniversalEditor
{
[DebuggerNonUserCode()]
public abstract class Accessor
{
public Accessor()
{
mvarReader = new Reader(this);
mvarWriter = new Writer(this);
}
[DebuggerNonUserCode()]
public abstract class Accessor
{
public Accessor()
{
mvarReader = new Reader(this);
mvarWriter = new Writer(this);
}
public abstract long Length { get; set; }
public abstract long Length { get; set; }
protected abstract long GetPosition();
public virtual long Position { get { return GetPosition(); } set { Seek(value, SeekOrigin.Begin); } }
public virtual long Position { get { return GetPosition(); } set { Seek(value, SeekOrigin.Begin); } }
public long Remaining
{
get
{
long r = Length - Position;
if (r <= 0) return 0;
return r;
}
}
public long Remaining
{
get
{
long r = Length - Position;
if (r <= 0) return 0;
return r;
}
}
public void Seek(int length, SeekOrigin position)
{
Seek((long)length, position);
}
public abstract void Seek(long length, SeekOrigin position);
public void Seek(int length, SeekOrigin position)
{
Seek((long)length, position);
}
public abstract void Seek(long length, SeekOrigin position);
internal abstract int ReadInternal(byte[] buffer, int start, int count);
internal abstract int WriteInternal(byte[] buffer, int start, int count);
internal abstract int ReadInternal(byte[] buffer, int start, int count);
internal abstract int WriteInternal(byte[] buffer, int start, int count);
internal virtual void FlushInternal()
{
}
internal virtual void FlushInternal()
{
}
private bool mvarIsOpen = false;
public bool IsOpen { get { return mvarIsOpen; } protected set { mvarIsOpen = value; } }
private bool mvarIsOpen = false;
public bool IsOpen { get { return mvarIsOpen; } protected set { mvarIsOpen = value; } }
public void Open()
{
if (mvarIsOpen) return;
public void Open()
{
if (mvarIsOpen) return;
OpenInternal();
mvarIsOpen = true;
}
public void Close()
{
if (!mvarIsOpen) return;
OpenInternal();
mvarIsOpen = true;
}
public void Close()
{
if (!mvarIsOpen) return;
CloseInternal();
mvarIsOpen = false;
}
CloseInternal();
mvarIsOpen = false;
}
protected abstract void OpenInternal();
protected abstract void CloseInternal();
protected abstract void OpenInternal();
protected abstract void CloseInternal();
private Encoding mvarDefaultEncoding = Encoding.Default;
/// <summary>
/// The default <see cref="Encoding" /> to use when reading and writing strings.
/// </summary>
public Encoding DefaultEncoding { get { return mvarDefaultEncoding; } set { mvarDefaultEncoding = value; } }
private Encoding mvarDefaultEncoding = Encoding.Default;
/// <summary>
/// The default <see cref="Encoding" /> to use when reading and writing strings.
/// </summary>
public Encoding DefaultEncoding { get { return mvarDefaultEncoding; } set { mvarDefaultEncoding = value; } }
private Reader mvarReader = null;
public Reader Reader { get { return mvarReader; } }
private Writer mvarWriter = null;
public Writer Writer { get { return mvarWriter; } }
private Reader mvarReader = null;
public Reader Reader { get { return mvarReader; } }
private Writer mvarWriter = null;
public Writer Writer { get { return mvarWriter; } }
public virtual string Title
{

View File

@ -40,7 +40,7 @@ namespace UniversalEditor.Accessors
_data = data;
}
// [DebuggerNonUserCode()]
// [DebuggerNonUserCode()]
public override void Seek(long length, SeekOrigin position)
{
long start = 0;
@ -81,8 +81,8 @@ namespace UniversalEditor.Accessors
internal override int ReadInternal(byte[] buffer, int start, int count)
{
System.Array.Copy(_data, Position, buffer, start, count);
Position += count;
System.Array.Copy(_data, Position, buffer, start, count);
Position += count;
return count;
}
internal override int WriteInternal(byte[] buffer, int start, int count)
@ -92,10 +92,10 @@ namespace UniversalEditor.Accessors
return count;
}
protected override void OpenInternal()
protected override void OpenInternal()
{
}
protected override void CloseInternal()
protected override void CloseInternal()
{
}
}

View File

@ -102,10 +102,10 @@ namespace UniversalEditor.Accessors
return count;
}
protected override void OpenInternal()
protected override void OpenInternal()
{
}
protected override void CloseInternal()
protected override void CloseInternal()
{
}
}

View File

@ -76,10 +76,10 @@ namespace UniversalEditor.Checksum.Modules.Adler32
/// <see cref="ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream"/>
public sealed class Adler32 : ChecksumModule
{
public override string Name
{
get { return "Adler32"; }
}
public override string Name
{
get { return "Adler32"; }
}
/// <summary>
/// largest prime smaller than 65536

View File

@ -40,40 +40,40 @@ using System;
namespace UniversalEditor.Checksum.Modules.CRC32
{
/// <summary>
/// Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
/// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
///
/// Polynomials over GF(2) are represented in binary, one bit per coefficient,
/// with the lowest powers in the most significant bit. Then adding polynomials
/// is just exclusive-or, and multiplying a polynomial by x is a right shift by
/// one. If we call the above polynomial p, and represent a byte as the
/// polynomial q, also with the lowest power in the most significant bit (so the
/// byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
/// where a mod b means the remainder after dividing a by b.
///
/// This calculation is done using the shift-register method of multiplying and
/// taking the remainder. The register is initialized to zero, and for each
/// incoming bit, x^32 is added mod p to the register if the bit is a one (where
/// x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
/// x (which is shifting right by one and adding x^32 mod p if the bit shifted
/// out is a one). We start with the highest power (least significant bit) of
/// q and repeat for all eight bits of q.
///
/// The table is simply the CRC of all possible eight bit values. This is all
/// the information needed to generate CRC's on data a byte at a time for all
/// combinations of CRC register values and incoming bytes.
/// </summary>
public sealed class CRC32ChecksumModule : ChecksumModule
{
const uint CrcSeed = 0xFFFFFFFF;
/// <summary>
/// Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
/// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
///
/// Polynomials over GF(2) are represented in binary, one bit per coefficient,
/// with the lowest powers in the most significant bit. Then adding polynomials
/// is just exclusive-or, and multiplying a polynomial by x is a right shift by
/// one. If we call the above polynomial p, and represent a byte as the
/// polynomial q, also with the lowest power in the most significant bit (so the
/// byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
/// where a mod b means the remainder after dividing a by b.
///
/// This calculation is done using the shift-register method of multiplying and
/// taking the remainder. The register is initialized to zero, and for each
/// incoming bit, x^32 is added mod p to the register if the bit is a one (where
/// x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
/// x (which is shifting right by one and adding x^32 mod p if the bit shifted
/// out is a one). We start with the highest power (least significant bit) of
/// q and repeat for all eight bits of q.
///
/// The table is simply the CRC of all possible eight bit values. This is all
/// the information needed to generate CRC's on data a byte at a time for all
/// combinations of CRC register values and incoming bytes.
/// </summary>
public sealed class CRC32ChecksumModule : ChecksumModule
{
const uint CrcSeed = 0xFFFFFFFF;
public override string Name
{
get { return "CRC32"; }
}
public override string Name
{
get { return "CRC32"; }
}
readonly static uint[] CrcTable = new uint[] {
readonly static uint[] CrcTable = new uint[] {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
@ -128,81 +128,81 @@ namespace UniversalEditor.Checksum.Modules.CRC32
0x2D02EF8D
};
private static uint ComputeCrc32(uint oldCrc, byte value)
{
return (uint)(CrcTable[(oldCrc ^ value) & 0xFF] ^ (oldCrc >> 8));
}
private static uint ComputeCrc32(uint oldCrc, byte value)
{
return (uint)(CrcTable[(oldCrc ^ value) & 0xFF] ^ (oldCrc >> 8));
}
/// <summary>
/// The crc data checksum so far.
/// </summary>
uint crc;
/// <summary>
/// The crc data checksum so far.
/// </summary>
uint crc;
/// <summary>
/// Returns the CRC32 data checksum computed so far.
/// </summary>
public override long Value
{
get
{
return (long)crc;
}
}
/// <summary>
/// Returns the CRC32 data checksum computed so far.
/// </summary>
public override long Value
{
get
{
return (long)crc;
}
}
/// <summary>
/// Updates the checksum with the int bval.
/// </summary>
/// <param name = "value">
/// the byte is taken as the lower 8 bits of value
/// </param>
public override void Update(int value)
{
crc ^= CrcSeed;
crc = CrcTable[(crc ^ value) & 0xFF] ^ (crc >> 8);
crc ^= CrcSeed;
}
/// <summary>
/// Updates the checksum with the int bval.
/// </summary>
/// <param name = "value">
/// the byte is taken as the lower 8 bits of value
/// </param>
public override void Update(int value)
{
crc ^= CrcSeed;
crc = CrcTable[(crc ^ value) & 0xFF] ^ (crc >> 8);
crc ^= CrcSeed;
}
/// <summary>
/// Adds the byte array to the data checksum.
/// </summary>
/// <param name = "buffer">
/// The buffer which contains the data
/// </param>
/// <param name = "offset">
/// The offset in the buffer where the data starts
/// </param>
/// <param name = "count">
/// The number of data bytes to update the CRC with.
/// </param>
public override void Update(byte[] buffer, int offset, int count)
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
/// <summary>
/// Adds the byte array to the data checksum.
/// </summary>
/// <param name = "buffer">
/// The buffer which contains the data
/// </param>
/// <param name = "offset">
/// The offset in the buffer where the data starts
/// </param>
/// <param name = "count">
/// The number of data bytes to update the CRC with.
/// </param>
public override void Update(byte[] buffer, int offset, int count)
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (count < 0)
{
if (count < 0)
{
#if NETCF_1_0
throw new ArgumentOutOfRangeException("count");
#else
throw new ArgumentOutOfRangeException("count", "Count cannot be less than zero");
throw new ArgumentOutOfRangeException("count", "Count cannot be less than zero");
#endif
}
}
if (offset < 0 || offset + count > buffer.Length)
{
throw new ArgumentOutOfRangeException("offset");
}
if (offset < 0 || offset + count > buffer.Length)
{
throw new ArgumentOutOfRangeException("offset");
}
crc ^= CrcSeed;
crc ^= CrcSeed;
while (--count >= 0)
{
crc = CrcTable[(crc ^ buffer[offset++]) & 0xFF] ^ (crc >> 8);
}
while (--count >= 0)
{
crc = CrcTable[(crc ^ buffer[offset++]) & 0xFF] ^ (crc >> 8);
}
crc ^= CrcSeed;
}
}
crc ^= CrcSeed;
}
}
}

View File

@ -45,10 +45,10 @@ namespace UniversalEditor.Checksum.Modules.StrangeCRC
/// </summary>
public class StrangeCRCChecksumModule : ChecksumModule
{
public override string Name { get { return "StrangeCRC"; } }
public override string Name { get { return "StrangeCRC"; } }
readonly static uint[] crc32Table =
{
{
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,

View File

@ -5,19 +5,19 @@ using System.Text;
namespace UniversalEditor
{
/// <summary>
/// Represents a combination of <see cref="InputDataFormat" />, <see cref="ObjectModel" />, and <see cref="Accessor" />
/// that allows you to easily manipulate documents. The Accessor determines WHERE the data is read from and written
/// to, the DataFormat determines HOW the data is written, and the ObjectModel contains the actual data in a format-
/// agnostic representation.
/// </summary>
public class Document
{
private Accessor mvarInputAccessor = null;
/// <summary>
/// The <see cref="Accessor" /> which determines where the data is read from.
/// </summary>
public Accessor InputAccessor { get { return mvarInputAccessor; } set { mvarInputAccessor = value; } }
/// <summary>
/// Represents a combination of <see cref="InputDataFormat" />, <see cref="ObjectModel" />, and <see cref="Accessor" />
/// that allows you to easily manipulate documents. The Accessor determines WHERE the data is read from and written
/// to, the DataFormat determines HOW the data is written, and the ObjectModel contains the actual data in a format-
/// agnostic representation.
/// </summary>
public class Document
{
private Accessor mvarInputAccessor = null;
/// <summary>
/// The <see cref="Accessor" /> which determines where the data is read from.
/// </summary>
public Accessor InputAccessor { get { return mvarInputAccessor; } set { mvarInputAccessor = value; } }
private Accessor mvarOutputAccessor = null;
/// <summary>
@ -25,11 +25,11 @@ namespace UniversalEditor
/// </summary>
public Accessor OutputAccessor { get { return mvarOutputAccessor; } set { mvarOutputAccessor = value; } }
private DataFormat mvarInputDataFormat = null;
/// <summary>
private DataFormat mvarInputDataFormat = null;
/// <summary>
/// The <see cref="DataFormat" /> which determines how the data is read from the accessor.
/// </summary>
public DataFormat InputDataFormat { get { return mvarInputDataFormat; } set { mvarInputDataFormat = value; } }
/// </summary>
public DataFormat InputDataFormat { get { return mvarInputDataFormat; } set { mvarInputDataFormat = value; } }
private DataFormat mvarOutputDataFormat = null;
/// <summary>
@ -37,57 +37,57 @@ namespace UniversalEditor
/// </summary>
public DataFormat OutputDataFormat { get { return mvarOutputDataFormat; } set { mvarOutputDataFormat = value; } }
private ObjectModel mvarObjectModel = null;
/// <summary>
/// The <see cref="ObjectModel" />, which stores the actual data in a format-agnostic representation.
/// </summary>
public ObjectModel ObjectModel { get { return mvarObjectModel; } set { mvarObjectModel = value; } }
private ObjectModel mvarObjectModel = null;
/// <summary>
/// The <see cref="ObjectModel" />, which stores the actual data in a format-agnostic representation.
/// </summary>
public ObjectModel ObjectModel { get { return mvarObjectModel; } set { mvarObjectModel = value; } }
/// <summary>
/// Reads data into the current <see cref="ObjectModel" /> from the <see cref="Accessor" /> using the
/// current <see cref="InputDataFormat" />.
/// </summary>
public void Load()
{
mvarInputDataFormat.Accessor = mvarInputAccessor;
mvarObjectModel.Accessor = mvarInputAccessor;
/// <summary>
/// Reads data into the current <see cref="ObjectModel" /> from the <see cref="Accessor" /> using the
/// current <see cref="InputDataFormat" />.
/// </summary>
public void Load()
{
mvarInputDataFormat.Accessor = mvarInputAccessor;
mvarObjectModel.Accessor = mvarInputAccessor;
mvarInputDataFormat.Load(ref mvarObjectModel);
mvarLastUsedAccessor = LastUsedAccessor.Input;
}
/// <summary>
/// Writes the data contained in the <see cref="ObjectModel" /> to the <see cref="Accessor" /> using the
/// current <see cref="OutputDataFormat" />.
/// </summary>
public void Save()
{
mvarOutputDataFormat.Accessor = mvarOutputAccessor;
mvarObjectModel.Accessor = mvarOutputAccessor;
}
/// <summary>
/// Writes the data contained in the <see cref="ObjectModel" /> to the <see cref="Accessor" /> using the
/// current <see cref="OutputDataFormat" />.
/// </summary>
public void Save()
{
mvarOutputDataFormat.Accessor = mvarOutputAccessor;
mvarObjectModel.Accessor = mvarOutputAccessor;
mvarOutputDataFormat.Save(mvarObjectModel);
mvarLastUsedAccessor = LastUsedAccessor.Output;
}
}
public Document(ObjectModel objectModel, DataFormat dataFormat) : this(objectModel, dataFormat, null)
{
}
public Document(ObjectModel objectModel, DataFormat dataFormat, Accessor accessor) : this(objectModel, dataFormat, dataFormat, accessor)
public Document(ObjectModel objectModel, DataFormat dataFormat) : this(objectModel, dataFormat, null)
{
}
public Document(ObjectModel objectModel, DataFormat dataFormat, Accessor accessor) : this(objectModel, dataFormat, dataFormat, accessor)
{
}
public Document(ObjectModel objectModel, DataFormat inputDataFormat, DataFormat outputDataFormat, Accessor accessor) : this(objectModel, inputDataFormat, outputDataFormat, accessor, accessor)
{
}
public Document(ObjectModel objectModel, DataFormat inputDataFormat, DataFormat outputDataFormat, Accessor inputAccessor, Accessor outputAccessor)
{
mvarObjectModel = objectModel;
{
mvarObjectModel = objectModel;
mvarInputDataFormat = inputDataFormat;
mvarOutputDataFormat = outputDataFormat;
mvarInputAccessor = inputAccessor;
mvarInputAccessor = inputAccessor;
mvarOutputAccessor = outputAccessor;
}
}
public static Document Load(ObjectModel objectModel, DataFormat dataFormat, Accessor accessor, bool autoClose = true)
{
Document document = new Document(objectModel, dataFormat, accessor);
objectModel.Accessor = document.InputAccessor;
objectModel.Accessor = document.InputAccessor;
document.InputAccessor.Open();
document.Load();
if (autoClose) document.InputAccessor.Close();
@ -95,8 +95,8 @@ namespace UniversalEditor
}
public static Document Save(ObjectModel objectModel, DataFormat dataFormat, Accessor accessor, bool autoClose = true)
{
Document document = new Document(objectModel, dataFormat, accessor);
objectModel.Accessor = document.OutputAccessor;
Document document = new Document(objectModel, dataFormat, accessor);
objectModel.Accessor = document.OutputAccessor;
document.OutputAccessor.Open();
document.Save();
if (autoClose) document.OutputAccessor.Close();

View File

@ -528,13 +528,13 @@ namespace UniversalEditor
}
public static byte[] ToByteArray(this System.IO.Stream stream)
{
long oldpos = stream.Position;
long oldpos = stream.Position;
byte[] array = new byte[(int)((IntPtr)stream.Length)];
stream.Position = 0L;
stream.Read(array, 0, array.Length);
stream.Position = oldpos;
stream.Position = oldpos;
return array;
}
#endregion

View File

@ -17,12 +17,12 @@
namespace UniversalEditor.IO
{
public abstract class Encoding
{
private static Encoding _Default = new DefaultEncoding();
public static Encoding Default
{
get { return _Default; }
public abstract class Encoding
{
private static Encoding _Default = new DefaultEncoding();
public static Encoding Default
{
get { return _Default; }
}
private static Encoding _ASCII = new ASCIIEncoding();
public static Encoding ASCII
@ -62,32 +62,32 @@ namespace UniversalEditor.IO
get { return _ShiftJIS; }
}
public byte[] GetBytes(string value)
{
return GetBytes(value.ToCharArray());
}
public byte[] GetBytes(char[] chars)
{
return GetBytes(chars, 0, chars.Length);
}
public abstract byte[] GetBytes(char[] chars, int index, int count);
public byte[] GetBytes(string value)
{
return GetBytes(value.ToCharArray());
}
public byte[] GetBytes(char[] chars)
{
return GetBytes(chars, 0, chars.Length);
}
public abstract byte[] GetBytes(char[] chars, int index, int count);
public string GetString(byte[] bytes)
{
return GetString(bytes, 0, bytes.Length);
}
public string GetString(byte[] bytes, int index, int count)
{
char[] chars = GetChars(bytes, index, count);
public string GetString(byte[] bytes)
{
return GetString(bytes, 0, bytes.Length);
}
public string GetString(byte[] bytes, int index, int count)
{
char[] chars = GetChars(bytes, index, count);
string retval = new string(chars);
return retval;
}
return retval;
}
public char[] GetChars(byte[] bytes)
{
return GetChars(bytes, 0, bytes.Length);
}
public abstract char[] GetChars(byte[] bytes, int index, int count);
public char[] GetChars(byte[] bytes)
{
return GetChars(bytes, 0, bytes.Length);
}
public abstract char[] GetChars(byte[] bytes, int index, int count);
public virtual int GetMaxByteCount(int count)
{
@ -115,27 +115,27 @@ namespace UniversalEditor.IO
return GetByteCount(chars, 0, chars.Length);
}
}
public class DefaultEncoding : Encoding
{
public override byte[] GetBytes(char[] chars, int index, int count)
{
byte[] bytes = new byte[count];
for (int i = 0; i < chars.Length; i++)
{
bytes[i] = (byte)(chars[i]);
}
return bytes;
}
public override char[] GetChars(byte[] bytes, int index, int count)
{
char[] retval = new char[count];
for (int i = 0; i < count; i++)
{
retval[i] = (char)bytes[i];
}
return retval;
}
}
public class DefaultEncoding : Encoding
{
public override byte[] GetBytes(char[] chars, int index, int count)
{
byte[] bytes = new byte[count];
for (int i = 0; i < chars.Length; i++)
{
bytes[i] = (byte)(chars[i]);
}
return bytes;
}
public override char[] GetChars(byte[] bytes, int index, int count)
{
char[] retval = new char[count];
for (int i = 0; i < count; i++)
{
retval[i] = (char)bytes[i];
}
return retval;
}
}
public class ASCIIEncoding : Encoding
{
private System.Text.Encoding _encoding = System.Text.Encoding.ASCII;

File diff suppressed because it is too large Load Diff

View File

@ -4,24 +4,24 @@ using System.Text;
namespace UniversalEditor.Localization
{
public static class StringTable
{
private static string mvarApplicationName = "Universal Editor";
public static string ApplicationName { get { return mvarApplicationName; } }
public static class StringTable
{
private static string mvarApplicationName = "Universal Editor";
public static string ApplicationName { get { return mvarApplicationName; } }
private static string mvarErrorDataFormatNotOpen = "The data format is not open.";
public static string ErrorDataFormatNotOpen { get { return mvarErrorDataFormatNotOpen; } }
private static string mvarErrorDataFormatNotOpen = "The data format is not open.";
public static string ErrorDataFormatNotOpen { get { return mvarErrorDataFormatNotOpen; } }
private static string mvarErrorDataCorrupted = "The file is corrupted.";
public static string ErrorDataCorrupted { get { return mvarErrorDataCorrupted; } }
private static string mvarErrorDataCorrupted = "The file is corrupted.";
public static string ErrorDataCorrupted { get { return mvarErrorDataCorrupted; } }
private static string mvarErrorFileNotFound = "The file could not be found.";
public static string ErrorFileNotFound { get { return mvarErrorFileNotFound; } }
private static string mvarErrorNotAnObjectModel = "The specified type is not an object model.";
public static string ErrorNotAnObjectModel { get { return mvarErrorNotAnObjectModel; } }
private static string mvarErrorFileNotFound = "The file could not be found.";
public static string ErrorFileNotFound { get { return mvarErrorFileNotFound; } }
private static string mvarErrorNotAnObjectModel = "The specified type is not an object model.";
public static string ErrorNotAnObjectModel { get { return mvarErrorNotAnObjectModel; } }
private static string mvarErrorObjectModelNull = "The object model must not be null.";
public static string ErrorObjectModelNull { get { return mvarErrorObjectModelNull; } set { mvarErrorObjectModelNull = value; } }
private static string mvarErrorObjectModelNull = "The object model must not be null.";
public static string ErrorObjectModelNull { get { return mvarErrorObjectModelNull; } set { mvarErrorObjectModelNull = value; } }
private static string mvarErrorDataFormatInvalid = "The data format is invalid.";
public static string ErrorDataFormatInvalid { get { return mvarErrorDataFormatInvalid; } set { mvarErrorDataFormatInvalid = value; } }

View File

@ -178,10 +178,10 @@ namespace UniversalEditor.UserInterface.Common
list.Add(editor);
}
}
if (!editorsByObjectModelType.ContainsKey(objectModelReference.ObjectModelType))
{
editorsByObjectModelType.Add(objectModelReference.ObjectModelType, list.ToArray());
}
if (!editorsByObjectModelType.ContainsKey(objectModelReference.ObjectModelType))
{
editorsByObjectModelType.Add(objectModelReference.ObjectModelType, list.ToArray());
}
}
// editorsByObjectModelType.Clear();
return editorsByObjectModelType[objectModelReference.ObjectModelType];

View File

@ -169,16 +169,16 @@ namespace UniversalEditor.UserInterface
editor.Redo();
});
#endregion
#region View
AttachCommandEventHandler("ViewFullScreen", delegate(object sender, EventArgs e)
{
Command cmd = (sender as Command);
LastWindow.FullScreen = !LastWindow.FullScreen;
cmd.Checked = LastWindow.FullScreen;
});
#endregion
#region Tools
// ToolsOptions should actually be under the Edit menu as "Preferences" on Linux systems
#region View
AttachCommandEventHandler("ViewFullScreen", delegate(object sender, EventArgs e)
{
Command cmd = (sender as Command);
LastWindow.FullScreen = !LastWindow.FullScreen;
cmd.Checked = LastWindow.FullScreen;
});
#endregion
#region Tools
// ToolsOptions should actually be under the Edit menu as "Preferences" on Linux systems
AttachCommandEventHandler("ToolsOptions", delegate(object sender, EventArgs e)
{
LastWindow.ShowOptionsDialog();

View File

@ -32,7 +32,7 @@ namespace UniversalEditor.UserInterface
IEditorImplementation GetCurrentEditor();
bool FullScreen { get; set; }
bool FullScreen { get; set; }
/// <summary>
/// Displays the "Options" dialog (on Windows, under the "Tools" menu; on Linux, under the "Edit"

View File

@ -6,178 +6,178 @@ namespace UniversalEditor.UserInterface
{
public class MenuBar
{
private MenuItem.MenuItemCollection mvarItems = new MenuItem.MenuItemCollection();
public MenuItem.MenuItemCollection Items { get { return mvarItems; } }
}
private MenuItem.MenuItemCollection mvarItems = new MenuItem.MenuItemCollection();
public MenuItem.MenuItemCollection Items { get { return mvarItems; } }
}
public abstract class MenuItem
{
public class MenuItemCollection
: System.Collections.ObjectModel.Collection<MenuItem>
{
private System.Collections.Generic.Dictionary<string, MenuItem> itemsByName = new Dictionary<string, MenuItem>();
public abstract class MenuItem
{
public class MenuItemCollection
: System.Collections.ObjectModel.Collection<MenuItem>
{
private System.Collections.Generic.Dictionary<string, MenuItem> itemsByName = new Dictionary<string, MenuItem>();
public ActionMenuItem Add(string name, string title)
{
return Add(name, title, null);
}
public ActionMenuItem Add(string name, string title, EventHandler onClick)
{
return Add(name, title, onClick, Count);
}
public ActionMenuItem Add(string name, string title, int position)
{
return Add(name, title, null, position);
}
public ActionMenuItem Add(string name, string title, EventHandler onClick, int position)
{
ActionMenuItem item = new ActionMenuItem(name, title);
if (onClick != null)
{
item.Click += onClick;
}
item.Position = position;
Add(item);
return item;
}
public SeparatorMenuItem AddSeparator()
{
return AddSeparator(Count);
}
public SeparatorMenuItem AddSeparator(int position)
{
SeparatorMenuItem item = new SeparatorMenuItem();
item.Position = position;
item.Name = "separator__" + (Count + 1).ToString();
Add(item);
return item;
}
public ActionMenuItem Add(string name, string title)
{
return Add(name, title, null);
}
public ActionMenuItem Add(string name, string title, EventHandler onClick)
{
return Add(name, title, onClick, Count);
}
public ActionMenuItem Add(string name, string title, int position)
{
return Add(name, title, null, position);
}
public ActionMenuItem Add(string name, string title, EventHandler onClick, int position)
{
ActionMenuItem item = new ActionMenuItem(name, title);
if (onClick != null)
{
item.Click += onClick;
}
item.Position = position;
Add(item);
return item;
}
public SeparatorMenuItem AddSeparator()
{
return AddSeparator(Count);
}
public SeparatorMenuItem AddSeparator(int position)
{
SeparatorMenuItem item = new SeparatorMenuItem();
item.Position = position;
item.Name = "separator__" + (Count + 1).ToString();
Add(item);
return item;
}
public MenuItem this[string name]
{
get
{
return itemsByName[name];
}
}
public MenuItem this[string name]
{
get
{
return itemsByName[name];
}
}
public bool Contains(string name)
{
return itemsByName.ContainsKey(name);
}
public bool Remove(string name)
{
if (itemsByName.ContainsKey(name))
{
base.Remove(itemsByName[name]);
return true;
}
return false;
}
public bool Contains(string name)
{
return itemsByName.ContainsKey(name);
}
public bool Remove(string name)
{
if (itemsByName.ContainsKey(name))
{
base.Remove(itemsByName[name]);
return true;
}
return false;
}
protected override void InsertItem(int index, MenuItem item)
{
item.mvarParent = this;
base.InsertItem(index, item);
itemsByName.Add(item.Name, item);
}
protected override void RemoveItem(int index)
{
this[index].mvarParent = null;
itemsByName.Remove(this[index].Name);
base.RemoveItem(index);
}
protected override void InsertItem(int index, MenuItem item)
{
item.mvarParent = this;
base.InsertItem(index, item);
itemsByName.Add(item.Name, item);
}
protected override void RemoveItem(int index)
{
this[index].mvarParent = null;
itemsByName.Remove(this[index].Name);
base.RemoveItem(index);
}
internal void UpdateName(MenuItem item, string oldName)
{
itemsByName.Remove(oldName);
itemsByName.Add(item.Name, item);
}
}
internal void UpdateName(MenuItem item, string oldName)
{
itemsByName.Remove(oldName);
itemsByName.Add(item.Name, item);
}
}
private List<object> mvarNativeControls = new List<object>();
public List<object> NativeControls { get { return mvarNativeControls; } }
private List<object> mvarNativeControls = new List<object>();
public List<object> NativeControls { get { return mvarNativeControls; } }
private MenuItemCollection mvarParent = null;
private MenuItemCollection mvarParent = null;
private string mvarName = String.Empty;
public string Name
{
get { return mvarName; }
set
{
string oldName = mvarName; mvarName = value;
if (mvarParent != null)
{
mvarParent.UpdateName(this, oldName);
}
}
}
private string mvarName = String.Empty;
public string Name
{
get { return mvarName; }
set
{
string oldName = mvarName; mvarName = value;
if (mvarParent != null)
{
mvarParent.UpdateName(this, oldName);
}
}
}
private int mvarPosition = -1;
public int Position { get { return mvarPosition; } set { mvarPosition = value; } }
private int mvarPosition = -1;
public int Position { get { return mvarPosition; } set { mvarPosition = value; } }
private bool mvarEnabled = true;
public bool Enabled
{
get { return mvarEnabled; }
set
{
mvarEnabled = value;
foreach (object NativeControl in mvarNativeControls)
{
HostApplication.CurrentWindow.RefreshCommand(NativeControl);
}
}
}
private bool mvarEnabled = true;
public bool Enabled
{
get { return mvarEnabled; }
set
{
mvarEnabled = value;
foreach (object NativeControl in mvarNativeControls)
{
HostApplication.CurrentWindow.RefreshCommand(NativeControl);
}
}
}
private bool mvarVisible = true;
public bool Visible { get { return mvarVisible; }
set
{
mvarVisible = value;
foreach (object NativeControl in mvarNativeControls)
{
HostApplication.CurrentWindow.RefreshCommand(NativeControl);
}
}
}
}
public class ActionMenuItem : MenuItem
{
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private bool mvarVisible = true;
public bool Visible { get { return mvarVisible; }
set
{
mvarVisible = value;
foreach (object NativeControl in mvarNativeControls)
{
HostApplication.CurrentWindow.RefreshCommand(NativeControl);
}
}
}
}
public class ActionMenuItem : MenuItem
{
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private MenuItem.MenuItemCollection mvarItems = new MenuItem.MenuItemCollection();
public MenuItem.MenuItemCollection Items { get { return mvarItems; } }
private MenuItem.MenuItemCollection mvarItems = new MenuItem.MenuItemCollection();
public MenuItem.MenuItemCollection Items { get { return mvarItems; } }
private CommandDisplayStyle mvarDisplayStyle = CommandDisplayStyle.ImageOnly;
public CommandDisplayStyle DisplayStyle { get { return mvarDisplayStyle; } set { mvarDisplayStyle = value; } }
private CommandDisplayStyle mvarDisplayStyle = CommandDisplayStyle.ImageOnly;
public CommandDisplayStyle DisplayStyle { get { return mvarDisplayStyle; } set { mvarDisplayStyle = value; } }
public event EventHandler Click;
public event EventHandler Click;
public ActionMenuItem(string title)
{
base.Name = title;
mvarTitle = title;
}
public ActionMenuItem(string name, string title)
{
base.Name = name;
mvarTitle = title;
}
public ActionMenuItem(string title)
{
base.Name = title;
mvarTitle = title;
}
public ActionMenuItem(string name, string title)
{
base.Name = name;
mvarTitle = title;
}
public void OnClick(EventArgs e)
{
if (Click != null)
{
Click(this, e);
}
}
}
public class SeparatorMenuItem : MenuItem
{
public void OnClick(EventArgs e)
{
if (Click != null)
{
Click(this, e);
}
}
}
public class SeparatorMenuItem : MenuItem
{
}
}
}

View File

@ -9,30 +9,30 @@ namespace UniversalEditor.UserInterface
public class ToolbarCollection
: System.Collections.ObjectModel.Collection<Toolbar>
{
public Toolbar Add(string name)
{
return Add(name, name);
}
public Toolbar Add(string name, string title)
{
Toolbar tb = new Toolbar();
tb.Name = name;
tb.Title = title;
Add(tb);
return tb;
}
}
public Toolbar Add(string name)
{
return Add(name, name);
}
public Toolbar Add(string name, string title)
{
Toolbar tb = new Toolbar();
tb.Name = name;
tb.Title = title;
Add(tb);
return tb;
}
}
private string mvarName = String.Empty;
public string Name { get { return mvarName; } set { mvarName = value; } }
private string mvarName = String.Empty;
public string Name { get { return mvarName; } set { mvarName = value; } }
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private MenuItem.MenuItemCollection mvarItems = new MenuItem.MenuItemCollection();
public MenuItem.MenuItemCollection Items { get { return mvarItems; } }
private MenuItem.MenuItemCollection mvarItems = new MenuItem.MenuItemCollection();
public MenuItem.MenuItemCollection Items { get { return mvarItems; } }
private bool mvarVisible = true;
public bool Visible { get { return mvarVisible; } set { mvarVisible = value; } }
}
private bool mvarVisible = true;
public bool Visible { get { return mvarVisible; } set { mvarVisible = value; } }
}
}

View File

@ -24,32 +24,32 @@ namespace UniversalEditor.UserInterface
public sealed class ToolboxItemCollection
: System.Collections.ObjectModel.Collection<ToolboxItem>
{
public ToolboxCommandItem AddCommand(string name)
{
return AddCommand(name, name);
}
public ToolboxCommandItem AddCommand(string name, string title)
{
return AddCommand(name, title, null);
}
public ToolboxCommandItem AddCommand(string name, string title, string imageFileName)
{
ToolboxCommandItem item = new ToolboxCommandItem(name, title, imageFileName);
Add(item);
return item;
}
public ToolboxCommandItem AddCommand(string name)
{
return AddCommand(name, name);
}
public ToolboxCommandItem AddCommand(string name, string title)
{
return AddCommand(name, title, null);
}
public ToolboxCommandItem AddCommand(string name, string title, string imageFileName)
{
ToolboxCommandItem item = new ToolboxCommandItem(name, title, imageFileName);
Add(item);
return item;
}
public ToolboxGroupItem AddGroup(string name)
{
return AddGroup(name, name);
}
public ToolboxGroupItem AddGroup(string name, string title)
{
ToolboxGroupItem group = new ToolboxGroupItem(name, title);
Add(group);
return group;
}
}
public ToolboxGroupItem AddGroup(string name)
{
return AddGroup(name, name);
}
public ToolboxGroupItem AddGroup(string name, string title)
{
ToolboxGroupItem group = new ToolboxGroupItem(name, title);
Add(group);
return group;
}
}
private string mvarName = String.Empty;
public string Name { get { return mvarName; } set { mvarName = value; } }
@ -67,8 +67,8 @@ namespace UniversalEditor.UserInterface
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private ToolboxItem.ToolboxItemCollection mvarItems = new ToolboxItem.ToolboxItemCollection();
public ToolboxItem.ToolboxItemCollection Items { get { return mvarItems; } }
private ToolboxItem.ToolboxItemCollection mvarItems = new ToolboxItem.ToolboxItemCollection();
public ToolboxItem.ToolboxItemCollection Items { get { return mvarItems; } }
public ToolboxGroupItem(string name, string title) : base(name)
{