コード例 #1
0
        /// <summary>
        /// Gets all external storage files
        /// </summary>
        /// <param name="sdCard"></param>
        /// <returns></returns>
        public async Task <ObservableCollection <ExternalStorageFile> > GetExternal_GPXFiles(string folder, string fileExtension)
        {
            ObservableCollection <ExternalStorageFile> storageFIle = new ObservableCollection <ExternalStorageFile>();

            try
            {
                ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
                if (sdCard != null)
                {
                    ExternalStorageFolder routesFolder = await sdCard.GetFolderAsync(folder);

                    IEnumerable <ExternalStorageFile> routeFiles = await routesFolder.GetFilesAsync();

                    foreach (ExternalStorageFile extStoreFile in routeFiles)
                    {
                        if (extStoreFile.Path.EndsWith(fileExtension))
                        {
                            storageFIle.Add(extStoreFile);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("SD card not found, Please make sure the SD card is inserted properly.");
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("The file folder " + folder + " not found.");
                return(null);
            }
            return(storageFIle);
        }
コード例 #2
0
        public async Task <FilesResult> LoadSelectedFile()
        {
            FilesResult           result = new FilesResult();
            ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            if (sdCard != null)
            {
                IEnumerable <ExternalStorageFile> files = await sdCard.RootFolder.GetFilesAsync();

                if (SelectedFile.Name.EndsWith(".txt"))
                {
                    System.IO.Stream fileStream = await SelectedFile.OpenForReadAsync();

                    //Read the entire file into the FileText property
                    using (StreamReader streamReader = new StreamReader(fileStream))
                    {
                        FileText = streamReader.ReadToEnd();
                    }

                    fileStream.Close();
                    result.Success = true;
                }
                else
                {
                    result.Success = false;
                    result.Message = "Invalid file type. Can only open text files with a '.txt' extension";
                }
            }

            return(result);
        }
コード例 #3
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // Connect to the current SD card.
            sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            // If the SD card is present, add GPX files to the Routes collection.
            if (sdCard != null)
            {
                this.skydriveStack[0].Add(new SDCardListItem()
                {
                    Name       = "Root",
                    isFolder   = true,
                    ThisFolder = sdCard.RootFolder,
                    ParentPath = null
                });


                this.OpenFolder(sdCard.RootFolder);
            }
            else
            {
                // No SD card is present.
                MessageBox.Show(AppResources.SDCardMissingText);
            }

            base.OnNavigatedTo(e);
        }
コード例 #4
0
        async Task GetExtStorage()
        {
            ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            if (!appSettings.Contains("extstorage") || (int)appSettings["extstorage"] == -1)
            {
                if (sdCard != null)
                {
                    if (MessageBox.Show(UVEngine.Resources.UVEngine.sdinserted, UVEngine.Resources.UVEngine.tip, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        appSettings.Add("extstorage", 1);
                    }
                    else
                    {
                        appSettings.Add("extstorage", 0);
                    }
                }
                else
                {
                    //No SDCard Inserted
                    appSettings.Add("extstorage", -1);
                }
                appSettings.Save();
            }
            else if (sdCard == null)
            {
                appSettings["extstorage"] = -1;
            }
        }
コード例 #5
0
        /// <summary>
        /// Checks if there is an external storage and is ready for use.
        /// </summary>
        /// <returns>True, if there is an external device ready for use</returns>
        internal static async Task <ExternalStorageDevice> GetExternalStorageAsync()
        {
            if (sdCard == null)
            {
                IEnumerable <ExternalStorageDevice> devices =
                    await ExternalStorage.GetExternalStorageDevicesAsync();

                sdCard = devices.FirstOrDefault();
            }

            return(sdCard);
        }
コード例 #6
0
        async void Initialize()
        {
            _folderTree = new Stack<ExternalStorageFolder>();
            CurrentItems = new ObservableCollection<FileExplorerItem>();

            var storageAssets = await ExternalStorage.GetExternalStorageDevicesAsync();
            _currentStorageDevice = storageAssets.FirstOrDefault();

            LayoutRoot.Width = Application.Current.Host.Content.ActualWidth;
            LayoutRoot.Height = Application.Current.Host.Content.ActualHeight;

            if (_currentStorageDevice != null)
                GetTreeForFolder(_currentStorageDevice.RootFolder);
        }
コード例 #7
0
        public static async void ExportDb()
        {
            try
            {
                StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("weibodb.sqlite");

                ExternalStorageDevice device = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
                ExternalStorageFolder folder = await device.GetFolderAsync("WeiBo");

                //await file.CopyAsync(folder);
            }
            catch
            {
            }
        }
コード例 #8
0
        async void Initialize()
        {
            _folderTree  = new Stack <ExternalStorageFolder>();
            CurrentItems = new ObservableCollection <FileExplorerItem>();

            var storageAssets = await ExternalStorage.GetExternalStorageDevicesAsync();

            _currentStorageDevice = storageAssets.FirstOrDefault();

            LayoutRoot.Width  = Application.Current.Host.Content.ActualWidth;
            LayoutRoot.Height = Application.Current.Host.Content.ActualHeight;

            if (_currentStorageDevice != null)
            {
                GetTreeForFolder(_currentStorageDevice.RootFolder);
            }
        }
コード例 #9
0
ファイル: SdCardStorage.cs プロジェクト: karbazol/FBReaderCS
        public async Task<IEnumerable<ExternalStorageFile>> GetFilesAsync(params string[] extensions)
        {
            if (_sdCardStorage == null)
            {
                _sdCardStorage = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
            }

            //suppose SD-card is null
            if (_sdCardStorage == null)
            {
                throw new SdCardNotSupportedException();    
            }
            
            //read all files recursively
            var files = new List<ExternalStorageFile>();
            await GetFilesAsync(_sdCardStorage.RootFolder, files);
            return files;
        }
コード例 #10
0
        public async Task <IEnumerable <ExternalStorageFile> > GetFilesAsync(params string[] extensions)
        {
            if (_sdCardStorage == null)
            {
                _sdCardStorage = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
            }

            //suppose SD-card is null
            if (_sdCardStorage == null)
            {
                throw new SdCardNotSupportedException();
            }

            //read all files recursively
            var files = new List <ExternalStorageFile>();

            await GetFilesAsync(_sdCardStorage.RootFolder, files);

            return(files);
        }
コード例 #11
0
        public async Task <FilesResult> GetFiles()
        {
            FilesResult result = new FilesResult();

            ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            if (sdCard != null)
            {
                IEnumerable <ExternalStorageFile> files = await sdCard.RootFolder.GetFilesAsync();

                ExternalStorageFile file = files.FirstOrDefault();
                Files          = new ObservableCollection <ExternalStorageFile>(files.Where(f => f.Name.EndsWith(".txt")).ToList());
                result.Success = true;
            }
            else
            {
                result.Success = false;
                result.Message = "An SD card was not detected.";
            }
            return(result);
        }
コード例 #12
0
        private async void RefreshList()
        {
            // Clear the collection bound to the page.
            Files.Clear();

            // Connect to the current SD card.
            ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            // If the SD card is present, add KDBX files to the Files collection.
            if (_sdCard != null)
            {
                try
                {
                    // Look for a folder on the SD card named Files.
                    ExternalStorageFolder dbFolder = await _sdCard.GetFolderAsync("CodeSafe");

                    // Get all files from the CodeSafe folder.
                    IEnumerable <ExternalStorageFile> routeFiles = await dbFolder.GetFilesAsync();

                    // Add each KDBX file to the Files collection.
                    foreach (ExternalStorageFile esf in routeFiles)
                    {
                        if (esf.Path.EndsWith(".kdbx"))
                        {
                            Files.Add(esf);
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    // No CodeSafe folder is present.
                    MessageBox.Show("The CodeSafe folder is missing on your SD card. Add a CodeSafe folder containing at least one .kdbx file and try again.");
                }
            }
            else
            {
                // No SD card is present.
                MessageBox.Show("The SD card is mssing. Insert an SD card that has a CodeSafe folder containing at least one .kdbx file and try again.");
            }
        }
コード例 #13
0
        /// <summary>
        /// Checks to see if a folder exists on the sd card.
        /// </summary>
        /// <param name="folderName"></param>
        /// <returns></returns>
        public async Task <bool> SDCard_CheckFolder(string folderName)
        {
            try
            {
                if (folderName != string.Empty)
                {
                    ExternalStorageDevice sdcard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
                    if (sdcard != null)
                    {
                        ExternalStorageFolder folder = await sdcard.GetFolderAsync(folderName);

                        return(true);
                    }
                    return(false);
                }
                return(false);
            }
            catch (FileNotFoundException)
            {
                return(false);
            }
        }
コード例 #14
0
        private async System.Threading.Tasks.Task ShowList()
        {
            ExternalStorageDevice device = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
            ExternalStorageFolder folder = await device.RootFolder.GetFolderAsync("ADV");

            ExternalStorageFolder[] gamefolders = (await folder.GetFoldersAsync()).ToArray <ExternalStorageFolder>();
            foreach (ExternalStorageFolder f in gamefolders)
            {
                ExternalStorageFile[] files = (await f.GetFilesAsync()).ToArray <ExternalStorageFile>();
                int count = 0;
                foreach (ExternalStorageFile ef in files)
                {
                    if (ef.Name == "nscript.dat" || ef.Name == "nscript.___" || ef.Name == "nscr.dat")
                    {
                        count++;
                    }
                }
                if (count >= 1)
                {
                    List.Text += f.Name + '\n';
                }
            }
        }
コード例 #15
0
        async void InitializeStorageContainers()
        {
            if (StorageTarget == Interop.StorageTarget.ExternalStorage)
            {
                _externalFolderTree = new Stack <ExternalStorageFolder>();

                try
                {
                    var storageAssets = await ExternalStorage.GetExternalStorageDevicesAsync();

                    _currentStorageDevice = storageAssets.FirstOrDefault();

                    if (_currentStorageDevice != null)
                    {
                        GetTreeForExternalFolder(_currentStorageDevice.RootFolder);
                    }
                }
                catch
                {
                    Debug.WriteLine("EXT_STORAGE_ERROR: There was a problem accessing external storage.");
                }
            }
            else
            {
                _internalFolderTree = new Stack <StorageFolder>();

                try
                {
                    GetTreeForInternalFolder(ApplicationData.Current.LocalFolder);
                }
                catch
                {
                    Debug.WriteLine("INT_STORAGE_ERROR: There was a problem accessing internal storage.");
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Gets a file from SD Card
        /// </summary>
        /// <param name="sdfilePath"></param>
        /// <returns>File Stream</returns>
        public async Task <Stream> SDCard_ReadFile(string sdfilePath)
        {
            try
            {
                ExternalStorageDevice sdcard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

                if (sdcard != null)
                {
                    ExternalStorageFile file = await sdcard.GetFileAsync(sdfilePath);

                    return(await file.OpenForReadAsync());
                }
                else
                {
                    MessageBox.Show("Please check SD Card");
                    return(null);
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("File not found.");
                return(null);
            }
        }
コード例 #17
0
        GetFoldersAndFilesAsync(string path, StorageType storageType)
        {
            bool status = true;
            List <Dictionary <string, object> > fileList = new List <Dictionary <string, object> >();
            string error = String.Empty;

            try
            {
                if (storageType == StorageType.External)
                {
                    ExternalStorageDevice sdCard =
                        await FileManager.GetExternalStorageAsync();

                    if (sdCard != null)
                    {
                        ExternalStorageFolder root = await sdCard.GetFolderAsync(path);

                        IEnumerable <ExternalStorageFolder> folders = await root.GetFoldersAsync();

                        // Get the directories list
                        folders.ToList().ForEach(dir =>
                        {
                            Dictionary <string, object> fileInfo = new Dictionary <string, object>();
                            fileInfo.Add("name", dir.Path);
                            fileInfo.Add("type", FileType.Directory);
                            fileList.Add(fileInfo);
                        });

                        // Get the files list
                        IEnumerable <ExternalStorageFile> files = await root.GetFilesAsync();

                        files.ToList().ForEach(file =>
                        {
                            Dictionary <string, object> fileInfo = new Dictionary <string, object>();
                            fileInfo.Add("name", file.Path);
                            fileInfo.Add("type", FileType.File);
                            fileList.Add(fileInfo);
                        });
                    }
                    else
                    {
                        status = false;
                        error  = Constants.STRING_EXTERNAL_STORAGE_ERROR;
                    }
                }
                else if (FileManager.DirectoryExists(path))
                {
                    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        // Get the directories list
                        string[] files = storage.GetDirectoryNames(path + "\\*");
                        foreach (string file in files)
                        {
                            Dictionary <string, object> fileInfo = new Dictionary <string, object>();
                            fileInfo.Add("name", file);
                            fileInfo.Add("type", FileType.Directory);
                            fileList.Add(fileInfo);
                        }

                        // Get the files list
                        files = storage.GetFileNames(path + "\\*");
                        foreach (string file in files)
                        {
                            Dictionary <string, object> fileInfo = new Dictionary <string, object>();
                            fileInfo.Add("name", file);
                            fileInfo.Add("type", FileType.File);
                            fileList.Add(fileInfo);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                status = false;
                error  = e.Message;
                Logger.Error("Error retrieving file list as JSON. Reason - " + error);
            }

            return(Tuple.Create(status, fileList, error));
        }
コード例 #18
0
        async public void readfile(string filepath)
        {
            // enables progress indicator
            //ProgressIndicator indicator = SystemTray.ProgressIndicator;
            //if (indicator != null)
            //{
            //    //indicator.Text = "载入文件中 ...";
            //    //indicator.IsVisible = true;
            //}

            // Connect to the current SD card.
            ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            // If the SD card is present, add GPX files to the Routes collection.
            if (_sdCard != null)
            {
                try
                {
                    // get file of the specific path
                    ExternalStorageFile esf = await _sdCard.GetFileAsync(filepath);

                    if (esf != null)
                    {
                        Debug.WriteLine("found file " + esf.Name);
                        if (esf.Path.EndsWith(".txtx"))
                        {
                            // print its content
                            Stream x = await esf.OpenForReadAsync();

                            byte[] buffer = new byte[x.Length];
                            x.Read(buffer, 0, (int)x.Length);
                            x.Close();

                            string result = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                            //Debug.WriteLine(result);
                            //this.title.Text = "阅读器";
                            //Debug.WriteLine("title changed");
                            //this.content.Text = result.Substring(0, 10000);
                            //Debug.WriteLine("content changed");
                            this.contentString = result;

                            // cut content into pages
                            this.cutContentIntoPages();

                            // display first page
                            this.currentPage = 0;
                            this.displayCurrentPage();
                        }
                    }
                    Debug.WriteLine("done");
                }
                catch (FileNotFoundException)
                {
                    // No Routes folder is present.
                    this.content.Text = "Error loading file, reason: file not found";
                    Debug.WriteLine("file not found.");
                }
            }
            else
            {
                // No SD card is present.
                Debug.WriteLine("The SD card is mssing.");
            }
        }
コード例 #19
0
 public async Task <bool> GetIsAvailableAsync()
 {
     _sdCardStorage = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
     return(_sdCardStorage != null);
 }
コード例 #20
0
        async void InitializeStorageContainers()
        {
            if (StorageTarget == Interop.StorageTarget.ExternalStorage)
            {
                _externalFolderTree = new Stack<ExternalStorageFolder>();

                try
                {
                    var storageAssets = await ExternalStorage.GetExternalStorageDevicesAsync();
                    _currentStorageDevice = storageAssets.FirstOrDefault();

                    if (_currentStorageDevice != null)
                    {
                        GetTreeForExternalFolder(_currentStorageDevice.RootFolder);
                    }
                }
                catch
                {
                    Debug.WriteLine("EXT_STORAGE_ERROR: There was a problem accessing external storage.");
                }
            }
            else
            {
                _internalFolderTree = new Stack<StorageFolder>();

                try
                {
                    GetTreeForInternalFolder(ApplicationData.Current.LocalFolder);
                }
                catch
                {
                    Debug.WriteLine("INT_STORAGE_ERROR: There was a problem accessing internal storage.");
                }
            }
        }
コード例 #21
0
ファイル: SdCardUpdater.cs プロジェクト: puffchumpy/codesafe
        public static async void Update(DatabaseInfo info,
                                        Func <DatabaseInfo, bool> queryUpdate,
                                        ReportUpdateResult report)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (queryUpdate == null)
            {
                throw new ArgumentNullException("queryUpdate");
            }
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            // Connect to the current SD card.
            ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            // If the SD card is present, add KDBX files to the Files collection.
            if (_sdCard != null)
            {
                try
                {
                    // Look for a folder on the SD card named Files.
                    ExternalStorageFolder dbFolder = await _sdCard.GetFolderAsync("CodeSafe");

                    // Get all files from the CodeSafe folder.
                    IEnumerable <ExternalStorageFile> routeFiles = await dbFolder.GetFilesAsync();

                    bool found = false;
                    foreach (ExternalStorageFile esf in routeFiles)
                    {
                        if (esf.Name.RemoveKdbx() == info.Details.Name)
                        {
                            found = true;
                            Stream stream = await esf.OpenForReadAsync();

                            var check = DatabaseVerifier
                                        .VerifyUnattened(stream);

                            if (check.Result == VerifyResultTypes.Error)
                            {
                                report(info, SyncResults.Failed,
                                       check.Message);
                                return;
                            }

                            info.SetDatabase(stream, info.Details);
                            report(info, SyncResults.Downloaded, null);

                            break;
                        }
                    }

                    if (!found)
                    {
                        MessageBox.Show("The original database file is not found in CodeSafe folder on your SD card anymore. Did you delete it?");
                    }
                }
                catch (FileNotFoundException)
                {
                    // No CodeSafe folder is present.
                    MessageBox.Show("The CodeSafe folder is missing on your SD card. Add a CodeSafe folder containing at least one .kdbx file and try again.");
                }
            }
            else
            {
                // No SD card is present.
                MessageBox.Show("The SD card is mssing. Insert an SD card that has a CodeSafe folder containing at least one .kdbx file and try again.");
            }
        }
コード例 #22
0
ファイル: SdCardStorage.cs プロジェクト: karbazol/FBReaderCS
 public async Task<bool> GetIsAvailableAsync()
 {
     _sdCardStorage = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
     return _sdCardStorage != null;
 }
コード例 #23
0
        private async void buildFileList()
        {
            // enables progress indicator
            //ProgressIndicator indicator = SystemTray.ProgressIndicator;
            //if (indicator != null)
            //{
            //    //indicator.Text = "载入文件中 ...";
            //    //indicator.IsVisible = true;
            //}

            this.files = new List <Book>();

            Book sampleBook = new Book();

            sampleBook.Name     = "《三国演义》节选";
            sampleBook.Path     = "试阅文本";
            sampleBook.IsSample = true;
            this.files.Add(sampleBook);

            // sandbox
            try
            {
                // sandbox root folder
                IStorageFolder routesFolder = ApplicationData.Current.LocalFolder;

                // Get all files from the Routes folder.
                IEnumerable <StorageFile> files = await routesFolder.GetFilesAsync();

                Debug.WriteLine("found folder");
                // Add each GPX file to the Routes collection.
                foreach (StorageFile esf in files)
                {
                    Debug.WriteLine("found file " + esf.Name);
                    if (esf.Path.EndsWith(".txtx"))
                    {
                        int    loc      = esf.Name.LastIndexOf(".txtx");
                        string bookname = esf.Name.Substring(0, loc);

                        // remove first part of book names
                        loc = bookname.LastIndexOf("-");
                        if (loc + 1 < bookname.Length)
                        {
                            bookname = bookname.Substring(loc + 1).Trim();
                        }

                        // add to file list
                        Book newBook = new Book();
                        newBook.Name = bookname;
                        newBook.Path = "\\" + esf.Path.Split(new String[] { "\\" }, StringSplitOptions.RemoveEmptyEntries).Last();
                        this.files.Add(newBook);
                    }
                }
                Debug.WriteLine("done");
            }
            catch (FileNotFoundException)
            {
                // No Routes folder is present.
                Debug.WriteLine("Folder not found.");
            }

            // Connect to the current SD card.
            ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();

            // If the SD card is present, add GPX files to the Routes collection.
            if (_sdCard != null)
            {
                // root folder
                try
                {
                    // Look for a folder on the SD card
                    ExternalStorageFolder folder = _sdCard.RootFolder;

                    // Get all files from the Routes folder.
                    IEnumerable <ExternalStorageFile> files = await folder.GetFilesAsync();

                    Debug.WriteLine("found folder");
                    // Add each GPX file to the Routes collection.
                    foreach (ExternalStorageFile esf in files)
                    {
                        Debug.WriteLine("found file " + esf.Name);
                        if (esf.Path.EndsWith(".txtx"))
                        {
                            int    loc      = esf.Name.LastIndexOf(".txtx");
                            string bookname = esf.Name.Substring(0, loc);

                            // remove first part of book names
                            loc = bookname.LastIndexOf("-");
                            if (loc + 1 < bookname.Length)
                            {
                                bookname = bookname.Substring(loc + 1).Trim();
                            }

                            // add to file list
                            Book newBook = new Book();
                            newBook.Name = bookname;
                            newBook.Path = esf.Path;
                            this.files.Add(newBook);
                        }
                    }
                    Debug.WriteLine("done");
                }
                catch (FileNotFoundException)
                {
                    // No Routes folder is present.
                    Debug.WriteLine("Folder not found.");
                }

                // Book
                try
                {
                    // Look for a folder on the SD card named Routes.
                    ExternalStorageFolder folder = await _sdCard.GetFolderAsync("Book");

                    // Get all files from the Routes folder.
                    IEnumerable <ExternalStorageFile> files = await folder.GetFilesAsync();

                    Debug.WriteLine("found folder");
                    // Add each GPX file to the Routes collection.
                    foreach (ExternalStorageFile esf in files)
                    {
                        Debug.WriteLine("found file " + esf.Name);
                        if (esf.Path.EndsWith(".txtx"))
                        {
                            int    loc      = esf.Name.LastIndexOf(".txtx");
                            string bookname = esf.Name.Substring(0, loc);

                            // remove first part of book names
                            loc = bookname.LastIndexOf("-");
                            if (loc + 1 < bookname.Length)
                            {
                                bookname = bookname.Substring(loc + 1).Trim();
                            }

                            // add to file list
                            Book newBook = new Book();
                            newBook.Name = bookname;
                            newBook.Path = esf.Path;
                            this.files.Add(newBook);
                        }
                    }
                    Debug.WriteLine("done");
                }
                catch (FileNotFoundException)
                {
                    // No Routes folder is present.
                    Debug.WriteLine("Folder not found.");
                }

                // Books
                try
                {
                    // Look for a folder on the SD card named Routes.
                    ExternalStorageFolder folder = await _sdCard.GetFolderAsync("Books");

                    // Get all files from the Routes folder.
                    IEnumerable <ExternalStorageFile> files = await folder.GetFilesAsync();

                    Debug.WriteLine("found folder");
                    // Add each GPX file to the Routes collection.
                    foreach (ExternalStorageFile esf in files)
                    {
                        Debug.WriteLine("found file " + esf.Name);
                        if (esf.Path.EndsWith(".txtx"))
                        {
                            int    loc      = esf.Name.LastIndexOf(".txtx");
                            string bookname = esf.Name.Substring(0, loc);

                            // remove first part of book names
                            loc = bookname.LastIndexOf("-");
                            if (loc + 1 < bookname.Length)
                            {
                                bookname = bookname.Substring(loc + 1).Trim();
                            }

                            // add to file list
                            Book newBook = new Book();
                            newBook.Name = bookname;
                            newBook.Path = esf.Path;
                            this.files.Add(newBook);
                        }
                    }
                    Debug.WriteLine("done");
                }
                catch (FileNotFoundException)
                {
                    // No Routes folder is present.
                    Debug.WriteLine("Folder not found.");
                }
            }
            else
            {
                // No SD card is present.
                Debug.WriteLine("The SD card is mssing.");
            }

            this.fileList.ItemsSource = this.files;
        }