Example #1
0
        /// <summary>
        /// saves the changes to the project
        /// </summary>
        /// <param name="pro"></param>
        /// <returns></returns>
        private bool saveResults(Project pro)
        {
            bool wasMonitoring = false;
            if (pro.Location != null && !pro.Location.Equals(txtLocation.Text))
            {
                if (pro.ModrecorderCreated && pro.ModRecorder.isUpdating)
                {
                    MessageBox.Show("Unable to Change Location. Update is in progress please wait for the update to finish", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtLocation.Select();
                    return false;
                }
                else if (pro.isMonitoring)
                {
                    wasMonitoring = true;
                    pro.stopMonitoring();
                }

                try
                {
                    if (Directory.Exists(pro.Location))
                    {
                        if (Directory.GetDirectories(pro.Location).Length > 0 || Directory.GetFiles(pro.Location).Length > 0)
                        {
                            DialogResult res = MessageBox.Show("Do you want to move the contents of the previous location to the new location?", "Confim", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (res == DialogResult.Yes)
                            {
                                try
                                {
                                    copyDir(pro.Location, txtLocation.Text);
                                    Directory.Delete(pro.Location,true);
                                }
                                catch
                                {
                                    MessageBox.Show("Unable to Move Directory. Check location is valid and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    txtLocation.Select();
                                    return false;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Failed processing Directory check path is valid and try restarting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (!PathChanged)
            {
                try
                {
                    Directory.CreateDirectory(txtLocation.Text);
                    PathChanged = true;
                }
                catch
                {
                    MessageBox.Show("Unable to create Directory. Check location is valid and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtLocation.Select();
                    return false;
                }
            }
            else
            {
                if (!Directory.Exists(txtLocation.Text))
                {
                    DialogResult res = MessageBox.Show("Directory does not exist. Do you want to create the Directory?", "Confim", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (res == DialogResult.Yes)
                    {
                        try
                        {
                            Directory.CreateDirectory(txtLocation.Text);
                            PathChanged = true;
                        }
                        catch
                        {
                            MessageBox.Show("Unable to create Directory. Check location is valid and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtLocation.Select();
                            return false;
                        }

                    }
                    else
                    {
                        txtLocation.Select();
                        return false;
                    }
                }

            }

            pro.Name = txtName.Text;
            pro.Location = txtLocation.Text;
            pro.Description = txtDescription.Text;
            pro.Note = txtNotes.Text;
            pro.AutoMonitor = chkAutomatic.Checked;
            if (pro.NewEntry)
                pro.ModRecorder.updateChangeList += new EventHandler(ModRecorder_updateChangeList);

            if (excludeChanged)
            {
                List<string> excludeList = new List<string>();
                foreach (DataGridViewRow row in dgvExcludedFolders.Rows)
                {
                    if (!row.IsNewRow)
                        excludeList.Add(Convert.ToString(row.Cells[0].Value));
                }
                pro.ExcludeLocations = excludeList;
            }

            projectMan.updateProject(pro);
            changed = false;
            lsvProjectList.Sort();
            if (pro.ModrecorderCreated)
                pro.ModRecorder.reload(pro);
            if (wasMonitoring)
                pro.startMonitoring();
            return true;
        }
Example #2
0
        /// <summary>
        /// restores the files to prevoius state
        /// </summary>
        /// <param name="pro"></param>
        /// <param name="itemIndex"></param>
        private void restore(Project pro, int itemIndex)
        {
            if (lsvChanges.InvokeRequired)
            {
                lsvChanges.BeginInvoke(new MethodInvoker(() => restore(pro, itemIndex)));
            }
            else
            {
                selectProject(selProject);
                changeLogEntry lastEntry = (changeLogEntry)lsvChanges.Items[itemIndex].Tag;
                Thread restoreThread = new Thread(delegate()
                {
                    updateing++;
                    bool monitoringState = pro.isMonitoring;
                    if (monitoringState)
                        pro.stopMonitoring();
                    pro.ModRecorder.updateChangeList -= new EventHandler(ModRecorder_updateChangeList);

                    changeLogEntry lastRemoved = pro.ModRecorder.revertsChange();
                    while (lastRemoved != null && !lastRemoved.Equals(lastEntry))
                    {
                        lastRemoved = pro.ModRecorder.revertsChange();
                    }
                    ModRecorder_updateChangeList(pro.ModRecorder, EventArgs.Empty);
                    pro.ModRecorder.updateChangeList += new EventHandler(ModRecorder_updateChangeList);
                    if (monitoringState)
                        pro.startMonitoring();
                    updateing--;
                });
                restoreThread.Start();
            }
        }