-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite cache directory handling (#1279)
* Create CacheDirectoryService * Implement CacheDirectoryService in CLI * Implement CacheDirectoryService in WPF * Root cache directory * Implement CacheDirectoryService in Twitch tasks
- Loading branch information
Showing
8 changed files
with
119 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
|
||
namespace TwitchDownloaderCore.Services | ||
{ | ||
public static class CacheDirectoryService | ||
{ | ||
private const string CACHE_DIRECTORY_SUFFIX = "TwitchDownloader"; | ||
|
||
public static string GetCacheDirectory([AllowNull] string baseDirectory) | ||
{ | ||
if (string.IsNullOrWhiteSpace(baseDirectory)) | ||
baseDirectory = Path.GetTempPath(); | ||
|
||
baseDirectory = Path.GetFullPath(baseDirectory); | ||
|
||
if (new DirectoryInfo(baseDirectory).Name == CACHE_DIRECTORY_SUFFIX) | ||
{ | ||
return baseDirectory; | ||
} | ||
|
||
return Path.Combine(baseDirectory, CACHE_DIRECTORY_SUFFIX); | ||
} | ||
|
||
public static bool ClearCacheDirectory([AllowNull] string baseDirectory, out Exception exception) | ||
{ | ||
var cacheDirectory = GetCacheDirectory(baseDirectory); | ||
if (!Directory.Exists(cacheDirectory)) | ||
{ | ||
exception = null; | ||
return true; | ||
} | ||
|
||
try | ||
{ | ||
Directory.Delete(cacheDirectory, true); | ||
exception = null; | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
exception = ex; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.