Example #1
0
        public EnvironmentSnapshotManager()
        {
            EnvironmentVariableTarget usrTarget   = EnvironmentVariableTarget.User;
            EnvironmentSnapshot       usrSnapshot = new EnvironmentSnapshot("[Current]", usrTarget);

            foreach (DictionaryEntry entry in EnvironmentVariableManager.GetEnvironmentVariables(usrTarget))
            {
                EnvironmentVariable variable = new EnvironmentVariable();
                variable.Name  = entry.Key.ToString();
                variable.Value = entry.Value.ToString();
                usrSnapshot.Variables.Add(variable);
            }
            usrSnapshots.Add(usrSnapshot);
            try
            {
                foreach (var file in Directory.GetFiles(appFolder + "\\snapshots\\usr", "*.env", SearchOption.TopDirectoryOnly))
                {
                    EnvironmentSnapshot snapshot = new EnvironmentSnapshot(Path.GetFileNameWithoutExtension(file), usrTarget);
                    usrSnapshots.Add(snapshot);
                }
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(appFolder + "\\snapshots\\usr");
            }

            EnvironmentVariableTarget sysTarget   = EnvironmentVariableTarget.Machine;
            EnvironmentSnapshot       sysSnapshot = new EnvironmentSnapshot("[Current]", sysTarget);

            foreach (DictionaryEntry entry in EnvironmentVariableManager.GetEnvironmentVariables(sysTarget))
            {
                EnvironmentVariable variable = new EnvironmentVariable();
                variable.Name  = entry.Key.ToString();
                variable.Value = entry.Value.ToString();
                sysSnapshot.Variables.Add(variable);
            }
            sysSnapshots.Add(sysSnapshot);
            try
            {
                foreach (var file in Directory.GetFiles(appFolder + "\\snapshots\\sys", "*.env", SearchOption.TopDirectoryOnly))
                {
                    EnvironmentSnapshot snapshot = new EnvironmentSnapshot(Path.GetFileNameWithoutExtension(file), EnvironmentVariableTarget.Machine);
                    sysSnapshots.Add(snapshot);
                }
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(appFolder + "\\snapshots\\sys");
            }
        }
Example #2
0
 public bool RemoveSnapshot(EnvironmentSnapshot snapshot)
 {
     if (snapshot.Remove(appFolder))
     {
         var snapshots = (snapshot.Target == EnvironmentVariableTarget.User) ? usrSnapshots : sysSnapshots;
         var result    = snapshots.Find(delegate(EnvironmentSnapshot obj) { return(obj.Name.Equals(snapshot.Name)); });
         if (result != null)
         {
             snapshots.Remove(snapshot);
             return(true);
         }
     }
     return(false);
 }
        public EnvironmentSnapshotManager()
        {
            EnvironmentVariableTarget usrTarget = EnvironmentVariableTarget.User;
            EnvironmentSnapshot usrSnapshot = new EnvironmentSnapshot("[Current]", usrTarget);
            foreach (DictionaryEntry entry in EnvironmentVariableManager.GetEnvironmentVariables(usrTarget))
            {
                EnvironmentVariable variable = new EnvironmentVariable();
                variable.Name = entry.Key.ToString();
                variable.Value = entry.Value.ToString();
                usrSnapshot.Variables.Add(variable);
            }
            usrSnapshots.Add(usrSnapshot);
            try
            {
                foreach (var file in Directory.GetFiles(appFolder + "\\snapshots\\usr", "*.env", SearchOption.TopDirectoryOnly))
                {
                    EnvironmentSnapshot snapshot = new EnvironmentSnapshot(Path.GetFileNameWithoutExtension(file), usrTarget);
                    usrSnapshots.Add(snapshot);
                }
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(appFolder + "\\snapshots\\usr");
            }

            EnvironmentVariableTarget sysTarget = EnvironmentVariableTarget.Machine;
            EnvironmentSnapshot sysSnapshot = new EnvironmentSnapshot("[Current]", sysTarget);
            foreach (DictionaryEntry entry in EnvironmentVariableManager.GetEnvironmentVariables(sysTarget))
            {
                EnvironmentVariable variable = new EnvironmentVariable();
                variable.Name = entry.Key.ToString();
                variable.Value = entry.Value.ToString();
                sysSnapshot.Variables.Add(variable);
            }
            sysSnapshots.Add(sysSnapshot);
            try
            {
                foreach (var file in Directory.GetFiles(appFolder + "\\snapshots\\sys", "*.env", SearchOption.TopDirectoryOnly))
                {
                    EnvironmentSnapshot snapshot = new EnvironmentSnapshot(Path.GetFileNameWithoutExtension(file), EnvironmentVariableTarget.Machine);
                    sysSnapshots.Add(snapshot);
                }
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(appFolder + "\\snapshots\\sys");
            }
        }
Example #4
0
        public FrmEditEnvVar(ref EnvironmentSnapshot snapshot, EnvironmentVariable variable)
        {
            InitializeComponent();
            this.snapshot = snapshot;
            this.variable = variable;
            this.MinimumSize = new Size(327, 439);
            dgvValuesList.TabIndex = 0;
            LoadSettings();
            txtVariableName.CausesValidation = false;
            dgvHandler = new DgvHandler(ref dgvValuesList);

            // set default icon
            dgvValuesList_UserAddedRow(null, null);

            this.txtVariableName.Text = variable.Name;
            this.validator = new EnvironmentValueValidator();

            if (txtVariableName.Text.Length != 0)
            {
                // Check if we are editing variable
                LoadEnvironmentVariableValues();
            }

            // Set form title
            this.Text = (txtVariableName.Text.Length != 0
                ? "Edit" : "New") + " "
                + (this.snapshot.Target == EnvironmentVariableTarget.Machine
                ? "System" : "User") + " Variable";

            #region Create DgvHandler Commands
            commandsList = new CommandStack();
            dgvHandler.SetCurrentCell(0);
            editVarNameCommand = new EditVarNameCommand( txtVariableName );
            #endregion DgvHandler Commands

            // disable buttons
            SetBtnState();
            txtVariableName.CausesValidation = true;
            isVarNameChanged = false;

            // Open/Save File dialogs
            openFileDialog.Filter = FILE_FILTER;
            openFileDialog.DefaultExt = DEFAULT_FILTER_EXTENSION;
            saveFileDialog.Filter = FILE_FILTER;
            saveFileDialog.DefaultExt = DEFAULT_FILTER_EXTENSION;
        }
 public bool SaveSnapshot(ref EnvironmentSnapshot snapshot)
 {
     return snapshot.Save(this.appFolder);
 }
 public bool RemoveSnapshot(EnvironmentSnapshot snapshot)
 {
     if (snapshot.Remove(appFolder))
     {
         var snapshots = (snapshot.Target == EnvironmentVariableTarget.User) ? usrSnapshots : sysSnapshots;
         var result = snapshots.Find(delegate(EnvironmentSnapshot obj) { return obj.Name.Equals(snapshot.Name); });
         if (result != null)
         {
             snapshots.Remove(snapshot);
             return true;
         }
     }
     return false;
 }
 public bool LoadSnapshot(ref EnvironmentSnapshot snapshot)
 {
     return snapshot.Load(this.appFolder);
 }
Example #8
0
 public bool LoadSnapshot(ref EnvironmentSnapshot snapshot)
 {
     return(snapshot.Load(this.appFolder));
 }
Example #9
0
 public bool SaveSnapshot(ref EnvironmentSnapshot snapshot)
 {
     return(snapshot.Save(this.appFolder));
 }