Skip to content

Commit

Permalink
dokan test
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Jun 1, 2024
1 parent 1a34dad commit 3e22079
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions src/MDriveSync.Core/Services/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,15 @@ public void StartJob()

watcher.EnableRaisingEvents = true;
_localWatchers.Add(watcher);

//// 文件夹监听
//var dirFsWatcher = new FileSystemWatcher(localBackupPath)
//{
// IncludeSubdirectories = true,
// NotifyFilter = NotifyFilters.DirectoryName
//};
//dirFsWatcher.Deleted += OnCommonFileSystemWatcherDirectoryDeleted;
//dirFsWatcher.EnableRaisingEvents = true;
}
}

Expand Down Expand Up @@ -1069,9 +1078,18 @@ await AliyunDriveDownload(data.Url,

public void Dispose()
{
foreach (var watcher in _localWatchers)
try
{
foreach (var watcher in _localWatchers)
{
watcher.Dispose();
}

GC.SuppressFinalize(this);
}
catch
{
watcher.Dispose();

}
}

Expand Down Expand Up @@ -1618,7 +1636,8 @@ private bool ShouldFilter(string path)
foreach (var item in _jobConfig.Filters)
{
// 忽略注释
if (item.StartsWith("#")) continue;
if (item.StartsWith("#"))
continue;

// 处理其他规则
var pattern = ConvertToRegexPattern(item);
Expand All @@ -1636,7 +1655,7 @@ private bool ShouldFilter(string path)
}

/// <summary>
/// 将Kopia规则转换为正则表达式
/// 将 Kopia 规则转换为正则表达式
/// </summary>
/// <param name="kopiaPattern"></param>
/// <returns></returns>
Expand Down Expand Up @@ -2818,6 +2837,21 @@ public AliyunDriveOpenFileGetDownloadUrlResponse AliyunDriveGetDownloadUrl(strin

#region 文件监听事件

//private string AlterPathToMountPath(string path)
//{
// var relativeMirrorPath = path.Substring(_sourcePath.Length).TrimStart('\\');

// return Path.Combine(_targetPath, relativeMirrorPath);
//}

//private void OnCommonFileSystemWatcherDirectoryDeleted(object sender, FileSystemEventArgs e)
//{
// if (_dokanInstance.IsDisposed) return;
// var fullPath = AlterPathToMountPath(e.FullPath);

// Dokan.Notify.Delete(_dokanInstance, fullPath, true);
//}

/// <summary>
/// 文件/文件夹删除事件
/// </summary>
Expand Down Expand Up @@ -2848,6 +2882,8 @@ private void OnDeleted(object source, FileSystemEventArgs e, string localBackupF
// 未知
_log.LogInformation($"文件夹/文件删除: {e.FullPath}, 类型: {e.ChangeType}");
}

//Dokan.Notify.Delete(_dokanInstance, fullPath, false);
}

/// <summary>
Expand Down Expand Up @@ -2878,6 +2914,10 @@ private void OnCreated(object source, FileSystemEventArgs e, string localBackupF
// 文件或文件夹,不处理
_log.LogInformation($"文件/文件夹创建: {e.FullPath}, 类型: {e.ChangeType}");
}

//var fullPath = AlterPathToMountPath(e.FullPath);
//var isDirectory = Directory.Exists(fullPath);
//Dokan.Notify.Create(_dokanInstance, fullPath, isDirectory);
}

/// <summary>
Expand All @@ -2888,6 +2928,8 @@ private void OnCreated(object source, FileSystemEventArgs e, string localBackupF
private void OnChanged(object source, FileSystemEventArgs e)
{
_log.LogInformation($"文件/文件夹更改: {e.FullPath}, 类型: {e.ChangeType}");

//Dokan.Notify.Update(_dokanInstance, fullPath);
}

/// <summary>
Expand Down Expand Up @@ -2921,6 +2963,17 @@ private void OnRenamed(object source, RenamedEventArgs e, string localBackupFull
// 不处理
_log.LogInformation($"文件/文件夹夹重命名: {e.OldFullPath} 更改为 {e.FullPath}, 类型: {e.ChangeType}");
}

//var oldFullPath = AlterPathToMountPath(e.OldFullPath);
//var oldDirectoryName = Path.GetDirectoryName(e.OldFullPath);

//var fullPath = AlterPathToMountPath(e.FullPath);
//var directoryName = Path.GetDirectoryName(e.FullPath);

//var isDirectory = Directory.Exists(e.FullPath);
//var isInSameDirectory = String.Equals(oldDirectoryName, directoryName);

//Dokan.Notify.Rename(_dokanInstance, oldFullPath, fullPath, isDirectory, isInSameDirectory);
}

/// <summary>
Expand Down

0 comments on commit 3e22079

Please sign in to comment.