Example #1
0
        public MOCube(IChemForm parent)
        {
            Parent = parent;
            var iterDirs = new WindowsPath(parent.AssotiatedDir);

            foreach (var file in iterDirs.ListDir())
            {
                if (file.Extension.Contains("out"))
                {
                    Basis = BasisType.MO;
                    using (var sr = new StreamReader(file.FileInfo.FullName))
                    {
                        for (int i = 0; i < 30; i++)
                        {
                            var line = sr.ReadLine();
                            if (line.ToLower().Contains("savenbo"))
                            {
                                Basis = BasisType.Nbo;
                                break;
                            }
                        }
                    }
                }
            }
            foreach (var file in iterDirs.ListDir())
            {
                if (file.Extension.Contains("chk"))
                {
                    AssotiatedFile = file.Basename;
                    break;
                }
            }
            Data = new Dictionary <(int, int), string>();
        }
Example #2
0
        /// <summary>
        /// Factory method to create a new <see cref="PurePath"/> instance
        /// based upon the current operating system.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="path"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool TryCreate(PathFactoryOptions options, string path, out IPath result)
        {
            result = null;
            switch (PlatformChooser.GetPlatform())
            {
            case Platform.Posix:
                PurePosixPath purePosixPath;
                if (PurePosixPath.TryParse(path, out purePosixPath))
                {
                    result = new PosixPath(purePosixPath);
                    break;
                }
                return(false);

            case Platform.Windows:
                PureWindowsPath pureWindowsPath;
                if (PureWindowsPath.TryParse(path, out pureWindowsPath))
                {
                    result = new WindowsPath(path);
                    break;
                }
                return(false);
            }
            result = ApplyOptions(result, options);
            return(true);
        }
Example #3
0
        private Result CheckPathCaseSensitively(string path)
        {
            Result rc = GetCaseSensitivePathFull(out string caseSensitivePath, out _, path, _rootPath);

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (path.Length != caseSensitivePath.Length)
            {
                return(ResultFs.PathNotFound.Log());
            }

            for (int i = 0; i < path.Length; i++)
            {
                if (!(path[i] == caseSensitivePath[i] || WindowsPath.IsDosDelimiter(path[i]) &&
                      WindowsPath.IsDosDelimiter(caseSensitivePath[i])))
                {
                    return(ResultFs.PathNotFound.Log());
                }
            }

            return(Result.Success);
        }
Example #4
0
        public static Result VerifyHostPath(U8Span path)
        {
            if (path.IsEmpty())
            {
                return(Result.Success);
            }

            if (path[0] != StringTraits.DirectorySeparator)
            {
                return(ResultFs.InvalidPathFormat.Log());
            }

            U8Span path2 = path.Slice(1);

            if (path2.IsEmpty())
            {
                return(Result.Success);
            }

            int skipLength      = WindowsPath.GetWindowsPathSkipLength(path2);
            int remainingLength = PathTools.MaxPathLength - skipLength;

            Result rc = PathUtility.VerifyPath(null, path2.Slice(skipLength), remainingLength, remainingLength);

            if (rc.IsFailure())
            {
                return(rc);
            }

            using var normalizer = new PathNormalizer(path, PathNormalizer.Option.PreserveUnc);
            return(normalizer.Result);
        }
Example #5
0
        public void JoinWindowsPath_WithStringByDiv_ReturnsWindowsPath()
        {
            var path  = new WindowsPath(@"C:\tmp");
            var other = @"C:\tmp";

            var final = path / other;

            Assert.True(final is WindowsPath);
        }
Example #6
0
        public void IsJunction_WithJunction_ReturnsTrue()
        {
            var ret      = TestUtils.CreateJunctionAndTarget(TempFolder);
            var junction = ret.Item2;

            var path = new WindowsPath(junction);

            Assert.IsTrue(path.IsJunction());
        }
Example #7
0
        public void JoinIPath_WithAnotherPath_ReturnsWindowsPath()
        {
            IPath path  = new WindowsPath(@"C:\tmp");
            IPath other = new WindowsPath(@"C:\tmp");

            var final = path.Join(other);

            Assert.True(final is WindowsPath);
        }
Example #8
0
        public void ExpandUser_WithCustomHomeDirString_ExpandsDir()
        {
            var homeDir  = new WindowsPath(@"C:\users\test");
            var path     = new WindowsPath("~/tmp");
            var expected = homeDir.Join("tmp");

            var actual = path.ExpandUser(homeDir);

            Assert.Equal(expected, actual);
        }
Example #9
0
        public void ExpandUser_WithHomeDir_ExpandsDir()
        {
            var path     = new WindowsPath("~/tmp");
            var expected = new WindowsPath(
                Environment.GetEnvironmentVariable("USERPROFILE"), "tmp");

            var actual = path.ExpandUser();

            Assert.Equal(expected, actual);
        }
