Beispiel #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);
        }
Beispiel #2
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
            {
            }
        }
Beispiel #3
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.");
            }
        }
Beispiel #4
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);
            }
        }
        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;
        }
Beispiel #6
0
        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.");
            }
        }
Beispiel #7
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));
        }