aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Graphics/winder-small.png
blob: 4a9e5e77976c710fdda0aa0afaff906b2e171f86 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 40 00 00 00 40 08 06 00 00 00 aa 69 71 .PNG........IHDR...@...@......iq
0020 de 00 00 00 04 73 42 49 54 08 08 08 08 7c 08 64 88 00 00 00 09 70 48 59 73 00 00 01 bb 00 00 01 .....sBIT....|.d.....pHYs.......
0040 bb 01 3a ec e3 e2 00 00 00 19 74 45 58 74 53 6f 66 74 77 61 72 65 00 77 77 77 2e 69 6e 6b 73 63 ..:.......tEXtSoftware.www.inksc
0060 61 70 65 2e 6f 72 67 9b ee 3c 1a 00 00 0a 80 49 44 41 54 78 9c d5 9b 79 70 55 d5 19 c0 7f df 39 ape.org..<.....IDATx...ypU.....9
0080 f7 be e4 6d 09 90 05 48 80 40 80 97 bc 80 61 4d d4 54 ab 8e d6 11 97 d6 aa b5 2a b5 5a 75 ca d8 ...m...H.@....aM.T........*.Zu..
00a0 b1 ad 3a 63 dd ea 40 6c 47 1c 75 d4 6e 76 a6 9d 16 47 ac 43 19 d1 a9 ed b4 d3 3a 94 e9 b8 8e 4a ..:c..@lG.u.nv...G.C......:....J
00c0 41 40 12 1e 91 7d 5f 0c 10 42 f2 96 7b 4f ff c0 d0 6c 6f c9 5b a8 fd cd 64 72 ef 3d df f9 ce 77 A@...}_..B..{O...lo.[...dr.=...w
00e0 be fb 9d f5 9e 27 c6 18 92 f1 c0 03 cf f8 6d e9 be c4 68 16 60 b8 02 18 0f 1c 05 36 1b e4 0d d7 .....'........m...h.`......6....
0100 35 ab 9e 7a 6a f1 81 a4 0a fe 0f 90 64 0e 78 e4 c1 d6 7b 8d f0 24 50 94 22 7f 0c 58 61 50 cf 3e 5..zj.......d.x...{..$P."..XaP.>
0120 f9 e4 63 1f 17 c2 c0 42 33 c4 01 ad ad ad aa b7 97 e7 30 fc 60 24 8a 0c ac 56 8a 67 97 2e 5d fc ..c....B3.........0.`$...V.g..].
0140 37 63 48 1e 56 5f 30 06 38 a0 b5 b5 b5 b8 b7 87 15 c0 d7 72 d0 d9 26 c8 73 45 5e b3 7c f1 e2 c5 7cH.V_0.8..........r..&.sE^.|...
0160 bd 39 5b 58 60 06 38 e0 e1 87 5b 97 60 58 9c 27 dd 87 05 7e 1d 77 f8 d5 d3 f3 ff 1c 04 b3 c0 c5 .9[X`.8...[.`X.'...~.w..........
0180 34 88 c8 38 0c 63 81 b1 c0 38 ba 4e f8 10 89 83 f4 20 d2 85 70 d4 20 9b 95 a5 5f e0 d6 4d 6f e7 4..8.c...8.N........p....._..Mo.
01a0 c9 96 a4 9c 71 c0 83 0f b6 56 29 a1 03 f0 e6 aa 54 89 61 6a f0 30 75 25 87 a8 2b 39 68 ca 8a ba ....q....V).....T.aj.0u%..+9h...
01c0 25 a9 f0 f1 e3 c9 15 69 15 43 e9 4f 44 ab 57 71 2b 9f e5 f6 35 79 8f 28 ab ef 42 c1 75 e4 58 79 %......i.C.OD.Wq+...5y.(..B.u.Xy
01e0 2d 2e f3 ca 76 73 d1 d8 ad 8c f6 9c ea 7b 9c bc f2 e9 70 5c 0f 8e 3b c7 c4 99 83 ec 6d 95 65 0d -...vs.......{....p\..;.....m.e.
0200 2b 08 a8 bb f9 c6 a6 93 b9 d8 d9 9f 33 0e 40 b8 32 5b 25 b6 72 68 2a db c9 97 c7 76 50 62 17 a8 +...........3.@.2[%.rh*....vPb..
0220 d9 1b d7 32 f1 d8 b7 38 2e 37 b3 ac e1 0d 29 76 be cb cd 5b 8e e4 aa 56 f5 bb 6e ca 46 c1 44 7f ...2...8.7....)v...[...V..n.F.D.
0240 27 f7 86 d7 70 f5 84 4d 85 ab 7c 7f 5c a3 89 c7 be 6e 4e 9a fd ce b2 86 bb 72 55 27 c6 18 1e 78 '...p..M..|.\....nN......rU'...x
0260 a0 b5 d2 d2 1c 1c 51 46 0c 17 8d ed e0 b2 f1 ed 28 c9 61 d4 4b d5 07 64 82 6d bf 29 bb da af 6c ......QF........(.a.K..d.m.)...l
0280 65 89 bb 65 e3 96 90 a3 d5 7c 41 cd c3 98 79 c0 1c a0 18 88 03 bd c0 4b ca 72 96 be f2 ca 2b 67 e..e.....|A...y........K.r....+g
02a0 ea aa 00 3c 4a 66 8c a4 cc 12 bb 97 3b a7 bf c7 e5 55 6d b9 55 3e 1f c4 e3 5f e9 19 17 ee 89 ee ...<Jf......;....Um.U>..._......
02c0 d9 d0 e5 2a dd 26 46 96 63 cc bd c0 85 40 80 d3 cd dc 0b 8c 06 7e e8 26 f4 a7 37 dd 78 eb 3d 7d ...*.&F.c....@.......~.&..7.x.=}
02e0 d9 15 80 8b c9 d8 01 a5 9e 1e 16 85 de a6 36 90 73 f3 cb 1b c5 12 b3 1e 6f de e4 9b 36 aa 3b 13 ..............6.s.......o...6.;.
0300 71 3f f0 b3 9b 6f bc f5 2a f8 dc 01 22 34 64 92 33 68 f7 72 d7 b4 77 fb f7 f0 5f 18 b4 71 58 32 q?...o..*..."4d.3h.r..w..._..qX2
0320 ff 13 6a 4a 7a 32 11 57 06 fe b0 f0 86 85 b5 0a c0 40 da 08 08 58 51 ee 9a f6 2e 65 45 19 79 f9 ..jJz2.W.........@...XQ....eE.y.
0340 7f 82 c6 e1 a7 cd 1b a9 0e 64 e4 84 d2 84 e8 6f f6 8d 02 29 23 c0 56 0e 77 4c 7b 8f 8a e2 bc 0d .........d.....o...)#.V.wL{.....
0360 bf 05 c3 c2 61 e9 79 9b 08 d8 4e 5a 59 11 5a 74 77 b7 54 2a 95 7a fa 7b 65 f5 66 c2 a5 05 5a f5 ....a.y...NZY.Ztw.T*.z.{e.f...Z.
0380 46 a3 79 57 a9 71 69 1c db c5 ea dd 95 e9 44 c7 a8 74 23 40 6d e0 08 e7 57 6c cb 9f 75 67 89 c9 F.yW.qi.......D..t#@m...Wl..ug..
03a0 de 13 2c 98 92 76 64 3f a1 52 8d 00 45 2a c1 f5 35 eb 73 98 cb fe 6f 59 38 6d 27 a3 8b e2 c9 05 ..,..vd?.R..E*..5.s...oY8m'.....
03c0 84 b5 2a d5 08 70 79 55 db 17 b2 c7 cf 14 6d 1c 1e 6a 8a 24 4d 37 c8 3f 55 b2 11 c0 6f c5 68 2a ..*..pyU......m..j.$M7.?U...o.h*
03e0 db 59 30 e3 ce 16 93 8a bb 18 1f 18 b6 9f 79 df 98 de df 2a a0 7e b8 d4 e6 f2 1d 58 ca 2d a8 71 .Y0...........y....*.~.....X.-.q
0400 67 07 c3 77 1a 86 bc c8 4e 17 6e 5f b9 72 a5 a3 80 21 3d 9c 16 97 73 cb 77 9c 0d eb ce 0a 33 4a g..w....N.n_.r...!=...s.w.....3J
0420 3b f1 e8 be 97 69 fe 64 3b cc 58 b9 72 f9 16 00 85 f0 a8 c0 47 40 b4 ef ef 9c d1 fb e2 85 5e d9 ;....i.d;.X.r.......G@........^.
0440 19 e0 68 d4 4f fb 89 32 0a 1d 67 ca b8 3c d4 b4 f5 1d 17 d5 b2 62 e5 cb d7 2e 5f b5 7c 7f 5f da ..h.O..2..g..<.......b...._.|._.
0460 b0 bb c2 e6 8f f3 fe 0a 2c c8 b7 21 51 d7 e2 ad 83 53 d9 d9 5d c6 de 53 a5 f4 3a 36 db b7 75 a0 ........,..!Q....S..]..S..:6..u.
0480 95 a2 d4 2b d4 94 f4
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.IO;
using System.Text;

namespace Tango.Scripting.Editors.Utils
{
	/// <summary>
	/// Class that can open text files with auto-detection of the encoding.
	/// </summary>
	public static class FileReader
	{
		/// <summary>
		/// Gets if the given encoding is a Unicode encoding (UTF).
		/// </summary>
		/// <remarks>
		/// Returns true for UTF-7, UTF-8, UTF-16 LE, UTF-16 BE, UTF-32 LE and UTF-32 BE.
		/// Returns false for all other encodings.
		/// </remarks>
		public static bool IsUnicode(Encoding encoding)
		{
			if (encoding == null)
				throw new ArgumentNullException("encoding");
			switch (encoding.CodePage) {
				case 65000: // UTF-7
				case 65001: // UTF-8
				case 1200: // UTF-16 LE
				case 1201: // UTF-16 BE
				case 12000: // UTF-32 LE
				case 12001: // UTF-32 BE
					return true;
				default:
					return false;
			}
		}
		
		/// <summary>
		/// Reads the content of the given stream.
		/// </summary>
		/// <param name="stream">The stream to read.
		/// The stream must support seeking and must be positioned at its beginning.</param>
		/// <param name="defaultEncoding">The encoding to use if the encoding cannot be auto-detected.</param>
		/// <returns>The file content as string.</returns>
		public static string ReadFileContent(Stream stream, Encoding defaultEncoding)
		{
			using (StreamReader reader = OpenStream(stream, defaultEncoding)) {
				return reader.ReadToEnd();
			}
		}
		
		/// <summary>
		/// Reads the content of the file.
		/// </summary>
		/// <param name="fileName">The file name.</param>
		/// <param name="defaultEncoding">The encoding to use if the encoding cannot be auto-detected.</param>
		/// <returns>The file content as string.</returns>
		public static string ReadFileContent(string fileName, Encoding defaultEncoding)
		{
			using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
				return ReadFileContent(fs, defaultEncoding);
			}
		}
		
		/// <summary>
		/// Opens the specified file for reading.
		/// </summary>
		/// <param name="fileName">The file to open.</param>
		/// <param name="defaultEncoding">The encoding to use if the encoding cannot be auto-detected.</param>
		/// <returns>Returns a StreamReader that reads from the stream. Use
		/// <see cref="StreamReader.CurrentEncoding"/> to get the encoding that was used.</returns>
		public static StreamReader OpenFile(string fileName, Encoding defaultEncoding)
		{
			if (fileName == null)
				throw new ArgumentNullException("fileName");
			FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
			try {
				return OpenStream(fs, defaultEncoding);
				// don't use finally: the stream must be kept open until the StreamReader closes it
			} catch {
				fs.Dispose();
				throw;
			}
		}
		
		/// <summary>
		/// Opens the specified stream for reading.
		/// </summary>
		/// <param name="stream">The stream to open.</param>
		/// <param name="defaultEncoding">The encoding to use if the encoding cannot be auto-detected.</param>
		/// <returns>Returns a StreamReader that reads from the stream. Use
		/// <see cref="StreamReader.CurrentEncoding"/> to get the encoding that was used.</returns>
		public static StreamReader OpenStream(Stream stream, Encoding defaultEncoding)
		{
			if (stream == null)
				throw new ArgumentNullException("stream");
			if (stream.Position != 0)
				throw new ArgumentException("stream is not positioned at beginning.", "stream");
			if (defaultEncoding == null)
				throw new ArgumentNullException("defaultEncoding");
			
			if (stream.Length >= 2) {
				// the autodetection of StreamReader is not capable of detecting the difference
				// between ISO-8859-1 and UTF-8 without BOM.
				int firstByte = stream.ReadByte();
				int secondByte = stream.ReadByte();
				switch ((firstByte << 8) | secondByte) {
					case 0x0000: // either UTF-32 Big Endian or a binary file; use StreamReader
					case 0xfffe: // Unicode BOM (UTF-16 LE or UTF-32 LE)
					case 0xfeff: // UTF-16 BE BOM
					case 0xefbb: // start of UTF-8 BOM
						// StreamReader autodetection works
						stream.Position = 0;
						return new StreamReader(stream);
					default:
						return AutoDetect(stream, (byte)firstByte, (byte)secondByte, defaultEncoding);
				}
			} else {
				if (defaultEncoding != null) {
					return new StreamReader(stream, defaultEncoding);
				} else {
					return new StreamReader(stream);
				}
			}
		}
		
		static StreamReader AutoDetect(Stream fs, byte firstByte, byte secondByte, Encoding defaultEncoding)
		{
			int max = (int)Math.Min(fs.Length, 500000); // look at max. 500 KB
			const int ASCII = 0;
			const int Error = 1;
			const int UTF8  = 2;
			const int UTF8Sequence = 3;
			int state = ASCII;
			int sequenceLength = 0;
			byte b;
			for (int i = 0; i < max; i++) {
				if (i == 0) {
					b = firstByte;
				} else if (i == 1) {
					b = secondByte;
				} else {
					b = (byte)fs.ReadByte();
				}
				if (b < 0x80) {
					// normal ASCII character
					if (state == UTF8Sequence) {
						state = Error;
						break;
					}
				} else if (b < 0xc0) {
					// 10xxxxxx : continues UTF8 byte sequence
					if (state == UTF8Sequence) {
						--sequenceLength;
						if (sequenceLength < 0) {
							state = Error;
							break;
						} else if (sequenceLength == 0) {
							state = UTF8;
						}
					} else {
						state = Error;
						break;
					}
				} else if (b >= 0xc2 && b < 0xf5) {
					// beginning of byte sequence
					if (state == UTF8 || state == ASCII) {
						state = UTF8Sequence;
						if (b < 0xe0) {
							sequenceLength = 1; // one more byte following
						} else if (b < 0xf0) {
							sequenceLength = 2; // two more bytes following
						} else {
							sequenceLength = 3; // three more bytes following
						}
					} else {
						state = Error;
						break;
					}
				} else {
					// 0xc0, 0xc1, 0xf5 to 0xff are invalid in UTF-8 (see RFC 3629)
					state = Error;
					break;
				}
			}
			fs.Position = 0;
			switch (state) {
				case ASCII:
				case Error:
					// when the file seems to be ASCII or non-UTF8,
					// we read it using the user-specified encoding so it is saved again
					// using that encoding.
					if (IsUnicode(defaultEncoding)) {
						// the file is not Unicode, so don't read it using Unicode even if the
						// user has choosen Unicode as the default encoding.
						
						// If we don't do this, SD will end up always adding a Byte Order Mark
						// to ASCII files.
						defaultEncoding = Encoding.Default; // use system encoding instead
					}
					return new StreamReader(fs, defaultEncoding);
				default:
					return new StreamReader(fs);
			}
		}
	}
}