private bool DoCopyFiles([NotNull] UnityPluginDetector.InstallationInfo installation, out FileSystemPath installedPath) { installedPath = null; var originPaths = new List <FileSystemPath>(); originPaths.AddRange(installation.ExistingFiles); var backups = originPaths.ToDictionary(f => f, f => f.AddSuffix(".backup")); foreach (var originPath in originPaths) { var backupPath = backups[originPath]; if (originPath.ExistsFile) { originPath.MoveFile(backupPath, true); myLogger.Info($"backing up: {originPath.Name} -> {backupPath.Name}"); } else { myLogger.Info($"backing up failed: {originPath.Name} doesn't exist."); } } try { var editorPluginPathDir = myPluginPathsProvider.GetEditorPluginPathDir(); var editorPluginPath = editorPluginPathDir.Combine(PluginPathsProvider.BasicPluginDllFile); var targetPath = installation.PluginDirectory.Combine(editorPluginPath.Name); try { editorPluginPath.CopyFile(targetPath, true); } catch (Exception e) { myLogger.LogException(LoggingLevel.ERROR, e, ExceptionOrigin.Assertion, $"Failed to copy {editorPluginPath} => {targetPath}"); RestoreFromBackup(backups); } foreach (var backup in backups) { backup.Value.DeleteFile(); } installedPath = installation.PluginDirectory.Combine(PluginPathsProvider.BasicPluginDllFile); return(true); } catch (Exception e) { myLogger.LogExceptionSilently(e); RestoreFromBackup(backups); return(false); } }
private void BindPluginPathToSettings(Lifetime lf, EditorPluginModel editor) { var entry = myBoundSettingsStore.Schema.GetScalarEntry((UnitySettings s) => s.InstallUnity3DRiderPlugin); myBoundSettingsStore.GetValueProperty <bool>(lf, entry, null).Change.Advise(lf, val => { if (val.HasNew && val.New) { editor.FullPluginPath.SetValue(myPluginPathsProvider.GetEditorPluginPathDir() .Combine(PluginPathsProvider.FullPluginDllFile).FullPath); } editor.FullPluginPath.SetValue(string.Empty); }); }