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); 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 = new FileSystemWatcher(Path.Combine(General.AppPath, SCRIPT_FOLDER, "scripts"));
watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size; watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size;
watcher.IncludeSubdirectories = true; watcher.IncludeSubdirectories = true;
@ -139,6 +143,7 @@ namespace CodeImp.DoomBuilder.UDBScript
watcher.Created += OnWatcherEvent; watcher.Created += OnWatcherEvent;
watcher.Deleted += OnWatcherEvent; watcher.Deleted += OnWatcherEvent;
watcher.Renamed += OnWatcherEvent; watcher.Renamed += OnWatcherEvent;
}
editorexepath = General.Settings.ReadPluginSetting("externaleditor", string.Empty); 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 // Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously
new Task(LoadScripts).Start(); new Task(LoadScripts).Start();
if (watcher != null)
watcher.EnableRaisingEvents = true; watcher.EnableRaisingEvents = true;
} }
@ -164,11 +170,13 @@ namespace CodeImp.DoomBuilder.UDBScript
// Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously // Methods called by LoadScripts might sleep for some time, so call LoadScripts asynchronously
new Task(LoadScripts).Start(); new Task(LoadScripts).Start();
if (watcher != null)
watcher.EnableRaisingEvents = true; watcher.EnableRaisingEvents = true;
} }
public override void OnMapCloseBegin() public override void OnMapCloseBegin()
{ {
if (watcher != null)
watcher.EnableRaisingEvents = false; watcher.EnableRaisingEvents = false;
SaveScriptSlotsAndOptions(); SaveScriptSlotsAndOptions();
@ -230,6 +238,9 @@ namespace CodeImp.DoomBuilder.UDBScript
internal void SaveScriptDirectoryExpansionStatus(ScriptDirectoryStructure root) internal void SaveScriptDirectoryExpansionStatus(ScriptDirectoryStructure root)
{ {
if (root == null)
return;
if(root.Expanded) if(root.Expanded)
{ {
General.Settings.DeletePluginSetting("directoryexpand." + root.Hash); General.Settings.DeletePluginSetting("directoryexpand." + root.Hash);

View file

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