123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #if NETFX_CORE
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using System.IO;
- using System.Linq;
- using System.Text;
- using Windows.Storage;
- using Windows.Storage.Streams;
- using Windows.Foundation;
- namespace BestHTTP.PlatformSupport.IO
- {
- public abstract class FileSystemInfo
- {
- public FileAttributes Attributes
- {
- get
- {
- return this.GetAttributes();
- }
- }
- public DateTime CreationTime
- {
- get
- {
- return this.GetCreationTime().DateTime;
- }
- }
- public DateTime CreationTimeUtc
- {
- get
- {
- return this.GetCreationTime().ToUniversalTime().DateTime;
- }
- }
- public abstract bool Exists { get; }
- public string Extention
- {
- get
- {
- return Path.GetExtension(this.FullName);
- }
- }
- public abstract string FullName { get; }
- public abstract string Name { get; }
- internal abstract FileAttributes GetAttributes();
- internal abstract DateTimeOffset GetCreationTime();
- public abstract void Delete();
- public void Refresh()
- {
- this.RefreshInternal();
- }
- internal abstract void RefreshInternal();
- }
- public sealed class DirectoryInfo : FileSystemInfo
- {
- private string path;
- private StorageFolder folder;
- public override bool Exists
- {
- get
- {
- try
- {
- this.RefreshInternal();
- return true;
- }
- catch
- {
- return false;
- }
- }
- }
- public override string FullName
- {
- get
- {
- return this.folder.Path;
- }
- }
- public override string Name
- {
- get
- {
- return this.folder.Name;
- }
- }
- public DirectoryInfo(string path)
- {
- if (path == null)
- throw new ArgumentNullException();
- if (string.IsNullOrWhiteSpace(path))
- throw new ArgumentException();
- try
- {
- this.path = path;
- this.folder = FileHelper.GetFolderForPathOrURI(path);
- }
- catch (IOException ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo: " + ex.Message + "\n" + ex.StackTrace);
- throw;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo: " + ex.Message + "\n" + ex.StackTrace);
- throw new IOException(ex.Message, ex);
- }
- }
- internal DirectoryInfo(string path, StorageFolder folder)
- {
- this.path = path;
- this.folder = folder;
- }
- internal override FileAttributes GetAttributes()
- {
- try
- {
- return File.WinAttributesToSysAttributes(this.folder.Attributes);
- }
- catch (IOException ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.GetAttributes: " + ex.Message + "\n" + ex.StackTrace);
- throw;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.GetAttributes: " + ex.Message + "\n" + ex.StackTrace);
- throw new IOException(ex.Message, ex);
- }
- }
- internal override DateTimeOffset GetCreationTime()
- {
- try
- {
- return this.folder.DateCreated;
- }
- catch (IOException ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.GetCreationTime: " + ex.Message + "\n" + ex.StackTrace);
- throw;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.GetCreationTime: " + ex.Message + "\n" + ex.StackTrace);
- throw new IOException(ex.Message, ex);
- }
- }
- public override void Delete()
- {
- try
- {
- WindowsRuntimeSystemExtensions.AsTask(this.folder.DeleteAsync()).Wait();
- }
- catch (IOException ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.Delete: " + ex.Message + "\n" + ex.StackTrace);
- throw;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.Delete: " + ex.Message + "\n" + ex.StackTrace);
- throw new IOException(ex.Message, ex);
- }
- }
- internal override void RefreshInternal()
- {
- try
- {
- this.folder = FileHelper.GetFolderForPathOrURI(this.path);
- }
- catch (IOException ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.RefreshInternal: " + ex.Message + "\n" + ex.StackTrace);
- throw;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("DirectoryInfo.RefreshInternal: " + ex.Message + "\n" + ex.StackTrace);
- throw new IOException(ex.Message, ex);
- }
- }
- public override string ToString()
- {
- return this.path;
- }
- public override int GetHashCode()
- {
- return this.path.GetHashCode();
- }
- }
- }
- #endif
|