SHA256
Update FFmpegDownloadUI to Support Cross-Platform Downloads
This commit is contained in:
1 file changed
+94
-19
+94
-19
@@ -22,7 +22,12 @@ namespace ADOFAIRenderer.UI
|
|||||||
private TextMeshProUGUI _statusText = null!;
|
private TextMeshProUGUI _statusText = null!;
|
||||||
|
|
||||||
private bool _isDownloading;
|
private bool _isDownloading;
|
||||||
private readonly string _downloadUrl = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip";
|
private string DownloadUrl => Application.platform switch
|
||||||
|
{
|
||||||
|
RuntimePlatform.WindowsPlayer => "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip",
|
||||||
|
RuntimePlatform.OSXPlayer => "https://github.com/ColorsWind/FFmpeg-macOS/releases/download/n5.0.1-patch3/FFmpeg-shared-n5.0.1-OSX-universal.zip",
|
||||||
|
_ => "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl-shared.tar.xz"
|
||||||
|
};
|
||||||
|
|
||||||
private System.Threading.CancellationTokenSource? _cts;
|
private System.Threading.CancellationTokenSource? _cts;
|
||||||
private readonly System.Collections.Concurrent.ConcurrentQueue<Action> _mainThreadQueue = new();
|
private readonly System.Collections.Concurrent.ConcurrentQueue<Action> _mainThreadQueue = new();
|
||||||
@@ -32,8 +37,14 @@ namespace ADOFAIRenderer.UI
|
|||||||
var userLibs = MelonEnvironment.UserLibsDirectory;
|
var userLibs = MelonEnvironment.UserLibsDirectory;
|
||||||
if (!Directory.Exists(userLibs)) return false;
|
if (!Directory.Exists(userLibs)) return false;
|
||||||
|
|
||||||
// Check for avcodec-*.dll
|
string searchPattern = Application.platform switch
|
||||||
var files = Directory.GetFiles(userLibs, "avcodec-*.dll");
|
{
|
||||||
|
RuntimePlatform.WindowsPlayer => "avcodec-*.dll",
|
||||||
|
RuntimePlatform.OSXPlayer => "libavcodec.*.dylib",
|
||||||
|
_ => "libavcodec.so*"
|
||||||
|
};
|
||||||
|
|
||||||
|
var files = Directory.GetFiles(userLibs, searchPattern);
|
||||||
return files.Length > 0;
|
return files.Length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +413,13 @@ namespace ADOFAIRenderer.UI
|
|||||||
Directory.CreateDirectory(userLibsDir);
|
Directory.CreateDirectory(userLibsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempZipPath = Path.Combine(userLibsDir, "ffmpeg_temp.zip");
|
string extension = Application.platform switch
|
||||||
|
{
|
||||||
|
RuntimePlatform.WindowsPlayer => ".zip",
|
||||||
|
RuntimePlatform.OSXPlayer => ".zip",
|
||||||
|
_ => ".tar.xz"
|
||||||
|
};
|
||||||
|
tempZipPath = Path.Combine(userLibsDir, "ffmpeg_temp" + extension);
|
||||||
|
|
||||||
var progressReporter = new Progress<float>(percent =>
|
var progressReporter = new Progress<float>(percent =>
|
||||||
{
|
{
|
||||||
@@ -410,7 +427,7 @@ namespace ADOFAIRenderer.UI
|
|||||||
UpdateStatus($"다운로드 중... ({(percent * 100f):F1}%)", new Color(0f, 0.8f, 1f));
|
UpdateStatus($"다운로드 중... ({(percent * 100f):F1}%)", new Color(0f, 0.8f, 1f));
|
||||||
});
|
});
|
||||||
|
|
||||||
await DownloadFileAsync(_downloadUrl, tempZipPath, progressReporter, _cts.Token);
|
await DownloadFileAsync(DownloadUrl, tempZipPath, progressReporter, _cts.Token);
|
||||||
|
|
||||||
// 다운로드 완료 후 압축 해제
|
// 다운로드 완료 후 압축 해제
|
||||||
UpdateStatus("압축 해제 및 DLL 파일 복사 중...", new Color(0.9f, 0.9f, 0.2f));
|
UpdateStatus("압축 해제 및 DLL 파일 복사 중...", new Color(0.9f, 0.9f, 0.2f));
|
||||||
@@ -532,26 +549,84 @@ namespace ADOFAIRenderer.UI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.WindowsPlayer)
|
||||||
{
|
{
|
||||||
using var archive = ZipFile.OpenRead(zipPath);
|
await Task.Run(() =>
|
||||||
foreach (var entry in archive.Entries)
|
|
||||||
{
|
{
|
||||||
// dll 파일만 userlibs 디렉토리 경로에 바로 복사
|
var targetExtension = Application.platform == RuntimePlatform.OSXPlayer ? ".dylib" : ".dll";
|
||||||
if (entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
|
using var archive = ZipFile.OpenRead(zipPath);
|
||||||
|
foreach (var entry in archive.Entries)
|
||||||
{
|
{
|
||||||
var targetPath = Path.Combine(outputDirectory, entry.Name);
|
if (entry.FullName.EndsWith(targetExtension, StringComparison.OrdinalIgnoreCase))
|
||||||
|
|
||||||
var dir = Path.GetDirectoryName(targetPath);
|
|
||||||
if (dir != null && !Directory.Exists(dir))
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dir);
|
var targetPath = Path.Combine(outputDirectory, entry.Name);
|
||||||
|
|
||||||
|
var dir = Path.GetDirectoryName(targetPath);
|
||||||
|
if (dir != null && !Directory.Exists(dir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.ExtractToFile(targetPath, overwrite: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.ExtractToFile(targetPath, overwrite: true);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 리눅스 (또는 기타 플랫폼) - tar.xz 해제
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
var tempExtractDir = Path.Combine(outputDirectory, "ffmpeg_temp_extracted");
|
||||||
|
if (Directory.Exists(tempExtractDir))
|
||||||
|
{
|
||||||
|
Directory.Delete(tempExtractDir, true);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory(tempExtractDir);
|
||||||
|
|
||||||
|
var archiveUnixPath = zipPath.Replace('\\', '/');
|
||||||
|
var tempExtractUnixDir = tempExtractDir.Replace('\\', '/');
|
||||||
|
|
||||||
|
var startInfo = new System.Diagnostics.ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = "tar",
|
||||||
|
Arguments = $"-xf \"{archiveUnixPath}\" -C \"{tempExtractUnixDir}\"",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true
|
||||||
|
};
|
||||||
|
|
||||||
|
using (var process = System.Diagnostics.Process.Start(startInfo))
|
||||||
|
{
|
||||||
|
process!.WaitForExit();
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
{
|
||||||
|
var error = process.StandardError.ReadToEnd();
|
||||||
|
throw new Exception($"tar 압축 해제 실패 (ExitCode: {process.ExitCode}): {error}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 압축이 풀린 파일 중에서 .so 파일들을 찾아서 outputDirectory로 이동
|
||||||
|
var soFiles = Directory.GetFiles(tempExtractDir, "*.so*", SearchOption.AllDirectories);
|
||||||
|
foreach (var soFile in soFiles)
|
||||||
|
{
|
||||||
|
var fileName = Path.GetFileName(soFile);
|
||||||
|
var targetPath = Path.Combine(outputDirectory, fileName);
|
||||||
|
File.Copy(soFile, targetPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 임시 디렉토리 정리
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(tempExtractDir, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user