UDBScript: fixed a crash when the UDBScript folder was missing or empty. Fixes #789

This commit is contained in:
biwa 2022-09-17 13:53:02 +02:00
parent 419e86d9ca
commit 7f09ac752b
2 changed files with 24 additions and 10 deletions

View file

@ -132,13 +132,18 @@ namespace CodeImp.DoomBuilder.UDBScript
General.Actions.BindMethods(this);
watcher = new FileSystemWatcher(Path.Combine(General.AppPath, SCRIPT_FOLDER, "scripts"));
watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size;
watcher.IncludeSubdirectories = true;
watcher.Changed += OnWatcherEvent;
watcher.Created += OnWatcherEvent;
watcher.Deleted += OnWatcherEvent;
watcher.Renamed += OnWatcherEvent;
string scriptspath = Path.Combine(General.AppPath, SCRIPT_FOLDER, "scripts");
if (Directory.Exists(scriptspath))
{
watcher = new FileSystemWatcher(Path.Combine(General.AppPath, SCRIPT_FOLDER, "scripts"));
watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size;
watcher.IncludeSubdirectories = true;
watcher.Changed += OnWatcherEvent;
watcher.Created += OnWatcherEvent;
watcher.Deleted += OnWatcherEvent;
watcher.Renamed += OnWatcherEvent;
}
editorexepath = General.Settings.ReadPluginSetting("externaleditor", string.Empty);
@ -154,7 +159,8 @@ namespace CodeImp.DoomBuilder.UDBScript
// Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously
new Task(LoadScripts).Start();
watcher.EnableRaisingEvents = true;
if (watcher != null)
watcher.EnableRaisingEvents = true;
}
public override void OnMapOpenEnd()
@ -164,12 +170,14 @@ namespace CodeImp.DoomBuilder.UDBScript
// Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously
new Task(LoadScripts).Start();
watcher.EnableRaisingEvents = true;
if (watcher != null)
watcher.EnableRaisingEvents = true;
}
public override void OnMapCloseBegin()
{
watcher.EnableRaisingEvents = false;
if (watcher != null)
watcher.EnableRaisingEvents = false;
SaveScriptSlotsAndOptions();
SaveScriptDirectoryExpansionStatus(scriptdirectorystructure);
@ -230,6 +238,9 @@ namespace CodeImp.DoomBuilder.UDBScript
internal void SaveScriptDirectoryExpansionStatus(ScriptDirectoryStructure root)
{
if (root == null)
return;
if(root.Expanded)
{
General.Settings.DeletePluginSetting("directoryexpand." + root.Hash);

View file

@ -284,6 +284,9 @@ namespace CodeImp.DoomBuilder.UDBScript
{
List<TreeNode> newnodes = new List<TreeNode>();
if (sds == null)
return newnodes.ToArray();
// Go through folders and add files (and other folders) recusrively
foreach (ScriptDirectoryStructure subsds in sds.Directories.OrderBy(s => s.Name))
{