Rename and organize config values

This commit is contained in:
whimsical-c4lic0 2026-02-17 22:23:43 -06:00
parent ac1c814633
commit 56b951ace0
4 changed files with 104 additions and 93 deletions

View File

@ -105,8 +105,11 @@ public class Config : IFileNameFormatConfig
[ToggleableConfig] public bool DisableTextSanitization { get; set; } [ToggleableConfig] public bool DisableTextSanitization { get; set; }
public string? PaidPostFileNameFormat { get; set; } = ""; public string? PaidPostFileNameFormat { get; set; } = "";
public string? PostFileNameFormat { get; set; } = ""; public string? PostFileNameFormat { get; set; } = "";
public string? PaidMessageFileNameFormat { get; set; } = ""; public string? PaidMessageFileNameFormat { get; set; } = "";
public string? MessageFileNameFormat { get; set; } = ""; public string? MessageFileNameFormat { get; set; } = "";
public IFileNameFormatConfig GetCreatorFileNameFormatConfig(string username) public IFileNameFormatConfig GetCreatorFileNameFormatConfig(string username)

View File

@ -48,6 +48,18 @@ public partial class ConfigFieldViewModel : ViewModelBase
["dark"] = "Dark" ["dark"] = "Dark"
}; };
private static readonly Dictionary<string, string> s_displayNameOverridesByProperty =
new(StringComparer.Ordinal)
{
[nameof(Config.PostFileNameFormat)] = "Free Post File Name Format",
[nameof(Config.MessageFileNameFormat)] = "Free Message File Name Format",
[nameof(Config.DownloadVideoResolution)] = "Video Resolution",
[nameof(Config.IgnoredUsersListName)] = "Ignored Users List",
[nameof(Config.RenameExistingFilesWhenCustomFormatIsSelected)] =
"Rename Existing Files with Custom Formats",
[nameof(Config.DownloadPath)] = "Download Folder"
};
public ConfigFieldViewModel( public ConfigFieldViewModel(
PropertyInfo propertyInfo, PropertyInfo propertyInfo,
object? initialValue, object? initialValue,
@ -56,7 +68,7 @@ public partial class ConfigFieldViewModel : ViewModelBase
{ {
PropertyInfo = propertyInfo; PropertyInfo = propertyInfo;
PropertyName = propertyInfo.Name; PropertyName = propertyInfo.Name;
DisplayName = ToDisplayName(propertyInfo.Name); DisplayName = GetDisplayName(propertyInfo.Name);
PropertyType = propertyInfo.PropertyType; PropertyType = propertyInfo.PropertyType;
HelpText = helpText?.Trim() ?? string.Empty; HelpText = helpText?.Trim() ?? string.Empty;
@ -86,7 +98,8 @@ public partial class ConfigFieldViewModel : ViewModelBase
} }
SelectedFileNameVariable = AvailableFileNameVariables.FirstOrDefault(); SelectedFileNameVariable = AvailableFileNameVariables.FirstOrDefault();
string availableVariables = string.Join(", ", AvailableFileNameVariables.Select(variable => $"{{{variable}}}")); string availableVariables =
string.Join(", ", AvailableFileNameVariables.Select(variable => $"{{{variable}}}"));
string fileNameHelpText = string fileNameHelpText =
$"Available variables: {availableVariables}. Include {{mediaId}} or {{filename}} to avoid collisions."; $"Available variables: {availableVariables}. Include {{mediaId}} or {{filename}} to avoid collisions.";
HelpText = string.IsNullOrWhiteSpace(HelpText) HelpText = string.IsNullOrWhiteSpace(HelpText)
@ -165,13 +178,11 @@ public partial class ConfigFieldViewModel : ViewModelBase
private string _actualTextValue = string.Empty; private string _actualTextValue = string.Empty;
[ObservableProperty] [ObservableProperty] private string _textValue = string.Empty;
private string _textValue = string.Empty;
private bool _isNormalizingFileNameFormatInput; private bool _isNormalizingFileNameFormatInput;
[ObservableProperty] [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(InsertSelectedFileNameVariableCommand))]
[NotifyCanExecuteChangedFor(nameof(InsertSelectedFileNameVariableCommand))]
private string? _selectedFileNameVariable; private string? _selectedFileNameVariable;
private bool IsPathField => private bool IsPathField =>
@ -180,16 +191,13 @@ public partial class ConfigFieldViewModel : ViewModelBase
[ObservableProperty] private ConfigSelectOptionViewModel? _selectedIgnoredUsersListOption; [ObservableProperty] private ConfigSelectOptionViewModel? _selectedIgnoredUsersListOption;
[ObservableProperty] [ObservableProperty] [NotifyPropertyChangedFor(nameof(HasHelpText))]
[NotifyPropertyChangedFor(nameof(HasHelpText))]
private string _helpText = string.Empty; private string _helpText = string.Empty;
[ObservableProperty] [ObservableProperty] [NotifyPropertyChangedFor(nameof(HasUnknownFileNameVariables))]
[NotifyPropertyChangedFor(nameof(HasUnknownFileNameVariables))]
private string _unknownFileNameVariablesMessage = string.Empty; private string _unknownFileNameVariablesMessage = string.Empty;
[ObservableProperty] [ObservableProperty] [NotifyPropertyChangedFor(nameof(HasError))]
[NotifyPropertyChangedFor(nameof(HasError))]
private string _errorMessage = string.Empty; private string _errorMessage = string.Empty;
public bool HasError => !string.IsNullOrWhiteSpace(ErrorMessage); public bool HasError => !string.IsNullOrWhiteSpace(ErrorMessage);
@ -232,7 +240,7 @@ public partial class ConfigFieldViewModel : ViewModelBase
if (PropertyType == typeof(string)) if (PropertyType == typeof(string))
{ {
// Use actual value for path fields when privacy mode is enabled // Use actual value for path fields when privacy mode is enabled
string textToUse = (Program.HidePrivateInfo && IsPathField) ? _actualTextValue : TextValue; string textToUse = Program.HidePrivateInfo && IsPathField ? _actualTextValue : TextValue;
value = textToUse.Trim(); value = textToUse.Trim();
return true; return true;
} }
@ -311,15 +319,9 @@ public partial class ConfigFieldViewModel : ViewModelBase
return false; return false;
} }
public void ClearError() public void ClearError() => ErrorMessage = string.Empty;
{
ErrorMessage = string.Empty;
}
public void SetError(string message) public void SetError(string message) => ErrorMessage = message;
{
ErrorMessage = message;
}
public void SetIgnoredUsersListOptions(IEnumerable<string> listNames) public void SetIgnoredUsersListOptions(IEnumerable<string> listNames)
{ {
@ -428,6 +430,7 @@ public partial class ConfigFieldViewModel : ViewModelBase
{ {
EnumValue = EnumOptions.FirstOrDefault(); EnumValue = EnumOptions.FirstOrDefault();
} }
return; return;
} }
@ -548,4 +551,9 @@ public partial class ConfigFieldViewModel : ViewModelBase
? $" {character}" ? $" {character}"
: character.ToString())); : character.ToString()));
} }
private static string GetDisplayName(string propertyName) =>
s_displayNameOverridesByProperty.TryGetValue(propertyName, out string? displayName)
? displayName
: ToDisplayName(propertyName);
} }

