public DifferencingFolder(DriveLetter drive, ArchiveFile archive, string hostPath) : base(hostPath) { this.Drive = drive; this.Archive = archive ?? throw new ArgumentNullException(nameof(archive)); this.deletes = this.ReadDeletes(); }
public NodeUncInfo(SystemNode Node, UncRoot Root, DriveLetter DriveLetter, params FolderName[] TopShareNames) { this.Node = Node; this.UncRoot = new NodeUncRoot(Node, Root); this.DriveLetter = new NodeDriveLetter(Node, DriveLetter); this.TopShareNames = TopShareNames; }
/// <summary> /// Deletes a mapped drive /// </summary> /// <param name="Drive"></param> /// <returns></returns> public static Option <DriveLetter> UnMap(this DriveLetter Drive) { var result = WNetCancelConnection2(Drive.ToString(), ConnectionFlags.CONNECT_UPDATE_PROFILE, false); return (result == ErrorCodes.ERROR_SUCCESS ? some(Drive) : none <DriveLetter>(error("WinAPI call failed"))); }
/// <summary> /// Initialises the packages store by validating parameters, then connecting to the network share. /// </summary> /// <exception cref="ArgumentNullException"> if <paramref name="DriveLetter"/> is null or contains only whitespace or <paramref name="RootPath"/> is null or contains only whitespace or <paramref name="UserName"/> is null or contains only whitespace or <paramref name="AccessKey"/> is null or contains only whitespace or <paramref name="FileShareName"/> is null or contains only whitespace.</exception> /// <exception cref="ArgumentOutOfRangeException"> if <paramref name="DriveLetter"/> does not match ^[A-Za-z]:$ or <paramref name="RootPath"/> does not start with <paramref name="DriveLetter"/></exception> private void InitPackageStore() { _logger = Logger.Initialise(LogFileName); _fileSystemOperations.Logger = _logger; if (string.IsNullOrWhiteSpace(DriveLetter)) { throw new ArgumentNullException("DriveLetter"); } if (!Regex.IsMatch(DriveLetter, "^[A-Za-z]:$")) { throw new ArgumentOutOfRangeException("DriveLetter", "DriveLetter must be a single drive letter (A-Z) followed by a colon"); } if (string.IsNullOrWhiteSpace(RootPath)) { throw new ArgumentNullException("RootPath"); } if (!RootPath.ToLower().StartsWith(DriveLetter.ToLower())) { throw new ArgumentOutOfRangeException("RootPath", "RootPath must be on the drive specified by DriveLetter (ie, if DriveLetter='P:', then RootPath must start with 'P:\'"); } if (string.IsNullOrWhiteSpace(UserName)) { throw new ArgumentNullException("UserName"); } if (string.IsNullOrWhiteSpace(AccessKey)) { throw new ArgumentNullException("AccessKey"); } if (string.IsNullOrWhiteSpace(FileShareName)) { throw new ArgumentNullException("FileShareName"); } var uncPath = string.Format(@"\\{0}.file.core.windows.net\{1}", UserName, FileShareName); try { _logger.DebugFormat("Mapping network share '{0}' to drive '{1}' with username '{2}'", uncPath, DriveLetter, UserName); var stopWatch = new Stopwatch(); stopWatch.Start(); _fileShareMapper.Mount(DriveLetter, uncPath, UserName, AccessKey, _logger); stopWatch.Stop(); _logger.DebugFormat("Drive mapping successful and took {0} milliseconds.", stopWatch.ElapsedMilliseconds); } catch (Exception ex) { _logger.Error(String.Format("Exception occurred mapping drive '{0}' to '{1}' with username '{2}'", DriveLetter, uncPath, UserName), ex); throw; } }
/// <summary> /// Gets the current directory in the emulated system. /// </summary> public void GetCurrentDirectory() { var drive = vm.FileSystem.CurrentDrive; if (vm.Processor.DL > 0) { drive = new DriveLetter(vm.Processor.DL - 1); } var path = vm.FileSystem.GetCurrentDirectory(drive); vm.PhysicalMemory.SetString(vm.Processor.DS, vm.Processor.SI, path.Path); vm.Processor.Flags.Carry = false; }
/// <summary> /// Maps a drive letter to a UNC path /// </summary> /// <param name="Drive">The drive to map</param> /// <param name="UncPath">The unc path to assign to the drive</param> /// <remarks> /// Adapted from http://www.blackwasp.co.uk/MapDriveLetter.aspx /// </remarks> public static Option <DriveMount> Map(this DriveLetter Drive, string UncPath, string UserName = null, string UserPass = null) { var networkResource = new NETRESOURCE(); networkResource.dwType = RESOURCETYPE_DISK; networkResource.lpLocalName = Drive.ToString(); networkResource.lpRemoteName = UncPath; networkResource.lpProvider = null; var result = WNetAddConnection2(ref networkResource, UserName, UserPass, ConnectionFlags.CONNECT_UPDATE_PROFILE); return (result == ErrorCodes.ERROR_SUCCESS ? some(new DriveMount(Drive)) : none <DriveMount>(error("WinAPI call failed"))); }
public bool OnSameVolumeThan(IAbsolutePath otherAbsolutePath) { Argument.IsNotNull(nameof(otherAbsolutePath), otherAbsolutePath); if (Type != otherAbsolutePath.Type) { return(false); } if (Type == AbsolutePathType.DriveLetter) { return(DriveLetter.Equals(otherAbsolutePath.DriveLetter)); } return(string.Compare(UNCServer, otherAbsolutePath.UNCServer, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(UNCShare, otherAbsolutePath.UNCShare, StringComparison.OrdinalIgnoreCase) == 0); }
public bool OnSameVolumeThan(IAbsolutePath otherAbsolutePath) { Debug.Assert(otherAbsolutePath != null); // Enforced by contract if (Kind != otherAbsolutePath.Kind) { return(false); } switch (Kind) { case AbsolutePathKind.DriveLetter: return(DriveLetter.Equals(otherAbsolutePath.DriveLetter)); default: Debug.Assert(Kind == AbsolutePathKind.UNC); // Compare UNC server and share, with ignorcase. return(String.Compare(UNCServer, otherAbsolutePath.UNCServer, true) == 0 && String.Compare(UNCShare, otherAbsolutePath.UNCShare, true) == 0); } }
/// <summary> /// Returns whether the current PathInfo is a valid parent of the child path info /// passed as argument. /// </summary> /// <param name = "child">The path info to verify</param> /// <returns>Whether it is true that the current path info is a parent of child.</returns> /// <exception cref = "NotSupportedException">If this instance of path info and child aren't rooted.</exception> public bool IsParentOf(PathInfo child) { Contract.Requires(child != null); if (Root == string.Empty || child.Root == string.Empty) { throw new NotSupportedException("Non-rooted paths are not supported."); } // TODO: Normalize Path var OK = child.FolderAndFiles.StartsWith(FolderAndFiles); switch (Type) { case PathType.Device: OK &= child.DeviceName.Equals(DeviceName, StringComparison.InvariantCultureIgnoreCase); break; case PathType.Server: OK &= child.ServerName.Equals(ServerName, StringComparison.InvariantCultureIgnoreCase); break; case PathType.IPv4: OK &= child.IPv4.Equals(IPv4); break; case PathType.IPv6: OK &= child.IPv6.Equals(IPv6); break; case PathType.Relative: throw new NotSupportedException("Since root isn't empty we should never get relative paths."); case PathType.Drive: OK &= DriveLetter.ToLowerInvariant() == child.DriveLetter.ToLowerInvariant(); break; } return(OK); }
public void Test_TraditionalDos_1() { { // relative var path = Filepath.Parse(@"c:"); var prefix = path.Prefix as Dos; Assert.IsNotNull(prefix); Assert.AreEqual("c:", prefix !.Drive); Assert.AreEqual("C", prefix !.DriveLetter.ToUpper()); Assert.IsFalse(path.IsAbsolute); Assert.AreEqual(0, path.Items.Count); } { // absolute var path = Filepath.Parse(@"z:\"); var prefix = path.Prefix as Dos; Assert.IsNotNull(prefix); Assert.AreEqual("z:", prefix !.Drive); Assert.AreEqual("Z", prefix !.DriveLetter.ToUpper()); Assert.IsTrue(path.IsAbsolute); Assert.AreEqual(0, path.Items.Count); } }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (DriveLetter.Expression != null) { targetCommand.AddParameter("DriveLetter", DriveLetter.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
public string MountVirtualDrive() { try { _virtualDrive.OnRequestFileOpen += OnRequestFileOpen; // Get mount point, maybe the SecureBox file system already mounted _mountPoint = GetMountPoint(); if (string.IsNullOrEmpty(_mountPoint)) { _mountPoint = DriveLetter.UnusedDriveLetter(); _virtualDrive.Mount(_mountPoint, DokanOptions.DebugMode | DokanOptions.EnableNotificationAPI, 5); } return(_mountPoint); } catch (DokanException ex) { throw; } }
public void Test_Slice_2_WithPrefix() { var basepath = Filepath.Parse(@"C:\home\kuma\foo\bar\baz.txt"); // 色々なパラメータを入力しても // へんな例外が発生しなければOK { for (var c = -20; c < 20; c++) { for (var s = -20; s < 20; s++) { var path = basepath.Slice(s, c); Assert.IsTrue(true); } } } { // Slice(0) ... 実質、何も変わらないはず var path = basepath.Slice(0); Assert.IsInstanceOfType(path.Prefix, typeof(PathPrefix.Dos)); Assert.AreEqual((path.Prefix as PathPrefix.Dos) !.DriveLetter.ToLower(), "c"); Assert.IsTrue(path.IsAbsolute); Assert.AreEqual("home", path.Items[0]); Assert.AreEqual("baz.txt", path.Items[4]); } { // Slice(1) ... 相対パスを表すようになるはず var path = basepath.Slice(1); Assert.IsInstanceOfType(path.Prefix, typeof(PathPrefix.Dos)); Assert.AreEqual((path.Prefix as PathPrefix.Dos) !.DriveLetter.ToLower(), "c"); Assert.IsFalse(path.IsAbsolute); Assert.AreEqual("kuma", path.Items[0]); Assert.AreEqual("baz.txt", path.Items[3]); } }
/// <summary> /// Returns whether the current PathInfo is a valid parent of the child path info /// passed as argument. /// </summary> /// <param name="child">The path info to verify</param> /// <returns>Whether it is true that the current path info is a parent of child.</returns> /// <exception cref="NotSupportedException">If this instance of path info and child aren't rooted.</exception> public bool IsParentOf(PathInfo child) { if (Root == string.Empty || child.Root == string.Empty) { throw new NotSupportedException("Non-rooted paths are not supported."); } var OK = child.FolderAndFiles.StartsWith(FolderAndFiles); switch (Type) { case PathType.Device: OK &= child.DeviceName.ToLowerInvariant() == DeviceName.ToLowerInvariant(); break; case PathType.Server: OK &= child.ServerName.ToLowerInvariant() == ServerName.ToLowerInvariant(); break; case PathType.IPv4: OK &= IPAddress.Parse(child.IPv4).Equals(IPAddress.Parse(IPv4)); break; case PathType.IPv6: OK &= (IPAddress.Parse(child.IPv6).Equals(IPAddress.Parse(IPv6))); break; case PathType.Relative: throw new InvalidOperationException("Since root isn't empty we should never get relative paths."); case PathType.Drive: OK &= DriveLetter.ToLowerInvariant() == child.DriveLetter.ToLowerInvariant(); break; } return(OK); }
/// <summary> /// Gets the drive on which the file lives, if applicable /// </summary> public static Option <DriveLetter> HostDrive(this IFilePath path) => from p in some(path.FileSystemPath) let uri = new FilePath(path.FileSystemPath).AsUri() let letter = uri.LocalPath.Length != 0 ? uri.LocalPath[0] : '0' from d in DriveLetter.TryParse(letter) select d;
public MappedArchive(DriveLetter drive, ArchiveFile archive) { this.Drive = drive; this.Archive = archive ?? throw new ArgumentNullException(nameof(archive)); }
public DriveMount(DriveLetter Location) => this.Location = (Location, none <FolderPath>());
public SetCurrentDriveCommand(DriveLetter driveLetter) { this.Drive = driveLetter; }
/// <summary> /// Abstracts the location of a filesystem object path, whether it's local or remote or a /// file or a directory, and the approprite local or remote UNC is returned /// </summary> /// <param name="hostMachine">The machine hosting the file path</param> /// <param name="localPath"> /// Either a local path (e.g., 'c:\foo\bar\this.txt' or a single drive letter, e.g., 'D' /// </param> /// <param name="verifyExistence"> /// If TRUE, validates that the virtual .Path exists, throws an exception if not /// </param> public VirtualPath ( string hostMachine, string localPath, Boolean isFile, Boolean throwOnNotExists = false) { if (string.IsNullOrEmpty(hostMachine)) { throw new ArgumentNullException(nameof(hostMachine)); } else if (string.IsNullOrEmpty(localPath)) { throw new ArgumentNullException(nameof(localPath)); } else if (!Utilities.IsLocalPath(localPath)) { throw new ArgumentException("Must be local path", nameof(localPath)); } this.hostName = hostMachine.ToUpper(); this.isFile = isFile; // So Int64 as the path is a UNC path on the same machine as hostMachine, we can deal if (CommonRegex.UncPathWithDriveDollarRegex.IsMatch(localPath)) { Match m = CommonRegex.UncPathWithDriveDollarRegex.Match(localPath); Debug.Assert(m.Groups[1].Value == this.hostName); this.localPath = m.Groups[2].Value.Replace("$", ":"); } else { this.localPath = localPath; } if (this.LocalPath.Length == 1) { // 'C' on 'MACHINE' -> \\MACHINE\c$ this.remotePath = string.Format(@"\\{0}\{1}$", this.hostName, this.LocalPath); // 'C' -> C: this.localPath += ":"; // TODO or should this be C:\ this.driveLetter = ( DriveLetter )Enum.Parse ( typeof(DriveLetter), this.LocalPath.Substring(0, 1), true ); } else { // 'C:' on 'MACHINE' -> \\MACHINE\C$ // c: \foo\bar.txt on MACHINE -> \\MACHINE\c$\foo\bar.txt this.remotePath = string.Format(@"\\{0}\{1}", this.HostName, this.LocalPath.Replace(":", "$")); this.localPath = localPath.Replace("$", ":"); this.driveLetter = ( DriveLetter )Enum.Parse ( typeof(DriveLetter), this.RemotePath[this.RemotePath.IndexOf('$') - 1].ToString(), true // IgnoreCase ); } if (throwOnNotExists && !this.Exists) { throw new ScarabException("Path '{0}' not found", this.Path); } }