I put some logging in. Sorry for the Quick & Dirty instead of a proper pull request with a fix but I'm about to be unavailable for most of this coming week and I traced this down this afternoon so I thought I'd go ahead and report in case you wanted to fix it before I got to it.
private void WatcherOnChanged(object sender, FileSystemEventArgs e)
{
if (e.FullPath.Contains("FFXIV_CHR") && !e.FullPath.Contains("\\log\\"))
{
string filepath = @"D:log.log";
using (StreamWriter streamWriter = File.AppendText(filepath))
{
streamWriter.WriteLine("file path: " + e.FullPath.ToString());
streamWriter.WriteLine("dir name: " + (new FileInfo(e.FullPath).DirectoryName));
}
ReadFiles(new FileInfo(e.FullPath).DirectoryName);
}
}
crash happens when log reads (added some linebreaks):
<snip>
file path: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn\FFXIV_CHR<digits>\ADDON.DAT
dir name: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn\FFXIV_CHR<digits>
file path: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn\FFXIV_CHR<digits>\log
dir name: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn\FFXIV_CHR<digits>
file path: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn\FFXIV_CHR<digits>
dir name: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn
file path: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn\FFXIV_CHR<digits>
dir name: d:\Users\MarauderIIC\Documents\My Games\FINAL FANTASY XIV - A Realm Reborn
WatcherOnChanged() is occasionally triggered by the FFXIV_CHR directory itself updating, which causes DirectoryName to strip FFXIV_CHR from the path, which is what then causes ReadFiles to fail its extra folder.Contains() check, which then throws. The simplest fix, of course, is remove the (redundant?) check from WatcherOnChanged and return
instead of throw
in ReadFiles, or drop the check from ReadFiles.
Some more "correct" things are:
- use
FileInfo(e.FullPath).DirectoryName.Contains("FFXIV_CHR")
in the check(s)
- it should probably check only the last directory in the path instead of full path contain
Also the !e.FullPath.Contains("\\log\\")
check does not work as intended when the log dir is updated instead of a file in the log dir, due to the trailing slash.
I'll send a PR if I get to fixing it later this week.