DirectoryExists() public method

public DirectoryExists ( string path ) : bool
path string
return bool
Exemplo n.º 1
0
 private static void VerifyFolderExistsAsync(IsolatedStorageFile isolatedStorageFile)
 {
     if (!isolatedStorageFile.DirectoryExists(MonthFolder))
     {
         isolatedStorageFile.CreateDirectory(MonthFolder);
     }
 }
Exemplo n.º 2
0
        public AssemblyStorageService()
        {
            Store = IsolatedStorageFile.GetUserStoreForApplication();
            Store.IncreaseQuotaTo(20971520);
            if (!Store.DirectoryExists("Modules"))
                Store.CreateDirectory("Modules");

        }
 public IsolatedStorageResponseCache(TimeSpan expiresIn)
 {
     this.expiresIn = expiresIn;
     storage = IsolatedStorageFile.GetUserStoreForApplication();
     if (!storage.DirectoryExists("Cache"))
     {
         storage.CreateDirectory("Cache");
     }
 }
Exemplo n.º 4
0
        public static void CreateDirectoryTree(Uri feedUri, IsolatedStorageFile storage)
        {
            if (!feedUri.OriginalString.Contains('\\')) return;

            var directory = GetDirectoryPath(feedUri);

            if (!storage.DirectoryExists(directory)) 
                storage.CreateDirectory(directory);
        }
        public IsolatedStorageResponseCache(string session)
        {
            if (session == null) throw new ArgumentNullException("session");
            this._sessionKey = HashUtil.ToSHA1(session);

            //create cache dir
            _storage = IsolatedStorageFile.GetUserStoreForApplication();
            if (!_storage.DirectoryExists("ECollegeCache"))
            {
                _storage.CreateDirectory("ECollegeCache");
            }

            //create session dir
            string thisSessionDirectory = string.Format("ECollegeCache\\{0}", _sessionKey);
            if (!_storage.DirectoryExists(thisSessionDirectory))
            {
                _storage.CreateDirectory(thisSessionDirectory);
            }
        }
Exemplo n.º 6
0
        public static void CreateDirectory(string path)
        {
            System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();



            if (isf.DirectoryExists(path))
            {
                isf.CreateDirectory(path);
            }
        }
        /// <summary>
        /// Creates all of the directories included in the given filepath.
        /// </summary>
        /// <param name="filepath">A string containing a filepath which may or may not contain any number of directories.</param>
        /// <param name="storage">A reference to a valid IsolatedStorageFile instance</param>
        public static void CreateDirectoryTree(string filepath, IsolatedStorageFile storage)
        {
            //If this filepath is flat and doesn't contain any folders - bail.
             if (!HasDirectories(filepath)) return;

            //Extract the full directory path from the filename
            var directory = GetFullDirectoryPath(filepath);

            //If the directory doesn't already exist, create it.
            if (!storage.DirectoryExists(directory))
                storage.CreateDirectory(directory);
        }
Exemplo n.º 8
0
 private void DeleteAllFilesInDirectory(IsolatedStorageFile store, string path)
 {
     if (!store.DirectoryExists(path))
     {
         return;
     }
     var files = store.GetFileNames(path + "/*");
     foreach (var file in files)
     {
         store.DeleteFile(path + "/" + file);
     }
 }
Exemplo n.º 9
0
        private void CreateDirIfNecessary(IsolatedStorageFile local, string path)
        {
            int pos = 0;
            string dir = path;

            while ((pos = dir.IndexOf('\\', pos)) != -1)
            {
                var dirname = dir.Substring(0, pos);
                if (!local.DirectoryExists(dirname))
                    local.CreateDirectory(dirname);
                pos++;
            }
        }
Exemplo n.º 10
0
        public MainPage()
        {
            InitializeComponent();

            _recorder = new Recorder(new WaveFormat());
            _storage = IsolatedStorageFile.GetUserStoreForApplication();

            if (!_storage.DirectoryExists(STORAGE_DIRECTORY))
            {
                _storage.CreateDirectory(STORAGE_DIRECTORY);
            }

            UpdateRecordings();
        }
