Пример #1
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            Log.Info("Listing files...");

            var filesList = GetFilesList(app).ToList();

            Log.Info($"Starting the analyze on {filesList.Count} files.");

            var xcode = new UoeEncryptor(null);

            var i          = 0;
            var outputList = new List <string>();

            foreach (var file in filesList)
            {
                CancelToken?.ThrowIfCancellationRequested();
                var isEncrypted = xcode.IsFileEncrypted(file);
                if (isEncrypted && !ListDecrypted || !isEncrypted && ListDecrypted)
                {
                    outputList.Add(file);
                }
                i++;
                Log.ReportProgress(filesList.Count, i, $"Analyzing {file}.");
            }

            foreach (var file in outputList)
            {
                Out.WriteResultOnNewLine(file);
            }

            Log.Info($"A total of {outputList.Count} files are {(ListDecrypted ? "decrypted" : "encrypted")}.");

            return(0);
        }
Пример #2
0
        protected void ProcessFiles(CommandLineApplication app, bool encrypt)
        {
            ValidateOptions();

            if (!string.IsNullOrEmpty(OutputDirectory) && !Directory.Exists(OutputDirectory))
            {
                Log.Info($"Creating directory : {OutputDirectory}.");
                Directory.CreateDirectory(OutputDirectory);
            }

            Log.Info("Listing files...");

            var filesList = GetFilesList(app).ToList();

            Log.Info($"Processing {filesList.Count} files.");

            var xcode = new UoeEncryptor(EncryptionKey);

            var i          = 0;
            var outputList = new List <string>();

            foreach (var file in filesList)
            {
                CancelToken?.ThrowIfCancellationRequested();
                var outputFile = Path.Combine((string.IsNullOrEmpty(OutputDirectory) ? Path.GetDirectoryName(file) : OutputDirectory) ?? "", $"{Path.GetFileName(file)}{(string.IsNullOrEmpty(OutputFileSuffix) ? "" : OutputFileSuffix)}");
                try {
                    xcode.ConvertFile(file, encrypt, outputFile);
                    outputList.Add($"{file} >> {outputFile}");
                } catch (UoeAlreadyConvertedException) { }
                i++;
                Log.ReportProgress(filesList.Count, i, $"Converting file to : {outputFile}.");
            }

            foreach (var file in outputList)
            {
                Out.WriteResultOnNewLine(file);
            }

            Log.Info($"A total of {outputList.Count} files were converted.");
        }
        public void Test()
        {
            foreach (var password in new List <string> {
                null, "pwd", "waytoolongbutitsok"
            })
            {
                var xcode = new UoeEncryptor(password);

                var content         = "this is a test!";
                var filePath        = Path.Combine(TestFolder, "test.txt");
                var filePathEncoded = Path.Combine(TestFolder, "test.txt.encoded");
                var filePathDecoded = Path.Combine(TestFolder, "test.txt.decoded");

                File.WriteAllText(filePath, content, Encoding.Default);

                xcode.ConvertFile(filePath, true, filePathEncoded);
                xcode.ConvertFile(filePathEncoded, false, filePathDecoded);

                Assert.AreEqual(content, File.ReadAllText(filePathDecoded, Encoding.Default));

                Assert.IsTrue(xcode.IsFileEncrypted(filePathEncoded));
                Assert.IsFalse(xcode.IsFileEncrypted(filePathDecoded));
            }
        }