Skip to content

Commit

Permalink
自定义临时文件保留时长
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeric-X committed Nov 23, 2024
1 parent 95507aa commit 4b093d8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/SyncClipboard.Core/AppCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,16 @@ private static void PlannedTask(ConfigManager configManager)
try
{
var config = configManager.GetConfig<ProgramConfig>();
var tempFolders = new DirectoryInfo(Env.AppDataFileFolder).EnumerateDirectories("????????");
foreach (var dirs in tempFolders)
if (config.TempFileRemainDays != 0)
{
var createTime = DateTime.ParseExact(dirs.Name, "yyyyMMdd", CultureInfo.InvariantCulture);
if ((DateTime.Today - createTime) > TimeSpan.FromDays(1))
var tempFolders = new DirectoryInfo(Env.AppDataFileFolder).EnumerateDirectories("????????");
foreach (var dirs in tempFolders)
{
dirs.Delete(true);
var createTime = DateTime.ParseExact(dirs.Name, "yyyyMMdd", CultureInfo.InvariantCulture);
if ((DateTime.Today - createTime) > TimeSpan.FromDays(config.TempFileRemainDays))
{
dirs.Delete(true);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/SyncClipboard.Core/I18n/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/SyncClipboard.Core/I18n/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,7 @@
<data name="CopyAndUploadWithoutFilter" xml:space="preserve">
<value>Copy And Upload without Content Control</value>
</data>
<data name="TempFileRemainDays" xml:space="preserve">
<value>Temp Files Remain Days</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/SyncClipboard.Core/I18n/Strings.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,7 @@
<data name="CopyAndUploadWithoutFilter" xml:space="preserve">
<value>复制并上传本地到远程(忽略内容控制)</value>
</data>
<data name="TempFileRemainDays" xml:space="preserve">
<value>临时文件保留时长(日)</value>
</data>
</root>
1 change: 1 addition & 0 deletions src/SyncClipboard.Core/Models/UserConfigs/ProgramConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public record ProgramConfig
{
public string Proxy { get; set; } = "";
public bool DeleteTempFilesOnStartUp { get; set; } = true;
public uint TempFileRemainDays { get; set; } = 1;
public uint LogRemainDays { get; set; } = 8;
public bool CheckUpdateOnStartUp { get; set; } = true;
public bool CheckUpdateForBeta { get; set; } = false;
Expand Down
6 changes: 6 additions & 0 deletions src/SyncClipboard.Core/ViewModels/SystemSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public partial class SystemSettingViewModel : ObservableObject
private uint logRemainDays;
partial void OnLogRemainDaysChanged(uint value) => ProgramConfig = ProgramConfig with { LogRemainDays = value };

[ObservableProperty]
private uint tempFileRemainDays;
partial void OnTempFileRemainDaysChanged(uint value) => ProgramConfig = ProgramConfig with { TempFileRemainDays = value };

[ObservableProperty]
private string font;
partial void OnFontChanged(string value)
Expand Down Expand Up @@ -52,6 +56,7 @@ partial void OnProgramConfigChanged(ProgramConfig value)
{
HideWindowOnStartUp = value.HideWindowOnStartup;
LogRemainDays = value.LogRemainDays;
TempFileRemainDays = value.TempFileRemainDays;
DiagnoseMode = value.DiagnoseMode;
Font = value.Font;
Language = Languages.FirstOrDefault(x => x.LocaleTag == value.Language) ?? Languages[0];
Expand Down Expand Up @@ -98,6 +103,7 @@ public SystemSettingViewModel(ConfigManager configManager, IServiceProvider serv
theme = Themes.FirstOrDefault(x => x.String == programConfig.Theme) ?? Themes[0];
hideWindowOnStartUp = programConfig.HideWindowOnStartup;
logRemainDays = programConfig.LogRemainDays;
tempFileRemainDays = programConfig.TempFileRemainDays;
diagnoseMode = programConfig.DiagnoseMode;
}

Expand Down
8 changes: 8 additions & 0 deletions src/SyncClipboard.Desktop/Views/SystemSettingPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<ToggleSwitch OnContent="{x:Static i18n:Strings.On}" OffContent="{x:Static i18n:Strings.Off}" IsChecked="{Binding HideWindowOnStartUp, Mode=TwoWay}" />
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
<ui:SettingsExpander Header="{x:Static i18n:Strings.TempFileRemainDays}">
<ui:SettingsExpander.IconSource>
<ui:FontIconSource Glyph="&#xE130;" FontFamily="{StaticResource SymbolThemeFontFamily}" />
</ui:SettingsExpander.IconSource>
<ui:SettingsExpander.Footer>
<ui:NumberBox Minimum="0" Maximum="1000" Value="{Binding TempFileRemainDays, Mode=TwoWay}" />
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
<ui:SettingsExpander Header="{x:Static i18n:Strings.LogRemainDays}">
<ui:SettingsExpander.IconSource>
<ui:FontIconSource Glyph="&#xE9F9;" FontFamily="{StaticResource SymbolThemeFontFamily}" />
Expand Down
6 changes: 6 additions & 0 deletions src/SyncClipboard.WinUI3/Views/SystemSettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
</ui:SettingsCard.HeaderIcon>
<ToggleSwitch OnContent="{x:Bind i18n:Strings.On}" OffContent="{x:Bind i18n:Strings.Off}" IsOn="{x:Bind _viewModel.HideWindowOnStartUp, Mode=TwoWay}" />
</ui:SettingsCard>
<ui:SettingsCard Header="{x:Bind i18n:Strings.TempFileRemainDays}">
<ui:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE130;" />
</ui:SettingsCard.HeaderIcon>
<NumberBox Minimum="0" Maximum="1000" Value="{x:Bind _viewModel.TempFileRemainDays, Mode=TwoWay}" />
</ui:SettingsCard>
<ui:SettingsCard Header="{x:Bind i18n:Strings.LogRemainDays}">
<ui:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE9F9;" />
Expand Down

0 comments on commit 4b093d8

Please sign in to comment.