public override void Evaluate() { String targetFile = RegexMatch.Groups[1].Value.Trim(); String operation = RegexMatch.Groups[3].Value.Trim().ToUpper(); String volumeName = RegexMatch.Groups[5].Value.Trim(); File file = null; Volume targetVolume = null; switch (operation) { case "FROM": targetVolume = GetVolume(volumeName); // Will throw if not found file = targetVolume.GetByName(targetFile); if (file == null) { throw new kOSException("File '" + targetFile + "' not found"); } targetVolume.DeleteByName(targetFile); break; default: file = SelectedVolume.GetByName(targetFile); if (file == null) { throw new kOSException("File '" + targetFile + "' not found"); } SelectedVolume.DeleteByName(targetFile); break; } State = ExecutionState.DONE; }
public override void Evaluate() { String targetFile = RegexMatch.Groups[1].Value.Trim(); String volumeName = RegexMatch.Groups[3].Value.Trim(); File file = null; Volume targetVolume = null; if (volumeName.Trim() != "") { targetVolume = GetVolume(volumeName); // Will throw if not found file = targetVolume.GetByName(targetFile); if (file == null) { throw new kOSException("File '" + targetFile + "' not found", this); } targetVolume.DeleteByName(targetFile); } else { file = SelectedVolume.GetByName(targetFile); if (file == null) { throw new kOSException("File '" + targetFile + "' not found", this); } SelectedVolume.DeleteByName(targetFile); } State = ExecutionState.DONE; }
public override void Execute(SharedObjects shared) { string newName = shared.Cpu.PopValue().ToString(); object oldName = shared.Cpu.PopValue(); string objectToRename = shared.Cpu.PopValue().ToString(); if (shared.VolumeMgr != null) { if (objectToRename == "file") { Volume volume = shared.VolumeMgr.CurrentVolume; if (volume != null) { if (volume.GetByName(newName) == null) { if (!volume.RenameFile(oldName.ToString(), newName)) { throw new Exception(string.Format("File '{0}' not found", oldName.ToString())); } } else { throw new Exception(string.Format("File '{0}' already exists.", newName)); } } else { throw new Exception("Volume not found"); } } else { Volume volume = shared.VolumeMgr.GetVolume(oldName); if (volume != null) { if (volume.Renameable) { volume.Name = newName; } else { throw new Exception("Volume cannot be renamed"); } } else { throw new Exception("Volume not found"); } } } }
public override void Evaluate() { String targetFile = RegexMatch.Groups[1].Value.Trim(); String volumeName = RegexMatch.Groups[4].Value.Trim(); String operation = RegexMatch.Groups[2].Value.Trim().ToUpper(); Volume targetVolume = GetVolume(volumeName); // Will throw if not found File file = null; switch (operation) { case "FROM": file = targetVolume.GetByName(targetFile); if (file == null) { throw new kOSException("File '" + targetFile + "' not found", this); } if (!SelectedVolume.SaveFile(new File(file))) { throw new kOSException("File copy failed", this); } break; case "TO": file = SelectedVolume.GetByName(targetFile); if (file == null) { throw new kOSException("File '" + targetFile + "' not found", this); } if (!targetVolume.SaveFile(new File(file))) { throw new kOSException("File copy failed", this); } break; } State = ExecutionState.DONE; }