So I’ve got some code that writes out a readme file when the game is first run, and Avast blocks this.
I know the file it’s blocking so I try to check it with File.Exists
The procedure should work as follows:
Try to write file
Check to see if file was written
If the file was blocked put up an error message and force an exit
the problem is that it actually works like this:
Try to write out a file
Avast Av blocks it.
Unity doesn’t run the rest of the function including the test because the write was blocked. But it keeps on running the rest of the game like nothing happened, except the game is borked because half the setup didn’t work.
So what happens when unity hits an issue like this? Does it terminate the rest of the call stack or what?
Interresting problem. Definitely not an expert and maybe someone knows exactly what to do.
But do you handle exceptions when trying to write the file? It feels like the write action being blocked for any reasons should cause an exception, which you could catch and handle accordingly.
That’s a good idea and probably the way I should do it. Right now I put the test for the file in an invoke (delay of .1) right before I try to write the file. This makes the test execute reliably, but the exception still messes with the game.
The interesting thing is that the virus checker (avast) lets me create directories to my heart’s content, but as soon as I try to write out a text file, it blocks it.
I just switched it to use try, catch, and finally. It works, more or less.
The interesting thing is that it didn’t catch any exceptions. I went through and wrote log messages for every exception type listed for System.IO.File.WriteAllLines and none of them triggered. The only thing that detected it was actually checking for the file in the finally block.
Anyway, it’s not perfect, but it’s a whole lot better to tell the user that their AV is causing issues rather than letting them think the game is buggy.