Holit / SaveMyGame

一个即时文件保存工具。用于定时自动保存某文件夹的文件,并提供还原点可以一键还原
GNU General Public License v3.0
2 stars 1 forks source link

Refactor backup method with the ability to monitor file changes using the FileSystemWatcher #2

Open MadLongTom opened 6 months ago

MadLongTom commented 6 months ago

Example:

string dllpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Replace("Roaming", ""), "Local", "Temp", "lab", "Main_Data", "Managed", "Assembly-CSharp.dll");
string folderpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Replace("Roaming", ""), "Local", "Temp", "lab", "Main_Data", "Managed");
string temppath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Replace("Roaming", ""), "Local", "Temp");

FileSystemWatcher watcher = new FileSystemWatcher(temppath);
watcher.EnableRaisingEvents = true;
watcher.IncludeSubdirectories = true;

Console.WriteLine("Service started,you can press start button now.");

while (true)
{
    while (watcher.WaitForChanged(WatcherChangeTypes.Changed).Name != Path.Combine("lab", "Main_Data", "Managed", "Assembly-CSharp.dll")) { }
    //do backup there
}
watcher.Dispose();
Holit commented 6 months ago

tbd

Sonetto1999 commented 6 months ago

nb