Skip to content

Commit

Permalink
🐛 修复版本迁移导致的脚本失效。
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossimos committed Nov 16, 2023
1 parent d5592b4 commit ea315a9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,43 @@ await AttemptAndRetry(async t =>
public async Task SaveScriptCachePathAsync(ScriptDTO item, CancellationToken cancellationToken)
{
var dbConnection = await GetDbConnection().ConfigureAwait(false);
await AttemptAndRetry(async t =>
{
t.ThrowIfCancellationRequested();
const string sql_ =
const string sql_ =
$"{SQLStrings.Update}[{Script.TableName}] " +
$"set [{Script.ColumnName_CachePath}] = '{{0}}' " +
$"where [{Script.ColumnName_CachePath}] = {{1}}";
var sql = string.Format(sql_, item.CachePath, item.LocalId);
//var sql =
// SQLStrings.Update +
// "[" + Script.TableName + "]" +
// " set " +
// "[" + Script.ColumnName_Enable + "]" +
// $" = {item.Enable}" +
// " where " +
// "[" + Script.ColumnName_Id + "]" +
// $" = {item.LocalId}";
var r = await dbConnection.ExecuteAsync(sql);
return r;
}, cancellationToken: cancellationToken).ConfigureAwait(false);
$"where [{Script.ColumnName_Id}] = {{1}}";
var sql = string.Format(sql_, item.CachePath, item.LocalId);
//var sql =
// SQLStrings.Update +
// "[" + Script.TableName + "]" +
// " set " +
// "[" + Script.ColumnName_Enable + "]" +
// $" = {item.Enable}" +
// " where " +
// "[" + Script.ColumnName_Id + "]" +
// $" = {item.LocalId}";
var r = await dbConnection.ExecuteAsync(sql);
Console.WriteLine(r);
//return r;
//await AttemptAndRetry(async t =>
//{
// t.ThrowIfCancellationRequested();
// const string sql_ =
// $"{SQLStrings.Update}[{Script.TableName}] " +
// $"set [{Script.ColumnName_CachePath}] = '{{0}}' " +
// $"where [{Script.ColumnName_Id}] = {{1}}";
// var sql = string.Format(sql_, item.CachePath, item.LocalId);
// //var sql =
// // SQLStrings.Update +
// // "[" + Script.TableName + "]" +
// // " set " +
// // "[" + Script.ColumnName_Enable + "]" +
// // $" = {item.Enable}" +
// // " where " +
// // "[" + Script.ColumnName_Id + "]" +
// // $" = {item.LocalId}";
// var r = await dbConnection.ExecuteAsync(sql);
// return r;
//}, cancellationToken: cancellationToken).ConfigureAwait(false);
}

public async Task<IList<Script>> GetAllAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,16 @@ public async Task<IEnumerable<ScriptDTO>> CheckFiles(IEnumerable<ScriptDTO> list
foreach (var item in list)
{
//检查缓存文件夹如果不是 IScriptManager.DirName_Build 替换成 IScriptManager.DirName_Build 开头
if (!item.CachePath.StartsWith($"{IScriptManager.DirName_Build}/"))
if (!item.CachePath.StartsWith($"{IScriptManager.DirName_Build}{Path.DirectorySeparatorChar}"))
{
item.CachePath = Path.Combine(IScriptManager.DirName_Build, item.FileName!);
var cachePath = Path.Combine(Plugin.Instance.CacheDirectory, item.CachePath);
if (File.Exists(cachePath))
{
File.Delete(cachePath);
}
await TryReadFileAsync(item, true);
item.Content = string.Empty;
await scriptRepository.SaveScriptCachePathAsync(item, default);
}
if (!CheckFile(item))
Expand Down Expand Up @@ -405,8 +412,9 @@ public bool CheckFile(ScriptDTO item)
/// 修改为仅尝试判断文件是否存在
/// </summary>
/// <param name="item"></param>
/// <param name="isReadContent"></param>
/// <returns></returns>
public async Task<ScriptDTO> TryReadFileAsync(ScriptDTO item)
public async Task<ScriptDTO> TryReadFileAsync(ScriptDTO item, bool isReadContent = false)
{
var cachePath = Path.Combine(Plugin.Instance.CacheDirectory, item.CachePath);
if (File.Exists(cachePath))
Expand All @@ -419,7 +427,10 @@ public async Task<ScriptDTO> TryReadFileAsync(ScriptDTO item)
var infoPath = Path.Combine(Plugin.Instance.AppDataDirectory, item.FilePath);
if (File.Exists(infoPath))
{
//item.Content = File.ReadAllText(infoPath);
if (isReadContent)
{
item.Content = File.ReadAllText(infoPath);
}
if (!await BuildScriptAsync(item, fileInfo, item.IsCompile))
{
toast.Show(ToastIcon.Error, AppResources.Script_ReadFileError_.Format(item.Name));
Expand Down

0 comments on commit ea315a9

Please sign in to comment.