Skip to content

Commit

Permalink
Add possibility to automatically remove completed downloads from list
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye116477 committed Nov 18, 2024
1 parent d4d58c3 commit d2c67f8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions make_scripts/config/commonLocKeys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ LOCLegendaryMigratingGamesEpic
LOCLegendaryMigrationConfirm
LOCLegendaryInstanceNotice
LOCLegendaryLauncherUpdatePolicy
LOCLegendaryAutoRemoveCompletedDownloads
1 change: 1 addition & 0 deletions src/Localization/en_US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<sys:String x:Key="LOCNileUnattendedInstallToolTip">You won't have to choose anything in the installer window and the installation will start automatically after downloading the required information.</sys:String>
<sys:String x:Key="LOCNileMaxWorkers">Maximum number of worker processes</sys:String>
<sys:String x:Key="LOCNileAfterDownloadComplete">Action after download is complete</sys:String>
<sys:String x:Key="LOCNileAutoRemoveCompletedDownloads">Automatically remove completed downloads from list</sys:String>
<sys:String x:Key="LOCNileSystemShutdownCountdown">System will be turned off soon...</sys:String>
<sys:String x:Key="LOCNileSystemRestartCountdown">System will be restarted soon...</sys:String>
<sys:String x:Key="LOCNileSystemHibernateCountdown">System will be hibernated soon...</sys:String>
Expand Down
30 changes: 29 additions & 1 deletion src/NileLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ public bool StopDownloadManager(bool displayConfirm = false)
}
download.status = DownloadStatus.Paused;
}
downloadManager.SaveData();
}
downloadManager.SaveData();
return true;
}

Expand Down Expand Up @@ -585,9 +585,36 @@ public override async void OnApplicationStarted(OnApplicationStartedEventArgs ar
public override void OnApplicationStopped(OnApplicationStoppedEventArgs args)
{
StopDownloadManager();
NileDownloadManagerView downloadManager = GetNileDownloadManager();
var settings = GetSettings();
if (settings != null)
{
if (settings.AutoRemoveCompletedDownloads != ClearCacheTime.Never)
{
var nextRemovingCompletedDownloadsTime = settings.NextRemovingCompletedDownloadsTime;
if (nextRemovingCompletedDownloadsTime != 0)
{
DateTimeOffset now = DateTime.UtcNow;
if (now.ToUnixTimeSeconds() >= nextRemovingCompletedDownloadsTime)
{
foreach (var downloadItem in downloadManager.downloadManagerData.downloads.ToList())
{
if (downloadItem.status == DownloadStatus.Completed)
{
downloadManager.downloadManagerData.downloads.Remove(downloadItem);
downloadManager.downloadsChanged = true;
}
}
settings.NextRemovingCompletedDownloadsTime = GetNextClearingTime(settings.AutoRemoveCompletedDownloads);
SavePluginSettings(settings);
}
}
else
{
settings.NextRemovingCompletedDownloadsTime = GetNextClearingTime(settings.AutoRemoveCompletedDownloads);
SavePluginSettings(settings);
}
}
if (settings.AutoClearCache != ClearCacheTime.Never)
{
var nextClearingTime = settings.NextClearingTime;
Expand All @@ -607,6 +634,7 @@ public override void OnApplicationStopped(OnApplicationStoppedEventArgs args)
SavePluginSettings(settings);
}
}
downloadManager.SaveData();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/NileLibrarySettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="{DynamicResource LOCNileMaxWorkers}" Grid.Column="0"
Grid.Row="0" Margin="0,0,10,5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<common:NumericInput Grid.Row="0" Grid.Column="1" Margin="0,0,0,5" MinValue="0" x:Name="MaxWorkersNI" Value="{Binding Settings.MaxWorkers}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="0" Grid.Row="1"
Text="{DynamicResource LOCNileAfterDownloadComplete}" Margin="0,0,10,5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<ComboBox Grid.Column="1" Grid.Row="1" x:Name="AfterDownloadCompleteCBo" DisplayMemberPath="Value" SelectedValue="{Binding Settings.DoActionAfterDownloadComplete}" SelectedValuePath="Key" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" Margin="0,0,0,5" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="{DynamicResource LOCNileAutoRemoveCompletedDownloads}" Margin="0,0,0,5" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
<ComboBox Grid.Row="2" Grid.Column="1" x:Name="AutoRemoveCompletedDownloadsCBo" DisplayMemberPath="Value" SelectedValue="{Binding Settings.AutoRemoveCompletedDownloads}" SelectedValuePath="Key" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" Margin="10,0,0,5" HorizontalAlignment="Left" />
</Grid>
</StackPanel>
</TabItem>
Expand Down
1 change: 1 addition & 0 deletions src/NileLibrarySettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private async void NileSettingsUC_Loaded(object sender, RoutedEventArgs e)
{ ClearCacheTime.Never, ResourceProvider.GetString(LOC.Nile3P_PlayniteSettingsPlaytimeImportModeNever) }
};
AutoClearCacheCBo.ItemsSource = autoClearOptions;
AutoRemoveCompletedDownloadsCBo.ItemsSource = autoClearOptions;

var updatePolicyOptions = new Dictionary<UpdatePolicy, string>
{
Expand Down
13 changes: 13 additions & 0 deletions src/NileLibrarySettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public class NileLibrarySettings
public DownloadCompleteAction DoActionAfterDownloadComplete { get; set; } = DownloadCompleteAction.Nothing;
public bool DisplayDownloadSpeedInBits { get; set; } = false;
public bool DisplayDownloadTaskFinishedNotifications { get; set; } = true;
public ClearCacheTime AutoRemoveCompletedDownloads { get; set; } = ClearCacheTime.Never;
public ClearCacheTime AutoClearCache { get; set; } = ClearCacheTime.Never;
public UpdatePolicy GamesUpdatePolicy { get; set; } = UpdatePolicy.Month;
public long NextClearingTime { get; set; } = 0;
public long NextRemovingCompletedDownloadsTime { get; set; } = 0;
public long NextGamesUpdateTime { get; set; } = 0;
public UpdatePolicy LauncherUpdatePolicy { get; set; } = UpdatePolicy.Month;
public long NextLauncherUpdateTime { get; set; } = 0;
Expand Down Expand Up @@ -89,6 +91,17 @@ public override void EndEdit()
Settings.NextClearingTime = 0;
}
}
if (EditingClone.AutoRemoveCompletedDownloads != Settings.AutoRemoveCompletedDownloads)
{
if (Settings.AutoRemoveCompletedDownloads != ClearCacheTime.Never)
{
Settings.NextRemovingCompletedDownloadsTime = NileLibrary.GetNextClearingTime(Settings.AutoRemoveCompletedDownloads);
}
else
{
Settings.NextRemovingCompletedDownloadsTime = 0;
}
}
if (EditingClone.GamesUpdatePolicy != Settings.GamesUpdatePolicy)
{
if (Settings.GamesUpdatePolicy != UpdatePolicy.Never)
Expand Down

0 comments on commit d2c67f8

Please sign in to comment.