Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                System.Console.WriteLine("Arguments: Path to encrypted file, Output path, Path to private key, passphrase");
                return;
            }

            if (!PathValidation.ValidateFilePath(args[0]))
            {
                return;
            }
            if (!PathValidation.ValidateDirectoryPath(args[1]))
            {
                return;
            }
            if (!PathValidation.ValidateFilePath(args[2]))
            {
                return;
            }

            string path        = Path.GetFullPath(args[0]); //@"c:\test\MyTest.txt";
            string outputPath  = Path.GetFullPath(args[1]); //@"c:\temp";
            string privKeypath = Path.GetFullPath(args[2]); //@"c:\test\keyPrivate.txt";

            PgpDecryptionKeys decryptionKeys = new PgpDecryptionKeys(privKeypath, args[3]);
            PGPDecrypt        test           = new PGPDecrypt(decryptionKeys);

            using (FileStream fs = File.Open(path, FileMode.Open))
            {
                test.decrypt(fs, outputPath);
                fs.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Maps a relative path into the storage path.
        /// </summary>
        /// <param name="path">The relative path to be mapped.</param>
        /// <returns>The relative path combined with the storage path.</returns>
        private string MapStorage(string path)
        {
            if (!string.IsNullOrEmpty(path))
            {
                if (!path.StartsWith("\\"))
                {
                    path = "\\" + path;
                }
            }
            string mappedPath = string.IsNullOrEmpty(path) ? _storagePath : _storagePath + path;

            return(PathValidation.ValidatePath(_storagePath, mappedPath));
        }
Ejemplo n.º 3
0
        public void ValidatePath_SpaceOnly_Invalid()
        {
            //Arrange
            IFolder dirManager = Helpers.CreateStubHelpers.GetIFolderStub();

            IPathValidation controller = new PathValidation(s => dirManager, GetMockOperatingSystemVersion());

            //Act
            String  errorMessage;
            Boolean valid = controller.ValidPath("  ", out errorMessage);

            //Assert
            Assert.IsFalse(valid);
            Assert.IsNotEmpty(errorMessage);
        }
Ejemplo n.º 4
0
        public void ValidatePath_UNCPathOnVista_Valid()
        {
            //Arrange
            IFolder dirManager = Helpers.CreateStubHelpers.GetIFolderStub();

            IPathValidation controller = new PathValidation(s => dirManager, GetMockOperatingSystemVersion(isXp: false));

            //Act
            String  errorMsg;
            Boolean valid = controller.ValidPath(@"\\network\share", out errorMsg);

            //Assert
            Assert.IsTrue(valid);
            Assert.IsEmpty(errorMsg);
        }
Ejemplo n.º 5
0
        public void ValidatePath_PathContainsIllegalCharacter_Invalid()
        {
            //Arrange
            IFolder dirManager = Helpers.CreateStubHelpers.GetIDirectoryManagerStub(new Char[] { '|', '?', ':' });

            IPathValidation controller = new PathValidation(s => dirManager, GetMockOperatingSystemVersion());

            //Act
            String  errorMessage;
            Boolean valid = controller.ValidPath(GetPathAddingChar('|'), out errorMessage);


            //Assert
            Assert.IsFalse(valid);
            Assert.IsNotEmpty(errorMessage);
        }
Ejemplo n.º 6
0
        public FileAccessor(string filePath)
        {
            var pathValidation = new PathValidation();

            if (!pathValidation.IsValid(filePath))
            {
                throw new DirectoryNotFoundException(filePath);
            }
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(filePath);
            }

            Name     = Path.GetFileNameWithoutExtension(filePath);
            FullPath = filePath;
            Data     = Load(filePath);
        }
Ejemplo n.º 7
0
        public void ValidatePath_DriveHasColonPathDoesnContainAnyIllegalCharacters_Valid()
        {
            //MSDN states that : is illegal and is returned so need to check that when a drive is there it is still valid
            //Arrange
            IFolder dirManager = Helpers.CreateStubHelpers.GetIDirectoryManagerStub(new Char[] { '|', '?', ':' });

            IPathValidation controller = new PathValidation(s => dirManager, GetMockOperatingSystemVersion());

            //Act
            String  errorMessage;
            Boolean valid = controller.ValidPath(m_Path, out errorMessage);


            //Assert
            Assert.IsTrue(valid);
            Assert.IsEmpty(errorMessage);
        }
