public void CanRenameFilesAndUndo() { const string oldPath = @"C:\my-image.png"; const string newFileName = "my-renamed-image"; const string newPath = @"C:\my-renamed-image.png"; var canAct = false; var canRevert = false; var fsMock = new Mock <IFileSystem>(); fsMock.Setup(fs => fs.FileExists(oldPath)).Returns(true); fsMock.Setup(fs => fs.FileExists(newPath)).Returns(false); fsMock.Setup(fs => fs.Move(oldPath, newPath)).Verifiable(); fsMock.Setup(fs => fs.Move(newPath, oldPath)).Verifiable(); var renameAction = new RenameAction(oldPath, newFileName, fsMock.Object, (o, n) => canAct = true, (n, o) => canRevert = true); renameAction.Act(); fsMock.Verify(fs => fs.Move(oldPath, newPath)); renameAction.Revert(); fsMock.Verify(fs => fs.Move(newPath, oldPath)); Assert.True(canAct); Assert.True(canRevert); }
/** * Actived the writeMode * */ private void activedWriteMode() { if (this.objectSelected != null && this.objectSelected.GetComponentInChildren <TextMesh>() != null) { textMesh = this.objectSelected.GetComponentInChildren <TextMesh>(); textMesh.text += " "; // the space to show the choice letter renameAction = new RenameAction(textMesh); writeMode = true; } }
public void FileRename_NoFileNameCollision() { var rename = Substitute.For <Rename>(); var action = new RenameAction(rename); var fileSystem = SetupFileSystem(); var fileInfo = fileSystem.FileInfo.FromFileName(@"c:\dir\filename123.jpg"); var file = new FileWrapper(fileInfo); rename.GetRenamedFileName("filename123").Returns("file_name"); action.ActOnFile(file); Assert.AreEqual("file_name", file.GetFileName()); Assert.AreEqual("jpg", file.GetExtension()); Assert.True(fileSystem.File.Exists(@"c:\dir\file_name.jpg")); Assert.False(fileSystem.File.Exists(@"c:\dir\filename123.jpg")); }
public void FileRename_FileNameCollision() { var rename = Substitute.For <Rename>(); var action = new RenameAction(rename); var fileSystem = SetupFileSystem(); var fileInfo = fileSystem.FileInfo.FromFileName(@"c:\dir\textFile007.txt"); var file = new FileWrapper(fileInfo); rename.GetRenamedFileName("textFile007").Returns("textFile"); rename.TryMakeFileNameUnique("textFile", "textFile007").Returns("textFile1"); action.ActOnFile(file); Assert.AreEqual("textFile1", file.GetFileName()); Assert.AreEqual("txt", file.GetExtension()); Assert.True(fileSystem.File.Exists(@"c:\dir\textFile1.txt")); Assert.False(fileSystem.File.Exists(@"c:\dir\textFile007.txt")); }
public static List <FileAction> PerformRollup(List <RawUSNEntry> rawEntries, MonitoredMountpoint syncFrom, Repository repository) { //logger.Info("{0} rawEntries", rawEntries.Count); var entries = rawEntries.Where(f => f.Close.HasValue && f.Close.Value && (!f.RenameOldName.HasValue || !f.RenameOldName.Value)); //logger.Info("{0} entries", entries.Count()); if (syncFrom.IgnoreList != null && syncFrom.IgnoreList.Any()) { entries = syncFrom.IgnoreList.Select(ignore => new Regex(ignore)).Aggregate(entries, (current, regex) => current.Where(f => !regex.IsMatch(f.RelativePath))); } //logger.Info("{0} entries2", entries.Count()); entries = entries.OrderBy(f => f.Path).ThenBy(f => f.FileCreate); var toReturn = new List <FileAction>(); foreach (var entry in entries) { try { if (entry.RenameNewName.HasValue) { var item = new RenameAction(); item.IsDirectory = entry.Directory.HasValue && entry.Directory.Value; item.RenameFrom = entry.RenameFromRelativePath; if (string.IsNullOrWhiteSpace(item.RenameFrom)) { logger.Warn("Unable to find RenameFrom for USN item " + item.USN); continue; } item.RelativePath = entry.RelativePath; item.USNEntry = entry; item.USN = entry.USN; item.RawPath = entry.Path; item.Mountpoint = syncFrom; toReturn.Add(item); } else if (entry.FileDelete.HasValue) { toReturn.Add(new DeleteAction() { RelativePath = entry.RelativePath, USN = entry.USN, USNEntry = entry, RawPath = entry.Path, IsDirectory = entry.Directory.HasValue && entry.Directory.Value, Mountpoint = syncFrom }); } else { toReturn.Add(new UpdateAction() { IsDirectory = entry.Directory.HasValue && entry.Directory.Value, RawPath = entry.Path, RelativePath = entry.RelativePath, USN = entry.USN, USNEntry = entry, Mountpoint = syncFrom }); } } catch (Exception e) { logger.Error("Error processing item " + entry.Id, e); continue; } } var deletedFiles = toReturn.OfType <DeleteAction>().ToList(); foreach (var deletedFile in deletedFiles) { if (toReturn.OfType <UpdateAction>().Select(f => f.RelativePath).Contains(deletedFile.RelativePath)) { toReturn.Remove(deletedFile); } toReturn.RemoveAll(f => f.RelativePath == deletedFile.RelativePath && f.USN < deletedFile.USN); } var fileActions = toReturn.Select(e => e.RelativePath).Distinct().Select(f => toReturn.FirstOrDefault(a => a.RelativePath == f)).ToList(); foreach (var source in fileActions.OfType <RenameAction>().ToList()) { if (fileActions.Any(f => f.RawPath == source.RenameFrom)) { fileActions.RemoveAll(f => f.RawPath == source.RenameFrom); fileActions.Remove(source); fileActions.Add(new RenameAction() { RelativePath = source.RelativePath, RawPath = source.RawPath, USN = source.USN, IsDirectory = source.IsDirectory, Mountpoint = syncFrom, RenameFrom = source.RenameFrom }); } } return(fileActions); }
public void onGamePadEvent(ref Event e) { if (writeMode) { updateWriteMode(ref e); print("writemode"); return; } // Rename Action else if (UnityEngine.Input.GetKey(KeyCode.Joystick1Button1)) // A button { textMesh = select.GetComponentInChildren <TextMesh>(); renameAction = new RenameAction(textMesh); writeMode = true; } else if (UnityEngine.Input.GetKey(KeyCode.Joystick1Button6)) // LT button { InputLeftControlAction(); } else { if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button3)) // Y button { AddAction addAction = new AddAction(PrimitiveType.Cube, new Vector3(0, 0, -8)); base.managerListener.doAction(addAction); print("action: add"); this.nodeCourant.Add(new Node(addAction.GameObject)); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button2) && !deleteMode) // B button { RemoveAction removeAction = new RemoveAction(ref this.nodeCourant); base.managerListener.doAction(removeAction); print("action: remove"); this.nodeCourant = removeAction.NodeCourant; if (this.nodeCourant == null) { Select(instance); } else { Select(nodeCourant.Gameobject); } deleteMode = true; } else if (UnityEngine.Input.GetKeyUp(KeyCode.Joystick1Button2) && deleteMode) // B button { deleteMode = false; } else if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button5)) // RB button { base.managerListener.undoAction(); print("action: undo"); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button4)) // LB button { base.managerListener.redoAction(); print("action: redo"); } else { InputMoveAction(); } } }
public static void applyManualPatches(ModuleDefinition mainModule) { OnElement("ConnectionManager.connectedClients", mainModule.GetType("ConnectionManager").Fields, field => HasType(field.FieldType, "ClientInfoCollection"), MakeFieldPublicAction, RenameAction <FieldDefinition> ("connectedClients")); OnElement("ClientInfoCollection.clients", mainModule.GetType("ClientInfoCollection").Fields, field => HasType(field.FieldType, "System.Collections.Generic.List") && HasGenericParams(field.FieldType, "ClientInfo"), MakeFieldPublicAction, RenameAction <FieldDefinition>("clients")); TypeDefinition typeClientInfoCollection = mainModule.GetType("ClientInfoCollection"); foreach (MethodDefinition method in typeClientInfoCollection.Methods.Where((md, index) => (md.Name.StartsWith("By") && md.ReturnType.Name.Equals("ClientInfo") && md.Parameters.Count == 1))) { FieldDefinition targetField; if (method.Body.Instructions[1].OpCode == OpCodes.Ldfld && method.Body.Instructions[3].OpCode == OpCodes.Callvirt && (targetField = ((FieldReference)method.Body.Instructions[1].Operand).Resolve()).DeclaringType.Equals(typeClientInfoCollection) && HasGenericParams(targetField.FieldType, method.Parameters[0].ParameterType, method.ReturnType)) { MakeFieldPublicAction(targetField); RenameAction <FieldDefinition>("clients" + method.Name) (targetField); success++; } else { errors++; } } /*OnElement ("ClientInfoCollection.clientsByEntityId", mainModule.GetType ("ClientInfoCollection").Fields, * field => HasType (field.FieldType, "System.Collections.Generic.Dictionary") && HasGenericParams (field.FieldType, "System.Int32", "ClientInfo"), * MakeFieldPublicAction, RenameAction<FieldDefinition> ("clientsByEntityId")); * * OnElement ("ClientInfoCollection.clientsBySteamId", mainModule.GetType ("ClientInfoCollection").Fields, * field => HasType (field.FieldType, "System.Collections.Generic.Dictionary") && HasGenericParams (field.FieldType, "Steamworks.CSteamID", "ClientInfo"), * MakeFieldPublicAction, RenameAction<FieldDefinition> ("clientsBySteamId")); * * OnElement ("ClientInfoCollection.clientsByNetworkPlayer", mainModule.GetType ("ClientInfoCollection").Fields, * field => HasType (field.FieldType, "System.Collections.Generic.Dictionary") && HasGenericParams (field.FieldType, "UnityEngine.NetworkPlayer", "ClientInfo"), * MakeFieldPublicAction, RenameAction<FieldDefinition> ("clientsByNetworkPlayer")); * * OnElement ("ClientInfoCollection.clientsByPlayerId", mainModule.GetType ("ClientInfoCollection").Fields, * field => HasType (field.FieldType, "System.Collections.Generic.Dictionary") && HasGenericParams (field.FieldType, "System.String", "ClientInfo"), * MakeFieldPublicAction, RenameAction<FieldDefinition> ("clientsByPlayerId"));*/ // Console and ConsoleCommand { TypeDefinition typeSdtdConsole = mainModule.GetType("SdtdConsole"); TypeDefinition typeQueuedCommand = null; // Console if (typeSdtdConsole != null) { OnElement("SdtdConsole.executeCommand()", typeSdtdConsole.Methods, method => !method.IsConstructor && !method.IsPublic && method.Parameters.Count == 2 && HasType(method.Parameters[0].ParameterType, "System.String") && HasType(method.Parameters[1].ParameterType, "CommandSenderInfo"), MakeMethodPublicAction ); OnElement("SdtdConsole.commands", typeSdtdConsole.Fields, field => HasType(field.FieldType, "System.Collections.Generic.SortedList") && HasGenericParams(field.FieldType, "System.String", "IConsoleCommand"), MakeFieldPublicAction, RenameAction <FieldDefinition> ("commands")); OnElement("SdtdConsole.servers", typeSdtdConsole.Fields, field => HasType(field.FieldType, "System.Collections.Generic.List") && HasGenericParams(field.FieldType, "IConsoleServer"), MakeFieldPublicAction, RenameAction <FieldDefinition> ("servers")); OnElement("SdtdConsole::QueuedCommand", typeSdtdConsole.NestedTypes, type => { if (Find("SdtdConsole::QueuedCommand.command", type.Fields, field => HasType(field.FieldType, "System.String")) != null && Find("SdtdConsole::QueuedCommand.sender", type.Fields, field => HasType(field.FieldType, "IConsoleConnection")) != null) { typeQueuedCommand = type; return(true); } return(false); }, MakeTypePublicAction, RenameAction <TypeDefinition> ("QueuedCommand")); if (typeQueuedCommand != null) { OnElement("SdtdConsole.asyncCommands", typeSdtdConsole.Fields, field => HasType(field.FieldType, "System.Collections.Generic.List") && HasGenericParams(field.FieldType, typeQueuedCommand), MakeFieldPublicAction, RenameAction <FieldDefinition> ("asyncCommands")); OnElement("SdtdConsole::QueuedCommand.command", typeQueuedCommand.Fields, field => HasType(field.FieldType, "System.String"), RenameAction <FieldDefinition>("command")); OnElement("SdtdConsole::QueuedCommand.sender", typeQueuedCommand.Fields, field => HasType(field.FieldType, "IConsoleConnection"), RenameAction <FieldDefinition>("sender")); } } // END Console } // END Console and ConsoleCommand }
public void onKeyboardEvent(ref Event e) { if (writeMode) { updateWriteMode(ref e); print("writemode"); return; } // Rename Action else if (UnityEngine.Input.GetKey(KeyCode.F2)) { textMesh = select.GetComponentInChildren <TextMesh>(); renameAction = new RenameAction(textMesh); writeMode = true; } // Action avec la touche "Controle" else if (UnityEngine.Input.GetKey(KeyCode.LeftControl)) { // Selection des objets avec les fleches directionnelles InputLeftControlAction(); } // Action sans la touche "Controle" else { // A: AddAction if (UnityEngine.Input.GetKeyDown(KeyCode.A)) { addObject(); print("action: add"); } // D: RemoveAction else if (UnityEngine.Input.GetKeyDown(KeyCode.D) && !deleteMode) { // Remove Action /*RemoveAction removeAction = new RemoveAction(this.select); * base.managerListener.doAction(removeAction); * print("action: remove"); * * // Supprimer de l'arbre pour ne plus pouvoir le selectionner * this.nodeCourant = this.nodeCourant.Remove(); */ // Remove Action RemoveAction removeAction = new RemoveAction(ref this.nodeCourant); base.managerListener.doAction(removeAction); print("action: remove"); this.nodeCourant = removeAction.NodeCourant; // Selectionner le precedent if (this.nodeCourant == null) { Select(instance); } else { Select(nodeCourant.Gameobject); } deleteMode = true; } else if (UnityEngine.Input.GetKeyUp(KeyCode.D) && deleteMode) { deleteMode = false; } // U: UndoAction else if (UnityEngine.Input.GetKeyDown(KeyCode.U)) { base.managerListener.undoAction(); print("action: undo"); } // R: RedoAction else if (UnityEngine.Input.GetKeyDown(KeyCode.R)) { base.managerListener.redoAction(); print("action: redo"); } // Deplacer un objet selectionne avec les fleches directionnelles else { InputMoveAction(); } } }