+ static DateTime? defaultLocalFileTime;
+ static DateTime DefaultLocalFileTime {
+ get {
+ if (defaultLocalFileTime == null)
+ defaultLocalFileTime = new DateTime (1601, 1, 1).ToLocalTime ();
+
+ return defaultLocalFileTime.Value;
+ }
+ }
+
+
+ [MonoLimitation ("File encryption isn't supported (even on NTFS).")]
+ public static void Encrypt (string path)
+ {
+ // MS.NET support this only on NTFS file systems, i.e. it's a file-system (not a framework) feature.
+ // otherwise it throws a NotSupportedException (or a PlatformNotSupportedException on older OS).
+ // we throw the same (instead of a NotImplementedException) because most code should already be
+ // handling this exception to work properly.
+ throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
+ }
+
+ [MonoLimitation ("File encryption isn't supported (even on NTFS).")]
+ public static void Decrypt (string path)
+ {
+ // MS.NET support this only on NTFS file systems, i.e. it's a file-system (not a framework) feature.
+ // otherwise it throws a NotSupportedException (or a PlatformNotSupportedException on older OS).
+ // we throw the same (instead of a NotImplementedException) because most code should already be
+ // handling this exception to work properly.
+ throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
+ }
+
+#if NET_4_0
+ public static IEnumerable<string> ReadLines (string path)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (path.Length == 0)
+ throw new ArgumentException ("path");
+
+ using (StreamReader reader = File.OpenText (path)) {
+ string s;
+ while ((s = reader.ReadLine ()) != null)
+ yield return s;
+ }
+ }
+
+ public static IEnumerable<string> ReadLines (string path, Encoding encoding)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (path.Length == 0)
+ throw new ArgumentException ("path");
+
+ using (StreamReader reader = new StreamReader (path, encoding)) {
+ string s;
+ while ((s = reader.ReadLine ()) != null)
+ yield return s;
+ }
+ }
+
+ public static void AppendAllLines (string path, IEnumerable<string> contents)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (path.Length == 0)
+ throw new ArgumentException ("path");
+ if (contents == null)
+ return;
+
+ using (TextWriter w = new StreamWriter (path, true)) {
+ foreach (var line in contents)
+ w.Write (line);
+ }
+ }
+
+ public static void AppendAllLines (string path, IEnumerable<string> contents, Encoding encoding)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (path.Length == 0)
+ throw new ArgumentException ("path");
+ if (contents == null)
+ return;
+
+ using (TextWriter w = new StreamWriter (path, true, encoding)) {
+ foreach (var line in contents)
+ w.Write (line);
+ }
+ }
+
+ public static void WriteAllLines (string path, IEnumerable<string> contents)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (path.Length == 0)
+ throw new ArgumentException ("path");
+ if (contents == null)
+ return;
+
+ using (TextWriter w = new StreamWriter (path, false)) {
+ foreach (var line in contents)
+ w.Write (line);
+ }
+ }
+
+ public static void WriteAllLines (string path, IEnumerable<string> contents, Encoding encoding)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (path.Length == 0)
+ throw new ArgumentException ("path");
+ if (contents == null)
+ return;
+
+ using (TextWriter w = new StreamWriter (path, false, encoding)) {
+ foreach (var line in contents)
+ w.Write (line);
+ }
+ }