feat: polish VR gameplay and sync tools
This commit is contained in:
@@ -8,7 +8,8 @@ public class DownloadManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string baseUrl = "http://whdwo798.synology.me/beatsaber";
|
||||
|
||||
private static string CacheRoot => Path.Combine(Application.temporaryCachePath, "beatsaber");
|
||||
private static string CacheRoot => Path.Combine(Application.persistentDataPath, "beatsaber");
|
||||
private static string LegacyCacheRoot => Path.Combine(Application.temporaryCachePath, "beatsaber");
|
||||
|
||||
// ── Public API ───────────────────────────────────────────
|
||||
|
||||
@@ -38,20 +39,35 @@ public class DownloadManager : MonoBehaviour
|
||||
Directory.Delete(dir, recursive: true);
|
||||
Debug.Log($"[DownloadManager] 삭제: {songId}");
|
||||
}
|
||||
|
||||
string legacyDir = LegacySongDir(songId);
|
||||
if (Directory.Exists(legacyDir))
|
||||
Directory.Delete(legacyDir, recursive: true);
|
||||
}
|
||||
|
||||
public void DeleteDifficulty(SongInfo song, string difficulty)
|
||||
{
|
||||
TryMigrateLegacySong(song.id);
|
||||
|
||||
string path = MapPath(song, difficulty);
|
||||
if (path != null && File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
string songDir = SongDir(song.id);
|
||||
if (Directory.Exists(songDir) && Directory.GetFileSystemEntries(songDir).Length == 0)
|
||||
Directory.Delete(songDir);
|
||||
}
|
||||
|
||||
public bool IsSongDownloaded(string songId)
|
||||
=> File.Exists(AudioPath(songId));
|
||||
{
|
||||
TryMigrateLegacySong(songId);
|
||||
return File.Exists(AudioPath(songId));
|
||||
}
|
||||
|
||||
public bool IsDifficultyDownloaded(SongInfo song, string difficulty)
|
||||
{
|
||||
TryMigrateLegacySong(song.id);
|
||||
|
||||
string path = MapPath(song, difficulty);
|
||||
return path != null && File.Exists(path);
|
||||
}
|
||||
@@ -73,6 +89,8 @@ public class DownloadManager : MonoBehaviour
|
||||
private IEnumerator DownloadSongCoroutine(SongInfo song, string difficulty,
|
||||
Action<float> onProgress, Action onComplete, Action<string> onError)
|
||||
{
|
||||
TryMigrateLegacySong(song.id);
|
||||
|
||||
string songDir = Path.GetFullPath(SongDir(song.id));
|
||||
Directory.CreateDirectory(songDir);
|
||||
|
||||
@@ -157,4 +175,37 @@ public class DownloadManager : MonoBehaviour
|
||||
|
||||
private static string SongDir(string songId)
|
||||
=> Path.Combine(CacheRoot, songId);
|
||||
|
||||
private static string LegacySongDir(string songId)
|
||||
=> Path.Combine(LegacyCacheRoot, songId);
|
||||
|
||||
private static void TryMigrateLegacySong(string songId)
|
||||
{
|
||||
string sourceDir = LegacySongDir(songId);
|
||||
string targetDir = SongDir(songId);
|
||||
|
||||
if (Directory.Exists(targetDir) || !Directory.Exists(sourceDir))
|
||||
return;
|
||||
|
||||
CopyDirectory(sourceDir, targetDir);
|
||||
Directory.Delete(sourceDir, recursive: true);
|
||||
Debug.Log($"[DownloadManager] 기존 캐시를 영구 저장소로 이동: {songId}");
|
||||
}
|
||||
|
||||
private static void CopyDirectory(string sourceDir, string targetDir)
|
||||
{
|
||||
Directory.CreateDirectory(targetDir);
|
||||
|
||||
foreach (string file in Directory.GetFiles(sourceDir))
|
||||
{
|
||||
string targetFile = Path.Combine(targetDir, Path.GetFileName(file));
|
||||
File.Copy(file, targetFile, overwrite: true);
|
||||
}
|
||||
|
||||
foreach (string dir in Directory.GetDirectories(sourceDir))
|
||||
{
|
||||
string targetSubDir = Path.Combine(targetDir, Path.GetFileName(dir));
|
||||
CopyDirectory(dir, targetSubDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user