IEnumerator Start() { bool firstLoad = true; while (true) { if (File.Exists(_filePath)) { string lastTimeFileModified = "" + DateTimeToUnixTimestamp(File.GetLastWriteTimeUtc(_filePath));; if (lastTimeFileModified != _lastTimeWrited) { _lastTimeWrited = lastTimeFileModified; _isUpdated = false; } if (!_isUpdated) { string fileContent = null; try { fileContent = File.ReadAllText(_filePath); if (firstLoad && !string.IsNullOrEmpty(fileContent)) { _onFirstLoad.Invoke(fileContent); } else if (!string.IsNullOrEmpty(fileContent)) { _onFileChanged.Invoke(fileContent); } _fileUnreadable = false; _isUpdated = true; firstLoad = false; } catch (IOException) { _fileUnreadable = true; // Debug.Log("File unreadabe"); } } } yield return(new WaitForEndOfFrame()); } }
static void OnFileChangedEvent(object sender, EventArgs e) { FileChangedEvent?.Invoke(sender, e); }
int IVsFileChangeEvents.DirectoryChanged(string pszDirectory) { FileChangedEvent?.Invoke(this, new TestFileChangedEventArgs(null, pszDirectory, TestFileChangedReason.Changed)); return(VSConstants.S_OK); }