Skip to content

Commit

Permalink
新增支持同步输出文件的修改文件为输入文件的修改时间(暂无设置UI)
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 9, 2023
1 parent 9337b6a commit 25ed184
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
64 changes: 64 additions & 0 deletions SimpleFFmpegGUI.Core/Manager/ConfigManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Newtonsoft.Json;
using SimpleFFmpegGUI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleFFmpegGUI.Manager
{
public static class ConfigManager
{
public const string SyncModifiedTimeKey = "SyncModifiedTime";

public static bool SyncModifiedTime
{
get => GetConfig(SyncModifiedTimeKey, true);
set => SetConfig(SyncModifiedTimeKey, value);
}

public static T GetConfig<T>(string key, T defaultValue)
{
using var db = FFmpegDbContext.GetNew();
var item = db.Configs.Where(p => p.Key == key).FirstOrDefault();
if (item == null)
{
return defaultValue;
}
return Parse<T>(item.Value);
}

public static void SetConfig<T>(string key, T value)
{
using var db = FFmpegDbContext.GetNew();
var item = db.Configs.Where(p => p.Key == key).FirstOrDefault();
if (item == null)
{
item = new Config()
{
Key = key,
Value = GetString(value)
};
db.Configs.Add(item);
}
else
{
item.Value = GetString(value);
db.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
}

db.SaveChanges();
}

private static T Parse<T>(string data)
{
return JsonConvert.DeserializeObject<T>(data);
}

private static string GetString<T>(T data)
{
return JsonConvert.SerializeObject(data);
}
}
}
14 changes: 14 additions & 0 deletions SimpleFFmpegGUI.Core/Manager/FFmpegManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ public async Task RunAsync()
_ => throw new NotSupportedException("不支持的任务类型:" + task.Type),
});


if (task.RealOutput!=null && File.Exists(task.RealOutput) && ConfigManager.SyncModifiedTime)
{
try
{
File.SetLastWriteTime(task.RealOutput, File.GetLastWriteTime(task.Inputs[^1].FilePath));
}
catch(Exception ex)
{
logger.Error(task, "修改输出文件的修改时间失败:"+ex.Message);
}
}

logger.Info(task, "完成任务");
}
finally
Expand Down Expand Up @@ -466,6 +479,7 @@ private async Task RunCodeProcessAsync(CancellationToken cancellationToken)
arg = ArgumentsGenerator.GetArguments(task, 2);
await RunAsync(arg, message, cancellationToken, tempDirectory);
}

}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion 日志.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,8 @@

## 20230416

【WPF】优化在转码时的缩略图显示
【WPF】优化在转码时的缩略图显示

## 20230509

【Core】新增支持同步输出文件的修改文件为输入文件的修改时间(暂无设置UI)

0 comments on commit 25ed184

Please sign in to comment.