Ejemplo n.º 8
0
        public void ValidatePath_GreaterThanMaxPath_Invalid()
        {
            //Arrange
            IFolder dirManager = Helpers.CreateStubHelpers.GetIDirectoryManagerStub(1);

            IPathValidation controller = new PathValidation(s => dirManager, GetMockOperatingSystemVersion());

            String longPath = @"c:\testPathThatIsLongerTheDirManagerAllows";


            //Act
            String  errorMessage;
            Boolean valid = controller.ValidPath(longPath, out errorMessage);


            //Assert
            Assert.IsFalse(valid);
            Assert.IsNotEmpty(errorMessage);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                System.Console.WriteLine("Arguments: Path to input file, Path to output file, Path to public key");
                return;
            }

            if (!PathValidation.ValidateFilePath(args[0]))
            {
                return;
            }
            if (!PathValidation.ValidateDirectoryPath(args[1]))
            {
                return;
            }
            if (!PathValidation.ValidateFilePath(args[2]))
            {
                return;
            }

            string unEncryptedFilePath = Path.GetFullPath(args[0]);//@"c:\test\unEncryptedFile.txt";

            string newFileName = String.Format(@"{0}\{1}_encrypted{2}", Path.GetFullPath(args[1]), Path.GetFileNameWithoutExtension(args[0]), Path.GetExtension(args[0]));
            string outputFilePath = Path.GetFullPath(newFileName); //@"c:\test\";
            string pubKeypath = Path.GetFullPath(args[2]); //@"c:\test\keyPublic.txt";

            // Delete the file if it exists.
            if (File.Exists(outputFilePath))
            {
                File.Delete(outputFilePath);
            }

            FileInfo fi = new FileInfo(unEncryptedFilePath);
            PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(pubKeypath);
            PgpEncrypt objPgpEncrypt = new PgpEncrypt(encryptionKeys);

            using (FileStream str = new FileStream(outputFilePath, FileMode.Create))
            {
                objPgpEncrypt.Encrypt(str, fi);
            }
        }
 /// <summary>
 /// Combine a set of virtual paths relative to "~/App_Data" into an absolute physical path
 /// starting with "_basePath".
 /// </summary>
 private string CombineToPhysicalPath(params string[] paths)
 {
     return(PathValidation.ValidatePath(RootFolder, Path.Combine(RootFolder, Path.Combine(paths)).Replace('/', Path.DirectorySeparatorChar)));
 }
        /// <summary>
        /// Maps a relative path into the storage path.
        /// </summary>
        /// <param name="path">The relative path to be mapped.</param>
        /// <returns>The relative path combined with the storage path.</returns>
        private string MapStorage(string path)
        {
            string mappedPath = string.IsNullOrEmpty(path) ? _storagePath : Path.Combine(_storagePath, path);

            return(PathValidation.ValidatePath(_storagePath, mappedPath));
        }
 // Start is called before the first frame update
 void Start()
 {
     pathValidation = GameObject.Find("Game Manager").GetComponent <PathValidation>();
 }
Ejemplo n.º 13
0
    private void GenerateLevel()
    {
        GameObject[,,] levelLayout  = new GameObject[sizeX, sizeY, sizeZ];
        Vector3[,,] layoutPositions = new Vector3[sizeX, sizeY, sizeZ];
        bool validateSpawn = false;
        bool validateGoal  = false;

        pathValidator = new PathValidation();

        levelTiles = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast <GameObject>()
                     .Where(g => g.tag == "LevelBlock")
                     .Where(g => g.GetComponentInChildren <GridLevelBlock>().selectedBlockType == 0)
                     .Where(g => g.GetComponentInChildren <GridLevelBlock>().selectedLevelType == selectedLevelType)
                     .ToArray();
        spawnTiles = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast <GameObject>()
                     .Where(g => g.tag == "LevelBlock")
                     .Where(g => g.GetComponentInChildren <GridLevelBlock>().selectedBlockType == 1)
                     .Where(g => g.GetComponentInChildren <GridLevelBlock>().selectedLevelType == selectedLevelType)
                     .ToArray();
        goalTiles = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast <GameObject>()
                    .Where(g => g.tag == "LevelBlock")
                    .Where(g => g.GetComponentInChildren <GridLevelBlock>().selectedBlockType == 2)
                    .Where(g => g.GetComponentInChildren <GridLevelBlock>().selectedLevelType == selectedLevelType)
                    .ToArray();

        cornerTiles  = pathValidator.FindPossibleCorner(ref levelTiles);
        wayUpTiles   = pathValidator.FindPossibleWayUp(ref levelTiles);
        wayDownTiles = pathValidator.FindPossibleWayDown(ref levelTiles);

        if (cornerTiles.Count() < 1)
        {
            Debug.LogError("No corner blocks found");
        }

        if (spawnTiles.Count() != 0)
        {
            validateSpawn = true;
        }

        if (goalTiles.Count() != 0)
        {
            validateGoal = true;
        }

        if (validateSpawn && validateGoal)
        {
            // Handles the generation of key tiles like spawn and goal
            GenerateKeyTiles(levelLayout, layoutPositions);
            // Handles tiles that will give access to upper areas
            GenerateWayUp(levelLayout, layoutPositions);
            // Handles tiles that allow for access to the left or right
            GenerateCorners(levelLayout, layoutPositions);
            // Handles the way forward between the rest of the tiles
            GenerateRows(levelLayout, layoutPositions);
            // Intantiates the object of the generated level
            InstantiateLevel(levelLayout, layoutPositions);
        }
        else if (!validateSpawn && validateGoal)
        {
            Debug.LogError("Missing Spawn block");
        }
        else if (!validateGoal && validateSpawn)
        {
            Debug.LogError("Missing End block");
        }
        else
        {
            Debug.LogError("Missing Spawn and End blocks");
        }
    }