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,6 +132,10 @@ namespace CodeImp.DoomBuilder.UDBScript
General.Actions.BindMethods(this);
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;
@ -139,6 +143,7 @@ namespace CodeImp.DoomBuilder.UDBScript
watcher.Created += OnWatcherEvent;
watcher.Deleted += OnWatcherEvent;
watcher.Renamed += OnWatcherEvent;
}
editorexepath = General.Settings.ReadPluginSetting("externaleditor", string.Empty);
@ -154,6 +159,7 @@ namespace CodeImp.DoomBuilder.UDBScript
// Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously
new Task(LoadScripts).Start();
if (watcher != null)
watcher.EnableRaisingEvents = true;
}
@ -164,11 +170,13 @@ namespace CodeImp.DoomBuilder.UDBScript
// Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously
new Task(LoadScripts).Start();
if (watcher != null)
watcher.EnableRaisingEvents = true;
}
public override void OnMapCloseBegin()
{
if (watcher != null)
watcher.EnableRaisingEvents = false;
SaveScriptSlotsAndOptions();
@ -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))
{