예제 #1
0
        public bool Close()
        {
            this.writer.Close();
            var memoryString = new IO.StreamReader(
                new IO.MemoryStream(this.stream.ToArray()), this.encoding).
                               ReadToEnd();
            string fileString = "";

            using (var file = new IO.FileStream(
                       this.filename, IO.FileMode.OpenOrCreate))
            {
                using (var fileReader = new IO.StreamReader(file))
                {
                    fileString = fileReader.ReadToEnd();
                }
            }
            if (memoryString != fileString)
            {
                using (var file = new IO.FileStream(this.filename, IO.FileMode.Create))
                {
                    using (var fileWriter = new IO.StreamWriter(file, this.encoding))
                    {
                        fileWriter.Write(memoryString);
                        file.SetLength(file.Position);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
		public bool Close()
		{
			this.writer.Close();
			var memoryString = new IO.StreamReader(
					new IO.MemoryStream(this.stream.ToArray()), this.encoding).
				ReadToEnd();
			string fileString = "";
			using (var file = new IO.FileStream(
				this.filename, IO.FileMode.OpenOrCreate))
			{
				using (var fileReader = new IO.StreamReader(file))
				{
					fileString = fileReader.ReadToEnd();
				}
			}
			if (memoryString != fileString)
			{
				using (var file = new IO.FileStream(this.filename, IO.FileMode.Create))
				{
					using (var fileWriter = new IO.StreamWriter(file, this.encoding))
					{
						fileWriter.Write(memoryString);
						file.SetLength(file.Position);
					}
				}
				return true;
			}
			else
			{
				return false;
			}
		}
예제 #3
0
        public static Encoding GetEncoding(FileInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            using (FStream fs = info.Open(FileMode.Open, FileAccess.Read))
            {
                byte[] buffer = new byte[3];
                int    len    = fs.Read(buffer, 0, 3);
                if (len < 2)
                {
                    return(Encoding.Default);
                }

                fixed(byte *pinned = buffer)
                {
                    return(GetEncoding(pinned));
                }
            }
        }
예제 #4
0
        private static void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string     path   = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;
            FileMode   mode   = FileMode.Open;
            FileAccess access = FileAccess.ReadWrite;

            if (arguments.Length > 1)
            {
                NSJSInt32 n = arguments[1] as NSJSInt32;
                if (n != null)
                {
                    mode = (FileMode)n.Value;
                }
                n = arguments.Length > 2 ? arguments[2] as NSJSInt32 : null;
                if (n != null)
                {
                    access = (FileAccess)n.Value;
                }
            }
            Exception exception = null;
            FStream   stream    = null;

            try
            {
                stream = new FStream(path, mode, access);
            }
            catch (Exception e)
            {
                exception = e;
            }
            if (exception == null)
            {
                arguments.SetReturnValue(Stream.New(arguments.VirtualMachine, stream));
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }