Skip to content

Commit

Permalink
suspending filewatcher during file validation
Browse files Browse the repository at this point in the history
  • Loading branch information
manavortex committed May 3, 2024
1 parent 3e28b62 commit 298e383
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Scripts/Wolvenkit_FileValidation.wscript
Original file line number Diff line number Diff line change
Expand Up @@ -2259,8 +2259,11 @@ function workspotFile_CheckAnimSet(idx, animSet) {
}

for (let i = 0; i < animSet.Data.list.length; i++) {
const childItem = animSet.Data.list[i];
const childItemName = childItem.Data.animName.value || '';
const childItem = animSet.Data.list[i];
const childItemName = childItem.Data?.animName?.value || '';
if (!childItemName) {
continue;
}
workEntryIndicesByAnimName[childItemName] = idx;

animSetId = childItem.Data.id.id;
Expand Down Expand Up @@ -2395,7 +2398,7 @@ export function validateWorkspotFile(workspot, _workspotSettings) {
});
}

const unusedAnimSetNames = workspotAnimSetNames.filter((name) => !allAnimNamesFromAnimFiles.includes(name));
const unusedAnimSetNames = workspotAnimSetNames.filter((name) => !!name && !allAnimNamesFromAnimFiles.includes(name));
if (workspotSettings.showUndefinedWorkspotAnims && unusedAnimSetNames.length > 0) {
Logger.Info(`Items from .workspot not found in .anim files:`);
Logger.Info(unusedAnimSetNames.map((name) => `${workEntryIndicesByAnimName[name]}: ${name}`));
Expand Down
7 changes: 5 additions & 2 deletions Scripts/hook_global.wscript
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {hasUppercasePaths, isDataChangedForWriting} from "Wolvenkit_FileValidati
* If this is set to "true" and file validation runs into any errors, then YOUR FILES WILL NO LONGER SAVE.
* ONLY ENABLE THIS IF YOU KNOW WHAT YOU'RE DOING!
*/
const isWolvenkitDeveloper = true;
const isWolvenkitDeveloper = false;

const README_URL = 'https://wiki.redmodding.org/wolvenkit/wolvenkit-app/file-validation';

Expand All @@ -29,6 +29,7 @@ globalThis.onSave = function (ext, file) {
const fileName = (fileContent.Header?.ArchiveFileName || '').split('archive\\').pop() || '';
FileValidation.setPathToCurrentFile(fileName);

wkit.SuspendFileWatcher(true);
let success = true;
try {
const data = fileContent["Data"]["RootChunk"];
Expand Down Expand Up @@ -86,14 +87,16 @@ globalThis.onSave = function (ext, file) {
Logger.Info(`If you are using this as a hack to disable the feature, see ${README_URL}.`)
}

wkit.SuspendFileWatcher(false);

const retSuccess = {
success: success,
file: file
}

// either we have nothing to write or we aren't supposed to write => abort
if (!FileValidation.isDataChangedForWriting || Settings.DisableAutofix) return retSuccess;

const filePath = wkit.GetActiveDocument().FilePath;

// unless it's a workspot, automatically close and re-open it
Expand Down

0 comments on commit 298e383

Please sign in to comment.