public DecontainerizeOtherFileTask(string path, string password) : base(ResourceType.File, path)
        {
            InnerTask = new Task(() =>
            {
                ContainerHelper.DecontainerizeFile(path, password);

                var newFilePath = FileGeneratorHelper.GetValidFileNameForDirectory(
                    DirectoryHelper.GetDirectoryPath(path),
                    Path.GetFileNameWithoutExtension(path),
                    string.Empty);

                File.Move(path, newFilePath);
            });
        }
        public OpenAesPasswordStoreTask(string filePath, string password) : base(ResourceType.File, filePath)
        {
            InnerTask = new Task(() =>
            {
                if (!File.Exists(filePath))
                {
                    ContainerizeNewAesPasswordStore(filePath);
                }

                if (ContainerHelper.ValidateContainer(filePath, password))
                {
                    ContainerHelper.DecontainerizeFile(filePath, password);
                    using (var fs = new FileStream(filePath, FileMode.Open))
                    {
                        if (fs.Length > 0 && new BinaryFormatter().Deserialize(fs) is List <PasswordModel> models)
                        {
                            Result.Value = new OpenAesPasswordStoreTaskResultModel(models);
                        }
                        else
                        {
                            ContainerizeNewAesPasswordStore(filePath);
                        }
                    }

                    ContainerHelper.ContainerizeFile(filePath, AesHelper.GetNewAesKey(), password);
                }
                else
                {
                    ContainerizeNewAesPasswordStore(filePath);
                }

                void ContainerizeNewAesPasswordStore(string path)
                {
                    using (var fs = new FileStream(path, FileMode.Create))
                    {
                        new BinaryFormatter().Serialize(fs, new List <PasswordModel>());
                    }
                    ContainerHelper.ContainerizeFile(path, AesHelper.GetNewAesKey(), password);
                    Result.Value = new OpenAesPasswordStoreTaskResultModel(new List <PasswordModel>());
                    return;
                }
            });
        }
Beispiel #3
0
        public DecontainerizeFileTask(string filePath, string password, bool removeAfter = false, bool openAfter = false) : base(ResourceType.File, filePath)
        {
            InnerTask = new Task(() =>
            {
                ContainerHelper.DecontainerizeFile(filePath, password);

                var path = FileGeneratorHelper.GetValidFileNameForDirectory(
                    DirectoryHelper.GetDirectoryPath(filePath),
                    Path.GetFileNameWithoutExtension(filePath),
                    string.Empty);

                File.Move(filePath, path);

                Result.Value = new DecontainerizeFileTaskResultModel
                {
                    Model       = path.ToFileModel(),
                    NewPath     = path,
                    DeleteAfter = removeAfter,
                    OpenAfter   = openAfter
                };
            });
        }
Beispiel #4
0
        public DecontainerizeFileTask(FileModel model, string password, bool removeAfter = false, bool openAfter = false) : base(ResourceType.File, model.Secured)
        {
            InnerTask = new Task(() =>
            {
                ContainerHelper.DecontainerizeFile(model.Secured, password);

                var path = FileGeneratorHelper.GetValidFileNameForDirectory(
                    DirectoryHelper.GetDirectoryPath(model.Secured),
                    Path.GetFileNameWithoutExtension(model.File),
                    Path.GetExtension(model.File));

                File.Move(model.Secured, path);

                Result.Value = new DecontainerizeFileTaskResultModel
                {
                    Model       = model,
                    NewPath     = path,
                    DeleteAfter = removeAfter,
                    OpenAfter   = openAfter
                };
            });
        }
        public AesSavePasswordsTask(string filePath, string password, List <PasswordModel> models) : base(ResourceType.File, filePath)
        {
            InnerTask = new Task(() =>
            {
                if (ContainerHelper.ValidateContainer(filePath, password))
                {
                    ContainerHelper.DecontainerizeFile(filePath, password);
                    using (var fs = new FileStream(filePath, FileMode.Open))
                    {
                        if (new BinaryFormatter().Deserialize(fs) is List <PasswordModel> existingModels)
                        {
                            models.AddRange(existingModels);
                        }
                    }
                }

                using (var fs = new FileStream(filePath, FileMode.Create))
                {
                    new BinaryFormatter().Serialize(fs, models);
                }

                ContainerHelper.ContainerizeFile(filePath, AesHelper.GetNewAesKey(), password);
            });
        }