mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-16 06:31:42 +02:00
Configuration
Core
Bridge
Controls
Handling
Notification
Other
Utils
BrowserCache.cs
BrowserUtils.cs
NativeMethods.cs
StringUtils.cs
TwitterUtils.cs
WindowsUtils.cs
FormBrowser.Designer.cs
FormBrowser.cs
FormBrowser.resx
FormManager.cs
TrayIcon.Designer.cs
TrayIcon.cs
Data
Plugins
Properties
Resources
Updates
bld
lib
subprocess
tests
video
.gitattributes
.gitignore
LICENSE.md
Program.cs
README.md
Reporter.cs
TweetDuck.csproj
TweetDuck.sln
TweetDuck.sln.DotSettings
packages.config
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
|
|
namespace TweetDuck.Core.Utils{
|
|
static class BrowserCache{
|
|
private static bool ClearOnExit { get; set; }
|
|
|
|
public static readonly string CacheFolder = Path.Combine(Program.StoragePath, "Cache");
|
|
|
|
private static IEnumerable<string> CacheFiles{
|
|
get{
|
|
return Directory.EnumerateFiles(CacheFolder);
|
|
}
|
|
}
|
|
|
|
public static void CalculateCacheSize(Action<long> callbackBytes){
|
|
Task<long> task = new Task<long>(() => {
|
|
return CacheFiles.Select(file => {
|
|
try{
|
|
return new FileInfo(file).Length;
|
|
}catch{
|
|
return 0L;
|
|
}
|
|
}).Sum();
|
|
});
|
|
|
|
task.ContinueWith(originalTask => callbackBytes(originalTask.Exception == null ? originalTask.Result : -1L), TaskContinuationOptions.ExecuteSynchronously);
|
|
task.Start();
|
|
}
|
|
|
|
public static void SetClearOnExit(){
|
|
ClearOnExit = true;
|
|
}
|
|
|
|
public static void Exit(){
|
|
if (ClearOnExit){
|
|
foreach(string file in CacheFiles){
|
|
try{
|
|
File.Delete(file);
|
|
}catch{
|
|
// welp, too bad
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|