in rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/MetaTracker.kt [62:134]
fun onEvent(events: MutableList<out VFileEvent>) {
val unityProjects = synchronized(lock) { mutableListOf<Project>().also { it.addAll(projects) } }.filter {
!isUndoRedoInProgress(it) && !it.isDisposed
}.toList()
for (event in events) {
if (!isValidEvent(event)) continue
for (project in unityProjects) {
if (isApplicableForProject(event, project)) {
val actions = getOrCreate(project)
if (isMetaFile(event)) // Collect modified meta files at first (LocalHistory or git or something else)
actions.addInitialSetOfChangedMetaFiles(Paths.get(event.path))
else {
try {
when (event) {
is VFileCreateEvent -> {
val metaFileName = getMetaFileName(event.childName)
val metaFile = event.parent.toNioPath().resolve(metaFileName)
val ls = event.file?.detectedLineSeparator
?: "\n" // from what I see, Unity 2020.3 always uses "\n", but lets use same as the main file.
actions.add(metaFile, project) {
if (shouldCreateMetaFile(project, event.file, event.parent)) createMetaFile(event.parent, metaFileName, ls)
}
}
is VFileDeleteEvent -> {
val metaFile = getMetaFile(event.path) ?: continue
actions.add(metaFile, project) {
val fileToDelete = VfsUtil.findFile(metaFile, true)
if (fileToDelete != null) {
fileToDelete.readBytes() // Preload file content into VFS to allow local history to restore it on undo operation
fileToDelete.delete(this)
}
}
}
is VFileCopyEvent -> {
val metaFile = getMetaFile(event.file.path) ?: continue
val ls = event.file.detectedLineSeparator ?: "\n"
actions.add(metaFile, project) {
if (shouldCreateMetaFile(project, event.file, event.newParent))
createMetaFile(event.newParent, getMetaFileName(event.newChildName), ls)
}
}
is VFileMoveEvent -> {
val metaFile = getMetaFile(event.oldPath) ?: continue
actions.add(metaFile, project) { VfsUtil.findFile(metaFile, true)?.move(this, event.newParent)
}
}
is VFilePropertyChangeEvent -> {
if (!event.isRename) continue
val metaFile = getMetaFile(event.oldPath) ?: continue
actions.add(metaFile, project) {
val target = getMetaFileName(event.newValue as String)
val origin = VfsUtil.findFile(metaFile, true)
val conflictingMeta = origin?.parent?.findChild(target)
if (conflictingMeta != null) {
logger.warn("Removing conflicting meta $conflictingMeta")
conflictingMeta.delete(this)
}
origin?.rename(this, target)
}
}
}
}
catch (t: Throwable) {
logger.error(t)
continue
}
}
}
}
}
}