-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileDeletionService.cs
More file actions
73 lines (65 loc) · 2.42 KB
/
FileDeletionService.cs
File metadata and controls
73 lines (65 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable MemberCanBeMadeStatic.Global
using System;
using System.IO;
using UnityEngine;
using System.Collections;
using AbyssMoth.Internal.Codebase.Runtime.Common.Components;
namespace AbyssMoth
{
[DisallowMultipleComponent]
[RequireComponent(typeof(ImmortalGameObject))]
public sealed class FileDeletionService : MonoSingleton<FileDeletionService>
{
/// <summary>
/// Удалить файл немедленно.
/// </summary>
public void DeleteFileImmediately(string filePath)
{
try
{
if (File.Exists(filePath))
{
File.Delete(filePath);
Debug.Log($"File deleted: {filePath}");
}
else
{
Debug.LogWarning($"File not found: {filePath}");
}
}
catch (Exception ex)
{
Debug.LogError($"Failed to delete file: {filePath}\n{ex.Message}");
}
}
/// <summary>
/// Удалить файл с задержкой.
/// </summary>
public void DeleteFileWithDelay(string filePath, float delayInSeconds) =>
StartCoroutine(DeleteFileCoroutine(filePath, delayInSeconds));
/// <summary>
/// Удалить файл в корутине с задержкой.
/// </summary>
private IEnumerator DeleteFileCoroutine(string filePath, float delayInSeconds)
{
yield return WaitForSecondsCache.Get(delayInSeconds);
DeleteFileImmediately(filePath);
}
/// <summary>
/// Удалить список файлов с задержкой.
/// </summary>
public void DeleteMultipleFilesWithDelay(string[] filePaths, float delayInSeconds) =>
StartCoroutine(DeleteMultipleFilesCoroutine(filePaths, delayInSeconds));
/// <summary>
/// Удалить список файлов в корутине с задержкой.
/// </summary>
private IEnumerator DeleteMultipleFilesCoroutine(string[] filePaths, float delayInSeconds)
{
yield return WaitForSecondsCache.Get(delayInSeconds);
foreach (var filePath in filePaths)
DeleteFileImmediately(filePath);
}
}
}