Skip to content

Commit fa3bce1

Browse files
yaira20x5bfa
andauthored
Feature: Save archive creation settings (#16409)
Co-authored-by: 0x5BFA <[email protected]>
1 parent 7e67dc4 commit fa3bce1

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

src/Files.App/Data/Contracts/IGeneralSettingsService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
250250
/// </summary>
251251
FileNameConflictResolveOptionType ConflictsResolveOption { get; set; }
252252

253+
/// <summary>
254+
/// Gets or sets a value indicating the default archive format.
255+
/// </summary>
256+
ArchiveFormats ArchiveFormatsOption { get; set; }
257+
258+
/// <summary>
259+
/// Gets or sets a value indicating the default archive compression level.
260+
/// </summary>
261+
ArchiveCompressionLevels ArchiveCompressionLevelsOption { get; set; }
262+
263+
/// <summary>
264+
/// Gets or sets a value indicating the default archive splitting size.
265+
/// </summary>
266+
ArchiveSplittingSizes ArchiveSplittingSizesOption { get; set; }
267+
253268
/// <summary>
254269
/// A dictionary to determine which hashes should be shown.
255270
/// </summary>

src/Files.App/Dialogs/CreateArchiveDialog.xaml.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ArchiveSplittingSizes SplittingSize
5151
get => ViewModel.SplittingSize.Key;
5252
set => ViewModel.SplittingSize = ViewModel.SplittingSizes.First(size => size.Key == value);
5353
}
54-
54+
5555
public int CPUThreads
5656
{
5757
get => ViewModel.CPUThreads;
@@ -107,6 +107,8 @@ private void ViewModel_PropertyChanged(object? _, PropertyChangedEventArgs e)
107107

108108
private sealed class DialogViewModel : ObservableObject
109109
{
110+
private readonly IGeneralSettingsService GeneralSettingsService = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
111+
110112
public bool IsNameValid => FilesystemHelpers.IsValidForFilename(fileName);
111113

112114
public bool ShowNameWarning => !string.IsNullOrEmpty(fileName) && !IsNameValid;
@@ -125,33 +127,41 @@ public string FileName
125127
}
126128
}
127129

128-
private FileFormatItem fileFormat;
129130
public FileFormatItem FileFormat
130131
{
131-
get => fileFormat;
132+
get => FileFormats.First(format => format.Key == GeneralSettingsService.ArchiveFormatsOption);
132133
set
133134
{
134-
if (SetProperty(ref fileFormat, value))
135+
if (value.Key != GeneralSettingsService.ArchiveFormatsOption)
136+
{
137+
GeneralSettingsService.ArchiveFormatsOption = value.Key;
135138
OnPropertyChanged(nameof(CanSplit));
139+
}
136140
}
137141
}
138142

139-
private CompressionLevelItem compressionLevel;
140143
public CompressionLevelItem CompressionLevel
141144
{
142-
get => compressionLevel;
143-
set => SetProperty(ref compressionLevel, value);
145+
get => CompressionLevels.First(level => level.Key == GeneralSettingsService.ArchiveCompressionLevelsOption);
146+
set
147+
{
148+
if (value.Key != GeneralSettingsService.ArchiveCompressionLevelsOption)
149+
GeneralSettingsService.ArchiveCompressionLevelsOption = value.Key;
150+
}
144151
}
145152

146153
public bool CanSplit => FileFormat.Key is ArchiveFormats.SevenZip;
147154

148-
private SplittingSizeItem splittingSize;
149155
public SplittingSizeItem SplittingSize
150156
{
151-
get => splittingSize;
152-
set => SetProperty(ref splittingSize, value);
157+
get => SplittingSizes.First(size => size.Key == GeneralSettingsService.ArchiveSplittingSizesOption);
158+
set
159+
{
160+
if (value.Key != GeneralSettingsService.ArchiveSplittingSizesOption)
161+
GeneralSettingsService.ArchiveSplittingSizesOption = value.Key;
162+
}
153163
}
154-
164+
155165
private int cpuThreads = Environment.ProcessorCount;
156166
public int CPUThreads
157167
{
@@ -215,9 +225,7 @@ public string Password
215225

216226
public DialogViewModel()
217227
{
218-
fileFormat = FileFormats.First(format => format.Key is ArchiveFormats.Zip);
219-
compressionLevel = CompressionLevels.First(level => level.Key is ArchiveCompressionLevels.Normal);
220-
splittingSize = SplittingSizes.First(size => size.Key is ArchiveSplittingSizes.None);
228+
221229
}
222230

223231
private static string ToSizeText(ulong megaBytes) => ByteSize.FromMebiBytes(megaBytes).ShortString;

src/Files.App/Services/Settings/GeneralSettingsService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,24 @@ public FileNameConflictResolveOptionType ConflictsResolveOption
309309
set => Set((long)value);
310310
}
311311

312+
public ArchiveFormats ArchiveFormatsOption
313+
{
314+
get => (ArchiveFormats)Get((long)ArchiveFormats.Zip);
315+
set => Set((long)value);
316+
}
317+
318+
public ArchiveCompressionLevels ArchiveCompressionLevelsOption
319+
{
320+
get => (ArchiveCompressionLevels)Get((long)ArchiveCompressionLevels.Normal);
321+
set => Set((long)value);
322+
}
323+
324+
public ArchiveSplittingSizes ArchiveSplittingSizesOption
325+
{
326+
get => (ArchiveSplittingSizes)Get((long)ArchiveSplittingSizes.None);
327+
set => Set((long)value);
328+
}
329+
312330
public Dictionary<string, bool> ShowHashesDictionary
313331
{
314332
get => Get<Dictionary<string, bool>>(null);

0 commit comments

Comments
 (0)