/// <summary> /// Delete all content that's not user specific or possibly loaded /// by the editor (dll files). /// </summary> /// <returns>True if no exception - otherwise false.</returns> public static bool DeleteContent() { try { var handler = new DirectoryContentHandler(Utils.AGXUnityPackageDirectory); handler.DeleteAllCollected(); } catch (System.Exception) { return(false); } return(true); }
private static void PostReload() { EditorApplication.LockReloadAssemblies(); try { Debug.Log("Verifying native libraries aren't loaded..."); { var processModules = Process.GetCurrentProcess().Modules; var nativePluginsId = new DirectoryInfo(IO.Utils.AGXUnityPluginDirectory); foreach (ProcessModule processModule in processModules) { if (processModule.FileName.Contains(nativePluginsId.FullName)) { throw new System.Exception($"AGX Dynamics module {processModule.ModuleName} is loaded. Unable to install new version of package."); } } } var packageName = string.Empty; foreach (var arg in System.Environment.GetCommandLineArgs()) { if (arg.StartsWith(s_packageIdentifier)) { packageName = arg.Substring(s_packageIdentifier.Length); } } if (string.IsNullOrEmpty(packageName)) { throw new System.Exception($"Unable to find package name identifier {s_packageIdentifier} in arguments list: " + string.Join(" ", System.Environment.GetEnvironmentVariables())); } Debug.Log("Removing old native binaries..."); foreach (var nativePlugin in NativePlugins) { var fi = new FileInfo(nativePlugin.assetPath); Debug.Log($" - {fi.Name}"); var fiMeta = new FileInfo(nativePlugin.assetPath + ".meta"); try { fi.Delete(); if (fiMeta.Exists) { fiMeta.Delete(); } } catch (System.Exception) { Debug.LogError("Fatal update error: Close Unity and remove AGX Dynamics for Unity directory and install the latest version."); throw; } } var newPackageFileInfo = new FileInfo(packageName); if (newPackageFileInfo.Name.EndsWith("_Plugins_x86_64.unitypackage")) { // Manager is loaded when the binaries hasn't been added and ExternalAGXInitializer // pops up and asks if the user would like to located AGX Dynamics. We're // installing the binaries so it's a "user said no!" to begin with. ExternalAGXInitializer.UserSaidNo = true; var dataDirectory = IO.Utils.AGXUnityPluginDirectory + Path.DirectorySeparatorChar + "agx"; if (Directory.Exists(dataDirectory)) { var directoryHandler = new IO.DirectoryContentHandler(dataDirectory); Debug.Log($"Removing AGX Dynamics data directory {directoryHandler.RootDirectory}..."); directoryHandler.DeleteAllCollected(); } } else { Debug.Log("Removing all non-user specific content..."); IO.DirectoryContentHandler.DeleteContent(); } // This will generate compile errors from scripts using AGXUnity and // we don't know how to hide these until we're done, mainly because // we have no idea when we're done with the update. // // If this isn't performed, the compiler will throw exception due // to missing references and Unity will crash the first time we // use AGX Dynamics. AssetDatabase.Refresh(); Debug.Log($"Starting import of package: {packageName}"); AssetDatabase.ImportPackage(packageName, false); } catch (System.Exception e) { Debug.LogException(e); } Build.DefineSymbols.Remove(Build.DefineSymbols.ON_AGXUNITY_UPDATE); EditorApplication.UnlockReloadAssemblies(); }