• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ParadoxGameConverters / Fronter.NET / 12979648212

27 Jan 2025 12:16AM UTC coverage: 18.767% (-0.006%) from 18.773%
12979648212

Pull #763

github

web-flow
Merge 3c653fa8a into dcd0095bb
Pull Request #763: Speed up OnFrameworkInitializationCompleted, remove some async void usage

73 of 628 branches covered (11.62%)

Branch coverage included in aggregate %.

2 of 18 new or added lines in 3 files covered. (11.11%)

1 existing line in 1 file now uncovered.

548 of 2681 relevant lines covered (20.44%)

9.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.45
/Fronter.NET/ViewModels/PathPickerViewModel.cs
1
using Avalonia.Platform.Storage;
2
using commonItems;
3
using Fronter.Extensions;
4
using Fronter.Models.Configuration;
5
using Fronter.Views;
6
using ReactiveUI;
7
using System.Collections.Generic;
8
using System.Collections.ObjectModel;
9
using System.Diagnostics.CodeAnalysis;
10
using System.IO;
11
using System.Linq;
12
using System.Reactive;
13
using System.Threading.Tasks;
14

15
namespace Fronter.ViewModels;
16

17
/// <summary>
18
///     The PathPickerViewModel lets the user select paths to various stuff the converter needs to know where to find.
19
/// </summary>
20
internal sealed class PathPickerViewModel : ViewModelBase {
21
        public PathPickerViewModel(Config config) {
4✔
22
                RequiredFolders = new ObservableCollection<RequiredFolder>(config.RequiredFolders);
2✔
23
                RequiredFiles = new ObservableCollection<RequiredFile>(config.RequiredFiles);
2✔
24

25
                // Create reactive commands.
26
                OpenFolderDialogCommand = ReactiveCommand.CreateFromTask<RequiredFolder>(OpenFolderDialog);
2✔
27
                OpenFileDialogCommand = ReactiveCommand.CreateFromTask<RequiredFile>(OpenFileDialog);
2✔
28
        }
2✔
29

30
        public ObservableCollection<RequiredFolder> RequiredFolders { get; }
×
31
        public ObservableCollection<RequiredFile> RequiredFiles { get; }
×
32

33
        public ReactiveCommand<RequiredFolder, Unit> OpenFolderDialogCommand { get; }
×
34
        public ReactiveCommand<RequiredFile, Unit> OpenFileDialogCommand { get; }
×
35

36
        private static async Task<IStorageFolder?> GetStartLocationForFile(RequiredFile file, IStorageProvider storageProvider) {
×
37
                string? path = null;
×
38
                if (file.InitialDirectory is not null) {
×
39
                        path = file.InitialDirectory;
×
40
                } else if (!string.IsNullOrEmpty(file.Value)) {
×
41
                        path = CommonFunctions.GetPath(file.Value);
×
42
                }
×
43

44
                if (string.IsNullOrEmpty(path)) {
×
45
                        return null;
×
46
                }
47
                if (!Directory.Exists(path)) {
×
48
                        return null;
×
49
                }
50

51
                return await storageProvider.TryGetFolderFromPathAsync(path);
×
52
        }
×
53

54
        private static async Task<IStorageFolder?> GetStartLocationForFolder(RequiredFolder folder, IStorageProvider storageProvider) {
×
55
                var folderPath = folder.Value;
×
56
                if (string.IsNullOrEmpty(folderPath)) {
×
57
                        return null;
×
58
                }
59
                if (!Directory.Exists(folderPath)) {
×
60
                        return null;
×
61
                }
62
                return await storageProvider.TryGetFolderFromPathAsync(folderPath);
×
63
        }
×
64

65
        [SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")]
NEW
66
        public async Task OpenFolderDialog(RequiredFolder folder) {
×
67
                var storageProvider = MainWindow.Instance.StorageProvider;
×
68

69
                var options = new FolderPickerOpenOptions {
×
70
                        Title = TranslationSource.Instance[folder.DisplayName],
×
71
                        SuggestedStartLocation = await GetStartLocationForFolder(folder, storageProvider),
×
72
                };
×
73

74
                var window = MainWindow.Instance;
×
75
                var result = await window.StorageProvider.OpenFolderPickerAsync(options);
×
76
                var selectedFile = result.FirstOrDefault(defaultValue: null);
×
77
                if (selectedFile is null) {
×
78
                        Logger.Warn($"{folder.Name}: no folder selected!");
×
79
                        return;
×
80
                }
81

82
                var selectedFileUri = selectedFile.Path;
×
83
                if (!selectedFileUri.IsAbsoluteUri) {
×
84
                        Logger.Warn($"URI of folder \"{selectedFile.Name}\" is not absolute!");
×
85
                }
×
86
                var absolutePath = selectedFileUri.LocalPath;
×
87
                folder.Value = absolutePath;
×
88
        }
×
89

90
        [SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")]
NEW
91
        public async Task OpenFileDialog(RequiredFile file) {
×
92
                var storageProvider = MainWindow.Instance.StorageProvider;
×
93

94
                var options = new FilePickerOpenOptions {
×
95
                        Title = TranslationSource.Instance[file.DisplayName],
×
96
                        AllowMultiple = false,
×
97
                        SuggestedStartLocation = await GetStartLocationForFile(file, storageProvider),
×
98
                };
×
99

100
                var fileType = new FilePickerFileType(file.AllowedExtension.TrimStart('*', '.')) {
×
101
                        Patterns = [file.AllowedExtension],
×
102
                };
×
103
                options.FileTypeFilter = new List<FilePickerFileType> { fileType };
×
104

105
                var result = await storageProvider.OpenFilePickerAsync(options);
×
106
                var selectedFile = result.FirstOrDefault(defaultValue: null);
×
107
                if (selectedFile is null) {
×
108
                        Logger.Warn($"{file.Name}: no file selected!");
×
109
                        return;
×
110
                }
111
                var selectedFileUri = selectedFile.Path;
×
112
                if (!selectedFileUri.IsAbsoluteUri) {
×
113
                        Logger.Warn($"URI of file \"{selectedFile.Name}\" is not absolute!");
×
114
                }
×
115
                var absolutePath = selectedFileUri.LocalPath;
×
116
                file.Value = absolutePath;
×
117
        }
×
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc