Skip to content

Commit

Permalink
修复一个启动时检查更新导致可能闪退的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jan 10, 2025
1 parent 566f685 commit cdda4a0
Showing 1 changed file with 50 additions and 41 deletions.
91 changes: 50 additions & 41 deletions Core/Tools/ProgramUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,57 +668,66 @@ public class Update_FFMPEG
{
public static async void CheckUpdateFFmpegAsync(object state)
{

if (Directory.Exists("./Plugins/ffmpeg/") && File.Exists("./Plugins/ffmpeg/ffmpeg.exe"))
try
{
if (new FileInfo("./Plugins/ffmpeg/ffmpeg.exe").Length < 70000000)


if (Directory.Exists("./Plugins/ffmpeg/") && File.Exists("./Plugins/ffmpeg/ffmpeg.exe"))
{
Log.Info(nameof(Update_FFMPEG), "检查到FFEMPG版本过老,开始更新");
string url = "FFMPEG/github.js";
re_run:

var config = new AmazonS3Config() { ServiceURL = endpoint, MaxErrorRetry = 2, Timeout = TimeSpan.FromSeconds(20) };
var ossClient = new AmazonS3Client(AKID, AKSecret, config);
GetObjectResponse response = ossClient.GetObjectAsync(Bucket, url).Result;
StreamReader reader = new StreamReader(response.ResponseStream);
string File_Url = reader.ReadToEndAsync().Result;


string downloadPath = $"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg.zip";
string extractPath = $"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg";
try
{
Log.Info(nameof(Update_FFMPEG),$"开始下载新ffmpeg文件:{File_Url}");
await DownloadFileAsync(File_Url, downloadPath);
Log.Info(nameof(Update_FFMPEG),$"开始解压新ffmpeg文件:{downloadPath}");
ExtractZipFile(downloadPath, extractPath);
Log.Info(nameof(Update_FFMPEG),$"解压新ffmpeg文件完成");
}
catch (Exception ex)
if (new FileInfo("./Plugins/ffmpeg/ffmpeg.exe").Length < 70000000)
{
Log.Info(nameof(Update_FFMPEG), "检查到FFEMPG版本过老,开始更新");
string url = "FFMPEG/github.js";
re_run:

if (url == "FFMPEG/github.js")
var config = new AmazonS3Config() { ServiceURL = endpoint, MaxErrorRetry = 2, Timeout = TimeSpan.FromSeconds(20) };
var ossClient = new AmazonS3Client(AKID, AKSecret, config);
GetObjectResponse response = ossClient.GetObjectAsync(Bucket, url).Result;
StreamReader reader = new StreamReader(response.ResponseStream);
string File_Url = reader.ReadToEndAsync().Result;


string downloadPath = $"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg.zip";
string extractPath = $"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg";
try
{
Log.Error(nameof(Update_FFMPEG), "更新FFMPEG出现错误,重试", ex, false);
url = "FFMPEG/cf.js";
goto re_run;
Log.Info(nameof(Update_FFMPEG), $"开始下载新ffmpeg文件:{File_Url}");
await DownloadFileAsync(File_Url, downloadPath);
Log.Info(nameof(Update_FFMPEG), $"开始解压新ffmpeg文件:{downloadPath}");
ExtractZipFile(downloadPath, extractPath);
Log.Info(nameof(Update_FFMPEG), $"解压新ffmpeg文件完成");
}
Log.Error(nameof(Update_FFMPEG), "更新FFMPE重试失败,本次放弃更新", ex, false);
return;
}
if(File.Exists($"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe"))
{
File.Copy($"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe", "./plugins/ffmpeg/new_ffmpeg.exe");

Log.Info(nameof(Update_FFMPEG),$"解压新ffmpeg文件到【./plugins/ffmpeg/new_ffmpeg.exe】,下次重新启动ddtv时自动替换生效");
Thread.Sleep(1000);
Tools.FileOperations.Delete(downloadPath);
Tools.FileOperations.DeletePathFile($"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg");
catch (Exception ex)
{

if (url == "FFMPEG/github.js")
{
Log.Error(nameof(Update_FFMPEG), "更新FFMPEG出现错误,重试", ex, false);
url = "FFMPEG/cf.js";
goto re_run;
}
Log.Error(nameof(Update_FFMPEG), "更新FFMPE重试失败,本次放弃更新", ex, false);
return;
}
if (File.Exists($"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe"))
{
File.Copy($"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe", "./plugins/ffmpeg/new_ffmpeg.exe", true);

Log.Info(nameof(Update_FFMPEG), $"解压新ffmpeg文件到【./plugins/ffmpeg/new_ffmpeg.exe】,下次重新启动ddtv时自动替换生效");
Thread.Sleep(1000);
Tools.FileOperations.Delete(downloadPath);
Tools.FileOperations.DeletePathFile($"{Core.Config.Core_RunConfig._TemporaryFileDirectory}new_ffmpeg");

return;
return;
}
}
}
}
catch (Exception)
{

throw;
}
}

static async Task DownloadFileAsync(string url, string destinationPath)
Expand Down

0 comments on commit cdda4a0

Please sign in to comment.