Exemplo n.º 11
0
 private static bool CheckDir(IsolatedStorageFile storage)
 {
     if (!storage.DirectoryExists(Folder))
     {
         try
         {
             storage.CreateDirectory(Folder);
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 12
0
        /// <summary>
        /// delete files in directory
        /// </summary>
        /// <param name="storageFolder"></param>
        /// <param name="directory"></param>
        private static void TryToDeleteAllFiles(IsolatedStorageFile storageFolder, string directory)
        {
            if (storageFolder.DirectoryExists(directory))
            {
                try
                {
                    string[] files = storageFolder.GetFileNames(directory);

                    foreach (string file in files)
                    {
                        storageFolder.DeleteFile(directory + file);
                    }
                }
                catch (Exception)
                {
                    // could be in use
                }
            }
        }
Exemplo n.º 13
0
        public static void TryToDeleteAllFiles(IsolatedStorageFile storageFolder, string directory)
        {
            if (storageFolder.DirectoryExists(directory))
            {
                try
                {
                    string[] files = storageFolder.GetFileNames(directory);
                    foreach (string File in files)
                    {
                        storageFolder.DeleteFile(directory + files);

                    }
                }
                catch (Exception)
                {
                    //ignoring the exception
                }
             }
        }
Exemplo n.º 14
0
        private static Stream OpenLogFile(IsolatedStorageFile store)
        {
            if (Profile == null)
            {
                return Stream.Null;
            }

            try
            {
                var fileName = string.Format(LOGFILE_TEMPLATE, DateTime.UtcNow.ToString("yyyy-MM-dd"));
                var folderPath = Path.Combine(Profile.CurrentProfilePath(), LOGFOLDER);

                if (!store.DirectoryExists(folderPath))
                {
                    store.CreateDirectory(folderPath);
                }

                var filePath = Path.Combine(folderPath, fileName);

                if (store.FileExists(filePath))
                {
                    return store.OpenFile(filePath, FileMode.Append);
                }
                else
                {
                    CleanupLogs(store, folderPath);

                    return store.OpenFile(filePath, FileMode.Create);
                }
            }
            catch (Exception ex)
            {
                // Logging Failed, don't kill the process because of it
                Debugger.Break();

                return Stream.Null;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 保存信息至本地文件,SilverLight缓存中
        /// </summary>
        /// <param name="rFileName">存储文件名</param>
        /// <param name="rText">消息文本</param>
        public static void WriteSlTextFile(string rFileName, string rText)
        {
            System.IO.IsolatedStorage.IsolatedStorageFile isf = null;
            System.IO.Stream     stream = null;
            System.IO.TextWriter writer = null;
            try
            {
                isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                if (rFileName.IndexOf(':') >= 0)
                {
                    rFileName = rFileName.Substring(rFileName.LastIndexOf(':') + 1);
                }
                string rPath = System.IO.Path.GetDirectoryName(rFileName);
                if (isf.DirectoryExists(rPath) == false)
                {
                    isf.CreateDirectory(rPath);
                }
                stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(rFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, isf);
                //stream.Seek(0, System.IO.SeekOrigin.End);
                writer = new System.IO.StreamWriter(stream);
                writer.Write(rText);

                writer.Flush();
            }
            finally
            {
                try
                {
                    writer.Close();
                    stream.Close();
                    isf.Dispose();
                }
                catch
                {
                }
            }
        }
Exemplo n.º 16
0
        public void CopyDirectory(string sourcePath, string destinationPath, IsolatedStorageFile iso)
        {
            if (!iso.DirectoryExists(sourcePath))
            return;

              var folders = iso.GetDirectoryNames(sourcePath + "/" + "*.*");

              foreach (var folder in folders)
              {
            string sourceFolderPath = sourcePath + "/" + folder;
            string destinationFolderPath = destinationPath + "/" + folder;

            iso.CreateDirectory(destinationFolderPath);
            CopyDirectory(sourceFolderPath, destinationFolderPath, iso);
              }

              foreach (var file in iso.GetFileNames(sourcePath + "/" + "*.*"))
              {
            string sourceFilePath = sourcePath + "/" + file;
            string destinationFilePath = destinationPath + "/" + file;

            iso.CopyFile(sourceFilePath, destinationFilePath);
              }
        }
Exemplo n.º 17
0
        private void DeleteDirectory(string path, IsolatedStorageFile iso)
        {
            if (!iso.DirectoryExists(path))
            return;

              var folders = iso.GetDirectoryNames(path + "/" + "*.*");

              foreach (var folder in folders)
              {
            string folderPath = path + "/" + folder;
            DeleteDirectory(folderPath, iso);
              }

              foreach (var file in iso.GetFileNames(path + "/" + "*.*"))
              {
            iso.DeleteFile(path + "/" + file);
              }

              if (path != "")
            iso.DeleteDirectory(path);
        }
Exemplo n.º 18
0
        private static string PrepareFilePath(DownloadItemDataModel item, IsolatedStorageFile storage)
        {
            if (item.BookID == Guid.Empty || !storage.DirectoryExists(item.BookID.ToString()))
            {
                item.BookID = CreateFolder(storage);
            }

            var bookPath = CreateBookPath(item);
            if (storage.FileExists(bookPath))
            {
                storage.DeleteFile(bookPath);
            }

            return bookPath;
        }
Exemplo n.º 19
0
            public static void EnsurePath(IsolatedStorageFile store, string filename)
            {
                for (string path = Path.GetDirectoryName(filename);
                            path != "";
                            path = Path.GetDirectoryName(path)) {

                    if (!store.DirectoryExists(path)) {
                        store.CreateDirectory(path);
                    }
                }
            }
Exemplo n.º 20
0
        private bool ExtractFile(StreamResourceInfo xapStream, IsolatedStorageFile isf, string fileName)
        {
            try
            {
                if (!isf.DirectoryExists("Temp"))
                    isf.CreateDirectory("Temp");
                if (!isf.DirectoryExists(IsoTempFolderPath))
                    isf.CreateDirectory(IsoTempFolderPath);

                var streamResource = Application.GetResourceStream(xapStream, new Uri(fileName, UriKind.Relative));

                if (streamResource == null)
                    return false;

                string shortFileName = ShortenFileName(fileName);

                var fs = new IsolatedStorageFileStream(IsoTempFolderPath + "\\" + shortFileName, FileMode.Create, isf);

                Byte[] bytes = new Byte[streamResource.Stream.Length];
                streamResource.Stream.Read(bytes, 0, bytes.Length);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();

                streamResource.Stream.Close();
                return true;
            }
            catch (Exception ex)
            {
            }
            return false;
        }
Exemplo n.º 21
0
 /// <summary>
 /// 确保Cache文件夹存在
 /// </summary>
 private void EnsureCacheFolder()
 {
     using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) {
         if ( !_storage.DirectoryExists( CACHE_FOLDER ) ) {
             _storage.CreateDirectory( CACHE_FOLDER );
         }
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Saves user password.
        /// </summary>
        /// <param name="store">The store.</param>
        /// <param name="xml">The XML.</param>
        private async void Save(IsolatedStorageFile store,
            DbPersistentData xml)
        {
            if (!store.DirectoryExists(Folder))
                store.CreateDirectory(Folder);

            using (var fs = store.CreateFile(ProtectionPath))
            {
                var protect = xml.Protection;
                fs.Write(protect, 0, protect.Length);
            }
            using (var fs = store.CreateFile(ParsedXmlPath))
            using (var buffer = new MemoryStream(xml.Xml))
                BufferEx.CopyStream(buffer, fs);

            using (var fs = store.CreateFile(MasterPasswordPath))
            {
                var data = xml.MasterKey;
                await fs.WriteAsync(data, 0, data.Length);

            }
        }
Exemplo n.º 23
0
        private static string PrepareFilePath(Book item, IsolatedStorageFile storage)
        {
            if (item.IsMyBook || item.IsFreeBook)
            {
                if (!storage.DirectoryExists(item.Id.ToString()))
                {
                    storage.CreateDirectory(Path.Combine(CatalogPath, item.Id.ToString()));
                }
            }
            else
            {
                if (!storage.DirectoryExists(item.Id + ".trial"))
                {
                    storage.CreateDirectory(Path.Combine(CatalogPath, item.Id + ".trial"));
                }
            }

            var bookPath = item.IsMyBook || item.IsFreeBook ? CreateBookPath(item.Id.ToString()) : CreateBookPath(item.Id + ".trial");
            if (storage.FileExists(bookPath))
            {
                storage.DeleteFile(bookPath);
            }

            return bookPath;
        }
Exemplo n.º 24
0
 public void MoveOldCrashlogsIfNeeded(IsolatedStorageFile store)
 {
     try
     {
         if (store.DirectoryExists(Constants.OldCrashDirectoryName))
         {
             var files = store.GetFileNames(Path.Combine(Constants.OldCrashDirectoryName, Constants.CrashFilePrefix + "*.log"));
             if (files.Length > 0)
             {
                 if (!store.DirectoryExists(Constants.CrashDirectoryName))
                 {
                     store.CreateDirectory(Constants.CrashDirectoryName);
                 }
                 foreach (var fileName in files)
                 {
                     store.MoveFile(Path.Combine(Constants.OldCrashDirectoryName, Path.GetFileName(fileName)), Path.Combine(Constants.CrashDirectoryName, Path.GetFileName(fileName)));
                 }
                 if (store.GetFileNames(Path.Combine(Constants.OldCrashDirectoryName, Constants.CrashFilePrefix + "*.*")).Length == 0)
                 {
                     store.DeleteDirectory(Constants.OldCrashDirectoryName);
                 }
             }
         }
     }
     catch (Exception e)
     {
         HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e);
     }
 }
Exemplo n.º 25
0
 private static void CreateDirIfNecessary(IsolatedStorageFile iso, string dir)
 {
     if (!iso.DirectoryExists(dir))
     {
         iso.CreateDirectory(dir);
     }
 }
 /// <summary>
 /// Verifies whether or not a given directory exists in IsolatedStorage
 /// </summary>
 /// <param name="directorypath">The path to a given directory</param>
 /// <param name="storage">A reference to a valid IsolatedStorageFile instance.</param>
 /// <returns>True if the directory exists, false otherwise.</returns>
 public static bool DirectoryExists(string directorypath, IsolatedStorageFile storage)
 {
     return storage.DirectoryExists(directorypath);
 }
Exemplo n.º 27
0
 // helper function from: http://stackoverflow.com/questions/18422331/easy-way-to-recursively-delete-directories-in-isolatedstorage-on-wp7-8
 private void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, String dirName)
 {
     try
     {
         String pattern = dirName + @"\*";
         String[] files = storageFile.GetFileNames(pattern);
         foreach (var fName in files)
         {
             storageFile.DeleteFile(Path.Combine(dirName, fName));
         }
         String[] dirs = storageFile.GetDirectoryNames(pattern);
         foreach (var dName in dirs)
         {
             DeleteDirectoryRecursively(storageFile, Path.Combine(dirName, dName));
         }
         if (storageFile.DirectoryExists(dirName))
         {
             storageFile.DeleteDirectory(dirName);
         }
     }
     catch(Exception e)
     {
         Debug.WriteLine("Unable to delete directory : " + dirName);
     }
 }
Exemplo n.º 28
0
 private static void TryToDeleteAllFiles( IsolatedStorageFile storagefolder, string Directory) {
     if (storagefolder.DirectoryExists(Directory))
     {
         try
         {
             string[] files = storagefolder.GetFileNames(Directory);
             foreach (var item in files)
             {
                 storagefolder.DeleteFile(Directory+item); 
             }
         }
         catch (Exception)
         {
             //In Use
             throw;
         }
     }
 
 }
Exemplo n.º 29
0
        // 构造函数
        public MainPage()
        {
            InitializeComponent();

            this.lat = 0.0;
            this.lon = 0.0;
            this.zoomlevel = MIN_ZOOM_LEVEL;
            this.targetZoomLevel = 19;
            this.scale = 1;
            this.threshold = getDPI() * 0.06f;

            this.hasTarget = false;
            this.isTracking = false;
            this.hasPosition = false;

            plotterHelper = new PlotterHelper();
            westCampus = new iustc.map.data.Rectangle(31.836497, 31.844080, 117.245445, 117.255058);
            eastCamput = new iustc.map.data.Rectangle(31.834236, 31.844189, 117.258920, 117.267889);
            arrowUri = new Uri("/iUSTCMap;component/resources/map_location_arrow.png", UriKind.Relative);
            dotUri = new Uri("/iUSTCMap;component/resources/map_location_dot.png", UriKind.Relative);
            arrowBitmap = new BitmapImage(arrowUri);
            dotBitmap = new BitmapImage(dotUri);

            if (cm == null)
                cm = new CacheManager(CACHE_CAPACITY, this);
            if (pThread == null)
                pThread = new PlotterThread(cm);

            watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); // using high accuracy

            LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(255, 236, 236, 236));

            isoFile = IsolatedStorageFile.GetUserStoreForApplication();
            if (!isoFile.DirectoryExists("cache"))
            {
                isoFile.CreateDirectory("cache");
            }
            #region appBar
            appBar = new ApplicationBar();
            appBar.Opacity = 0.5;
            locateButton = new ApplicationBarIconButton(new Uri("resources/appbar.locate.rest.png", UriKind.Relative));
            locateButton.Text = "定位";
            locateButton.Click += new EventHandler(locateButton_Click);
            appBar.Buttons.Add(locateButton);

            zoomInButton = new ApplicationBarIconButton(new Uri("resources/appbar.new.rest.png", UriKind.Relative));
            zoomInButton.Text = "放大";
            zoomInButton.Click += new EventHandler(zoomInButton_Click);
            appBar.Buttons.Add(zoomInButton);

            zoomOutButton = new ApplicationBarIconButton(new Uri("resources/appbar.minus.rest.png", UriKind.Relative));
            zoomOutButton.Text = "缩小";
            zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
            appBar.Buttons.Add(zoomOutButton);

            selectCampusButton = new ApplicationBarIconButton(new Uri("resources/appbar.east.rest.png", UriKind.Relative));
            selectCampusButton.Text = "东校区";
            selectCampusButton.Click += new EventHandler(selectCampusButton_Click);
            appBar.Buttons.Add(selectCampusButton);

            ApplicationBar = appBar;
            #endregion
        }
Exemplo n.º 30
0
 static Storage()
 {
     storage = IsolatedStorageFile.GetUserStoreForAssembly();
     if (!storage.DirectoryExists(rootDirectory)) storage.CreateDirectory(rootDirectory);
 }
Exemplo n.º 31
0
        private void CopyDirectory(string sourceDir, string destDir, IsolatedStorageFile isoFile)
        {
            string path = File.AddSlashToDirectory(sourceDir);

            bool bExists = isoFile.DirectoryExists(destDir);

            if (!bExists)
            {
                isoFile.CreateDirectory(destDir);
            }

            destDir = File.AddSlashToDirectory(destDir);

            string[] files = isoFile.GetFileNames(path + "*");

            if (files.Length > 0)
            {
                foreach (string file in files)
                {
                    isoFile.CopyFile(path + file, destDir + file, true);
                }
            }
            string[] dirs = isoFile.GetDirectoryNames(path + "*");
            if (dirs.Length > 0)
            {
                foreach (string dir in dirs)
                {
                    CopyDirectory(path + dir, destDir + dir, isoFile);
                }
            }
        }
Exemplo n.º 32
0
        private static void DeleteAllFiles(IsolatedStorageFile isf)
        {
            if (false == isf.DirectoryExists(Constants.MyScriptsDirectoryName))
                return;

            var filesDel = isf.GetFileNames(string.Format("{0}\\*", Constants.MyScriptsDirectoryName));
            foreach (var f in filesDel)
            {
                isf.DeleteFile(Constants.MyScriptsDirectoryName + "\\" + f);
            }
            isf.DeleteDirectory(Constants.MyScriptsDirectoryName);
        }
Exemplo n.º 33
0
 public override Task <bool> GetDirectoryExistsAsync(string path)
 {
     return(Task <bool> .Factory.StartNew(() => file.DirectoryExists(path)));
 }