Esempio n. 1
0
        private void LoadUI()
        {
            if (PackageInfo.I386Install)
            {
                __restore.Enabled = false;
                __restore.Checked = false;
            }
            else
            {
                if (__restore.Enabled = __restoreDesc.Enabled = SystemRestore.IsSystemRestoreAvailable())
                {
                    __restore.Checked = PackageInfo.SystemRestore;
                }
                else
                {
                    __restore.Checked = false;
                }
            }

            __lite.Checked     = PackageInfo.LiteMode;
            __feedback.Checked = InstallationInfo.FeedbackSend;

            __feedback.Enabled     = InstallationInfo.FeedbackCanSend;
            __feedbackDesc.Enabled = InstallationInfo.FeedbackCanSend;

            if (!__feedback.Enabled)
            {
                __feedback.Checked = false;
            }
        }
 private void BeginUninstallTaskWizard_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (DialogResult != DialogResult.OK)
     {
         SystemRestore.CancelSysRestore();
     }
 }
Esempio n. 3
0
        protected override void Localize()
        {
            base.Localize();

            if (!SystemRestore.IsSystemRestoreAvailable())
            {
                __restoreDesc.Text = InstallerResources.GetString("C_F2_RestoreDescNA");
            }
        }
 public PartialViewResult RestorePoints(AssetViewModel viewModel)
 {
     try
     {
         PSRemoting    psr     = new PSRemoting(viewModel.ComputerName, config.FALCON_FORENSICS_USERNAME, config.FALCON_FORENSICS_PASSWORD, config.FALCON_FORENSICS_DOMAIN);
         SystemRestore restore = new SystemRestore(psr);
         points = restore.GetRestorePoints();
         return(PartialView("_RestorePoints", points));
     }
     catch (Exception e)
     {
         return(PartialView("_Error", e.Message));
     }
 }
 public PartialViewResult ExecuteRestore(string computerName, string sequenceNumber)
 {
     try
     {
         PSRemoting    psr     = new PSRemoting(computerName, config.FALCON_FORENSICS_USERNAME, config.FALCON_FORENSICS_PASSWORD, config.FALCON_FORENSICS_DOMAIN);
         SystemRestore restore = new SystemRestore(psr);
         restore.RestoreSystem(sequenceNumber);
         return(PartialView("_Success", "Restore has been successfully initialized on host " + computerName));
     }
     catch (Exception e)
     {
         return(PartialView("_Error", e.Message));
     }
 }
 public PartialViewResult MountShadowCopy(string computerName, string timestamp)
 {
     try
     {
         PSRemoting    psr     = new PSRemoting(computerName, config.FALCON_FORENSICS_USERNAME, config.FALCON_FORENSICS_PASSWORD, config.FALCON_FORENSICS_DOMAIN);
         SystemRestore restore = new SystemRestore(psr);
         ShadowCopy    copy    = restore.GetShadowCopyByTime(Convert.ToDateTime(timestamp));
         restore.MountShadowCopyVolume(copy.DeviceObject + @"\");
         return(BrowserRefresh(computerName, @"C:\shadow", copy.DeviceObject));
     }
     catch (Exception e)
     {
         Response.StatusCode = 500;
         return(PartialView("_Error", e.Message));
     }
 }
Esempio n. 7
0
        public void Execute(PackageExecutionSettings settings)
        {
            ///////////////////////////////////
            // Prepare

            EnsureState();

            if (IsBusy)
            {
                throw new InvalidOperationException("Cannot execute another package whilst executing a package.");
            }
            IsBusy = true;

            if (settings.LiteMode)
            {
                FactoryOptions.Populate();
                FactoryOptions.Instance[Anolis.Core.Data.DirectoryResourceDataFactory.IconSizeLimit] = 128;
            }

            ///////////////////////////////////
            // Create Backup Details

            Group backupGroup = null;

            if (settings.BackupDirectory != null)
            {
                if (settings.BackupDirectory.Exists)
                {
                    settings.BackupDirectory = new DirectoryInfo(PackageUtility.GetUnusedDirectoryName(settings.BackupDirectory.FullName));
                }

                settings.BackupDirectory.Create();
                settings.BackupDirectory.Refresh();

                Package backupPackage = new Package(settings.BackupDirectory);
                backupPackage.Version     = this.Version;
                backupPackage.Name        = this.Name + " Uninstallation Package";
                backupPackage.Attribution = "Anolis Installer";
                backupPackage.FeedbackUri = this.FeedbackUri;

                backupGroup = backupPackage.RootGroup;
            }

            ExecutionInfo = new PackageExecutionSettingsInfo(this, settings.ExecutionMode, settings.CreateSystemRestorePoint, settings.LiteMode, backupGroup, settings.I386Directory);

            ///////////////////////////////////
            // Flatten

            Log.Add(LogSeverity.Info, "Beginning package execution: " + this.Name + ", with mode " + ExecutionInfo.ExecutionMode.ToString());

            OnProgressEvent(new PackageProgressEventArgs(0, "Flattening Package Tree"));

            List <Operation> operations = new List <Operation>();

            RootGroup.Flatten(operations);

            List <Operation> obsoleteOperations = new List <Operation>();

            Dictionary <String, Operation> uniques = new Dictionary <String, Operation>();

            foreach (Operation op in operations)
            {
                if (!op.IsEnabled)
                {
                    obsoleteOperations.Add(op);
                    continue;
                }

                Operation originalOperation;
                if (uniques.TryGetValue(op.Key, out originalOperation))
                {
                    if (originalOperation.Merge(op))
                    {
                        obsoleteOperations.Add(op);
                    }
                }
                else
                {
                    uniques.Add(op.Key, op);
                }
            }

            operations.RemoveAll(op => obsoleteOperations.Contains(op));

            ///////////////////////////////////
            // Prepare

            if (ExecutionInfo.ExecutionMode == PackageExecutionMode.Regular)
            {
                PackageUtility.AllowProtectedRenames();
            }

            Int64 restorePointSequenceNumber = -2;

            ///////////////////////////////////
            // System Restore, Part 1
            if (ExecutionInfo.ExecutionMode == PackageExecutionMode.Regular && ExecutionInfo.CreateSystemRestorePoint)
            {
                if (SystemRestore.IsSystemRestoreAvailable())
                {
                    OnProgressEvent(new PackageProgressEventArgs(-1, "Creating System Restore Point"));

                    String pointName = "Installed Anolis Package \"" + this.Name + '"';

                    restorePointSequenceNumber = SystemRestore.CreateRestorePoint(pointName, SystemRestoreType.ApplicationInstall);

                    if (restorePointSequenceNumber < 0)
                    {
                        Log.Add(LogSeverity.Error, "Failed to create System Restore point");
                    }
                }
                else
                {
                    Log.Add(LogSeverity.Error, "System Restore not supported");
                }
            }

            ///////////////////////////////////
            // Install (Backup and Execute; backups are the responisiblity of each Operation)

            try {
                float i = 0, cnt = operations.Count;

                foreach (Operation op in operations)
                {
                    OnProgressEvent(new PackageProgressEventArgs((int)(100 * i++ / cnt), op.ToString()));

                    if (!op.SupportsCDImage && ExecutionInfo.ExecutionMode == PackageExecutionMode.CDImage)
                    {
                        continue;
                    }

                    try {
                        if (op.CustomEvaluation)
                        {
                            op.Execute();
                        }
                        else
                        {
                            EvaluationResult result = op.Evaluate();

                            switch (result)
                            {
                            case EvaluationResult.False:
                                Log.Add(LogSeverity.Info, "Evaluation False - " + op.Key);
                                break;

                            case EvaluationResult.FalseParent:
                                Log.Add(LogSeverity.Info, "Evaluation ParentFalse - " + op.Key);
                                break;

                            case EvaluationResult.Error:
                                Log.Add(LogSeverity.Error, "Evaluation Error - " + op.Key);
                                break;

                            case EvaluationResult.True:
                                op.Execute();
                                break;
                            }
                        }
                    } catch (Exception ex) {
                        Log.Add(new LogItem(LogSeverity.Error, ex, op.Name + " failed: \"" + ex.Message + "\""));
                        continue;
                    }

#if !DEBUG
                    // don't add "Info - Done {op}" in debug mode because it's too verbose and clutters up the logfile
                    PathOperation pathOp = op as PathOperation;
                    if (pathOp != null)
                    {
                        Log.Add(LogSeverity.Info, "Done " + op.Name + ": " + pathOp.Path);
                    }
                    else
                    {
                        Log.Add(LogSeverity.Info, "Done " + op.Name);
                    }
#endif
                }                //foreach

                OnProgressEvent(new PackageProgressEventArgs(100, "Complete"));
            } finally {
                ///////////////////////////////////
                // System Restore, Part 2
                if (restorePointSequenceNumber >= 0)
                {
                    OnProgressEvent(new PackageProgressEventArgs(-1, "Finishing System Restore Point"));

                    SystemRestore.EndRestorePoint(restorePointSequenceNumber);
                }

                ///////////////////////////////////
                // Backup, Part 2

                if (ExecutionInfo.BackupGroup != null)
                {
                    String backupFileName = Path.Combine(ExecutionInfo.BackupDirectory.FullName, "Package.xml");

                    ExecutionInfo.BackupPackage.Write(backupFileName);
                }

                ///////////////////////////////////
                // Dump the log to disk

                Log.Save(Path.Combine(this.RootDirectory.FullName, "Anolis.Installer.log"));

                IsBusy = false;
            }            //try/finally
        }
 private void CreateRestorePoint(object sender, EventArgs e)
 {
     _restorePointWasCreated = SystemRestore.BeginSysRestore(uninstallConfirmation1.GetResults().Count());
 }
        public override void Execute()
        {
            //Check for sufficient privileges to run the unused space erasure.
            if (!Security.IsAdministrator())
            {
                if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                    Environment.OSVersion.Version >= new Version(6, 0))
                {
                    Logger.Log(S._("The program does not have the required permissions to erase " +
                                   "the unused space on disk. Run the program as an administrator and retry " +
                                   "the operation."), LogLevel.Error);
                }
                else
                {
                    Logger.Log(S._("The program does not have the required permissions to erase " +
                                   "the unused space on disk."), LogLevel.Error);
                }

                return;
            }

            //Check whether System Restore has any available checkpoints.
            if (SystemRestore.GetInstances().Count != 0)
            {
                Logger.Log(S._("This computer has had System Restore or Volume Shadow Copies " +
                               "enabled. This may allow copies of files stored on the disk to be recovered " +
                               "and pose a security concern.", Drive), LogLevel.Warning);
            }

            //If the user is under disk quotas, log a warning message
            if (VolumeInfo.FromMountPoint(Drive).HasQuota)
            {
                Logger.Log(S._("The drive {0} has disk quotas active. This will prevent the " +
                               "complete erasure of unused space and may pose a security concern.",
                               Drive), LogLevel.Warning);
            }

            //Get the erasure method if the user specified he wants the default.
            IErasureMethod method = EffectiveMethod;

            //Make a folder to dump our temporary files in
            DirectoryInfo info      = new DirectoryInfo(Drive);
            VolumeInfo    volInfo   = VolumeInfo.FromMountPoint(Drive);
            IFileSystem   fsManager = Host.Instance.FileSystems[volInfo];

            //Start sampling the speed of the task.
            Progress = new SteppedProgressManager();

            //Erase the cluster tips of every file on the drive.
            if (EraseClusterTips)
            {
                //Define the callback handlers
                ProgressManager tipSearch = new ProgressManager();
                tipSearch.MarkIndeterminate();
                Progress.Steps.Add(new SteppedProgressManagerStep(tipSearch,
                                                                  0.0f, S._("Searching for files' cluster tips...")));
                ClusterTipsSearchProgress searchProgress = delegate(string path)
                {
                    if (Task.Canceled)
                    {
                        throw new OperationCanceledException(S._("The task was cancelled."));
                    }

                    tipSearch.Tag = path;
                };

                ProgressManager tipProgress = new ProgressManager();
                Progress.Steps.Add(new SteppedProgressManagerStep(tipProgress, 0.1f,
                                                                  S._("Erasing cluster tips...")));
                ClusterTipsEraseProgress eraseProgress =
                    delegate(int currentFile, int totalFiles, string currentFilePath)
                {
                    tipSearch.MarkComplete();
                    tipProgress.Total     = totalFiles;
                    tipProgress.Completed = currentFile;
                    tipProgress.Tag       = currentFilePath;

                    if (Task.Canceled)
                    {
                        throw new OperationCanceledException(S._("The task was cancelled."));
                    }
                };

                //Start counting statistics
                fsManager.EraseClusterTips(VolumeInfo.FromMountPoint(Drive),
                                           method, searchProgress, eraseProgress);
                tipProgress.MarkComplete();
            }

            bool lowDiskSpaceNotifications = Shell.LowDiskSpaceNotificationsEnabled;

            info = info.CreateSubdirectory(Path.GetFileName(
                                               FileSystemBase.GenerateRandomFileName(info, 18)));
            try
            {
                //Set the folder's compression flag off since we want to use as much
                //space as possible
                if (info.IsCompressed())
                {
                    info.Uncompress();
                }

                //Disable the low disk space notifications
                Shell.LowDiskSpaceNotificationsEnabled = false;

                //Fill the disk
                EraseUnusedSpace(volInfo, info, fsManager, method);

                //Erase old resident file system table files
                ProgressManager residentProgress = new ProgressManager();
                Progress.Steps.Add(new SteppedProgressManagerStep(residentProgress,
                                                                  0.05f, S._("Old resident file system table files")));
                fsManager.EraseOldFileSystemResidentFiles(volInfo, info, method,
                                                          delegate(int currentFile, int totalFiles)
                {
                    residentProgress.Completed = currentFile;
                    residentProgress.Total     = totalFiles;

                    if (Task.Canceled)
                    {
                        throw new OperationCanceledException(S._("The task was cancelled."));
                    }
                }
                                                          );

                residentProgress.MarkComplete();
            }
            finally
            {
                //Remove the folder holding all our temporary files.
                ProgressManager tempFiles = new ProgressManager();
                Progress.Steps.Add(new SteppedProgressManagerStep(tempFiles,
                                                                  0.0f, S._("Removing temporary files...")));

                fsManager.DeleteFolder(info, true);
                tempFiles.MarkComplete();

                //Reset the low disk space notifications
                Shell.LowDiskSpaceNotificationsEnabled = lowDiskSpaceNotifications;
            }

            //Then clean the old file system entries
            ProgressManager structureProgress = new ProgressManager();

            Progress.Steps.Add(new SteppedProgressManagerStep(structureProgress,
                                                              0.05f, S._("Erasing unused directory structures...")));
            fsManager.EraseDirectoryStructures(volInfo,
                                               delegate(int currentFile, int totalFiles)
            {
                if (Task.Canceled)
                {
                    throw new OperationCanceledException(S._("The task was cancelled."));
                }

                //Compute the progress
                structureProgress.Total     = totalFiles;
                structureProgress.Completed = currentFile;
            }
                                               );

            structureProgress.MarkComplete();
            Progress = null;
        }