Skip to content

Commit d3fe83d

Browse files
committed
Add filetype assoc
1 parent 4d72a1b commit d3fe83d

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

src/Files.Backend/Services/Settings/IPreferencesSettingsService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,5 @@ public interface IPreferencesSettingsService : IBaseSettingsService, INotifyProp
109109
/// A list containing all paths to tabs closed on last session.
110110
/// </summary>
111111
List<string> LastSessionTabList { get; set; }
112-
113-
/// <summary>
114-
/// Gets or sets a value indicating whether or not to open archives in Files.
115-
/// </summary>
116-
bool OpenArchivesInFiles { get; set; }
117112
}
118113
}

src/Files.Package/Package.appxmanifest

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@
6969
</uap5:Extension>
7070
<Extension Category="windows.updateTask" EntryPoint="BackgroundTasks.UpdateTask" />
7171
<uap:Extension Category="windows.fileTypeAssociation">
72-
<uap:FileTypeAssociation Name="zip">
72+
<uap:FileTypeAssociation Name="archives">
7373
<uap:SupportedFileTypes>
7474
<uap:FileType>.zip</uap:FileType>
75+
<uap:FileType>.7z</uap:FileType>
76+
<uap:FileType>.rar</uap:FileType>
77+
<uap:FileType>.tar</uap:FileType>
7578
</uap:SupportedFileTypes>
7679
</uap:FileTypeAssociation>
7780
</uap:Extension>

src/Files.Shared/Extensions/LinqExtensions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ public static class LinqExtensions
4242
return defaultValue;
4343
}
4444

45+
public static async Task<TValue?> GetAsync<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<Task<TValue?>> defaultValueFunc)
46+
{
47+
if (dictionary is null || key is null)
48+
{
49+
return await defaultValueFunc();
50+
}
51+
if (!dictionary.ContainsKey(key))
52+
{
53+
var defaultValue = await defaultValueFunc();
54+
if (defaultValue is TValue value)
55+
{
56+
dictionary.Add(key, value);
57+
}
58+
return defaultValue;
59+
}
60+
return dictionary[key];
61+
}
62+
4563
public static async Task<IEnumerable<T>> WhereAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
4664
{
4765
var results = await Task.WhenAll(source.Select(async x => (x, await predicate(x))));

src/Files.Uwp/Filesystem/StorageItems/ZipStorageFolder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public static bool IsZipPath(string path, bool includeRoot = true)
7979
private static Dictionary<string, bool> defaultAppDict = new Dictionary<string, bool>();
8080
public static async Task<bool> CheckDefaultZipApp(string filePath)
8181
{
82-
IUserSettingsService userSettingsService = Ioc.Default.GetService<IUserSettingsService>();
8382
Func<Task<bool>> queryFileAssoc = async () =>
8483
{
8584
var assoc = await NativeWinApiHelper.GetFileAssociationAsync(filePath);
@@ -91,7 +90,7 @@ public static async Task<bool> CheckDefaultZipApp(string filePath)
9190
return true;
9291
};
9392
var ext = System.IO.Path.GetExtension(filePath)?.ToLowerInvariant();
94-
return userSettingsService.PreferencesSettingsService.OpenArchivesInFiles || await defaultAppDict.Get(ext, queryFileAssoc());
93+
return await defaultAppDict.GetAsync(ext, queryFileAssoc);
9594
}
9695

9796
public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
@@ -106,7 +105,7 @@ public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
106105
if (marker is not -1)
107106
{
108107
var containerPath = path.Substring(0, marker + ext.Length);
109-
if (await CheckDefaultZipApp(path) && CheckAccess(containerPath))
108+
if (CheckAccess(containerPath))
110109
{
111110
return new ZipStorageFolder(path, containerPath);
112111
}

src/Files.Uwp/ServicesImplementation/Settings/PreferencesSettingsService.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ public List<string> LastSessionTabList
140140
set => Set(value);
141141
}
142142

143-
public bool OpenArchivesInFiles
144-
{
145-
get => Get(true);
146-
set => Set(value);
147-
}
148-
149143
protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
150144
{
151145
switch (e.SettingName)
@@ -167,7 +161,6 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
167161
case nameof(ContinueLastSessionOnStartUp):
168162
case nameof(OpenNewTabOnStartup):
169163
case nameof(AlwaysOpenNewInstance):
170-
case nameof(OpenArchivesInFiles):
171164
Analytics.TrackEvent($"{e.SettingName} {e.NewValue}");
172165
break;
173166
}
@@ -194,7 +187,6 @@ public void ReportToAppCenter()
194187
Analytics.TrackEvent($"{nameof(ContinueLastSessionOnStartUp)}, {ContinueLastSessionOnStartUp}");
195188
Analytics.TrackEvent($"{nameof(OpenNewTabOnStartup)}, {OpenNewTabOnStartup}");
196189
Analytics.TrackEvent($"{nameof(AlwaysOpenNewInstance)}, {AlwaysOpenNewInstance}");
197-
Analytics.TrackEvent($"{nameof(OpenArchivesInFiles)}, {OpenArchivesInFiles}");
198190
}
199191
}
200192
}

0 commit comments

Comments
 (0)