Esempio n. 1
0
        public static async Task <FileModel> OpenFile(StorageFile file, bool addToRecentList)
        {
            try
            {
                FileModel fileModel = new FileModel();
                fileModel.ContentType = file.ContentType;

                if (addToRecentList)
                {
                    if (!RecentFiles.Any(x => x.Path == file.Path))
                    {
                        RecentFiles.Add(new FileModel()
                        {
                            Path = file.Path, Name = file.Name
                        });
                        SaveRecentFileList();
                        StorageApplicationPermissions.FutureAccessList.Add(file);
                    }
                }

                var openResponse = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                fileModel.Stream = openResponse;

                return(fileModel);
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog("There was an error opening the specified file.\r\n\r\n" + ex.Message, "Error opening file");
                await dialog.ShowAsync();

                return(null);
            }
        }
Esempio n. 2
0
        public string GetDefaultDictionariesFolder()
        {
            // Try to use the directory of the last opened dictionary.
            if (RecentFiles.Any())
            {
                string folder = Path.GetDirectoryName(RecentFiles[0]);
                if (folder != null && Directory.Exists(folder))
                {
                    return(folder);
                }
            }

            // Try to use the directory from the release package.
            {
                string folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dictionaries");
                if (Directory.Exists(folder))
                {
                    return(folder);
                }
            }

            return(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
        }