Exemplo n.º 1
0
        private void decryptFileDrop_Click(object sender, EventArgs e)
        {
            string fileToDecrypt = "";

            if (openFileToDecrypt.ShowDialog() == DialogResult.OK)
            {
                if (!FileAES_Utilities.isFileDecryptable(openFileToDecrypt.FileName))
                {
                    MessageBox.Show("Please select a valid filetype.", "Invalid Filetype");
                }
                else
                {
                    fileToDecrypt     = openFileToDecrypt.FileName;
                    Program.doDecrypt = true;
                    using (FileAES_Decrypt decrypt = new FileAES_Decrypt(fileToDecrypt.Replace(@"\\", @"\")))
                    {
                        decrypt.StartPosition = FormStartPosition.CenterParent;
                        decrypt.ShowDialog();
                        decrypt.Focus();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void decryptFileDrop_DragDrop(object sender, DragEventArgs e)
        {
            string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);

            if (FileList.Length > 1)
            {
                MessageBox.Show("You may only decrypt a single file at a time.", "Multiple Files Unsupported");
            }
            else if (!FileAES_Utilities.isFileDecryptable(FileList[0]))
            {
                MessageBox.Show("Please select a valid filetype.", "Invalid Filetype");
            }
            else
            {
                Program.doDecrypt = true;
                using (FileAES_Decrypt decrypt = new FileAES_Decrypt(FileList[0].Replace(@"\\", @"\")))
                {
                    decrypt.StartPosition = FormStartPosition.CenterParent;
                    decrypt.ShowDialog();
                    decrypt.Focus();
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            for (int i = 0; i < args.Length; i++)
            {
                string strippedArg = args[i].ToLower();

                if (Directory.Exists(args[i]))
                {
                    _directory = args[i];
                }
                else if (File.Exists(args[i]))
                {
                    _directory = args[i];
                }

                strippedArg = strippedArg.TrimStart('-', '/', '\\');

                if (strippedArg == "verbose" || strippedArg == "v")
                {
                    _verbose = true;
                    FileAES_Utilities.SetVerboseLogging(_verbose);
                }
                else if (String.IsNullOrEmpty(_password) && (strippedArg == "password" || strippedArg == "p") && !string.IsNullOrEmpty(args[i + 1]))
                {
                    _password = args[i + 1];
                }
                else if (strippedArg == "purgetemp" || strippedArg == "deletetemp")
                {
                    _purgeTemp = true;
                }
                else if (strippedArg == "help")
                {
                    _help = true;
                }
                else if (String.IsNullOrEmpty(_passwordHint) && (strippedArg == "hint" || strippedArg == "passwordhint" || strippedArg == "h") && !string.IsNullOrEmpty(args[i + 1]))
                {
                    _passwordHint = args[i + 1];
                }
                else if (strippedArg == "gethint" || strippedArg == "getpasswordhint")
                {
                    _getHint = true;
                }
                else if (strippedArg == "gettimestamp" || strippedArg == "timestamp" || strippedArg == "encryptiondate")
                {
                    _getEncryptTimestamp = true;
                }
                else if (strippedArg == "getcompression" || strippedArg == "getcompressionmethod")
                {
                    _getEncryptCompression = true;
                }
                else if (strippedArg == "showprogress" || strippedArg == "progress" || strippedArg == "prog")
                {
                    if (!string.IsNullOrEmpty(args[i + 1]) && UInt16.TryParse(args[i + 1], out _progressSleep))
                    {
                    }
                    _showProgress = true;
                }
                else if (strippedArg == "faesversion" || strippedArg == "faes" || strippedArg == "faesver")
                {
                    _getFaesVersion = true;
                }
                else if (strippedArg == "faescliversion" || strippedArg == "faescliver" || strippedArg == "faescli" || strippedArg == "cliver" || strippedArg == "ver" || strippedArg == "version")
                {
                    _getVersion     = true;
                    _getFaesVersion = true;
                }
                else if (String.IsNullOrEmpty(_compressionMethod) && (strippedArg == "compression" || strippedArg == "compressionmethod" || strippedArg == "c") && !string.IsNullOrEmpty(args[i + 1]))
                {
                    _compressionMethod = args[i + 1].ToUpper();
                }
                else if ((strippedArg == "level" || strippedArg == "compressionlevel" || strippedArg == "l") && !string.IsNullOrEmpty(args[i + 1]))
                {
                    Int32.TryParse(args[i + 1], out _compressionLevel);
                }
                else if (strippedArg == "buffer" || strippedArg == "cryptostreambuffer" || strippedArg == "csbuffer" && !string.IsNullOrEmpty(args[i + 1]))
                {
                    UInt32.TryParse(args[i + 1], out _csBuffer);
                }
                else if (strippedArg == "overwrite" || strippedArg == "overwriteduplicates" || strippedArg == "o")
                {
                    _overwriteDuplicates = true;
                }
                else if (strippedArg == "preserveoriginal" || strippedArg == "original" || strippedArg == "po")
                {
                    _deleteOriginalFile = false;
                }
                else if (strippedArg == "showallmetadata" || strippedArg == "showmetadata" || strippedArg == "metadata")
                {
                    _showAllMetadata = true;
                }
                else if (strippedArg == "showallutf8metadata" || strippedArg == "showutf8metadata" || strippedArg == "utf8metadata")
                {
                    _showAllMetadataString = true;
                }
                else if (strippedArg == "" || strippedArg == "showutf8metadata" || strippedArg == "utf8metadata")
                {
                    _showAllMetadataString = true;
                }
                else if (strippedArg == "tempencrypt" || strippedArg == "temp")
                {
                    _useLocalEncrypt = false;
                }
                else if (strippedArg == "localencrypt" || strippedArg == "local")
                {
                    _useLocalEncrypt = true;
                }
                else if (strippedArg == "showlatest" || strippedArg == "getlatest" || strippedArg == "getlatestversion" || strippedArg == "latestversion" || strippedArg == "latest")
                {
                    _showLatestVer = true;

                    if (args.Length > (i + 1) && !string.IsNullOrEmpty(args[i + 1]))
                    {
                        string arg = args[i + 1];

                        if (arg.ToLower() == "dev" || arg.ToLower() == "developer" || arg.ToLower() == "d")
                        {
                            _showLatestBranch = "dev";
                        }
                        else if (arg.ToLower() == "beta" || arg.ToLower() == "b")
                        {
                            _showLatestBranch = "beta";
                        }
                        else if (arg.ToLower() == "stable" || arg.ToLower() == "s" || arg.ToLower() == "release" || arg.ToLower() == "r")
                        {
                            _showLatestBranch = "stable";
                        }
                    }
                }
                else if (strippedArg == "noupdatecheck" || strippedArg == "nocheck" || strippedArg == "offline" || strippedArg == "noupdate")
                {
                    _checkForUpdate = false;
                }
                else if (strippedArg == "update" || strippedArg == "u")
                {
                    string branch  = "";
                    string version = "";

                    if (args.Length > (i + 1) && !string.IsNullOrEmpty(args[i + 1]))
                    {
                        string arg = args[i + 1];

                        {
BranchFinder:
                            if (arg.ToLower() == "dev" || arg.ToLower() == "developer" || arg.ToLower() == "d")
                            {
                                branch = "dev";
                            }
                            else if (arg.ToLower() == "beta" || arg.ToLower() == "b")
                            {
                                branch = "beta";
                            }
                            else if (arg.ToLower() == "stable" || arg.ToLower() == "s" || arg.ToLower() == "release" || arg.ToLower() == "r")
                            {
                                branch = "stable";
                            }
                            else if (args.Length > (i + 2) && !string.IsNullOrEmpty(args[i + 2]) && String.IsNullOrWhiteSpace(version))
                            {
                                version = args[i + 1];
                                arg     = args[i + 2];
                                goto BranchFinder;
                            }
                        }

                        if (string.IsNullOrEmpty(branch) && string.IsNullOrEmpty(version) && args.Length > (i + 1) && !string.IsNullOrEmpty(args[i + 1]))
                        {
                            version = args[i + 1];
                        }
                    }

                    if (args.Length > (i + 1) && string.IsNullOrEmpty(args[i + 1]) && args[i + 1].ToLower() == "force")
                    {
                        _forceUpdate = true;
                    }
                    else if (args.Length > (i + 2) && string.IsNullOrEmpty(args[i + 2]) && args[i + 2].ToLower() == "force")
                    {
                        _forceUpdate = true;
                    }
                    else if (args.Length > (i + 3) && string.IsNullOrEmpty(args[i + 3]) && args[i + 3].ToLower() == "force")
                    {
                        _forceUpdate = true;
                    }

                    if (!String.IsNullOrWhiteSpace(branch))
                    {
                        _updateBranch = branch;
                    }
                    if (!String.IsNullOrWhiteSpace(version))
                    {
                        _updateToVer = version;
                    }

                    _doUpdate = true;
                }

                _strippedArgs.Add(strippedArg);
            }

            if (_checkForUpdate)
            {
                if (_updateBranch == "unknown")
                {
                    if (IsDevBuild())
                    {
                        _updateBranch = "dev";
                    }
                    else if (IsBetaBuild())
                    {
                        _updateBranch = "beta";
                    }
                    else
                    {
                        _updateBranch = "stable";
                    }
                }

                _update = new Update("dev");
            }

            if (_showLatestBranch == "unknown")
            {
                _showLatestBranch = _updateBranch;
            }

            if (_help)
            {
                Logging.Log("A FAES-based tool for encrypting and decrypting files using the command-line.\n\nPossible Launch Parameters:\n'--verbose' or '-v': Show more debugging information in the console (WIP)." +
                            "\n'--purgeTemp' or '-p': Purge the FileAES Temp folder to resolve possible errors.\n'--password <password>' or '-p <password>': Sets the password that will be used to encrypt/decrypt the file/folder." +
                            "\n'--hint <Password Hint>' or '-h <Password Hint>': Sets a password hint.\n'--compression <ZIP/TAR/LZMA/LEGACYZIP>' or '-c <ZIP/TAR/LZMA/LEGACYZIP>': Sets the compression method that will be used to encrypt the file/folder." +
                            "\n'--level <0-9>' or '-l <0-9>': Sets the compression level that will be used to encrypt the file/folder. (Only works for with the ZIP compression method)" +
                            ".\n'--getHint': Gets the password hint for the encrypted file.\n'--getTimestamp': Gets the encryption timestamp of the encrypted file." +
                            "\n'--getCompression': Gets the compression method of the encrypted file.\n'--ver': Gets the current version of FileAES-CLI and FAES being used." +
                            "\n'--FAES': Gets the current version of FAES being used.\n'--overwrite' or '-o': Overwrites any duplicate files found within the FAES process." +
                            "\n'--original' or '-po': Preserves the original file used in the encrypt/decrypt process." +
                            "\n'--progress [<Polling Rate (ms)>]': Outputs the current encryption/decryption progress to the console after desired time (Leaving polling rate blank defaults to 5000ms)." +
                            "\n'--buffer <Size (bytes)>': Sets the size of the FAES CryptoStream buffer.\n'--metadata': Shows the raw metadeta (Hex) of the encrypted file." +
                            "\n'--utf8metadata': Shows the raw metadeta (Decoded UTF8) of the encrypted file.\n'--offline': Disables auto-update checking." +
                            "\n'--latest [<branch>]': Outputs the latest version of FileAES-CLI on that branch (Leaving branch blank defaults to current builds branch)." +
                            "\n'--update [<version>] [<branch>] [force]': Updates FileAES-CLI as specified. Using no arguments updates to the latest version on the current branch.\n\n" +
                            "\n'--localEncrypt' or '-local': Encrypt files within the same folder as the source file (Default behaviour).\n\n" +
                            "\n'--tempEncrypt' or '-temp': Encrypt files within the OS' Temp folder (Old behaviour).\n\n" +
                            "File/Folder names can be entered as a launch parameter to select what to encrypt/decrypt (also allows for dragging/dropping a file/folder on the .exe).\n\n" +
                            "Example: 'FileAES-CLI.exe File.txt -p password123'");
                return;
            }

            if (_doUpdate)
            {
                if (_update != null && _checkForUpdate)
                {
                    _update.CheckForUpdateNonThreadded(true);

                    bool doUpdate = false;

                    if ((!_forceUpdate && _update.IsUpdate()) || _forceUpdate || _updateToVer != "latest")
                    {
                        if (_updateToVer == "latest")
                        {
                            string latestVer = _update.GetLatestVersion();
                            Logging.Log(String.Format("Installing FileAES-CLI {0}...", latestVer));
                            doUpdate = true;
                        }
                        else if (_update.DoesVersionExist(_updateToVer, "dev"))
                        {
                            Logging.Log(String.Format("Installing FileAES-CLI {0}...", _updateToVer));
                            doUpdate = true;
                        }
                        else
                        {
                            Logging.Log(String.Format("Could not find FileAES-CLI {0}!", _updateToVer), Severity.WARN);
                        }

                        if (doUpdate)
                        {
                            _update.UpdateSelf(true, _updateToVer);
                            return;
                        }
                    }
                }
            }
            else if (_checkForUpdate)
            {
                _update.CheckForUpdate();
            }

            if (_purgeTemp)
            {
                FileAES_Utilities.PurgeTempFolder();
            }

            if (_getVersion)
            {
                Logging.Log(String.Format("Current FileAES-CLI Version: {0}", GetVersion()));
                if (!_getFaesVersion)
                {
                    return;
                }
            }

            if (_getFaesVersion)
            {
                Logging.Log(String.Format("Current FAES Version: {0}", FileAES_Utilities.GetVersion()));
                return;
            }

            if (_showLatestVer)
            {
                if (_checkForUpdate)
                {
                    _update.SetBranch(_showLatestBranch);

                    string latestVer = _update.GetLatestVersion();

                    if (latestVer != "v0.0.0")
                    {
                        Logging.Log(String.Format("The latest FileAES-CLI version on branch '{0}' is: {1}", _showLatestBranch.ToUpper(), latestVer));
                    }
                    else
                    {
                        Logging.Log("The latest FileAES-CLI version could not be found! Please check your internet connection.", Severity.WARN);
                    }

                    _update.SetBranch(_updateBranch);
                }

                else
                {
                    Logging.Log("The latest version cannot be displayed when the program is in offline mode!");
                }

                return;
            }

            if (_getHint)
            {
                if (File.Exists(_directory) && FileAES_Utilities.isFileDecryptable(_directory))
                {
                    string passHint = FileAES_Utilities.GetPasswordHint(_directory);

                    if (passHint != "No Password Hint Set")
                    {
                        Logging.Log(String.Format("The hint for '{0}' is: {1}", Path.GetFileName(_directory), passHint));
                    }
                    else
                    {
                        Logging.Log(String.Format("'{0}' does not contain a password hint!", Path.GetFileName(_directory)));
                    }

                    if (String.IsNullOrEmpty(_password) && (!_getEncryptTimestamp || !_getEncryptCompression))
                    {
                        return;
                    }
                }
                else
                {
                    Logging.Log("You have not specified a valid encrypted file!", Severity.WARN);
                    return;
                }
            }

            if (_getEncryptTimestamp)
            {
                if (File.Exists(_directory) && FileAES_Utilities.isFileDecryptable(_directory))
                {
                    long timestamp = FileAES_Utilities.GetEncryptionTimeStamp(_directory);

                    if (timestamp >= 0)
                    {
                        DateTime dateTime = FileAES_Utilities.UnixTimeStampToDateTime((double)timestamp);
                        Logging.Log(String.Format("'{0}' was encrypted on {1} at {2}.", Path.GetFileName(_directory), dateTime.ToString("dd/MM/yyyy"), dateTime.ToString("HH:mm:ss tt")));
                    }
                    else
                    {
                        Logging.Log("This file does not contain a encryption date. This is likely due to this file being encrypted using an older FAES version.");
                    }

                    if (String.IsNullOrEmpty(_password) && !_getEncryptCompression)
                    {
                        return;
                    }
                }
                else
                {
                    Logging.Log("You have not specified a valid encrypted file!", Severity.WARN);
                    return;
                }
            }

            if (_getEncryptCompression)
            {
                if (File.Exists(_directory) && FileAES_Utilities.isFileDecryptable(_directory))
                {
                    string compressionMode = FileAES_Utilities.GetCompressionMode(_directory);

                    if (compressionMode != "LGYZIP")
                    {
                        Logging.Log(String.Format("The Compression Mode used for '{0}' is: {1}", Path.GetFileName(_directory), compressionMode));
                    }
                    else
                    {
                        Logging.Log(String.Format("The Compression Mode used for '{0}' is: LGYZIP (LEGACYZIP)", Path.GetFileName(_directory)));
                    }

                    if (String.IsNullOrEmpty(_password))
                    {
                        return;
                    }
                }
                else
                {
                    Logging.Log("You have not specified a valid encrypted file!", Severity.WARN);
                    return;
                }
            }

            if (_showAllMetadata)
            {
                if (File.Exists(_directory) && FileAES_Utilities.isFileDecryptable(_directory))
                {
                    string compressionMode = FileAES_Utilities.GetCompressionMode(_directory);

                    MetaData faesMetaData = new MetaData(_directory);

                    if (faesMetaData.IsLegacyVersion())
                    {
                        Logging.Log(String.Format("The metadata (bytes) for '{0}' is (FAESv2):\n{1}", Path.GetFileName(_directory), BitConverter.ToString(faesMetaData.GetMetaData())));
                    }
                    else
                    {
                        Logging.Log(String.Format("The metadata (bytes) for '{0}' is (FAESv3):\n{1}", Path.GetFileName(_directory), BitConverter.ToString(faesMetaData.GetMetaData())));
                    }

                    if (String.IsNullOrEmpty(_password))
                    {
                        return;
                    }
                }
                else
                {
                    Logging.Log("You have not specified a valid encrypted file!", Severity.WARN);
                    return;
                }
            }

            if (_showAllMetadataString)
            {
                if (File.Exists(_directory) && FileAES_Utilities.isFileDecryptable(_directory))
                {
                    string compressionMode = FileAES_Utilities.GetCompressionMode(_directory);

                    MetaData faesMetaData = new MetaData(_directory);

                    if (faesMetaData.IsLegacyVersion())
                    {
                        Logging.Log(String.Format("The metadata (string) for '{0}' is (FAESv2):\n{1}", Path.GetFileName(_directory), Encoding.UTF8.GetString(faesMetaData.GetMetaData())));
                    }
                    else
                    {
                        Logging.Log(String.Format("The metadata (string) for '{0}' is (FAESv3):\n{1}", Path.GetFileName(_directory), Encoding.UTF8.GetString(faesMetaData.GetMetaData())));
                    }

                    if (String.IsNullOrEmpty(_password))
                    {
                        return;
                    }
                }
                else
                {
                    Logging.Log("You have not specified a valid encrypted file!", Severity.WARN);
                    return;
                }
            }

            if (String.IsNullOrEmpty(_directory))
            {
                while (true)
                {
                    Console.Write("File/Folder: ");
                    _directory = Console.ReadLine();

                    if (File.Exists(_directory) || Directory.Exists(_directory))
                    {
                        break;
                    }
                    Logging.Log("You have not specified a valid file or folder!", Severity.WARN);
                }
            }
            if (String.IsNullOrEmpty(_password))
            {
                while (true)
                {
                    Console.Write("Password: "******"\nConf. Password: "******"Passwords do not match!");
                    }
                    else
                    {
                        Console.Write(Environment.NewLine);
                        _password = password;
                        break;
                    }
                }
            }

            if (!File.Exists(_directory) && !Directory.Exists(_directory))
            {
                Logging.Log("You have not specified a valid file or folder!", Severity.WARN);
            }
            else if (String.IsNullOrEmpty(_password))
            {
                Logging.Log("Please specify a password!", Severity.WARN);
            }
            else
            {
                FAES_File faesFile = new FAES_File(_directory);
                FileAES_Utilities.SetCryptoStreamBuffer(_csBuffer);

                try
                {
                    if (_compressionLevel < 0 || _compressionLevel > 9)
                    {
                        Logging.Log("You have not specified a valid compression level! Please choose a value between 0 and 9.", Severity.WARN);
                        return;
                    }
                    else
                    {
                        if (_verbose)
                        {
                            Logging.Log(String.Format("CryptoStream Buffer Size: {0} bytes", FileAES_Utilities.GetCryptoStreamBuffer()), Severity.DEBUG);
                        }

                        if (faesFile.isFileEncryptable())
                        {
                            FileAES_Utilities.LocalEncrypt = _useLocalEncrypt;
                            FileAES_Encrypt encrypt = new FileAES_Encrypt(faesFile, _password, _passwordHint, Optimise.Balanced, null, _deleteOriginalFile, _overwriteDuplicates);

                            if (!String.IsNullOrEmpty(_compressionMethod))
                            {
                                switch (_compressionMethod)
                                {
                                case "ZIP":
                                {
                                    encrypt.SetCompressionMode(CompressionMode.ZIP, _compressionLevel);
                                    break;
                                }

                                case "TAR":
                                {
                                    encrypt.SetCompressionMode(CompressionMode.TAR, _compressionLevel);
                                    break;
                                }

                                case "LZMA":
                                {
                                    encrypt.SetCompressionMode(CompressionMode.LZMA, _compressionLevel);
                                    break;
                                }

                                case "LGYZIP":
                                case "LEGACYZIP":
                                case "LEGACY":
                                {
                                    encrypt.SetCompressionMode(CompressionMode.LGYZIP, _compressionLevel);
                                    break;
                                }

                                default:
                                    Logging.Log(String.Format("Unknown Compression Method: {0}", _compressionMethod), Severity.ERROR);
                                    return;
                                }
                            }

                            Thread progressThread = new Thread(() =>
                            {
                                while (_showProgress)
                                {
                                    ushort percentComplete = Convert.ToUInt16(encrypt.GetEncryptionPercentComplete());
                                    Logging.Log(String.Format("Progress: {0}%", percentComplete));
                                    Thread.Sleep(_progressSleep);
                                }
                            });

                            Thread eThread = new Thread(() =>
                            {
                                try
                                {
                                    if (encrypt.encryptFile())
                                    {
                                        if (_showProgress)
                                        {
                                            Logging.Log("Progress: 100%");
                                        }

                                        Logging.Log(String.Format("Encryption on {0} succeeded!", faesFile.getFaesType().ToLower()));
                                    }
                                    else
                                    {
                                        Logging.Log(String.Format("Encryption on {0} failed!", faesFile.getFaesType().ToLower()));
                                    }
                                }
                                catch (Exception e)
                                {
                                    #if NETFRAMEWORK
                                    progressThread.Abort();
                                    #endif
                                    HandleException(e);
                                }
                            });

                            if (_showProgress)
                            {
                                progressThread.Start();
                            }
                            eThread.Start();

                            while (eThread.ThreadState == ThreadState.Running)
                            {
                            }
                            #if NETFRAMEWORK
                            progressThread.Abort();
                            #endif
                        }
                        else
                        {
                            FileAES_Decrypt decrypt = new FileAES_Decrypt(faesFile, _password, _deleteOriginalFile, _overwriteDuplicates);

                            Thread progressThread = new Thread(() =>
                            {
                                while (_showProgress)
                                {
                                    ushort percentComplete = Convert.ToUInt16(decrypt.GetDecryptionPercentComplete());

                                    Logging.Log(String.Format("Progress: {0}%", percentComplete));
                                    Thread.Sleep(_progressSleep);
                                }
                            });

                            Thread dThread = new Thread(() =>
                            {
                                try
                                {
                                    if (decrypt.decryptFile())
                                    {
                                        if (_showProgress)
                                        {
                                            Logging.Log("Progress: 100%");
                                        }

                                        Logging.Log(String.Format("Decryption on {0} succeeded!", faesFile.getFaesType().ToLower()));
                                    }
                                    else
                                    {
                                        Logging.Log(String.Format("Decryption on {0} failed!", faesFile.getFaesType().ToLower()));
                                        Logging.Log("Ensure that you entered the correct password!");
                                        Logging.Log(String.Format("Password Hint: {0}", faesFile.GetPasswordHint()));
                                    }
                                }
                                catch (Exception e)
                                {
                                    #if NETFRAMEWORK
                                    progressThread.Abort();
                                    #endif
                                    HandleException(e);
                                }
                            });

                            if (_showProgress)
                            {
                                progressThread.Start();
                            }
                            dThread.Start();

                            while (dThread.ThreadState == ThreadState.Running)
                            {
                            }
                            #if NETFRAMEWORK
                            progressThread.Abort();
                            #endif
                        }
                    }
                }
                catch (Exception e)
                {
                    HandleException(e);
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            tempPathInstance = Path.Combine(Path.GetTempPath(), "FileAES");
            List <string> arguments = new List <string>();

            arguments.AddRange(args);
            if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), _fullInstallPath)))
            {
                arguments.AddRange(ReadLaunchParams());
            }
            if (File.Exists(_localInstallPath))
            {
                arguments.AddRange(ReadLaunchParams(true));
            }

            string[] param = arguments.ToArray();

            for (int i = 0; i < param.Length; i++)
            {
                param[i].ToLower();

                if (File.Exists(param[i]) && FileAES_Utilities.isFileDecryptable(param[i]) && !doEncryptFile && !doEncryptFolder)
                {
                    doDecrypt = true;
                    fileName  = param[i];
                }
                else if (Directory.Exists(param[i]) && !doDecrypt && !doEncryptFile)
                {
                    doEncryptFolder = true;
                    fileName        = param[i];
                }
                else if (File.Exists(param[i]) && !doDecrypt && !doEncryptFolder)
                {
                    doEncryptFile = true;
                    fileName      = param[i];
                }

                if (param[i].Equals("-fullinstall") || param[i].Equals("--fullinstall") || param[i].Equals("-f") || param[i].Equals("--f"))
                {
                    _fullInstall = true;
                }
                else if (param[i] == "--associatefiletypes")
                {
                    _associateFileTypes = true;
                }
                else if (param[i] == "--startmenushortcuts")
                {
                    _startMenuShortcuts = true;
                }
                else if (param[i] == "--contextmenus")
                {
                    _contextMenus = true;
                }
                else if (param[i] == "--dev")
                {
                    _branch = "dev";
                }
                else if (param[i] == "--beta")
                {
                    _branch = "beta";
                }
                else if (param[i] == "--stable")
                {
                    _branch = "stable";
                }
                else if (param[i] == "--skipupdate" || param[i] == "-skipupdate")
                {
                    _skipUpdate = true;
                }
                else if (param[i].Equals("-cleanupdates") || param[i].Equals("--cleanupdates") || param[i].Equals("-c") || param[i].Equals("--c"))
                {
                    _cleanUpdates = true;
                }
                else if (param[i].Equals("-update") || param[i].Equals("--update") || param[i].Equals("-u") || param[i].Equals("--u"))
                {
                    FileAES_Update.UpdateSelf(_cleanUpdates);
                }
                else if (param[i].Equals("-password") || param[i].Equals("--password") || param[i].Equals("-p") || param[i].Equals("--p") && !String.IsNullOrEmpty(param[i + 1]))
                {
                    _autoPassword = param[i + 1];
                }
                else if (param[i].Equals("-purgetemp") || param[i].Equals("--purgetemp") || param[i].Equals("-deletetemp") || param[i].Equals("--deletetemp"))
                {
                    _purgeTemp = true;
                }
                else if (param[i].Equals("-debug") || param[i].Equals("--debug") || param[i].Equals("-developer") || param[i].Equals("--developer"))
                {
                    _debugMode = true;
                }
                else if (param[i].Equals("-peek") || param[i].Equals("--peek") || param[i].Equals("-filepeek") || param[i].Equals("--filepeek"))
                {
                    _doFilePeek = true;
                }
                else if (param[i].Equals("-tempencrypt") || param[i].Equals("--tempencrypt") || param[i].Equals("-temp") || param[i].Equals("--temp"))
                {
                    _useLocalEncrypt = false;
                }
            }
            if (String.IsNullOrEmpty(_branch))
            {
                _branch = "stable";
            }

            if (_purgeTemp)
            {
                FileAES_Utilities.PurgeTempFolder();
            }
            if (File.Exists("FAES-Updater.exe"))
            {
                File.Delete("FAES-Updater.exe");
            }

            Core core = new Core();

            if (_branch == "stable" && (core.IsBetaBuild() || core.IsDevBuild()))
            {
                _branch = core.GetBuild();
            }
            else if (_branch == "beta" && core.IsDevBuild())
            {
                _branch = core.GetBuild();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (doEncryptFile || doEncryptFolder)
            {
                Application.Run(new FileAES_Encrypt(fileName, _autoPassword));
            }
            else if (doDecrypt)
            {
                if (_doFilePeek && IsFileValidForPeek(new FAES_File(fileName)))
                {
                    Application.Run(new FileAES_Peek(fileName, _autoPassword));
                }
                else
                {
                    Application.Run(new FileAES_Decrypt(fileName, _autoPassword));
                }
            }
            else
            {
                Application.Run(new FileAES_Main());
            }
        }