private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                // Application now has read/write access to the picked file
                StorageFolder folder = await file.GetParentAsync();

                List <string> fileTypeFilter = new List <string>();
                fileTypeFilter.Add(".png");
                var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);

                // Create query and retrieve files
                var query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
                IReadOnlyList <StorageFile> fileList = await query.GetFilesAsync();

                // Process results
                foreach (StorageFile item in fileList)
                {
                    // Process file
                    System.Diagnostics.Debug.WriteLine(item.DisplayName);
                }
            }
            else
            {
            }
        }
예제 #2
0
        public async void ButtonOpen(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add("*");
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            texteditor editor = new texteditor();

            editor.Editorclass.Readfile(file, ref editor1.edit);
            editors.Add(editor);
            StorageFolder tempfold = await file.GetParentAsync();

            fileviewer1.setdirectory(tempfold);
        }
예제 #3
0
        /// <summary>
        /// Opens a file picker to choose a local .2fa datafile
        /// </summary>
        /// <returns></returns>
        public async Task <bool> SetLocalFile(bool changePath = false)
        {
            if (!changePath)
            {
                SelectedIndex = 1;
            }
            FileOpenPicker filePicker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.ComputerFolder
            };

            filePicker.FileTypeFilter.Add(".2fa");
            IsLoading = true;
            Windows.Storage.StorageFile file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                IsLoading          = false;
                LocalStorageFolder = await file.GetParentAsync();

                //set folder to the access list
                //StorageApplicationPermissions.FutureAccessList.Add(LocalStorageFolder, "metadata");
                //StorageApplicationPermissions.FutureAccessList.Add(file, "metadata");

                DateFileName = file.Name;
                return(true);
            }
            else
            {
                //prevents the change of the index, if the user want to change
                //the path, but cancel the dialog
                IsLoading = false;
                if (!changePath)
                {
                    SelectedIndex = 0;
                }
                return(false);
            }
        }
예제 #4
0
 private async Task<string> GetPath(StorageFile file)
 {
     string path = "";
     if (file != null)
     {
         if (!string.IsNullOrEmpty(file.Path))
             return file.Path;
         path = file.Name;
         var folder = await file.GetParentAsync();
         while (folder != null)
         {
             path = folder.Name + "\\" + path;
             folder = await folder.GetParentAsync();
         }
     }
     return path;
 }
 /// <summary>
 /// Accepts a StorageFile and returns the name of the folder the file is stored within
 /// </summary>
 public static async Task<string> GetParentFolderNameAsync(StorageFile imageFile)
 {
     var parentFolder = await imageFile.GetParentAsync();
     return parentFolder.Name;
 }
        public async Task<bool> AddImageToWhitelistAsync(StorageFile imageFile, string personName = null)
        {
            bool isSuccess = true;

            // imageFile should be valid image file
            if (!FaceApiUtils.ValidateImageFile(imageFile))
            {
                isSuccess = false;
            }
            else
            {
                var filePath = imageFile.Path;

                // If personName is null/empty, use the folder name as person name
                if(string.IsNullOrEmpty(personName))
                {
                    personName = await FaceApiUtils.GetParentFolderNameAsync(imageFile);
                }

                // If person name doesn't exists, add it
                var personId = _whitelist.GetPersonIdByName(personName);
                if(personId == Guid.Empty)
                {
                    var folder = await imageFile.GetParentAsync();
                    personId = await CreatePerson(personName, folder);
                }

                // detect faces
                var faceId = await DetectFaceFromImage(imageFile);
                await AddFace(personId, faceId, imageFile.Path);

                // train whitelist
                isSuccess = await TrainingWhitelistAsync();
            }

            return isSuccess;
        }
        public async Task FinishDownload(StorageFile destinationFile)
        {
            if (destinationFile != null)
            {
                StorageFolder parentFolder = await destinationFile.GetParentAsync();

                if (destinationFile.FileType.EndsWith(DownloadExtension, StringComparison.OrdinalIgnoreCase))
                {
                    var realDestinationFileName = destinationFile.Name.Substring(0,
                        destinationFile.Name.IndexOf(DownloadExtension, StringComparison.OrdinalIgnoreCase));
                    await FileUtils.MoveFile(destinationFile, parentFolder, realDestinationFileName);
                    destinationFile = await FileUtils.GetFile(parentFolder, realDestinationFileName);
                    if (destinationFile == null)
                    {
                        throw new InvalidOperationException("File move while finalizing file failed.");
                    }
                }

                if (destinationFile.FileType.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    IsDownloading = true;
                    IsIndeterminate = true;
                    InstallationStep = Resources.extracting_message;

                    try
                    {
                        await QuranApp.NativeProvider.ExtractZip(destinationFile, parentFolder);
                    }
                    finally
                    {
                        await FileUtils.SafeFileDelete(destinationFile);
                    }
                }
            }
        }