Exemple #1
0
		private static void ProcessDataDirEvents()
		{
			List<ResourceRenamedEventArgs> renameEventBuffer = null;

			// Process events
			while (dataDirEventBuffer.Count > 0)
			{
				FileSystemEventArgs e = FetchFileSystemEvent(dataDirEventBuffer, dataDirWatcher.Path);
				if (e == null) continue;

				if (e.ChangeType == WatcherChangeTypes.Changed)
				{
					ResourceEventArgs args = new ResourceEventArgs(e.FullPath);
					bool justSaved = editorJustSavedRes.Contains(Path.GetFullPath(e.FullPath));
					// Ignore stuff saved by the editor itself
					if (!justSaved && (Resource.IsResourceFile(e.FullPath) || args.IsDirectory))
					{
						// Unregister outdated resources, if modified outside the editor
						if (!args.IsDirectory && ContentProvider.IsContentAvailable(args.Path))
						{
							bool isCurrentScene = args.Content.Is<Scene>() && Scene.Current == args.Content.Res;
							if (isCurrentScene || DualityEditorApp.IsResourceUnsaved(e.FullPath))
							{
								DialogResult result = MessageBox.Show(
									String.Format(EditorRes.GeneralRes.Msg_ConfirmReloadResource_Text, e.FullPath), 
									EditorRes.GeneralRes.Msg_ConfirmReloadResource_Caption, 
									MessageBoxButtons.YesNo,
									MessageBoxIcon.Exclamation);
								if (result == DialogResult.Yes)
								{
									string curScenePath = Scene.CurrentPath;
									ContentProvider.RemoveContent(args.Path);
									if (isCurrentScene) Scene.Current = ContentProvider.RequestContent<Scene>(curScenePath).Res;
								}
							}
							else
								ContentProvider.RemoveContent(args.Path);
						}

						if (ResourceModified != null) ResourceModified(null, args);
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Created)
				{
					if (File.Exists(e.FullPath))
					{
						// Register newly detected ressource file
						if (Resource.IsResourceFile(e.FullPath))
						{
							if (ResourceCreated != null)
								ResourceCreated(null, new ResourceEventArgs(e.FullPath));
						}
						// Import non-ressource file
						else
						{
							bool abort = false;

							if (FileImportProvider.IsImportFileExisting(e.FullPath))
							{
								DialogResult result = MessageBox.Show(
									String.Format(EditorRes.GeneralRes.Msg_ImportConfirmOverwrite_Text, e.FullPath), 
									EditorRes.GeneralRes.Msg_ImportConfirmOverwrite_Caption, 
									MessageBoxButtons.YesNo, 
									MessageBoxIcon.Warning);
								abort = result == DialogResult.No;
							}

							if (!abort)
							{
								bool importedSuccessfully = FileImportProvider.ImportFile(e.FullPath);
								if (!importedSuccessfully)
								{
									MessageBox.Show(
										String.Format(EditorRes.GeneralRes.Msg_CantImport_Text, e.FullPath), 
										EditorRes.GeneralRes.Msg_CantImport_Caption, 
										MessageBoxButtons.OK, 
										MessageBoxIcon.Error);
								}
								abort = !importedSuccessfully;
							}
						}
					}
					else if (Directory.Exists(e.FullPath))
					{
						// Register newly detected ressource directory
						if (ResourceCreated != null)
							ResourceCreated(null, new ResourceEventArgs(e.FullPath));
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Deleted)
				{
					// Is it a Resource file or just something else?
					ResourceEventArgs args = new ResourceEventArgs(e.FullPath);
					if (Resource.IsResourceFile(e.FullPath) || args.IsDirectory)
					{

						// Unregister no-more existing resources
						if (args.IsDirectory)	ContentProvider.RemoveContentTree(args.Path);
						else					ContentProvider.RemoveContent(args.Path);

						if (ResourceDeleted != null)
							ResourceDeleted(null, args);
					}
				}
				else if (e.ChangeType == WatcherChangeTypes.Renamed)
				{
					// Is it a Resource file or just something else?
					RenamedEventArgs re = e as RenamedEventArgs;
					ResourceRenamedEventArgs args = new ResourceRenamedEventArgs(re.FullPath, re.OldFullPath);
					if (Resource.IsResourceFile(e.FullPath) || args.IsDirectory)
					{
						// Rename content registerations
						if (args.IsDirectory)	ContentProvider.RenameContentTree(args.OldPath, args.Path);
						else					ContentProvider.RenameContent(args.OldPath, args.Path);

						// Query skipped paths
						bool isSkippedPath = false;
						if (BeginGlobalRename != null)
						{
							BeginGlobalRenameEventArgs beginGlobalRenameArgs = new BeginGlobalRenameEventArgs(args.Path, args.OldPath);
							BeginGlobalRename(null, beginGlobalRenameArgs);
							isSkippedPath = beginGlobalRenameArgs.Cancel;
						}

						if (!isSkippedPath)
						{
							// Buffer rename event to perform the global rename for all at once.
							if (renameEventBuffer == null) renameEventBuffer = new List<ResourceRenamedEventArgs>();
							renameEventBuffer.Add(args);
						}

						if (ResourceRenamed != null) ResourceRenamed(null, args);
					}
				}
			}

			// If required, perform a global rename operation in all existing content
			if (renameEventBuffer != null)
			{
				// Don't do it now - schedule it for the main form event loop so we don't block here.
				DualityEditorApp.MainForm.BeginInvoke((Action)delegate() {
					ProcessingBigTaskDialog taskDialog = new ProcessingBigTaskDialog( 
						EditorRes.GeneralRes.TaskRenameContentRefs_Caption, 
						EditorRes.GeneralRes.TaskRenameContentRefs_Desc, 
						async_RenameContentRefs, renameEventBuffer);
					taskDialog.ShowDialog(DualityEditorApp.MainForm);
				});
			}
		}
		private void FileEventManager_BeginGlobalRename(object sender, BeginGlobalRenameEventArgs e)
		{
			if (this.skipGlobalRenamePath.Remove(Path.GetFullPath(e.OldPath)))
				e.Cancel = true;
		}
Exemple #3
0
        private static void ProcessDataDirEvents()
        {
            List <ResourceRenamedEventArgs> renameEventBuffer = null;

            // Process events
            while (dataDirEventBuffer.Count > 0)
            {
                FileSystemEventArgs e = FetchFileSystemEvent(dataDirEventBuffer, dataDirWatcher.Path);
                if (e == null)
                {
                    continue;
                }

                if (e.ChangeType == WatcherChangeTypes.Changed)
                {
                    ResourceEventArgs args = new ResourceEventArgs(e.FullPath);
                    bool justSaved         = editorJustSavedRes.Contains(Path.GetFullPath(e.FullPath));
                    // Ignore stuff saved by the editor itself
                    if (!justSaved && (Resource.IsResourceFile(e.FullPath) || args.IsDirectory))
                    {
                        // Unregister outdated resources, if modified outside the editor
                        if (!args.IsDirectory && ContentProvider.IsContentAvailable(args.Path))
                        {
                            bool isCurrentScene = args.Content.Is <Scene>() && Scene.Current == args.Content.Res;
                            if (isCurrentScene || DualityEditorApp.IsResourceUnsaved(e.FullPath))
                            {
                                DialogResult result = MessageBox.Show(
                                    String.Format(EditorRes.GeneralRes.Msg_ConfirmReloadResource_Text, e.FullPath),
                                    EditorRes.GeneralRes.Msg_ConfirmReloadResource_Caption,
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Exclamation);
                                if (result == DialogResult.Yes)
                                {
                                    string curScenePath = Scene.CurrentPath;
                                    ContentProvider.RemoveContent(args.Path);
                                    if (isCurrentScene)
                                    {
                                        Scene.Current = ContentProvider.RequestContent <Scene>(curScenePath).Res;
                                    }
                                }
                            }
                            else
                            {
                                ContentProvider.RemoveContent(args.Path);
                            }
                        }

                        if (ResourceModified != null)
                        {
                            ResourceModified(null, args);
                        }
                    }
                }
                else if (e.ChangeType == WatcherChangeTypes.Created)
                {
                    if (File.Exists(e.FullPath))
                    {
                        // Register newly detected ressource file
                        if (Resource.IsResourceFile(e.FullPath))
                        {
                            if (ResourceCreated != null)
                            {
                                ResourceCreated(null, new ResourceEventArgs(e.FullPath));
                            }
                        }
                        // Import non-ressource file
                        else
                        {
                            bool abort = false;

                            if (FileImportProvider.IsImportFileExisting(e.FullPath))
                            {
                                DialogResult result = MessageBox.Show(
                                    String.Format(EditorRes.GeneralRes.Msg_ImportConfirmOverwrite_Text, e.FullPath),
                                    EditorRes.GeneralRes.Msg_ImportConfirmOverwrite_Caption,
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Warning);
                                abort = result == DialogResult.No;
                            }

                            if (!abort)
                            {
                                bool importedSuccessfully = FileImportProvider.ImportFile(e.FullPath);
                                if (!importedSuccessfully)
                                {
                                    MessageBox.Show(
                                        String.Format(EditorRes.GeneralRes.Msg_CantImport_Text, e.FullPath),
                                        EditorRes.GeneralRes.Msg_CantImport_Caption,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                                }
                                abort = !importedSuccessfully;
                            }
                        }
                    }
                    else if (Directory.Exists(e.FullPath))
                    {
                        // Register newly detected ressource directory
                        if (ResourceCreated != null)
                        {
                            ResourceCreated(null, new ResourceEventArgs(e.FullPath));
                        }
                    }
                }
                else if (e.ChangeType == WatcherChangeTypes.Deleted)
                {
                    // Is it a Resource file or just something else?
                    ResourceEventArgs args = new ResourceEventArgs(e.FullPath);
                    if (Resource.IsResourceFile(e.FullPath) || args.IsDirectory)
                    {
                        // Unregister no-more existing resources
                        if (args.IsDirectory)
                        {
                            ContentProvider.RemoveContentTree(args.Path);
                        }
                        else
                        {
                            ContentProvider.RemoveContent(args.Path);
                        }

                        if (ResourceDeleted != null)
                        {
                            ResourceDeleted(null, args);
                        }
                    }
                }
                else if (e.ChangeType == WatcherChangeTypes.Renamed)
                {
                    // Is it a Resource file or just something else?
                    RenamedEventArgs         re   = e as RenamedEventArgs;
                    ResourceRenamedEventArgs args = new ResourceRenamedEventArgs(re.FullPath, re.OldFullPath);
                    if (Resource.IsResourceFile(e.FullPath) || args.IsDirectory)
                    {
                        // Rename content registerations
                        if (args.IsDirectory)
                        {
                            ContentProvider.RenameContentTree(args.OldPath, args.Path);
                        }
                        else
                        {
                            ContentProvider.RenameContent(args.OldPath, args.Path);
                        }

                        // Query skipped paths
                        bool isSkippedPath = false;
                        if (BeginGlobalRename != null)
                        {
                            BeginGlobalRenameEventArgs beginGlobalRenameArgs = new BeginGlobalRenameEventArgs(args.Path, args.OldPath);
                            BeginGlobalRename(null, beginGlobalRenameArgs);
                            isSkippedPath = beginGlobalRenameArgs.Cancel;
                        }

                        if (!isSkippedPath)
                        {
                            // Buffer rename event to perform the global rename for all at once.
                            if (renameEventBuffer == null)
                            {
                                renameEventBuffer = new List <ResourceRenamedEventArgs>();
                            }
                            renameEventBuffer.Add(args);
                        }

                        if (ResourceRenamed != null)
                        {
                            ResourceRenamed(null, args);
                        }
                    }
                }
            }

            // If required, perform a global rename operation in all existing content
            if (renameEventBuffer != null)
            {
                // Don't do it now - schedule it for the main form event loop so we don't block here.
                DualityEditorApp.MainForm.BeginInvoke((Action) delegate() {
                    ProcessingBigTaskDialog taskDialog = new ProcessingBigTaskDialog(
                        EditorRes.GeneralRes.TaskRenameContentRefs_Caption,
                        EditorRes.GeneralRes.TaskRenameContentRefs_Desc,
                        async_RenameContentRefs, renameEventBuffer);
                    taskDialog.ShowDialog(DualityEditorApp.MainForm);
                });
            }
        }