View File

@ -43,15 +43,15 @@ public partial class MainWindowViewModel(
private static readonly (string DisplayName, string PropertyName)[] s_mediaSourceOptions = private static readonly (string DisplayName, string PropertyName)[] s_mediaSourceOptions =
[ [
("Avatar/Header Photo", nameof(Config.DownloadAvatarHeaderPhoto)), ("Free Posts", nameof(Config.DownloadPosts)),
("Posts", nameof(Config.DownloadPosts)),
("Paid Posts", nameof(Config.DownloadPaidPosts)), ("Paid Posts", nameof(Config.DownloadPaidPosts)),
("Free Messages", nameof(Config.DownloadMessages)),
("Paid Messages", nameof(Config.DownloadPaidMessages)),
("Archived", nameof(Config.DownloadArchived)), ("Archived", nameof(Config.DownloadArchived)),
("Streams", nameof(Config.DownloadStreams)), ("Streams", nameof(Config.DownloadStreams)),
("Stories", nameof(Config.DownloadStories)), ("Stories", nameof(Config.DownloadStories)),
("Highlights", nameof(Config.DownloadHighlights)), ("Highlights", nameof(Config.DownloadHighlights)),
("Messages", nameof(Config.DownloadMessages)), ("Avatar/Header Photo", nameof(Config.DownloadAvatarHeaderPhoto))
("Paid Messages", nameof(Config.DownloadPaidMessages))
]; ];
private static readonly Dictionary<string, string> s_configHelpTextByProperty = new(StringComparer.Ordinal) private static readonly Dictionary<string, string> s_configHelpTextByProperty = new(StringComparer.Ordinal)
@ -1247,10 +1247,10 @@ public partial class MainWindowViewModel(
return propertyName switch return propertyName switch
{ {
nameof(Config.RenameExistingFilesWhenCustomFormatIsSelected) => 0, nameof(Config.RenameExistingFilesWhenCustomFormatIsSelected) => 0,
nameof(Config.PaidPostFileNameFormat) => 1, nameof(Config.PostFileNameFormat) => 1,
nameof(Config.PostFileNameFormat) => 2, nameof(Config.PaidPostFileNameFormat) => 2,
nameof(Config.PaidMessageFileNameFormat) => 3, nameof(Config.MessageFileNameFormat) => 3,
nameof(Config.MessageFileNameFormat) => 4, nameof(Config.PaidMessageFileNameFormat) => 4,
nameof(Config.CreatorConfigs) => 5, nameof(Config.CreatorConfigs) => 5,
_ => 100 _ => 100
}; };

View File

@ -48,7 +48,7 @@
<Grid RowDefinitions="Auto,Auto,*"> <Grid RowDefinitions="Auto,Auto,*">
<Menu Grid.Row="0"> <Menu Grid.Row="0">
<MenuItem Header="_File"> <MenuItem Header="_File">
<MenuItem Header="_Refresh Users" Command="{Binding RefreshUsersCommand}" /> <MenuItem Header="_Refresh" Command="{Binding RefreshUsersCommand}" />
<MenuItem Header="_Logout" <MenuItem Header="_Logout"
IsVisible="{Binding IsAuthenticated}" IsVisible="{Binding IsAuthenticated}"
Command="{Binding LogoutCommand}" /> Command="{Binding LogoutCommand}" />
@ -530,14 +530,14 @@
ToolTip.Tip="{Binding FolderStructureHelpText}" /> ToolTip.Tip="{Binding FolderStructureHelpText}" />
</Grid> </Grid>
<StackPanel Grid.Column="1" Spacing="6"> <StackPanel Grid.Column="1" Spacing="6">
<CheckBox Content="Paid Posts"
IsChecked="{Binding FolderPerPaidPostField.BoolValue, FallbackValue=False}" />
<CheckBox Content="Free Posts" <CheckBox Content="Free Posts"
IsChecked="{Binding FolderPerPostField.BoolValue, FallbackValue=False}" /> IsChecked="{Binding FolderPerPostField.BoolValue, FallbackValue=False}" />
<CheckBox Content="Paid Messages" <CheckBox Content="Paid Posts"
IsChecked="{Binding FolderPerPaidMessageField.BoolValue, FallbackValue=False}" /> IsChecked="{Binding FolderPerPaidPostField.BoolValue, FallbackValue=False}" />
<CheckBox Content="Free Messages" <CheckBox Content="Free Messages"
IsChecked="{Binding FolderPerMessageField.BoolValue, FallbackValue=False}" /> IsChecked="{Binding FolderPerMessageField.BoolValue, FallbackValue=False}" />
<CheckBox Content="Paid Messages"
IsChecked="{Binding FolderPerPaidMessageField.BoolValue, FallbackValue=False}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<ItemsControl ItemsSource="{Binding Fields}"> <ItemsControl ItemsSource="{Binding Fields}">
@ -1005,6 +1005,47 @@
Foreground="{DynamicResource TextSecondaryBrush}" Foreground="{DynamicResource TextSecondaryBrush}"
Text="File Name Formats (leave blank to use global defaults)" /> Text="File Name Formats (leave blank to use global defaults)" />
<StackPanel Spacing="8">
<TextBlock FontWeight="SemiBold" Foreground="{DynamicResource TextPrimaryBrush}"
Text="Free Post File Name Format" />
<Grid ClipToBounds="True">
<TextBox x:Name="PostFileNameFormatTextBox"
Classes="fileNameOverlayInput"
Text="{Binding PostFileNameFormat}"
Watermark="Optional: override global post format"
Padding="8,6"
CaretBrush="{DynamicResource TextPrimaryBrush}" />
<controls:FileNameFormatOverlayTextBlock IsHitTestVisible="False"
Margin="{Binding #PostFileNameFormatTextBox.Padding}"
VerticalAlignment="Center"
Segments="{Binding PostSegments}"
SourceTextBox="{Binding #PostFileNameFormatTextBox}"
FontFamily="{Binding #PostFileNameFormatTextBox.FontFamily}"
FontSize="{Binding #PostFileNameFormatTextBox.FontSize}"
FontWeight="{Binding #PostFileNameFormatTextBox.FontWeight}"
FontStyle="{Binding #PostFileNameFormatTextBox.FontStyle}" />
</Grid>
<Grid ColumnDefinitions="*,Auto">
<ComboBox Grid.Column="0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding PostVariables}"
SelectedItem="{Binding SelectedPostVariable}" />
<Button Grid.Column="1"
Margin="8,0,0,0"
Classes="secondary"
Content="Insert"
Command="{Binding InsertPostVariableCommand}" />
</Grid>
<TextBlock IsVisible="{Binding HasUnknownPostVariables}"
Foreground="{DynamicResource ErrorTextBrush}"
Text="{Binding UnknownPostVariablesMessage}"
TextWrapping="Wrap" />
<TextBlock IsVisible="{Binding HasPostFileNameFormatError}"
Foreground="{DynamicResource ErrorTextBrush}"
Text="{Binding PostFileNameFormatError}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel Spacing="8"> <StackPanel Spacing="8">
<TextBlock FontWeight="SemiBold" Foreground="{DynamicResource TextPrimaryBrush}" <TextBlock FontWeight="SemiBold" Foreground="{DynamicResource TextPrimaryBrush}"
Text="Paid Post File Name Format" /> Text="Paid Post File Name Format" />
@ -1048,42 +1089,42 @@
<StackPanel Spacing="8"> <StackPanel Spacing="8">
<TextBlock FontWeight="SemiBold" Foreground="{DynamicResource TextPrimaryBrush}" <TextBlock FontWeight="SemiBold" Foreground="{DynamicResource TextPrimaryBrush}"
Text="Post File Name Format" /> Text="Free Message File Name Format" />
<Grid ClipToBounds="True"> <Grid ClipToBounds="True">
<TextBox x:Name="PostFileNameFormatTextBox" <TextBox x:Name="MessageFileNameFormatTextBox"
Classes="fileNameOverlayInput" Classes="fileNameOverlayInput"
Text="{Binding PostFileNameFormat}" Text="{Binding MessageFileNameFormat}"
Watermark="Optional: override global post format" Watermark="Optional: override global message format"
Padding="8,6" Padding="8,6"
CaretBrush="{DynamicResource TextPrimaryBrush}" /> CaretBrush="{DynamicResource TextPrimaryBrush}" />
<controls:FileNameFormatOverlayTextBlock IsHitTestVisible="False" <controls:FileNameFormatOverlayTextBlock IsHitTestVisible="False"
Margin="{Binding #PostFileNameFormatTextBox.Padding}" Margin="{Binding #MessageFileNameFormatTextBox.Padding}"
VerticalAlignment="Center" VerticalAlignment="Center"
Segments="{Binding PostSegments}" Segments="{Binding MessageSegments}"
SourceTextBox="{Binding #PostFileNameFormatTextBox}" SourceTextBox="{Binding #MessageFileNameFormatTextBox}"
FontFamily="{Binding #PostFileNameFormatTextBox.FontFamily}" FontFamily="{Binding #MessageFileNameFormatTextBox.FontFamily}"
FontSize="{Binding #PostFileNameFormatTextBox.FontSize}" FontSize="{Binding #MessageFileNameFormatTextBox.FontSize}"
FontWeight="{Binding #PostFileNameFormatTextBox.FontWeight}" FontWeight="{Binding #MessageFileNameFormatTextBox.FontWeight}"
FontStyle="{Binding #PostFileNameFormatTextBox.FontStyle}" /> FontStyle="{Binding #MessageFileNameFormatTextBox.FontStyle}" />
</Grid> </Grid>
<Grid ColumnDefinitions="*,Auto"> <Grid ColumnDefinitions="*,Auto">
<ComboBox Grid.Column="0" <ComboBox Grid.Column="0"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemsSource="{Binding PostVariables}" ItemsSource="{Binding MessageVariables}"
SelectedItem="{Binding SelectedPostVariable}" /> SelectedItem="{Binding SelectedMessageVariable}" />
<Button Grid.Column="1" <Button Grid.Column="1"
Margin="8,0,0,0" Margin="8,0,0,0"
Classes="secondary" Classes="secondary"
Content="Insert" Content="Insert"
Command="{Binding InsertPostVariableCommand}" /> Command="{Binding InsertMessageVariableCommand}" />
</Grid> </Grid>
<TextBlock IsVisible="{Binding HasUnknownPostVariables}" <TextBlock IsVisible="{Binding HasUnknownMessageVariables}"
Foreground="{DynamicResource ErrorTextBrush}" Foreground="{DynamicResource ErrorTextBrush}"
Text="{Binding UnknownPostVariablesMessage}" Text="{Binding UnknownMessageVariablesMessage}"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<TextBlock IsVisible="{Binding HasPostFileNameFormatError}" <TextBlock IsVisible="{Binding HasMessageFileNameFormatError}"
Foreground="{DynamicResource ErrorTextBrush}" Foreground="{DynamicResource ErrorTextBrush}"
Text="{Binding PostFileNameFormatError}" Text="{Binding MessageFileNameFormatError}"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
</StackPanel> </StackPanel>
@ -1128,47 +1169,6 @@
TextWrapping="Wrap" /> TextWrapping="Wrap" />
</StackPanel> </StackPanel>
<StackPanel Spacing="8">
<TextBlock FontWeight="SemiBold" Foreground="{DynamicResource TextPrimaryBrush}"
Text="Message File Name Format" />
<Grid ClipToBounds="True">
<TextBox x:Name="MessageFileNameFormatTextBox"
Classes="fileNameOverlayInput"
Text="{Binding MessageFileNameFormat}"
Watermark="Optional: override global message format"
Padding="8,6"
CaretBrush="{DynamicResource TextPrimaryBrush}" />
<controls:FileNameFormatOverlayTextBlock IsHitTestVisible="False"
Margin="{Binding #MessageFileNameFormatTextBox.Padding}"
VerticalAlignment="Center"
Segments="{Binding MessageSegments}"
SourceTextBox="{Binding #MessageFileNameFormatTextBox}"
FontFamily="{Binding #MessageFileNameFormatTextBox.FontFamily}"
FontSize="{Binding #MessageFileNameFormatTextBox.FontSize}"
FontWeight="{Binding #MessageFileNameFormatTextBox.FontWeight}"
FontStyle="{Binding #MessageFileNameFormatTextBox.FontStyle}" />
</Grid>
<Grid ColumnDefinitions="*,Auto">
<ComboBox Grid.Column="0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding MessageVariables}"
SelectedItem="{Binding SelectedMessageVariable}" />
<Button Grid.Column="1"
Margin="8,0,0,0"
Classes="secondary"
Content="Insert"
Command="{Binding InsertMessageVariableCommand}" />
</Grid>
<TextBlock IsVisible="{Binding HasUnknownMessageVariables}"
Foreground="{DynamicResource ErrorTextBrush}"
Text="{Binding UnknownMessageVariablesMessage}"
TextWrapping="Wrap" />
<TextBlock IsVisible="{Binding HasMessageFileNameFormatError}"
Foreground="{DynamicResource ErrorTextBrush}"
Text="{Binding MessageFileNameFormatError}"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="10" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" Spacing="10" HorizontalAlignment="Right">
<Button Content="Cancel" <Button Content="Cancel"
Classes="secondary" Classes="secondary"