Exemplo n.º 1
0
		unsafe public void Load()
		{
			List<NodeInstance> oldInstances = new List<NodeInstance>();
			foreach (var instance in FInstances)
				oldInstances.Add(instance);

			Unload();

			try
			{
				if (!File.Exists(FFilename))
					throw (new Exception("File not found"));

				FTemporaryFilename = System.IO.Path.GetTempPath() + Path.GetFileName(FFilename);
				if (File.Exists(FTemporaryFilename))
				{
					try
					{
						File.Delete(FTemporaryFilename);
					}
					catch
					{
						int index = 0;
						string noExtension = FTemporaryFilename.Substring(0, FTemporaryFilename.Length - 4);

						while (File.Exists(FTemporaryFilename))
						{
							FTemporaryFilename = noExtension + "~" + index.ToString() + ".dll";
							index++;
						}
					}
				}

                WaitForAccess(100);

                File.Copy(FFilename, FTemporaryFilename);
                FWatcher.Path = Path.GetDirectoryName(FFilename);
				FWatcher.EnableRaisingEvents = true;

				FLibrary = LoadLibrary(FTemporaryFilename);
				if (FLibrary == IntPtr.Zero)
					throw (new Exception("Failed to load temporary dll copy at " + FTemporaryFilename + ". Check that you have the openFrameworks dlls in the vvvv.exe folder"));
				SetDataPath = (NodeSetDataPath)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "SetDataPath"), typeof(NodeSetDataPath));
				Create = (NodeCreateDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeCreate"), typeof(NodeCreateDelegate));
				Destroy = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeDestroy"), typeof(NodeArgumentlessDelegate));
				Setup = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeSetup"), typeof(NodeArgumentlessDelegate));
				Update = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeUpdate"), typeof(NodeArgumentlessDelegate));
				Draw = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeDraw"), typeof(NodeArgumentlessDelegate));
				GetInputCount = (NodeCountPinsDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeInputCount"), typeof(NodeCountPinsDelegate));
				GetOutputCount = (NodeCountPinsDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeOutputCount"), typeof(NodeCountPinsDelegate));
				SetInputSliceCount = (NodeSetSpreadSliceCountDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeSetInputSliceCount"), typeof(NodeSetSpreadSliceCountDelegate));
				GetOutputSliceCount = (NodeGetSpreadSliceCountDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeGetOutputSliceCount"), typeof(NodeGetSpreadSliceCountDelegate));
				SetInputValue = (NodeSetSpreadValueDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeSetInputValue"), typeof(NodeSetSpreadValueDelegate));
				GetOutputValue = (NodeGetSpreadValueDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeGetOutputValue"), typeof(NodeGetSpreadValueDelegate));

				var dataPath = (Path.GetDirectoryName(FFilename) + "\\data").ToCharArray();
				fixed (char* pathAsChar = &dataPath[0])
					SetDataPath(pathAsChar, dataPath.Length);

				this.FLoaded = true;

				foreach (var instance in oldInstances)
				{
					instance.Create();
					instance.Setup();
				}
			}
			catch (Exception e)
			{
				this.FLoaded = false;

				foreach (var instance in FInstances)
					instance.Destroy();

				throw (e);
			}
		}
Exemplo n.º 2
0
			unsafe public void Load()
			{
				Unload();

				try
				{
					if (!File.Exists(FFilename))
						throw (new Exception("File not found"));

					FTemporaryFilename = System.IO.Path.GetTempPath() + Path.GetFileName(FFilename);
					if (File.Exists(FTemporaryFilename))
					{
						try
						{
							File.Delete(FTemporaryFilename);
						}
						catch
						{
							int index = 0;
							string noExtension = FTemporaryFilename.Substring(0, FTemporaryFilename.Length - 4);

							while (File.Exists(FTemporaryFilename))
							{
								FTemporaryFilename = noExtension + "~" + index.ToString() + ".dll";
							}
						}
					}

					System.Threading.Thread.Sleep(1000);
					//WaitForAccess(0);

					File.Copy(FFilename, FTemporaryFilename);
					FLastWrite = File.GetLastWriteTime(FFilename);

					FLibrary = LoadLibrary(FTemporaryFilename);
					SetDataPath = (NodeSetDataPath)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "SetDataPath"), typeof(NodeSetDataPath));
					Create = (NodeCreateDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeCreate"), typeof(NodeCreateDelegate));
					Destroy = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeDestroy"), typeof(NodeArgumentlessDelegate));
					Setup = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeSetup"), typeof(NodeArgumentlessDelegate));
					Update = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeUpdate"), typeof(NodeArgumentlessDelegate));
					Draw = (NodeArgumentlessDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeDraw"), typeof(NodeArgumentlessDelegate));
					GetInputCount = (NodeCountPinsDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeInputCount"), typeof(NodeCountPinsDelegate));
					GetOutputCount = (NodeCountPinsDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeOutputCount"), typeof(NodeCountPinsDelegate));
					SetInputSliceCount = (NodeSetSpreadSliceCountDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeSetInputSliceCount"), typeof(NodeSetSpreadSliceCountDelegate));
					SetInputValue = (NodeSetSpreadValueDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(FLibrary, "NodeSetInputValue"), typeof(NodeSetSpreadValueDelegate));

					var dataPath = Path.GetDirectoryName(FFilename).ToCharArray();
					fixed (char * pathAsChar = &dataPath[0])
					    SetDataPath(pathAsChar, dataPath.Length);

					this.FLoaded = true;

					foreach (var instance in FInstances)
					{
						instance.Create();
						instance.Setup();
					}
				}
				catch (Exception e)
				{
					this.FLoaded = false;
					throw (e);
				}
			}