Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ListBoxImportGPX_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox lb = (ListBox)sender;

            if (lb.SelectedItem != null)
            {
                try
                {
                    SetProgressIndicator(true, "");

                    ExternalStorageFile esf = (ExternalStorageFile)lb.SelectedItem;
                    Stream fileStream       = await _fileIO.SDCard_ReadFile(esf.Path);

                    if (chkImport.IsChecked == true)
                    {
                        SetProgressIndicator(true, "Importing route to local memory.");
                        App.ImportTrk = _serializer.ReadGpxFileStastics(await _fileIO.SDCard_ReadFile(esf.Path), _miscFunctions.RemoveFileExtension(esf.Name));
                        NavigationService.Navigate(new Uri("/Save.xaml?import=true", UriKind.Relative));
                    }
                    else
                    {
                        SetProgressIndicator(true, "Loading route in map.");
                        App.MapFunctions.LoadTrackInMap(_serializer.ReadGPXFile(fileStream));
                        App.CenterMapLock = false;
                        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                    }
                    SetProgressIndicator(false, "");
                }
                catch (Exception ex)
                {
                    SetProgressIndicator(false, "");
                    MessageBox.Show(ex.Message);
                }
            }
        }
        async private void FileExplorerItemSelect(object sender, System.Windows.Input.GestureEventArgs e)
        {
            FileExplorerItem item = ((FrameworkElement)sender).Tag as FileExplorerItem;

            if (item.IsFolder)
            {
                if (StorageTarget == Interop.StorageTarget.ExternalStorage)
                {
                    GetTreeForExternalFolder(await _externalFolderTree.First().GetFolderAsync(item.Name));
                }
                else
                {
                    GetTreeForInternalFolder(await _internalFolderTree.First().GetFolderAsync(item.Name));
                }
            }
            else
            {
                if (SelectionMode == Interop.SelectionMode.File)
                {
                    if (StorageTarget == Interop.StorageTarget.ExternalStorage)
                    {
                        ExternalStorageFile file = await _currentStorageDevice.GetFileAsync(item.Path);

                        Dismiss(file);
                    }
                    else
                    {
                        StorageFolder folder = _internalFolderTree.Pop();
                        StorageFile   file   = await folder.GetFileAsync(item.Name);

                        Dismiss(file);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private async Task LoadDatabaseFile(ExternalStorageFile file)
        {
            Stream stream = await file.OpenForReadAsync();

            var info = new DatabaseInfo();

            info.SetDatabase(stream, new DatabaseDetails
            {
                Name   = file.Name.RemoveKdbx(),
                Type   = SourceTypes.Updatable,
                Source = DatabaseUpdater.SDCARD_UPDATER,
            });
        }
Ejemplo n.º 4
0
        async void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstCore.SelectedItem != null)
            {
                FileExplorerItem item = (FileExplorerItem)lstCore.SelectedItem;
                if (item.IsFolder)
                {
                    GetTreeForFolder(await _folderTree.First().GetFolderAsync(item.Name));
                }
                else
                {
                    ExternalStorageFile file = await _currentStorageDevice.GetFileAsync(item.Path);

                    Dismiss(file);
                }
            }
        }
Ejemplo n.º 5
0
 async void filePicker_OnDismiss(ExternalStorageFile file)
 {
     if (file != null)
     {
         StatusBox.Text = "Wait...";
        // string incomingRouteFilename = Windows.Phone.Storage.SharedAccess.SharedStorageAccessManager.GetSharedFileName(file.Name);
        // StatusBox.Text = incomingRouteFilename;
         Stream photoToSave = await file.OpenForReadAsync();
         StorageFolder localFolder = ApplicationData.Current.LocalFolder;
         StorageFile photoFile = await localFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting);
         using (var photoOutputStream = await photoFile.OpenStreamForWriteAsync())
         {
             await photoToSave.CopyToAsync(photoOutputStream);
         }
         StatusBox.Text = file.Path + file.Name;
     }
 }
Ejemplo n.º 6
0
        async void filePicker_OnDismiss(ExternalStorageFile file)
        {
            if (file != null)
            {
                StatusBox.Text = "Wait...";
                // string incomingRouteFilename = Windows.Phone.Storage.SharedAccess.SharedStorageAccessManager.GetSharedFileName(file.Name);
                // StatusBox.Text = incomingRouteFilename;
                Stream photoToSave = await file.OpenForReadAsync();

                StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                StorageFile   photoFile   = await localFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting);

                using (var photoOutputStream = await photoFile.OpenStreamForWriteAsync())
                {
                    await photoToSave.CopyToAsync(photoOutputStream);
                }
                StatusBox.Text = file.Path + file.Name;
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        void ExplorerControl_OnDismiss(Control.Interop.StorageTarget target, object file)
        {
            if (file != null)
            {
                switch (target)
                {
                case Control.Interop.StorageTarget.ExternalStorage:
                {
                    if (ExplorerControl.SelectionMode == SelectionMode.File)
                    {
                        ExternalStorageFile _stFile = (ExternalStorageFile)file;
                        Debug.WriteLine(_stFile.Path);
                    }
                    else if (ExplorerControl.SelectionMode == SelectionMode.Folder)
                    {
                        ExternalStorageFolder folder = (ExternalStorageFolder)file;
                        Debug.WriteLine(folder.Path);
                    }
                    else
                    {
                        List <FileExplorerItem> items = (List <FileExplorerItem>)file;
                        foreach (var item in items)
                        {
                            Debug.WriteLine(item.Path);
                        }
                    }
                    break;
                }

                case Control.Interop.StorageTarget.IsolatedStorage:
                {
                    StorageFile _stFile = (StorageFile)file;
                    Debug.WriteLine(_stFile.Path);
                    break;
                }
                }
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        private void Dismiss(ExternalStorageFile file)
        {
            if (_currentPage != null)
            {
                _currentPage.BackKeyPress -= OnBackKeyPress;
            }

            RootPopup.IsOpen = false;

            if (_mustRestoreApplicationBar)
            {
                _currentPage.ApplicationBar.IsVisible = true;
            }

            if (_mustRestoreSystemTray)
            {
                SystemTray.IsVisible = true;
            }

            if (OnDismiss != null)
            {
                OnDismiss(file);
            }
        }
Ejemplo n.º 11
0
        private async void lstBrowse_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox lb = (ListBox)sender;

            if (lb.SelectedItem != null)
            {
                try
                {
                    ExternalStorageFile esf = (ExternalStorageFile)lb.SelectedItem;
                    await LoadDatabaseFile(esf);
                }
                catch (FileNotFoundException)
                {
                    // The route is not present on the SD card.
                    MessageBox.Show("That file is missing on your SD card.");
                }
                catch (Exception)
                {
                    MessageBox.Show("Error opening file on your SD card.");
                }

                Dispatcher.BeginInvoke(this.BackToDBs);
            }
        }
Ejemplo n.º 12
0
        private void Dismiss(ExternalStorageFile file)
        {
            if (_currentPage != null)
            {
                _currentPage.BackKeyPress -= OnBackKeyPress;
            }

            RootPopup.IsOpen = false;

            if (_mustRestoreApplicationBar)
                _currentPage.ApplicationBar.IsVisible = true;

            if (_mustRestoreSystemTray)
                SystemTray.IsVisible = true;

            if (OnDismiss != null)
                OnDismiss(file);
        }
Ejemplo n.º 13
0
 public ExternalStorageHelper(ExternalStorageFile esf)
 {
     this.esf = esf;
 }
Ejemplo n.º 14
0
        private async Task LoadDatabaseFile(ExternalStorageFile file)
        {
            Stream stream = await file.OpenForReadAsync();

            var info = new DatabaseInfo();

            info.SetDatabase(stream, new DatabaseDetails
            {
                Name = file.Name.RemoveKdbx(),
                Type = SourceTypes.Updatable,
                Source = DatabaseUpdater.SDCARD_UPDATER,
            });
        }
Ejemplo n.º 15
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.");
            }
        }