Example #10
0
        public void SetCurrentDirectory_UponDispose_RestoresEnvironmentVariable()
        {
            var oldCwd = Environment.CurrentDirectory;
            var path   = new WindowsPath(@"C:\");
            var tmp    = path.SetCurrentDirectory();

            tmp.Dispose();

            Assert.Equal(oldCwd, Environment.CurrentDirectory);
        }
Example #11
0
        public void SetCurrentDirectory_WithDirectory_SetsEnvironmentVariable()
        {
            const string newCwd = @"C:\";
            var          path   = new WindowsPath(newCwd);

            using (path.SetCurrentDirectory())
            {
                Assert.Equal(newCwd, Environment.CurrentDirectory);
            }
        }
Example #12
0
        internal static Result GetMountNameAndSubPath(out MountName mountName, out U8Span subPath, U8Span path)
        {
            UnsafeHelpers.SkipParamInit(out mountName);
            subPath = default;

            int mountLen    = 0;
            int maxMountLen = Math.Min(path.Length, PathTools.MountNameLengthMax);

            if (WindowsPath.IsWindowsDrive(path) || WindowsPath.IsUnc(path))
            {
                StringUtils.Copy(mountName.Name, CommonPaths.HostRootFileSystemMountName);
                mountName.Name[PathTools.MountNameLengthMax] = StringTraits.NullTerminator;

                subPath = path;
                return(Result.Success);
            }

            for (int i = 0; i <= maxMountLen; i++)
            {
                if (path[i] == PathTools.MountSeparator)
                {
                    mountLen = i;
                    break;
                }
            }

            if (mountLen == 0)
            {
                return(ResultFs.InvalidMountName.Log());
            }

            if (mountLen > maxMountLen)
            {
                return(ResultFs.InvalidMountName.Log());
            }

            if (mountLen <= 0)
            {
                return(ResultFs.InvalidMountName.Log());
            }

            U8Span subPathTemp = path.Slice(mountLen + 1);

            if (subPathTemp.Length == 0 ||
                (subPathTemp[0] != DirectorySeparator && subPathTemp[0] != AltDirectorySeparator))
            {
                return(ResultFs.InvalidPathFormat.Log());
            }

            path.Value.Slice(0, mountLen).CopyTo(mountName.Name);
            mountName.Name[mountLen] = StringTraits.NullTerminator;
            subPath = subPathTemp;

            return(Result.Success);
        }
Example #13
0
        /// <summary>
        /// Create a new document uri from a string
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static DocumentUri From(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new UriFormatException("Given uri is null or empty");
            }
            if (url.StartsWith(@"\\") || (url.StartsWith("/")) || WindowsPath.IsMatch(url))
            {
                return(File(url));
            }

            return(Parse(url));
        }
Example #14
0
 /// <summary>
 /// Factory method to create a new <see cref="PurePath"/> instance
 /// based upon the current operating system.
 /// </summary>
 /// <param name="path"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public IPath Create(string path, PathFactoryOptions options)
 {
     IPath ret = null;
     switch (PlatformChooser.GetPlatform())
     {
         case Platform.Posix:
             ret = new PosixPath(path);
             break;
         case Platform.Windows:
             ret =  new WindowsPath(path);
             break;
     }
     return ApplyOptions(ret, options);
 }
Example #15
0
        /// <summary>
        /// Factory method to create a new <see cref="PurePath"/> instance
        /// based upon the current operating system.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public IPath Create(string path, PathFactoryOptions options)
        {
            IPath ret = null;

            switch (PlatformChooser.GetPlatform())
            {
            case Platform.Posix:
                ret = new PosixPath(path);
                break;

            case Platform.Windows:
                ret = new WindowsPath(path);
                break;
            }
            return(ApplyOptions(ret, options));
        }
Example #16
0
        private static Result GetCaseSensitivePathFull(out string caseSensitivePath, out int rootPathLength,
                                                       string path, string workingDirectoryPath)
        {
            caseSensitivePath = default;
            UnsafeHelpers.SkipParamInit(out rootPathLength);

            string fullPath;
            int    workingDirectoryPathLength;

            if (WindowsPath.IsPathRooted(path))
            {
                fullPath = path;
                workingDirectoryPathLength = 0;
            }
            else
            {
                // We only want to send back the relative part of the path starting with a '/', so
                // track where the root path ends.
                if (WindowsPath.IsDosDelimiter(workingDirectoryPath[^ 1]))
Example #17
0
 /// <summary>
 /// Factory method to create a new <see cref="PurePath"/> instance
 /// based upon the current operating system.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="path"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public bool TryCreate(PathFactoryOptions options, string path, out IPath result)
 {
     result = null;
     switch (PlatformChooser.GetPlatform())
     {
         case Platform.Posix:
             PurePosixPath purePosixPath;
             if (PurePosixPath.TryParse(path, out purePosixPath))
             {
                 result = new PosixPath(purePosixPath);
                 break;
             }
             return false;
         case Platform.Windows:
             PureWindowsPath pureWindowsPath;
             if (PureWindowsPath.TryParse(path, out pureWindowsPath))
             {
                 result = new WindowsPath(path);
                 break;
             }
             return false;
     }
     result = ApplyOptions(result, options);
     return true;
 }