Skip to content

Commit

Permalink
Add filetype assoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gave92 committed Aug 2, 2022
1 parent 4d72a1b commit d3fe83d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,5 @@ public interface IPreferencesSettingsService : IBaseSettingsService, INotifyProp
/// A list containing all paths to tabs closed on last session.
/// </summary>
List<string> LastSessionTabList { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to open archives in Files.
/// </summary>
bool OpenArchivesInFiles { get; set; }
}
}
5 changes: 4 additions & 1 deletion src/Files.Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@
</uap5:Extension>
<Extension Category="windows.updateTask" EntryPoint="BackgroundTasks.UpdateTask" />
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="zip">
<uap:FileTypeAssociation Name="archives">
<uap:SupportedFileTypes>
<uap:FileType>.zip</uap:FileType>
<uap:FileType>.7z</uap:FileType>
<uap:FileType>.rar</uap:FileType>
<uap:FileType>.tar</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
Expand Down
18 changes: 18 additions & 0 deletions src/Files.Shared/Extensions/LinqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ public static class LinqExtensions
return defaultValue;
}

public static async Task<TValue?> GetAsync<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<Task<TValue?>> defaultValueFunc)
{
if (dictionary is null || key is null)
{
return await defaultValueFunc();
}
if (!dictionary.ContainsKey(key))
{
var defaultValue = await defaultValueFunc();
if (defaultValue is TValue value)
{
dictionary.Add(key, value);
}
return defaultValue;
}
return dictionary[key];
}

public static async Task<IEnumerable<T>> WhereAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
{
var results = await Task.WhenAll(source.Select(async x => (x, await predicate(x))));
Expand Down
5 changes: 2 additions & 3 deletions src/Files.Uwp/Filesystem/StorageItems/ZipStorageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static bool IsZipPath(string path, bool includeRoot = true)
private static Dictionary<string, bool> defaultAppDict = new Dictionary<string, bool>();
public static async Task<bool> CheckDefaultZipApp(string filePath)
{
IUserSettingsService userSettingsService = Ioc.Default.GetService<IUserSettingsService>();
Func<Task<bool>> queryFileAssoc = async () =>
{
var assoc = await NativeWinApiHelper.GetFileAssociationAsync(filePath);
Expand All @@ -91,7 +90,7 @@ public static async Task<bool> CheckDefaultZipApp(string filePath)
return true;
};
var ext = System.IO.Path.GetExtension(filePath)?.ToLowerInvariant();
return userSettingsService.PreferencesSettingsService.OpenArchivesInFiles || await defaultAppDict.Get(ext, queryFileAssoc());
return await defaultAppDict.GetAsync(ext, queryFileAssoc);
}

public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
Expand All @@ -106,7 +105,7 @@ public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
if (marker is not -1)
{
var containerPath = path.Substring(0, marker + ext.Length);
if (await CheckDefaultZipApp(path) && CheckAccess(containerPath))
if (CheckAccess(containerPath))
{
return new ZipStorageFolder(path, containerPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ public List<string> LastSessionTabList
set => Set(value);
}

public bool OpenArchivesInFiles
{
get => Get(true);
set => Set(value);
}

protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
{
switch (e.SettingName)
Expand All @@ -167,7 +161,6 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
case nameof(ContinueLastSessionOnStartUp):
case nameof(OpenNewTabOnStartup):
case nameof(AlwaysOpenNewInstance):
case nameof(OpenArchivesInFiles):
Analytics.TrackEvent($"{e.SettingName} {e.NewValue}");
break;
}
Expand All @@ -194,7 +187,6 @@ public void ReportToAppCenter()
Analytics.TrackEvent($"{nameof(ContinueLastSessionOnStartUp)}, {ContinueLastSessionOnStartUp}");
Analytics.TrackEvent($"{nameof(OpenNewTabOnStartup)}, {OpenNewTabOnStartup}");
Analytics.TrackEvent($"{nameof(AlwaysOpenNewInstance)}, {AlwaysOpenNewInstance}");
Analytics.TrackEvent($"{nameof(OpenArchivesInFiles)}, {OpenArchivesInFiles}");
}
}
}

0 comments on commit d3fe83d

Please sign in to comment.